OLD | NEW |
| (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 part of charted.charts; | |
10 | |
11 class QuantumChartTheme extends ChartTheme { | |
12 static const List OTHER_COLORS = | |
13 const['#EEEEEE', '#BDBDBD', '#9E9E9E']; | |
14 | |
15 static const List<List<String>> COLORS = const[ | |
16 const [ '#C5D9FB', '#4184F3', '#2955C5' ], | |
17 const [ '#F3C6C2', '#DB4437', '#A52714' ], | |
18 const [ '#FBE7B1', '#F4B400', '#EF9200' ], | |
19 const [ '#B6E0CC', '#0F9D58', '#0A7F42' ], | |
20 const [ '#E0BDE6', '#AA46BB', '#691A99' ], | |
21 const [ '#B1EAF1', '#00ABC0', '#00828E' ], | |
22 const [ '#FFCBBB', '#FF6F42', '#E54918' ], | |
23 const [ '#EFF3C2', '#9D9C23', '#817616' ], | |
24 const [ '#C4C9E8', '#5B6ABF', '#3848AA' ], | |
25 const [ '#F7BACF', '#EF6191', '#E81D62' ], | |
26 const [ '#B1DEDA', '#00786A', '#004C3F' ], | |
27 const [ '#F38EB0', '#C1175A', '#870D4E' ], | |
28 ]; | |
29 | |
30 static const List<List<String>> COLORS_ASSIST = const[ | |
31 const [ '#C5D9FB', '#4184F3', '#2955C5' ], | |
32 const [ '#F3C6C2', '#DB4437', '#A52714' ], | |
33 const [ '#FBE7B1', '#F4B400', '#EF9200' ], | |
34 const [ '#B6E0CC', '#0F9D58', '#0A7F42' ], | |
35 const [ '#E0BDE6', '#AA46BB', '#691A99' ], | |
36 const [ '#B1EAF1', '#00ABC0', '#00828E' ], | |
37 const [ '#FFCBBB', '#FF6F42', '#E54918' ], | |
38 const [ '#EFF3C2', '#9D9C23', '#817616' ] | |
39 ]; | |
40 | |
41 final OrdinalScale _scale = new OrdinalScale()..range = COLORS; | |
42 | |
43 @override | |
44 String getColorForKey(key, [int state = 0]) { | |
45 var result = _scale.scale(key); | |
46 return result is Iterable ? colorForState(result, state) : result; | |
47 } | |
48 | |
49 colorForState(Iterable colors, int state) { | |
50 // Inactive color when another key is active or selected. | |
51 if (state & ChartState.COL_UNSELECTED != 0 || | |
52 state & ChartState.VAL_UNHIGHLIGHTED != 0) { | |
53 return colors.elementAt(0); | |
54 } | |
55 | |
56 // Active color when this key is being hovered upon | |
57 if (state & ChartState.COL_PREVIEW != 0 || | |
58 state & ChartState.VAL_HOVERED != 0) { | |
59 return colors.elementAt(2); | |
60 } | |
61 | |
62 // All others are normal. | |
63 return colors.elementAt(1); | |
64 } | |
65 | |
66 @override | |
67 String getFilterForState(int state) => | |
68 state & ChartState.COL_PREVIEW != 0 || | |
69 state & ChartState.VAL_HOVERED != 0 || | |
70 state & ChartState.COL_SELECTED != 0 || | |
71 state & ChartState.VAL_HIGHLIGHTED != 0 | |
72 ? 'url(#drop-shadow)' | |
73 : ''; | |
74 | |
75 @override | |
76 String getOtherColor([int state = 0]) => | |
77 OTHER_COLORS is Iterable | |
78 ? colorForState(OTHER_COLORS, state) | |
79 : OTHER_COLORS; | |
80 | |
81 @override | |
82 ChartAxisTheme getMeasureAxisTheme([Scale _]) => | |
83 const QuantumChartAxisTheme(ChartAxisTheme.FILL_RENDER_AREA, 5); | |
84 | |
85 @override | |
86 ChartAxisTheme getDimensionAxisTheme([Scale scale]) => | |
87 scale == null || scale is OrdinalScale | |
88 ? const QuantumChartAxisTheme(0, 10) | |
89 : const QuantumChartAxisTheme(4, 10); | |
90 | |
91 @override | |
92 AbsoluteRect get padding => const AbsoluteRect(10, 40, 0, 0); | |
93 | |
94 @override | |
95 String get filters => ''' | |
96 <filter id="drop-shadow" height="300%" width="300%" y="-100%" x="-100%"> | |
97 <feGaussianBlur stdDeviation="2" in="SourceAlpha"></feGaussianBlur> | |
98 <feOffset dy="1" dx="0"></feOffset> | |
99 <feComponentTransfer> | |
100 <feFuncA slope="0.4" type="linear"></feFuncA> | |
101 </feComponentTransfer> | |
102 <feMerge> | |
103 <feMergeNode></feMergeNode> | |
104 <feMergeNode in="SourceGraphic"></feMergeNode> | |
105 </feMerge> | |
106 </filter> | |
107 '''; | |
108 | |
109 @override | |
110 String get defaultFont => '14px Roboto'; | |
111 } | |
112 | |
113 class QuantumChartAxisTheme implements ChartAxisTheme { | |
114 @override | |
115 final axisOuterPadding = 0.1; | |
116 | |
117 @override | |
118 final axisBandInnerPadding = 0.35; | |
119 | |
120 @override | |
121 final axisBandOuterPadding = 0.175; | |
122 | |
123 @override | |
124 final axisTickPadding = 6; | |
125 | |
126 @override | |
127 final axisTickSize; | |
128 | |
129 @override | |
130 final axisTickCount; | |
131 | |
132 @override | |
133 final verticalAxisAutoResize = true; | |
134 | |
135 @override | |
136 final verticalAxisWidth = 75; | |
137 | |
138 @override | |
139 final horizontalAxisAutoResize = false; | |
140 | |
141 @override | |
142 final horizontalAxisHeight = 50; | |
143 | |
144 @override | |
145 final ticksFont = '12px Roboto'; | |
146 | |
147 const QuantumChartAxisTheme(this.axisTickSize, this.axisTickCount); | |
148 } | |
OLD | NEW |