|
| 1 | +import $ from 'jquery'; |
| 2 | +import 'jquery-sparkline'; |
| 3 | +import { debounce } from 'lodash'; |
| 4 | +import { COLORS } from './_colors.js'; |
| 5 | + |
| 6 | +export default (function () { |
| 7 | + // ------------------------------------------------------ |
| 8 | + // @Dashboard Sparklines |
| 9 | + // ------------------------------------------------------ |
| 10 | + |
| 11 | + const drawSparklines = () => { |
| 12 | + if ($('#sparklinedash').length > 0) { |
| 13 | + $('#sparklinedash').sparkline([0, 5, 6, 10, 9, 12, 4, 9], { |
| 14 | + type: 'bar', |
| 15 | + height: '20', |
| 16 | + barWidth: '3', |
| 17 | + resize: true, |
| 18 | + barSpacing: '3', |
| 19 | + barColor: '#4caf50', |
| 20 | + }); |
| 21 | + } |
| 22 | + |
| 23 | + if ($('#sparklinedash2').length > 0) { |
| 24 | + $('#sparklinedash2').sparkline([0, 5, 6, 10, 9, 12, 4, 9], { |
| 25 | + type: 'bar', |
| 26 | + height: '20', |
| 27 | + barWidth: '3', |
| 28 | + resize: true, |
| 29 | + barSpacing: '3', |
| 30 | + barColor: '#9675ce', |
| 31 | + }); |
| 32 | + } |
| 33 | + |
| 34 | + if ($('#sparklinedash3').length > 0) { |
| 35 | + $('#sparklinedash3').sparkline([0, 5, 6, 10, 9, 12, 4, 9], { |
| 36 | + type: 'bar', |
| 37 | + height: '20', |
| 38 | + barWidth: '3', |
| 39 | + resize: true, |
| 40 | + barSpacing: '3', |
| 41 | + barColor: '#03a9f3', |
| 42 | + }); |
| 43 | + } |
| 44 | + |
| 45 | + if ($('#sparklinedash4').length > 0) { |
| 46 | + $('#sparklinedash4').sparkline([0, 5, 6, 10, 9, 12, 4, 9], { |
| 47 | + type: 'bar', |
| 48 | + height: '20', |
| 49 | + barWidth: '3', |
| 50 | + resize: true, |
| 51 | + barSpacing: '3', |
| 52 | + barColor: '#f96262', |
| 53 | + }); |
| 54 | + } |
| 55 | + }; |
| 56 | + |
| 57 | + drawSparklines(); |
| 58 | + |
| 59 | + // Redraw sparklines on resize |
| 60 | + $(window).on('resize', debounce(drawSparklines, 150)); |
| 61 | + |
| 62 | + // ------------------------------------------------------ |
| 63 | + // @Other Sparklines |
| 64 | + // ------------------------------------------------------ |
| 65 | + |
| 66 | + $('#sparkline').sparkline( |
| 67 | + [5, 6, 7, 9, 9, 5, 3, 2, 2, 4, 6, 7], |
| 68 | + { |
| 69 | + type: 'line', |
| 70 | + resize: true, |
| 71 | + height: '20', |
| 72 | + } |
| 73 | + ); |
| 74 | + |
| 75 | + $('#compositebar').sparkline( |
| 76 | + 'html', |
| 77 | + { |
| 78 | + type: 'bar', |
| 79 | + resize: true, |
| 80 | + barColor: '#aaf', |
| 81 | + height: '20', |
| 82 | + } |
| 83 | + ); |
| 84 | + |
| 85 | + $('#compositebar').sparkline( |
| 86 | + [4, 1, 5, 7, 9, 9, 8, 7, 6, 6, 4, 7, 8, 4, 3, 2, 2, 5, 6, 7], |
| 87 | + { |
| 88 | + composite: true, |
| 89 | + fillColor: false, |
| 90 | + lineColor: 'red', |
| 91 | + resize: true, |
| 92 | + height: '20', |
| 93 | + } |
| 94 | + ); |
| 95 | + |
| 96 | + $('#normalline').sparkline( |
| 97 | + 'html', |
| 98 | + { |
| 99 | + fillColor: false, |
| 100 | + normalRangeMin: -1, |
| 101 | + resize: true, |
| 102 | + normalRangeMax: 8, |
| 103 | + height: '20', |
| 104 | + } |
| 105 | + ); |
| 106 | + |
| 107 | + $('.sparktristate').sparkline( |
| 108 | + 'html', |
| 109 | + { |
| 110 | + type: 'tristate', |
| 111 | + resize: true, |
| 112 | + height: '20', |
| 113 | + } |
| 114 | + ); |
| 115 | + |
| 116 | + $('.sparktristatecols').sparkline( |
| 117 | + 'html', |
| 118 | + { |
| 119 | + type: 'tristate', |
| 120 | + colorMap: { |
| 121 | + '-2': '#fa7', |
| 122 | + resize: true, |
| 123 | + '2': '#44f', |
| 124 | + height: '20', |
| 125 | + }, |
| 126 | + } |
| 127 | + ); |
| 128 | + |
| 129 | + const values = [5, 4, 5, -2, 0, 3, -5, 6, 7, 9, 9, 5, -3, -2, 2, -4]; |
| 130 | + const valuesAlt = [1, 1, 0, 1, -1, -1, 1, -1, 0, 0, 1, 1]; |
| 131 | + |
| 132 | + $('.sparkline').sparkline(values, { |
| 133 | + type: 'line', |
| 134 | + barWidth: 4, |
| 135 | + barSpacing: 5, |
| 136 | + fillColor: '', |
| 137 | + lineColor: COLORS['red-500'], |
| 138 | + lineWidth: 2, |
| 139 | + spotRadius: 3, |
| 140 | + spotColor: COLORS['red-500'], |
| 141 | + maxSpotColor: COLORS['red-500'], |
| 142 | + minSpotColor: COLORS['red-500'], |
| 143 | + highlightSpotColor: COLORS['red-500'], |
| 144 | + highlightLineColor: '', |
| 145 | + tooltipSuffix: ' Bzzt', |
| 146 | + tooltipPrefix: 'Hello ', |
| 147 | + width: 100, |
| 148 | + height: undefined, |
| 149 | + barColor: '9f0', |
| 150 | + negBarColor: 'ff0', |
| 151 | + stackedBarColor: ['ff0', '9f0', '999', 'f60'], |
| 152 | + sliceColors: ['ff0', '9f0', '000', 'f60'], |
| 153 | + offset: '30', |
| 154 | + borderWidth: 1, |
| 155 | + borderColor: '000', |
| 156 | + }); |
| 157 | + |
| 158 | + $('.sparkbar').sparkline(values, { |
| 159 | + type: 'bar', |
| 160 | + barWidth: 4, |
| 161 | + barSpacing: 1, |
| 162 | + fillColor: '', |
| 163 | + lineColor: COLORS['deep-purple-500'], |
| 164 | + tooltipSuffix: 'Celsius', |
| 165 | + width: 100, |
| 166 | + barColor: '39f', |
| 167 | + negBarColor: COLORS['deep-purple-500'], |
| 168 | + stackedBarColor: ['ff0', '9f0', '999', 'f60'], |
| 169 | + sliceColors: ['ff0', '9f0', '000', 'f60'], |
| 170 | + offset: '30', |
| 171 | + borderWidth: 1, |
| 172 | + borderColor: '000', |
| 173 | + }); |
| 174 | + |
| 175 | + $('.sparktri').sparkline(valuesAlt, { |
| 176 | + type: 'tristate', |
| 177 | + barWidth: 4, |
| 178 | + barSpacing: 1, |
| 179 | + fillColor: '', |
| 180 | + lineColor: COLORS['light-blue-500'], |
| 181 | + tooltipSuffix: 'Celsius', |
| 182 | + width: 100, |
| 183 | + barColor: COLORS['light-blue-500'], |
| 184 | + posBarColor: COLORS['light-blue-500'], |
| 185 | + negBarColor: 'f90', |
| 186 | + zeroBarColor: '000', |
| 187 | + stackedBarColor: ['ff0', '9f0', '999', 'f60'], |
| 188 | + sliceColors: ['ff0', '9f0', '000', 'f60'], |
| 189 | + offset: '30', |
| 190 | + borderWidth: 1, |
| 191 | + borderColor: '000', |
| 192 | + }); |
| 193 | + |
| 194 | + $('.sparkdisc').sparkline(values, { |
| 195 | + type: 'discrete', |
| 196 | + barWidth: 4, |
| 197 | + barSpacing: 5, |
| 198 | + fillColor: '', |
| 199 | + lineColor: '9f0', |
| 200 | + tooltipSuffix: 'Celsius', |
| 201 | + width: 100, |
| 202 | + barColor: '9f0', |
| 203 | + negBarColor: 'f90', |
| 204 | + stackedBarColor: ['ff0', '9f0', '999', 'f60'], |
| 205 | + sliceColors: ['ff0', '9f0', '000', 'f60'], |
| 206 | + offset: '30', |
| 207 | + borderWidth: 1, |
| 208 | + borderColor: '000', |
| 209 | + }); |
| 210 | + |
| 211 | + $('.sparkbull').sparkline(values, { |
| 212 | + type: 'bullet', |
| 213 | + barWidth: 4, |
| 214 | + barSpacing: 5, |
| 215 | + fillColor: '', |
| 216 | + lineColor: COLORS['amber-500'], |
| 217 | + tooltipSuffix: 'Celsius', |
| 218 | + height: 'auto', |
| 219 | + width: 'auto', |
| 220 | + targetWidth: 'auto', |
| 221 | + barColor: COLORS['amber-500'], |
| 222 | + negBarColor: 'ff0', |
| 223 | + stackedBarColor: ['ff0', '9f0', '999', 'f60'], |
| 224 | + sliceColors: ['ff0', '9f0', '000', 'f60'], |
| 225 | + offset: '30', |
| 226 | + borderWidth: 1, |
| 227 | + borderColor: '000', |
| 228 | + }); |
| 229 | + |
| 230 | + $('.sparkbox').sparkline(values, { |
| 231 | + type: 'box', |
| 232 | + barWidth: 4, |
| 233 | + barSpacing: 5, |
| 234 | + fillColor: '', |
| 235 | + lineColor: '9f0', |
| 236 | + tooltipSuffix: 'Celsius', |
| 237 | + width: 100, |
| 238 | + barColor: '9f0', |
| 239 | + negBarColor: 'ff0', |
| 240 | + stackedBarColor: ['ff0', '9f0', '999', 'f60'], |
| 241 | + sliceColors: ['ff0', '9f0', '000', 'f60'], |
| 242 | + offset: '30', |
| 243 | + borderWidth: 1, |
| 244 | + borderColor: '000', |
| 245 | + }); |
| 246 | +}()) |
0 commit comments