Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: charted/lib/charts/src/chart_config_impl.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 //
2 // Copyright 2014 Google Inc. All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 //
8
9 part of charted.charts;
10
11 class DefaultChartConfigImpl extends ChangeNotifier implements ChartConfig {
12 final Map<String,ChartAxisConfig> _measureAxisRegistry = {};
13 final Map<int,ChartAxisConfig> _dimensionAxisRegistry = {};
14 final SubscriptionsDisposer _disposer = new SubscriptionsDisposer();
15
16 bool _isRTL = false;
17 Iterable<ChartSeries> _series;
18 Iterable<int> _dimensions;
19 StreamSubscription _dimensionsSubscription;
20
21 @override
22 Rect minimumSize = const Rect.size(400, 300);
23
24 @override
25 bool isLeftAxisPrimary = false;
26
27 @override
28 bool autoResizeAxis = true;
29
30 @override
31 ChartLegend legend;
32
33 @override
34 Iterable<String> displayedMeasureAxes;
35
36 @override
37 bool renderDimensionAxes = true;
38
39 @override
40 bool switchAxesForRTL = true;
41
42 DefaultChartConfigImpl(Iterable<ChartSeries> series, Iterable<int> dimensions) {
43 this.series = series;
44 this.dimensions = dimensions;
45 }
46
47 @override
48 set series(Iterable<ChartSeries> values) {
49 assert(values != null && values.isNotEmpty);
50
51 _disposer.dispose();
52 _series = values;
53 notifyChange(const ChartConfigChangeRecord());
54
55 // Monitor each series for changes on them
56 values.forEach((item) {
57 if (item is Observable) {
58 _disposer.add(item.changes.listen(
59 (_) => notifyChange(const ChartConfigChangeRecord())), item);
60 }
61 });
62
63 // Monitor series for changes. When the list changes, update
64 // subscriptions to ChartSeries changes.
65 if (_series is ObservableList) {
66 var observable = _series as ObservableList;
67 _disposer.add(observable.listChanges.listen((records) {
68 records.forEach((record) {
69 record.removed.forEach((value) => _disposer.unsubscribe(value));
70 for (int i = 0; i < record.addedCount; i++) {
71 var added = observable[i + record.index];
72 _disposer.add(added.changes.listen(
73 (_) => notifyChange(const ChartConfigChangeRecord())));
74 }
75 });
76 notifyChange(const ChartConfigChangeRecord());
77 }));
78 }
79 }
80
81 @override
82 Iterable<ChartSeries> get series => _series;
83
84 @override
85 set dimensions(Iterable<int> values) {
86 _dimensions = values;
87
88 if (_dimensionsSubscription != null) {
89 _dimensionsSubscription.cancel();
90 _dimensionsSubscription = null;
91 }
92
93 if (values == null || values.isEmpty) return;
94
95 if (_dimensions is ObservableList) {
96 _dimensionsSubscription =
97 (_dimensions as ObservableList).listChanges.listen(
98 (_) => notifyChange(const ChartConfigChangeRecord()));
99 }
100 }
101
102 @override
103 Iterable<int> get dimensions => _dimensions;
104
105 @override
106 void registerMeasureAxis(String id, ChartAxisConfig config) {
107 assert(config != null);
108 _measureAxisRegistry[id] = config;
109 }
110
111 @override
112 ChartAxisConfig getMeasureAxis(String id) => _measureAxisRegistry[id];
113
114 @override
115 void registerDimensionAxis(int column, ChartAxisConfig config) {
116 assert(config != null);
117 assert(dimensions.contains(column));
118 _dimensionAxisRegistry[column] = config;
119 }
120
121 @override
122 ChartAxisConfig getDimensionAxis(int column) =>
123 _dimensionAxisRegistry[column];
124
125 @override
126 set isRTL(bool value) {
127 if (_isRTL != value && value != null) {
128 _isRTL = value;
129 notifyChange(const ChartConfigChangeRecord());
130 }
131 }
132
133 @override
134 bool get isRTL => _isRTL;
135 }
OLDNEW
« no previous file with comments | « charted/lib/charts/src/chart_axis_impl.dart ('k') | charted/lib/charts/src/chart_data_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698