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 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 ..[measure] = otherItemsValue; | 91 ..[measure] = otherItemsValue; |
92 indices = displayed..add(SMALL_INT_MAX); | 92 indices = displayed..add(SMALL_INT_MAX); |
93 } else { | 93 } else { |
94 otherRow = null; | 94 otherRow = null; |
95 } | 95 } |
96 | 96 |
97 if (area.config.isRTL) { | 97 if (area.config.isRTL) { |
98 indices = indices.reversed.toList(); | 98 indices = indices.reversed.toList(); |
99 } | 99 } |
100 | 100 |
101 var accessor = (d, i) { | 101 num accessor(d, int i) { |
102 var row = d == SMALL_INT_MAX ? otherRow : area.data.rows.elementAt(d); | 102 var row = d == SMALL_INT_MAX ? otherRow : area.data.rows.elementAt(d); |
103 return row == null || row.elementAt(measure) == null | 103 return row == null || row.elementAt(measure) == null |
104 ? 0 | 104 ? 0 |
105 : row.elementAt(measure); | 105 : row.elementAt(measure) as num; |
106 }; | 106 } |
107 var data = (new PieLayout()..accessor = accessor).layout(indices), | 107 var data = (new PieLayout()..accessor = accessor).layout(indices); |
108 arc = new SvgArc( | 108 var arc = new SvgArc( |
109 innerRadiusCallback: (d, i, e) => innerRadiusRatio * radius, | 109 innerRadiusCallback: (d, i, e) => innerRadiusRatio * radius, |
110 outerRadiusCallback: (d, i, e) => radius), | 110 outerRadiusCallback: (d, i, e) => radius); |
111 pie = root.selectAll('.pie-path').data(data); | 111 var pie = root.selectAll('.pie-path').data(data); |
112 | 112 |
113 pie.enter.append('path').classed('pie-path'); | 113 pie.enter.appendWithCallback((d, i, e) { |
114 pie | 114 var pieSector = Namespace.createChildElement('path', e) |
115 ..each((d, i, e) { | 115 ..classes.add('pie-path'); |
116 var styles = stylesForData(d.data, i); | 116 var styles = stylesForData(d.data, i); |
117 e.classes.removeAll(ChartState.VALUE_CLASS_NAMES); | 117 if (!isNullOrEmpty(styles)) { |
118 if (!isNullOrEmpty(styles)) { | 118 pieSector.classes.addAll(styles); |
119 e.classes.addAll(styles); | 119 } |
120 } | 120 pieSector.attributes |
121 e.attributes | 121 ..['fill'] = colorForData(d.data, i) |
122 ..['fill'] = colorForData(d.data, i) | 122 ..['d'] = arc.path(d, i, host) |
123 ..['d'] = arc.path(d, i, host) | 123 ..['stroke-width'] = '1px' |
124 ..['stroke-width'] = '1px' | 124 ..['stroke'] = '#ffffff'; |
125 ..['stroke'] = '#ffffff'; | |
126 | 125 |
127 e.append( | 126 pieSector.append(Namespace.createChildElement('text', pieSector) |
128 Namespace.createChildElement('text', e)..classes.add('pie-label')); | 127 ..classes.add('pie-label')); |
129 }) | 128 return pieSector; |
| 129 }) |
130 ..on('click', (d, i, e) => _event(mouseClickController, d, i, e)) | 130 ..on('click', (d, i, e) => _event(mouseClickController, d, i, e)) |
131 ..on('mouseover', (d, i, e) => _event(mouseOverController, d, i, e)) | 131 ..on('mouseover', (d, i, e) => _event(mouseOverController, d, i, e)) |
132 ..on('mouseout', (d, i, e) => _event(mouseOutController, d, i, e)); | 132 ..on('mouseout', (d, i, e) => _event(mouseOutController, d, i, e)); |
133 | 133 |
| 134 pie.each((d, i, e) { |
| 135 var styles = stylesForData(d.data, i); |
| 136 e.classes.removeAll(ChartState.VALUE_CLASS_NAMES); |
| 137 if (!isNullOrEmpty(styles)) { |
| 138 e.classes.addAll(styles); |
| 139 } |
| 140 e.attributes |
| 141 ..['fill'] = colorForData(d.data, i) |
| 142 ..['d'] = arc.path(d, i, host) |
| 143 ..['stroke-width'] = '1px' |
| 144 ..['stroke'] = '#ffffff'; |
| 145 }); |
| 146 |
134 pie.exit.remove(); | 147 pie.exit.remove(); |
135 | 148 |
136 _legend.clear(); | 149 _legend.clear(); |
137 var items = new List.generate(data.length, (i) { | 150 var items = new List<ChartLegendItem>.generate(data.length, (i) { |
138 SvgArcData d = data.elementAt(i); | 151 SvgArcData d = data.elementAt(i); |
139 Iterable row = | 152 Iterable row = |
140 d.data == SMALL_INT_MAX ? otherRow : area.data.rows.elementAt(d.data); | 153 d.data == SMALL_INT_MAX ? otherRow : area.data.rows.elementAt(d.data); |
141 | 154 |
142 return new ChartLegendItem( | 155 return new ChartLegendItem( |
143 index: d.data, | 156 index: d.data, |
144 color: colorForData(d.data, i), | 157 color: colorForData(d.data, i), |
145 label: row.elementAt(dimension), | 158 label: row.elementAt(dimension), |
146 series: [series], | 159 series: [series], |
147 value: | 160 value: |
(...skipping 26 matching lines...) Expand all Loading... |
174 root.selectAll('.pie-path').remove(); | 187 root.selectAll('.pie-path').remove(); |
175 } | 188 } |
176 | 189 |
177 void _event(StreamController controller, data, int index, Element e) { | 190 void _event(StreamController controller, data, int index, Element e) { |
178 // Currently, events are not supported on "Other" pie | 191 // Currently, events are not supported on "Other" pie |
179 if (controller == null || data.data == SMALL_INT_MAX) return; | 192 if (controller == null || data.data == SMALL_INT_MAX) return; |
180 controller.add(new DefaultChartEventImpl(scope.event, area, series, | 193 controller.add(new DefaultChartEventImpl(scope.event, area, series, |
181 data.data, series.measures.first, data.value)); | 194 data.data, series.measures.first, data.value)); |
182 } | 195 } |
183 } | 196 } |
OLD | NEW |