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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // _createLegendItems(tooltip, 'chart-legend-more', items); | 107 // _createLegendItems(tooltip, 'chart-legend-more', items); |
108 } | 108 } |
109 | 109 |
110 /// Creates legend items starting at the given index. | 110 /// Creates legend items starting at the given index. |
111 void _createLegendItems() { | 111 void _createLegendItems() { |
112 var state = _area.state, | 112 var state = _area.state, |
113 rows = | 113 rows = |
114 _root.selectAll('.chart-legend-row').data(_items, (x) => x.hashCode), | 114 _root.selectAll('.chart-legend-row').data(_items, (x) => x.hashCode), |
115 isFirstRender = rows.length == 0; | 115 isFirstRender = rows.length == 0; |
116 | 116 |
117 var enter = rows.enter.appendWithCallback((d, i, e) { | 117 var enter = rows.enter.appendWithCallback((ChartLegendItem d, i, e) { |
118 var row = Namespace.createChildElement('div', e), | 118 var row = Namespace.createChildElement('div', e), |
119 color = Namespace.createChildElement('div', e) | 119 color = Namespace.createChildElement('div', e) |
120 ..className = 'chart-legend-color', | 120 ..className = 'chart-legend-color', |
121 label = Namespace.createChildElement('div', e) | 121 label = Namespace.createChildElement('div', e) |
122 ..className = 'chart-legend-label', | 122 ..className = 'chart-legend-label', |
123 value = showValues | 123 value = showValues |
124 ? (Namespace.createChildElement('div', e) | 124 ? (Namespace.createChildElement('div', e) |
125 ..className = 'chart-legend-value') | 125 ..className = 'chart-legend-value') |
126 : null; | 126 : null; |
127 | 127 |
128 var rowStyles = ['chart-legend-row'].toList(); | 128 var rowStyles = <String>['chart-legend-row']; |
129 | 129 |
130 // If this is the first time we are adding rows, | 130 // If this is the first time we are adding rows, |
131 // Update elements before adding them to the DOM. | 131 // Update elements before adding them to the DOM. |
132 if (isFirstRender) { | 132 if (isFirstRender) { |
133 if (state != null) { | 133 if (state != null) { |
134 if (d.index == state.preview) { | 134 if (d.index == state.preview) { |
135 rowStyles.add('chart-legend-hover'); | 135 rowStyles.add('chart-legend-hover'); |
136 } | 136 } |
137 if (state.isSelected(d.index)) { | 137 if (state.isSelected(d.index)) { |
138 rowStyles.add('chart-legend-selected'); | 138 rowStyles.add('chart-legend-selected'); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } else { | 198 } else { |
199 state.select(d.index); | 199 state.select(d.index); |
200 } | 200 } |
201 }); | 201 }); |
202 } | 202 } |
203 | 203 |
204 rows.exit.remove(); | 204 rows.exit.remove(); |
205 } | 205 } |
206 | 206 |
207 /// Update legend to show chart's selection and visibility. | 207 /// Update legend to show chart's selection and visibility. |
208 void _handleStateChanges(_) => _createLegendItems(); | 208 void _handleStateChanges(List<ChangeRecord> _) => _createLegendItems(); |
209 } | 209 } |
OLD | NEW |