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

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

Powered by Google App Engine
This is Rietveld 408576698