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 = new LinkedHashSet<Pair<int,int>>(); | 29 LinkedHashSet<Pair<int, int>> highlights = |
| 30 new LinkedHashSet<Pair<int, int>>(); |
30 | 31 |
31 Pair<int,int> _hovered; | 32 Pair<int, int> _hovered; |
32 int _preview; | 33 int _preview; |
33 | 34 |
34 DefaultChartStateImpl({ | 35 DefaultChartStateImpl( |
35 this.supportColumnSelection: true, | 36 {this.supportColumnSelection: true, |
36 this.supportColumnPreview: true, | 37 this.supportColumnPreview: true, |
37 this.supportValueHighlight: true, | 38 this.supportValueHighlight: true, |
38 this.supportValueHover: true, | 39 this.supportValueHover: true, |
39 this.isMultiSelect: false, | 40 this.isMultiSelect: false, |
40 this.isMultiHighlight: false, | 41 this.isMultiHighlight: false, |
41 this.isSelectOrHighlight: true}); | 42 this.isSelectOrHighlight: true}); |
42 | 43 |
43 set hovered(Pair<int,int> value) { | 44 set hovered(Pair<int, int> value) { |
44 if (!this.supportValueHover) return null; | 45 if (!this.supportValueHover) return null; |
45 if (value != _hovered) { | 46 if (value != _hovered) { |
46 _hovered = value; | 47 _hovered = value; |
47 notifyChange(new ChartHoverChangeRecord(_hovered)); | 48 notifyChange(new ChartHoverChangeRecord(_hovered)); |
48 } | 49 } |
49 return value; | 50 return value; |
50 } | 51 } |
51 Pair<int,int> get hovered => _hovered; | 52 |
| 53 Pair<int, int> get hovered => _hovered; |
52 | 54 |
53 set preview(int value) { | 55 set preview(int value) { |
54 if (!this.supportColumnPreview) return null; | 56 if (!this.supportColumnPreview) return null; |
55 if (value != _preview) { | 57 if (value != _preview) { |
56 _preview = value; | 58 _preview = value; |
57 notifyChange(new ChartPreviewChangeRecord(_preview)); | 59 notifyChange(new ChartPreviewChangeRecord(_preview)); |
58 } | 60 } |
59 return value; | 61 return value; |
60 } | 62 } |
| 63 |
61 int get preview => _preview; | 64 int get preview => _preview; |
62 | 65 |
63 bool unhide(int id) { | 66 bool unhide(int id) { |
64 if (hidden.contains(id)) { | 67 if (hidden.contains(id)) { |
65 hidden.remove(id); | 68 hidden.remove(id); |
66 notifyChange(new ChartVisibilityChangeRecord(unhide:id)); | 69 notifyChange(new ChartVisibilityChangeRecord(unhide: id)); |
67 } | 70 } |
68 return true; | 71 return true; |
69 } | 72 } |
70 | 73 |
71 bool hide(int id) { | 74 bool hide(int id) { |
72 if (!hidden.contains(id)) { | 75 if (!hidden.contains(id)) { |
73 hidden.add(id); | 76 hidden.add(id); |
74 notifyChange(new ChartVisibilityChangeRecord(hide:id)); | 77 notifyChange(new ChartVisibilityChangeRecord(hide: id)); |
75 } | 78 } |
76 return false; | 79 return false; |
77 } | 80 } |
78 | 81 |
79 bool isVisible(int id) => !hidden.contains(id); | 82 bool isVisible(int id) => !hidden.contains(id); |
80 | 83 |
81 bool select(int id) { | 84 bool select(int id) { |
82 if (!this.supportColumnSelection) return false; | 85 if (!this.supportColumnSelection) return false; |
83 if (!selection.contains(id)) { | 86 if (!selection.contains(id)) { |
84 if (!isMultiSelect) { | 87 if (!isMultiSelect) { |
85 selection.clear(); | 88 selection.clear(); |
86 } | 89 } |
87 if (isSelectOrHighlight) { | 90 if (isSelectOrHighlight) { |
88 highlights.clear(); | 91 highlights.clear(); |
89 } | 92 } |
90 selection.add(id); | 93 selection.add(id); |
91 notifyChange(new ChartSelectionChangeRecord(add:id)); | 94 notifyChange(new ChartSelectionChangeRecord(add: id)); |
92 } | 95 } |
93 return true; | 96 return true; |
94 } | 97 } |
95 | 98 |
96 bool unselect(int id) { | 99 bool unselect(int id) { |
97 if (selection.contains(id)) { | 100 if (selection.contains(id)) { |
98 selection.remove(id); | 101 selection.remove(id); |
99 notifyChange(new ChartSelectionChangeRecord(remove:id)); | 102 notifyChange(new ChartSelectionChangeRecord(remove: id)); |
100 } | 103 } |
101 return false; | 104 return false; |
102 } | 105 } |
103 | 106 |
104 bool isSelected(int id) => selection.contains(id); | 107 bool isSelected(int id) => selection.contains(id); |
105 | 108 |
106 bool highlight(int column, int row) { | 109 bool highlight(int column, int row) { |
107 if (!this.supportValueHighlight) return false; | 110 if (!this.supportValueHighlight) return false; |
108 if (!isHighlighted(column, row)) { | 111 if (!isHighlighted(column, row)) { |
109 if (!isMultiHighlight) { | 112 if (!isMultiHighlight) { |
(...skipping 14 matching lines...) Expand all Loading... |
124 var item = new Pair(column, row); | 127 var item = new Pair(column, row); |
125 highlights.remove(item); | 128 highlights.remove(item); |
126 notifyChange(new ChartHighlightChangeRecord(remove: item)); | 129 notifyChange(new ChartHighlightChangeRecord(remove: item)); |
127 } | 130 } |
128 return false; | 131 return false; |
129 } | 132 } |
130 | 133 |
131 bool isHighlighted(int column, int row) => | 134 bool isHighlighted(int column, int row) => |
132 highlights.any((x) => x.first == column && x.last == row); | 135 highlights.any((x) => x.first == column && x.last == row); |
133 } | 136 } |
OLD | NEW |