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

Side by Side Diff: packages/charted/lib/charts/src/chart_data_impl.dart

Issue 2213693002: Updated charted DEP to 0.4.X (Closed) Base URL: https://github.com/dart-lang/observatory_pub_packages.git@master
Patch Set: Created 4 years, 4 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
1 // 1 //
2 // Copyright 2014 Google Inc. All rights reserved. 2 // Copyright 2014 Google Inc. All rights reserved.
3 // 3 //
4 // Use of this source code is governed by a BSD-style 4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at 5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd 6 // https://developers.google.com/open-source/licenses/bsd
7 // 7 //
8 8
9 part of charted.charts; 9 part of charted.charts;
10 10
11 class DefaultChartDataImpl extends ChangeNotifier implements ChartData { 11 class DefaultChartDataImpl extends ChangeNotifier implements ChartData {
12 Iterable<ChartColumnSpec> _columns; 12 List<ChartColumnSpec> _columns;
13 Iterable<Iterable> _rows; 13 List<List> _rows;
14 14
15 bool _hasObservableRows = false; 15 bool _hasObservableRows = false;
16 SubscriptionsDisposer _disposer = new SubscriptionsDisposer(); 16 SubscriptionsDisposer _disposer = new SubscriptionsDisposer();
17 17
18 DefaultChartDataImpl( 18 DefaultChartDataImpl(
19 Iterable<ChartColumnSpec> columns, Iterable<Iterable> rows) { 19 Iterable<ChartColumnSpec> columns, Iterable<Iterable> rows) {
20 this.columns = columns; 20 this.columns = new List<ChartColumnSpec>.from(columns);
21 this.rows = rows; 21 var rowsList = new List.from(rows);
22 this.rows = new List<List>.generate(
23 rowsList.length, (i) => new List.from(rowsList[i]));
22 } 24 }
23 25
24 set columns(Iterable<ChartColumnSpec> value) { 26 set columns(Iterable<ChartColumnSpec> value) {
25 assert(value != null); 27 assert(value != null);
26 28
27 // Create a copy of columns. We do not currently support 29 // Create a copy of columns. We do not currently support
28 // changes to the list of columns. Any changes to the spec 30 // changes to the list of columns. Any changes to the spec
29 // will be applied at the next ChartBase.draw(); 31 // will be applied at the next ChartBase.draw();
30 this._columns = new List<ChartColumnSpec>.from(value); 32 this._columns = new List<ChartColumnSpec>.from(value);
31 } 33 }
32 34
33 Iterable<ChartColumnSpec> get columns => _columns; 35 List<ChartColumnSpec> get columns => _columns;
34 36
35 set rows(Iterable<Iterable> value) { 37 set rows(List<List> value) {
36 assert(value != null); 38 assert(value != null);
37 39
38 _rows = value; 40 _rows = value;
39 if (_rows is ObservableList) { 41 if (_rows is ObservableList) {
40 _disposer.add((_rows as ObservableList).listChanges.listen(rowsChanged)); 42 _disposer.add((_rows as ObservableList).listChanges.listen(rowsChanged));
41 } 43 }
42 44
43 if (_rows.every((row) => row is ObservableList)) { 45 if (_rows.every((row) => row is ObservableList)) {
44 _hasObservableRows = true; 46 _hasObservableRows = true;
45 for (int i = 0; i < _rows.length; i++) { 47 for (int i = 0; i < _rows.length; i++) {
46 var row = _rows.elementAt(i); 48 var row = _rows.elementAt(i);
47 _disposer.add( 49 _disposer.add(
48 row.listChanges.listen((changes) => _valuesChanged(i, changes)), 50 (row as ObservableList)
51 .listChanges
52 .listen((changes) => _valuesChanged(i, changes)),
49 row); 53 row);
50 } 54 }
51 ; 55 ;
52 } else if (_rows is Observable) { 56 } else if (_rows is Observable) {
53 logger.info('List of rows is Observable, but not rows themselves!'); 57 logger.info('List of rows is Observable, but not rows themselves!');
54 } 58 }
55 } 59 }
56 60
57 Iterable<Iterable> get rows => _rows; 61 List<List> get rows => _rows;
58 62
59 rowsChanged(List<ListChangeRecord> changes) { 63 rowsChanged(List<ListChangeRecord> changes) {
60 if (_rows is! ObservableList) return; 64 if (_rows is! ObservableList) return;
61 notifyChange(new ChartRowChangeRecord(changes)); 65 notifyChange(new ChartRowChangeRecord(changes));
62 66
63 if (!_hasObservableRows) return; 67 if (!_hasObservableRows) return;
64 changes.forEach((ListChangeRecord change) { 68 changes.forEach((ListChangeRecord change) {
65 change.removed.forEach((item) => _disposer.unsubscribe(item)); 69 change.removed.forEach((item) => _disposer.unsubscribe(item));
66 70
67 for (int i = 0; i < change.addedCount; i++) { 71 for (int i = 0; i < change.addedCount; i++) {
68 var index = change.index + i, row = _rows.elementAt(index); 72 var index = change.index + i, row = _rows.elementAt(index);
69 73
70 if (row is! ObservableList) { 74 if (row is! ObservableList) {
71 logger.severe('A non-observable row was added! ' 75 logger.severe('A non-observable row was added! '
72 'Changes on this row will not be monitored'); 76 'Changes on this row will not be monitored');
73 } else { 77 } else {
74 _disposer.add( 78 _disposer.add(
75 row.listChanges 79 (row as ObservableList).listChanges
76 .listen((changes) => _valuesChanged(index, changes)), 80 .listen((changes) => _valuesChanged(index, changes)),
77 row); 81 row);
78 } 82 }
79 } 83 }
80 }); 84 });
81 } 85 }
82 86
83 _valuesChanged(int index, List<ListChangeRecord> changes) { 87 _valuesChanged(int index, List<ListChangeRecord> changes) {
84 if (!_hasObservableRows) return; 88 if (!_hasObservableRows) return;
85 notifyChange(new ChartValueChangeRecord(index, changes)); 89 notifyChange(new ChartValueChangeRecord(index, changes));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 strBuffer.write(' ' * lengthDiff + ' ${data} |'); 134 strBuffer.write(' ' * lengthDiff + ' ${data} |');
131 135
132 if (i == row.length - 1) { 136 if (i == row.length - 1) {
133 strBuffer.write('\n' + '-' * totalLength + '\n'); 137 strBuffer.write('\n' + '-' * totalLength + '\n');
134 } 138 }
135 } 139 }
136 } 140 }
137 return strBuffer.toString(); 141 return strBuffer.toString();
138 } 142 }
139 } 143 }
OLDNEW
« no previous file with comments | « packages/charted/lib/charts/src/chart_config_impl.dart ('k') | packages/charted/lib/charts/src/chart_events_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698