OLD | NEW |
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 /// | 11 /// |
12 /// Interface to be implemented by data providers to give tabular access to | 12 /// Interface to be implemented by data providers to give tabular access to |
13 /// data for chart renderers. | 13 /// data for chart renderers. |
14 /// | 14 /// |
15 abstract class ChartData { | 15 abstract class ChartData { |
16 /// Read-only access to column specs | 16 /// Read-only access to column specs |
17 Iterable<ChartColumnSpec> get columns; | 17 Iterable<ChartColumnSpec> get columns; |
18 | 18 |
19 /// Read-only access to rows | 19 /// Read-only access to rows |
20 Iterable<Iterable> get rows; | 20 Iterable<Iterable> get rows; |
21 | 21 |
22 /// Create a new instance of [ChartData]'s internal implementation | 22 /// Create a new instance of [ChartData]'s internal implementation |
23 factory ChartData( | 23 factory ChartData(Iterable<ChartColumnSpec> columns, |
24 Iterable<ChartColumnSpec> columns, Iterable<Iterable> rows) = DefaultChart
DataImpl; | 24 Iterable<Iterable> rows) = DefaultChartDataImpl; |
25 } | 25 } |
26 | 26 |
27 /// | 27 /// |
28 /// Interface implemented by [ChartData] transformers. | 28 /// Interface implemented by [ChartData] transformers. |
29 /// Examples: | 29 /// Examples: |
30 /// [AggregationTransformer] to compute aggregated rows/columns | 30 /// [AggregationTransformer] to compute aggregated rows/columns |
31 /// [FilterTransformer] to filter data | 31 /// [FilterTransformer] to filter data |
32 /// [TransposeTransformer] to convert rows to columns and vice-versa | 32 /// [TransposeTransformer] to convert rows to columns and vice-versa |
33 /// | 33 /// |
34 abstract class ChartDataTransform { | 34 abstract class ChartDataTransform { |
35 /// Create a new instance of [ChartData] by selecting a subset | 35 /// Create a new instance of [ChartData] by selecting a subset |
36 /// of rows and columns from the current one | 36 /// of rows and columns from the current one |
37 ChartData transform(ChartData source); | 37 ChartData transform(ChartData source); |
38 } | 38 } |
39 | 39 |
40 | |
41 /// | 40 /// |
42 /// Implementation of [ChangeRecord], that is used to notify when rows get added | 41 /// Implementation of [ChangeRecord], that is used to notify when rows get added |
43 /// or removed to ChartData | 42 /// or removed to ChartData |
44 /// | 43 /// |
45 class ChartRowChangeRecord implements ChangeRecord { | 44 class ChartRowChangeRecord implements ChangeRecord { |
46 /// Changes to the rows - contains all updates to rows since last notification
. | 45 /// Changes to the rows - contains all updates to rows since last notification
. |
47 final List<ListChangeRecord> changes; | 46 final List<ListChangeRecord> changes; |
48 | 47 |
49 const ChartRowChangeRecord(this.changes); | 48 const ChartRowChangeRecord(this.changes); |
50 } | 49 } |
(...skipping 16 matching lines...) Expand all Loading... |
67 /// | 66 /// |
68 /// Meta information for each column in ChartData | 67 /// Meta information for each column in ChartData |
69 /// | 68 /// |
70 class ChartColumnSpec { | 69 class ChartColumnSpec { |
71 static const String TYPE_BOOLEAN = 'boolean'; | 70 static const String TYPE_BOOLEAN = 'boolean'; |
72 static const String TYPE_DATE = 'date'; | 71 static const String TYPE_DATE = 'date'; |
73 static const String TYPE_NUMBER = 'number'; | 72 static const String TYPE_NUMBER = 'number'; |
74 static const String TYPE_STRING = 'string'; | 73 static const String TYPE_STRING = 'string'; |
75 static const String TYPE_TIMESTAMP = 'timestamp'; | 74 static const String TYPE_TIMESTAMP = 'timestamp'; |
76 | 75 |
77 static const List ORDINAL_SCALES = const [ TYPE_STRING ]; | 76 static const List ORDINAL_SCALES = const [TYPE_STRING]; |
78 static const List LINEAR_SCALES = const [ TYPE_NUMBER ]; | 77 static const List LINEAR_SCALES = const [TYPE_NUMBER]; |
79 static const List TIME_SCALES = const [ TYPE_DATE, TYPE_TIMESTAMP ]; | 78 static const List TIME_SCALES = const [TYPE_DATE, TYPE_TIMESTAMP]; |
80 | 79 |
81 /// Formatter for values that belong to this column | 80 /// Formatter for values that belong to this column |
82 final FormatFunction formatter; | 81 final FormatFunction formatter; |
83 | 82 |
84 /// Label for the column. Used in legend, tooltips etc; | 83 /// Label for the column. Used in legend, tooltips etc; |
85 /// When not specified, defaults to empty string. | 84 /// When not specified, defaults to empty string. |
86 final String label; | 85 final String label; |
87 | 86 |
88 /// Type of data in this column. Used for interpolations, computing | 87 /// Type of data in this column. Used for interpolations, computing |
89 /// scales and ranges. When not specified, it is assumed to be "number" | 88 /// scales and ranges. When not specified, it is assumed to be "number" |
90 /// for measures and "string" for dimensions. | 89 /// for measures and "string" for dimensions. |
91 final String type; | 90 final String type; |
92 | 91 |
93 /// Indicates if this column requires [OrdinalScale]. | 92 /// Indicates if this column requires [OrdinalScale]. |
94 /// | 93 /// |
95 /// If not specified, an ordinal scale is used for string columns and | 94 /// If not specified, an ordinal scale is used for string columns and |
96 /// quantitative scales are used for others. | 95 /// quantitative scales are used for others. |
97 final bool useOrdinalScale; | 96 final bool useOrdinalScale; |
98 | 97 |
99 /// Initialize axis scale according to [ChartColumnSpec] type. | 98 /// Initialize axis scale according to [ChartColumnSpec] type. |
100 /// This logic is extracted from [ChartArea] implementation for conveniently | 99 /// This logic is extracted from [ChartArea] implementation for conveniently |
101 /// adding more scale types. | 100 /// adding more scale types. |
102 Scale createDefaultScale() { | 101 Scale createDefaultScale() { |
103 if (useOrdinalScale == true) { | 102 if (useOrdinalScale == true) { |
104 return new OrdinalScale(); | 103 return new OrdinalScale(); |
105 } | 104 } else if (LINEAR_SCALES.contains(type)) { |
106 else if (LINEAR_SCALES.contains(type)) { | |
107 return new LinearScale(); | 105 return new LinearScale(); |
108 } | 106 } else if (TIME_SCALES.contains(type)) { |
109 else if (TIME_SCALES.contains(type)) { | |
110 return new TimeScale(); | 107 return new TimeScale(); |
111 } | 108 } |
112 return null; | 109 return null; |
113 } | 110 } |
114 | 111 |
115 ChartColumnSpec({this.label, String type : TYPE_NUMBER, | 112 ChartColumnSpec( |
116 this.formatter, bool useOrdinalScale}) | 113 {this.label, |
117 : useOrdinalScale = | 114 String type: TYPE_NUMBER, |
118 useOrdinalScale == true || | 115 this.formatter, |
| 116 bool useOrdinalScale}) |
| 117 : useOrdinalScale = useOrdinalScale == true || |
119 useOrdinalScale == null && ORDINAL_SCALES.contains(type), | 118 useOrdinalScale == null && ORDINAL_SCALES.contains(type), |
120 type = type; | 119 type = type; |
121 } | 120 } |
OLD | NEW |