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

Side by Side Diff: packages/charted/examples/charts/renderers/demo_cartesian_renderers.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 library charted.demo.charts.cartesian_renderers;
10
11 import 'dart:html';
12 import 'package:charted/core/text_metrics.dart' as tm;
13 import 'package:charted/charts/charts.dart';
14
15 import '../demo_charts.dart';
16
17 List<ChartDemo> charts = [];
18
19 class ChartDemo {
20 final List<ChartBehavior> behaviors;
21 final ChartConfig config;
22 final ChartData data;
23 final bool useTwoDimensions;
24 final Element host;
25 final String title;
26 final bool isLayout;
27
28 ChartArea area;
29
30 ChartDemo(this.title, this.host, this.config, this.data,
31 { this.useTwoDimensions: false, this.behaviors: const [],
32 this.isLayout: false }) {
33 var wrapper = document.createElement('div')..className = "chart-wrapper",
34 titleWrap = document.createElement('div')
35 ..className = "chart-title-wrapper",
36 titleContainer = document.createElement('div')
37 ..className = 'chart-title'
38 ..text = title,
39 chartHostWrapper =
40 document.createElement('div')..className = "chart-host-wrapper",
41 chartAreaHost = document.createElement('div')
42 ..className = "chart-host"
43 ..attributes['dir'] = 'ltr',
44 chartLegendHost =
45 document.createElement('div')..className = "chart-legend-host",
46 state = new ChartState();
47
48 titleWrap.append(titleContainer);
49 chartHostWrapper
50 ..append(chartAreaHost)
51 ..append(chartLegendHost);
52 wrapper
53 ..append(titleWrap)
54 ..append(chartHostWrapper);
55 host.append(wrapper);
56
57 config.legend = new ChartLegend(chartLegendHost, showValues: isLayout);
58 area = isLayout
59 ? new LayoutArea(chartAreaHost, data, config, state: state)
60 : new CartesianArea(chartAreaHost, data, config,
61 autoUpdate: false, useTwoDimensionAxes: useTwoDimensions,
62 state: state);
63
64 behaviors.forEach((behavior) {
65 area.addChartBehavior(behavior);
66 });
67
68 area.addChartBehavior(new Hovercard(isMultiValue: true));
69 if (!isLayout) {
70 area.addChartBehavior(new AxisLabelTooltip());
71 }
72 }
73
74 void setTheme(ChartTheme theme) {
75 area.theme = theme;
76 }
77
78 void draw() => area.draw(preRender: data.rows.isEmpty);
79 }
80
81 draw_charts() {
82 // Line chart
83 var line_series = new ChartSeries("one", [2, 3], new LineChartRenderer()),
84 line_config = new ChartConfig([line_series], [0]),
85 line_data = new ChartData(
86 ORDINAL_DATA_COLUMNS, ORDINAL_DATA),
87 line_demo = new ChartDemo('Line chart',
88 querySelector('.line-chart'), line_config, line_data);
89 charts.add(line_demo);
90
91 // Bar chart
92 var bar_series = new ChartSeries("one", [2], new BarChartRenderer()),
93 bar_config = new ChartConfig([bar_series], [0]),
94 bar_data = new ChartData(
95 ORDINAL_DATA_COLUMNS, ORDINAL_DATA),
96 bar_demo = new ChartDemo('Bar chart',
97 querySelector('.bar-chart'), bar_config, bar_data);
98 charts.add(bar_demo);
99
100 // Grouped bar chart
101 var grouped_bar_series =
102 new ChartSeries("one", [2, 3], new BarChartRenderer()),
103 grouped_bar_config = new ChartConfig([grouped_bar_series], [0]),
104 grouped_bar_data = new ChartData(
105 ORDINAL_DATA_COLUMNS, ORDINAL_DATA),
106 grouped_bar_demo = new ChartDemo('Group bar chart',
107 querySelector('.grouped-bar-chart'),
108 grouped_bar_config, grouped_bar_data);
109 charts.add(grouped_bar_demo);
110
111 // Stacked bar chart
112 var stacked_series =
113 new ChartSeries("one", [2, 3], new StackedBarChartRenderer()),
114 stacked_config = new ChartConfig([stacked_series], [0]),
115 stacked_data = new ChartData(
116 ORDINAL_DATA_COLUMNS, ORDINAL_DATA),
117 stacked_demo = new ChartDemo('Stacked bar chart',
118 querySelector('.stacked-bar-chart'), stacked_config, stacked_data);
119 charts.add(stacked_demo);
120
121 // Horizontal bar chart
122 var horiz_bar_series =
123 new ChartSeries("one", [2], new BarChartRenderer()),
124 horiz_bar_config = new ChartConfig([horiz_bar_series], [0])
125 ..isLeftAxisPrimary = true,
126 horiz_bar_data = new ChartData(
127 ORDINAL_DATA_COLUMNS, ORDINAL_DATA),
128 horiz_bar_demo = new ChartDemo('Horizontal bar chart',
129 querySelector('.horiz-bar-chart'), horiz_bar_config,
130 horiz_bar_data);
131 charts.add(horiz_bar_demo);
132
133 // Horizontal grouped bar chart
134 var horiz_grouped_bar_series =
135 new ChartSeries("one", [2, 3], new BarChartRenderer()),
136 horiz_grouped_bar_config =
137 new ChartConfig([horiz_grouped_bar_series], [0])
138 ..isLeftAxisPrimary = true,
139 horiz_grouped_bar_data = new ChartData(
140 ORDINAL_DATA_COLUMNS, ORDINAL_DATA),
141 horiz_grouped_bar_demo = new ChartDemo('Horizontal group bar chart',
142 querySelector('.horiz-grouped-bar-chart'),
143 horiz_grouped_bar_config, horiz_grouped_bar_data);
144 charts.add(horiz_grouped_bar_demo);
145
146 // Horizontal stacked bar chart
147 var horiz_stacked_series =
148 new ChartSeries("one", [2, 3], new StackedBarChartRenderer()),
149 horiz_stacked_config = new ChartConfig([horiz_stacked_series], [0])
150 ..isLeftAxisPrimary = true,
151 horiz_stacked_data = new ChartData(
152 ORDINAL_DATA_COLUMNS, ORDINAL_DATA),
153 horiz_stacked_demo = new ChartDemo('Horizontal stacked bar chart',
154 querySelector('.horiz-stacked-bar-chart'),
155 horiz_stacked_config, horiz_stacked_data);
156 charts.add(horiz_stacked_demo);
157
158 // Combo chart
159 var combo_bar_series =
160 new ChartSeries("one", [2, 3], new BarChartRenderer()),
161 combo_line_series = new ChartSeries("two", [1], new LineChartRenderer()),
162 combo_config =
163 new ChartConfig([combo_bar_series, combo_line_series], [0]),
164 combo_data = new ChartData(
165 ORDINAL_DATA_COLUMNS, ORDINAL_DATA),
166 combo_demo = new ChartDemo('Combo chart - bar and line',
167 querySelector('.combo-chart'), combo_config, combo_data);
168 charts.add(combo_demo);
169
170 // Combo chart
171 var combo2_bar_series =
172 new ChartSeries("one", [2, 3], new StackedBarChartRenderer()),
173 combo2_line_series = new ChartSeries("two", [1], new LineChartRenderer()),
174 combo2_config =
175 new ChartConfig([combo2_bar_series, combo2_line_series], [0]),
176 combo2_data = new ChartData(
177 ORDINAL_DATA_COLUMNS, ORDINAL_DATA),
178 combo2_demo = new ChartDemo('Combo chart - stacked and line',
179 querySelector('.combo2-chart'), combo2_config, combo2_data);
180 charts.add(combo2_demo);
181
182 charts.forEach((ChartDemo x) => x.draw());
183 }
184
185 main() {
186 new tm.TextMetrics(fontStyle: '14px Roboto');
187 draw_charts();
188
189 Element chartsContainer = querySelector('.demos-container');
190 InputElement useRTLScriptCheckBox = querySelector('#rtl-use-script'),
191 switchAxesForRTLCheckBox = querySelector('#rtl-switch-axes'),
192 useRTLLayoutCheckBox = querySelector('#rtl-use-layout');
193
194 useRTLLayoutCheckBox.onChange.listen((_) {
195 bool isRTL = useRTLLayoutCheckBox.checked;
196 charts.forEach((ChartDemo x) => x.config.isRTL = isRTL);
197 chartsContainer.attributes['dir'] = isRTL ? 'rtl' : 'ltr';
198 });
199
200 useRTLScriptCheckBox.onChange.listen((_) {
201 bool isRTL = useRTLScriptCheckBox.checked;
202 Iterable DATA_SOURCE = isRTL
203 ? ORDINAL_DATA_RTL
204 : ORDINAL_DATA;
205 charts.forEach((ChartDemo x) {
206 x.area.data = new ChartData(ORDINAL_DATA_COLUMNS, DATA_SOURCE);
207 x.draw();
208 });
209 });
210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698