| 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 /// Model that maintains state of each visualization item. Each entry in the | 12 /// Model that maintains state of each visualization item. Each entry in the |
| 13 /// legend is considered one visualization item. | 13 /// legend is considered one visualization item. |
| 14 /// - In [CartesianArea] it is always a column. | 14 /// - In [CartesianArea] it is always a column. |
| 15 /// - In [LayoutArea] renders choose either columns or rows. | 15 /// - In [LayoutArea] renders choose either columns or rows. |
| 16 /// | 16 /// |
| 17 class DefaultChartStateImpl extends ChangeNotifier implements ChartState { | 17 class DefaultChartStateImpl extends ChangeNotifier implements ChartState { |
| 18 final bool isMultiSelect; | 18 final bool isMultiSelect; |
| 19 final bool isMultiHighlight; | 19 final bool isMultiHighlight; |
| 20 final bool isSelectOrHighlight; | 20 final bool isSelectOrHighlight; |
| 21 final bool supportColumnSelection; | 21 final bool supportColumnSelection; |
| 22 final bool supportColumnPreview; | 22 final bool supportColumnPreview; |
| 23 final bool supportValueHighlight; | 23 final bool supportValueHighlight; |
| 24 final bool supportValueHover; | 24 final bool supportValueHover; |
| 25 | 25 |
| 26 LinkedHashSet<int> hidden = new LinkedHashSet<int>(); | 26 LinkedHashSet<int> hidden = new LinkedHashSet<int>(); |
| 27 | 27 |
| 28 LinkedHashSet<int> selection = new LinkedHashSet<int>(); | 28 LinkedHashSet<int> selection = new LinkedHashSet<int>(); |
| 29 LinkedHashSet<Pair<int, int>> highlights = | 29 LinkedHashSet<Pair<int, int>> highlights = new LinkedHashSet<Pair<int, int>>()
; |
| 30 new LinkedHashSet<Pair<int, int>>(); | |
| 31 | 30 |
| 32 Pair<int, int> _hovered; | 31 Pair<int, int> _hovered; |
| 33 int _preview; | 32 int _preview; |
| 34 | 33 |
| 35 DefaultChartStateImpl( | 34 DefaultChartStateImpl( |
| 36 {this.supportColumnSelection: true, | 35 {this.supportColumnSelection: true, |
| 37 this.supportColumnPreview: true, | 36 this.supportColumnPreview: true, |
| 38 this.supportValueHighlight: true, | 37 this.supportValueHighlight: true, |
| 39 this.supportValueHover: true, | 38 this.supportValueHover: true, |
| 40 this.isMultiSelect: false, | 39 this.isMultiSelect: false, |
| 41 this.isMultiHighlight: false, | 40 this.isMultiHighlight: false, |
| 42 this.isSelectOrHighlight: true}); | 41 this.isSelectOrHighlight: true}); |
| 43 | 42 |
| 44 set hovered(Pair<int, int> value) { | 43 set hovered(Pair<int, int> value) { |
| 45 if (!this.supportValueHover) return null; | 44 if (!this.supportValueHover) return null; |
| 46 if (value != _hovered) { | 45 if (value != _hovered) { |
| 47 _hovered = value; | 46 _hovered = value; |
| 48 notifyChange(new ChartHoverChangeRecord(_hovered)); | 47 notifyChange(new ChartHoverChangeRecord(_hovered)); |
| 49 } | 48 } |
| 50 return value; | |
| 51 } | 49 } |
| 52 | 50 |
| 53 Pair<int, int> get hovered => _hovered; | 51 Pair<int, int> get hovered => _hovered; |
| 54 | 52 |
| 55 set preview(int value) { | 53 set preview(int value) { |
| 56 if (!this.supportColumnPreview) return null; | 54 if (!this.supportColumnPreview) return null; |
| 57 if (value != _preview) { | 55 if (value != _preview) { |
| 58 _preview = value; | 56 _preview = value; |
| 59 notifyChange(new ChartPreviewChangeRecord(_preview)); | 57 notifyChange(new ChartPreviewChangeRecord(_preview)); |
| 60 } | 58 } |
| 61 return value; | |
| 62 } | 59 } |
| 63 | 60 |
| 64 int get preview => _preview; | 61 int get preview => _preview; |
| 65 | 62 |
| 66 bool unhide(int id) { | 63 bool unhide(int id) { |
| 67 if (hidden.contains(id)) { | 64 if (hidden.contains(id)) { |
| 68 hidden.remove(id); | 65 hidden.remove(id); |
| 69 notifyChange(new ChartVisibilityChangeRecord(unhide: id)); | 66 notifyChange(new ChartVisibilityChangeRecord(unhide: id)); |
| 70 } | 67 } |
| 71 return true; | 68 return true; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 105 |
| 109 bool highlight(int column, int row) { | 106 bool highlight(int column, int row) { |
| 110 if (!this.supportValueHighlight) return false; | 107 if (!this.supportValueHighlight) return false; |
| 111 if (!isHighlighted(column, row)) { | 108 if (!isHighlighted(column, row)) { |
| 112 if (!isMultiHighlight) { | 109 if (!isMultiHighlight) { |
| 113 highlights.clear(); | 110 highlights.clear(); |
| 114 } | 111 } |
| 115 if (isSelectOrHighlight) { | 112 if (isSelectOrHighlight) { |
| 116 selection.clear(); | 113 selection.clear(); |
| 117 } | 114 } |
| 118 var item = new Pair(column, row); | 115 var item = new Pair<int, int>(column, row); |
| 119 highlights.add(item); | 116 highlights.add(item); |
| 120 notifyChange(new ChartHighlightChangeRecord(add: item)); | 117 notifyChange(new ChartHighlightChangeRecord(add: item)); |
| 121 } | 118 } |
| 122 return true; | 119 return true; |
| 123 } | 120 } |
| 124 | 121 |
| 125 bool unhighlight(int column, int row) { | 122 bool unhighlight(int column, int row) { |
| 126 if (isHighlighted(column, row)) { | 123 if (isHighlighted(column, row)) { |
| 127 var item = new Pair(column, row); | 124 var item = new Pair<int, int>(column, row); |
| 128 highlights.remove(item); | 125 highlights.remove(item); |
| 129 notifyChange(new ChartHighlightChangeRecord(remove: item)); | 126 notifyChange(new ChartHighlightChangeRecord(remove: item)); |
| 130 } | 127 } |
| 131 return false; | 128 return false; |
| 132 } | 129 } |
| 133 | 130 |
| 134 bool isHighlighted(int column, int row) => | 131 bool isHighlighted(int column, int row) => |
| 135 highlights.any((x) => x.first == column && x.last == row); | 132 highlights.any((x) => x.first == column && x.last == row); |
| 136 } | 133 } |
| OLD | NEW |