1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | (function webpackUniversalModuleDefinition(root, factory) {
|
13 | if(typeof exports === 'object' && typeof module === 'object')
|
14 | module.exports = factory(require("d3-brush"), require("d3-selection"));
|
15 | else if(typeof define === 'function' && define.amd)
|
16 | define("bb", ["d3-brush", "d3-selection"], factory);
|
17 | else if(typeof exports === 'object')
|
18 | exports["bb"] = factory(require("d3-brush"), require("d3-selection"));
|
19 | else
|
20 | root["bb"] = root["bb"] || {}, root["bb"]["plugin"] = root["bb"]["plugin"] || {}, root["bb"]["plugin"]["sparkline"] = factory(root["d3"], root["d3"]);
|
21 | })(this, function(__WEBPACK_EXTERNAL_MODULE__3__, __WEBPACK_EXTERNAL_MODULE__1__) {
|
22 | return (function() {
|
23 | "use strict";
|
24 | var __webpack_modules__ = ([
|
25 | ,
|
26 |
|
27 | (function(module) {
|
28 |
|
29 | module.exports = __WEBPACK_EXTERNAL_MODULE__1__;
|
30 |
|
31 | }),
|
32 | ,
|
33 |
|
34 | (function(module) {
|
35 |
|
36 | module.exports = __WEBPACK_EXTERNAL_MODULE__3__;
|
37 |
|
38 | })
|
39 | ]);
|
40 |
|
41 |
|
42 | var __webpack_module_cache__ = {};
|
43 |
|
44 |
|
45 | function __webpack_require__(moduleId) {
|
46 |
|
47 | var cachedModule = __webpack_module_cache__[moduleId];
|
48 | if (cachedModule !== undefined) {
|
49 | return cachedModule.exports;
|
50 | }
|
51 |
|
52 | var module = __webpack_module_cache__[moduleId] = {
|
53 |
|
54 |
|
55 | exports: {}
|
56 | };
|
57 |
|
58 |
|
59 | __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
60 |
|
61 |
|
62 | return module.exports;
|
63 | }
|
64 |
|
65 |
|
66 |
|
67 | !function() {
|
68 |
|
69 | __webpack_require__.d = function(exports, definition) {
|
70 | for(var key in definition) {
|
71 | if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
72 | Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
73 | }
|
74 | }
|
75 | };
|
76 | }();
|
77 |
|
78 |
|
79 | !function() {
|
80 | __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
|
81 | }();
|
82 |
|
83 |
|
84 | var __webpack_exports__ = {};
|
85 |
|
86 | !function() {
|
87 |
|
88 |
|
89 | __webpack_require__.d(__webpack_exports__, {
|
90 | "default": function() { return Sparkline; }
|
91 | });
|
92 |
|
93 | ;
|
94 | var __defProp = Object.defineProperty;
|
95 | var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
96 | var __hasOwnProp = Object.prototype.hasOwnProperty;
|
97 | var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
98 | var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
99 | var __spreadValues = (a, b) => {
|
100 | for (var prop in b || (b = {}))
|
101 | if (__hasOwnProp.call(b, prop))
|
102 | __defNormalProp(a, prop, b[prop]);
|
103 | if (__getOwnPropSymbols)
|
104 | for (var prop of __getOwnPropSymbols(b)) {
|
105 | if (__propIsEnum.call(b, prop))
|
106 | __defNormalProp(a, prop, b[prop]);
|
107 | }
|
108 | return a;
|
109 | };
|
110 | const $COMMON = {
|
111 | button: "bb-button",
|
112 | chart: "bb-chart",
|
113 | empty: "bb-empty",
|
114 | main: "bb-main",
|
115 | target: "bb-target",
|
116 | EXPANDED: "_expanded_"
|
117 | };
|
118 | const $ARC = {
|
119 | arc: "bb-arc",
|
120 | arcLabelLine: "bb-arc-label-line",
|
121 | arcRange: "bb-arc-range",
|
122 | arcs: "bb-arcs",
|
123 | chartArc: "bb-chart-arc",
|
124 | chartArcs: "bb-chart-arcs",
|
125 | chartArcsBackground: "bb-chart-arcs-background",
|
126 | chartArcsTitle: "bb-chart-arcs-title",
|
127 | needle: "bb-needle"
|
128 | };
|
129 | const $AREA = {
|
130 | area: "bb-area",
|
131 | areas: "bb-areas"
|
132 | };
|
133 | const $AXIS = {
|
134 | axis: "bb-axis",
|
135 | axisX: "bb-axis-x",
|
136 | axisXLabel: "bb-axis-x-label",
|
137 | axisY: "bb-axis-y",
|
138 | axisY2: "bb-axis-y2",
|
139 | axisY2Label: "bb-axis-y2-label",
|
140 | axisYLabel: "bb-axis-y-label",
|
141 | axisXTooltip: "bb-axis-x-tooltip",
|
142 | axisYTooltip: "bb-axis-y-tooltip",
|
143 | axisY2Tooltip: "bb-axis-y2-tooltip"
|
144 | };
|
145 | const $BAR = {
|
146 | bar: "bb-bar",
|
147 | bars: "bb-bars",
|
148 | chartBar: "bb-chart-bar",
|
149 | chartBars: "bb-chart-bars"
|
150 | };
|
151 | const $CANDLESTICK = {
|
152 | candlestick: "bb-candlestick",
|
153 | candlesticks: "bb-candlesticks",
|
154 | chartCandlestick: "bb-chart-candlestick",
|
155 | chartCandlesticks: "bb-chart-candlesticks",
|
156 | valueDown: "bb-value-down",
|
157 | valueUp: "bb-value-up"
|
158 | };
|
159 | const $CIRCLE = {
|
160 | chartCircles: "bb-chart-circles",
|
161 | circle: "bb-circle",
|
162 | circles: "bb-circles"
|
163 | };
|
164 | const $COLOR = {
|
165 | colorPattern: "bb-color-pattern",
|
166 | colorScale: "bb-colorscale"
|
167 | };
|
168 | const $DRAG = {
|
169 | dragarea: "bb-dragarea",
|
170 | INCLUDED: "_included_"
|
171 | };
|
172 | const $FUNNEL = {
|
173 | funnel: "bb-funnel",
|
174 | chartFunnel: "bb-chart-funnel",
|
175 | chartFunnels: "bb-chart-funnels",
|
176 | funnelBackground: "bb-funnel-background"
|
177 | };
|
178 | const $GAUGE = {
|
179 | chartArcsGaugeMax: "bb-chart-arcs-gauge-max",
|
180 | chartArcsGaugeMin: "bb-chart-arcs-gauge-min",
|
181 | chartArcsGaugeUnit: "bb-chart-arcs-gauge-unit",
|
182 | chartArcsGaugeTitle: "bb-chart-arcs-gauge-title",
|
183 | gaugeValue: "bb-gauge-value"
|
184 | };
|
185 | const $LEGEND = {
|
186 | legend: "bb-legend",
|
187 | legendBackground: "bb-legend-background",
|
188 | legendItem: "bb-legend-item",
|
189 | legendItemEvent: "bb-legend-item-event",
|
190 | legendItemHidden: "bb-legend-item-hidden",
|
191 | legendItemPoint: "bb-legend-item-point",
|
192 | legendItemTile: "bb-legend-item-tile"
|
193 | };
|
194 | const $LINE = {
|
195 | chartLine: "bb-chart-line",
|
196 | chartLines: "bb-chart-lines",
|
197 | line: "bb-line",
|
198 | lines: "bb-lines"
|
199 | };
|
200 | const $EVENT = {
|
201 | eventRect: "bb-event-rect",
|
202 | eventRects: "bb-event-rects",
|
203 | eventRectsMultiple: "bb-event-rects-multiple",
|
204 | eventRectsSingle: "bb-event-rects-single"
|
205 | };
|
206 | const $FOCUS = {
|
207 | focused: "bb-focused",
|
208 | defocused: "bb-defocused",
|
209 | legendItemFocused: "bb-legend-item-focused",
|
210 | xgridFocus: "bb-xgrid-focus",
|
211 | ygridFocus: "bb-ygrid-focus"
|
212 | };
|
213 | const $GRID = {
|
214 | grid: "bb-grid",
|
215 | gridLines: "bb-grid-lines",
|
216 | xgrid: "bb-xgrid",
|
217 | xgridLine: "bb-xgrid-line",
|
218 | xgridLines: "bb-xgrid-lines",
|
219 | xgrids: "bb-xgrids",
|
220 | ygrid: "bb-ygrid",
|
221 | ygridLine: "bb-ygrid-line",
|
222 | ygridLines: "bb-ygrid-lines",
|
223 | ygrids: "bb-ygrids"
|
224 | };
|
225 | const $LEVEL = {
|
226 | level: "bb-level",
|
227 | levels: "bb-levels"
|
228 | };
|
229 | const $RADAR = {
|
230 | chartRadar: "bb-chart-radar",
|
231 | chartRadars: "bb-chart-radars"
|
232 | };
|
233 | const $REGION = {
|
234 | region: "bb-region",
|
235 | regions: "bb-regions"
|
236 | };
|
237 | const $SELECT = {
|
238 | selectedCircle: "bb-selected-circle",
|
239 | selectedCircles: "bb-selected-circles",
|
240 | SELECTED: "_selected_"
|
241 | };
|
242 | const $SHAPE = {
|
243 | shape: "bb-shape",
|
244 | shapes: "bb-shapes"
|
245 | };
|
246 | const $SUBCHART = {
|
247 | brush: "bb-brush",
|
248 | subchart: "bb-subchart"
|
249 | };
|
250 | const $TEXT = {
|
251 | chartText: "bb-chart-text",
|
252 | chartTexts: "bb-chart-texts",
|
253 | text: "bb-text",
|
254 | texts: "bb-texts",
|
255 | title: "bb-title",
|
256 | TextOverlapping: "text-overlapping"
|
257 | };
|
258 | const $TOOLTIP = {
|
259 | tooltip: "bb-tooltip",
|
260 | tooltipContainer: "bb-tooltip-container",
|
261 | tooltipName: "bb-tooltip-name"
|
262 | };
|
263 | const $TREEMAP = {
|
264 | treemap: "bb-treemap",
|
265 | chartTreemap: "bb-chart-treemap",
|
266 | chartTreemaps: "bb-chart-treemaps"
|
267 | };
|
268 | const $ZOOM = {
|
269 | buttonZoomReset: "bb-zoom-reset",
|
270 | zoomBrush: "bb-zoom-brush"
|
271 | };
|
272 | var classes = (__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, $COMMON), $ARC), $AREA), $AXIS), $BAR), $CANDLESTICK), $CIRCLE), $COLOR), $DRAG), $GAUGE), $LEGEND), $LINE), $EVENT), $FOCUS), $FUNNEL), $GRID), $RADAR), $REGION), $SELECT), $SHAPE), $SUBCHART), $TEXT), $TOOLTIP), $TREEMAP), $ZOOM));
|
273 |
|
274 |
|
275 | var external_commonjs_d3_brush_commonjs2_d3_brush_amd_d3_brush_root_d3_ = __webpack_require__(3);
|
276 |
|
277 | var external_commonjs_d3_selection_commonjs2_d3_selection_amd_d3_selection_root_d3_ = __webpack_require__(1);
|
278 | ;
|
279 | function getGlobal() {
|
280 | return typeof globalThis === "object" && globalThis !== null && globalThis.Object === Object && globalThis || typeof global === "object" && global !== null && global.Object === Object && global || typeof self === "object" && self !== null && self.Object === Object && self || Function("return this")();
|
281 | }
|
282 | function getFallback(w) {
|
283 | const hasRAF = typeof (w == null ? void 0 : w.requestAnimationFrame) === "function" && typeof (w == null ? void 0 : w.cancelAnimationFrame) === "function";
|
284 | const hasRIC = typeof (w == null ? void 0 : w.requestIdleCallback) === "function" && typeof (w == null ? void 0 : w.cancelIdleCallback) === "function";
|
285 | const request = (cb) => setTimeout(cb, 1);
|
286 | const cancel = (id) => clearTimeout(id);
|
287 | return [
|
288 | hasRAF ? w.requestAnimationFrame : request,
|
289 | hasRAF ? w.cancelAnimationFrame : cancel,
|
290 | hasRIC ? w.requestIdleCallback : request,
|
291 | hasRIC ? w.cancelIdleCallback : cancel
|
292 | ];
|
293 | }
|
294 | const win = getGlobal();
|
295 | const doc = win == null ? void 0 : win.document;
|
296 | const [
|
297 | requestAnimationFrame,
|
298 | cancelAnimationFrame,
|
299 | requestIdleCallback,
|
300 | cancelIdleCallback
|
301 | ] = getFallback(win);
|
302 |
|
303 |
|
304 | ;
|
305 | var util_defProp = Object.defineProperty;
|
306 | var util_getOwnPropSymbols = Object.getOwnPropertySymbols;
|
307 | var util_hasOwnProp = Object.prototype.hasOwnProperty;
|
308 | var util_propIsEnum = Object.prototype.propertyIsEnumerable;
|
309 | var util_defNormalProp = (obj, key, value) => key in obj ? util_defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
310 | var util_spreadValues = (a, b) => {
|
311 | for (var prop in b || (b = {}))
|
312 | if (util_hasOwnProp.call(b, prop))
|
313 | util_defNormalProp(a, prop, b[prop]);
|
314 | if (util_getOwnPropSymbols)
|
315 | for (var prop of util_getOwnPropSymbols(b)) {
|
316 | if (util_propIsEnum.call(b, prop))
|
317 | util_defNormalProp(a, prop, b[prop]);
|
318 | }
|
319 | return a;
|
320 | };
|
321 |
|
322 |
|
323 |
|
324 |
|
325 | const isValue = (v) => v || v === 0;
|
326 | const isFunction = (v) => typeof v === "function";
|
327 | const isString = (v) => typeof v === "string";
|
328 | const isNumber = (v) => typeof v === "number";
|
329 | const isUndefined = (v) => typeof v === "undefined";
|
330 | const isDefined = (v) => typeof v !== "undefined";
|
331 | const isBoolean = (v) => typeof v === "boolean";
|
332 | const ceil10 = (v) => Math.ceil(v / 10) * 10;
|
333 | const asHalfPixel = (n) => Math.ceil(n) + 0.5;
|
334 | const diffDomain = (d) => d[1] - d[0];
|
335 | const isObjectType = (v) => typeof v === "object";
|
336 | const isEmpty = (o) => isUndefined(o) || o === null || isString(o) && o.length === 0 || isObjectType(o) && !(o instanceof Date) && Object.keys(o).length === 0 || isNumber(o) && isNaN(o);
|
337 | const notEmpty = (o) => !isEmpty(o);
|
338 | const isArray = (arr) => Array.isArray(arr);
|
339 | const isObject = (obj) => obj && !(obj == null ? void 0 : obj.nodeType) && isObjectType(obj) && !isArray(obj);
|
340 | function getOption(options, key, defaultValue) {
|
341 | return isDefined(options[key]) ? options[key] : defaultValue;
|
342 | }
|
343 | function hasValue(dict, value) {
|
344 | let found = false;
|
345 | Object.keys(dict).forEach((key) => dict[key] === value && (found = true));
|
346 | return found;
|
347 | }
|
348 | function callFn(fn, thisArg, ...args) {
|
349 | const isFn = isFunction(fn);
|
350 | isFn && fn.call(thisArg, ...args);
|
351 | return isFn;
|
352 | }
|
353 | function endall(transition, cb) {
|
354 | let n = 0;
|
355 | const end = function(...args) {
|
356 | !--n && cb.apply(this, ...args);
|
357 | };
|
358 | if ("duration" in transition) {
|
359 | transition.each(() => ++n).on("end", end);
|
360 | } else {
|
361 | ++n;
|
362 | transition.call(end);
|
363 | }
|
364 | }
|
365 | function sanitize(str) {
|
366 | return isString(str) ? str.replace(/<(script|img)?/ig, "<").replace(/(script)?>/ig, ">") : str;
|
367 | }
|
368 | function setTextValue(node, text, dy = [-1, 1], toMiddle = false) {
|
369 | if (!node || !isString(text)) {
|
370 | return;
|
371 | }
|
372 | if (text.indexOf("\n") === -1) {
|
373 | node.text(text);
|
374 | } else {
|
375 | const diff = [node.text(), text].map((v) => v.replace(/[\s\n]/g, ""));
|
376 | if (diff[0] !== diff[1]) {
|
377 | const multiline = text.split("\n");
|
378 | const len = toMiddle ? multiline.length - 1 : 1;
|
379 | node.html("");
|
380 | multiline.forEach((v, i) => {
|
381 | node.append("tspan").attr("x", 0).attr("dy", `${i === 0 ? dy[0] * len : dy[1]}em`).text(v);
|
382 | });
|
383 | }
|
384 | }
|
385 | }
|
386 | function getRectSegList(path) {
|
387 | const { x, y, width, height } = path.getBBox();
|
388 | return [
|
389 | { x, y: y + height },
|
390 |
|
391 | { x, y },
|
392 |
|
393 | { x: x + width, y },
|
394 |
|
395 | { x: x + width, y: y + height }
|
396 |
|
397 | ];
|
398 | }
|
399 | function getPathBox(path) {
|
400 | const { width, height } = path.getBoundingClientRect();
|
401 | const items = getRectSegList(path);
|
402 | const x = items[0].x;
|
403 | const y = Math.min(items[0].y, items[1].y);
|
404 | return {
|
405 | x,
|
406 | y,
|
407 | width,
|
408 | height
|
409 | };
|
410 | }
|
411 | function getPointer(event, element) {
|
412 | var _a;
|
413 | const touches = event && ((_a = event.touches || event.sourceEvent && event.sourceEvent.touches) == null ? void 0 : _a[0]);
|
414 | let pointer = [0, 0];
|
415 | try {
|
416 | pointer = (0,external_commonjs_d3_selection_commonjs2_d3_selection_amd_d3_selection_root_d3_.pointer)(touches || event, element);
|
417 | } catch (e) {
|
418 | }
|
419 | return pointer.map((v) => isNaN(v) ? 0 : v);
|
420 | }
|
421 | function getBrushSelection(ctx) {
|
422 | const { event, $el } = ctx;
|
423 | const main = $el.subchart.main || $el.main;
|
424 | let selection;
|
425 | if (event && event.type === "brush") {
|
426 | selection = event.selection;
|
427 | } else if (main && (selection = main.select(".bb-brush").node())) {
|
428 | selection = (0,external_commonjs_d3_brush_commonjs2_d3_brush_amd_d3_brush_root_d3_.brushSelection)(selection);
|
429 | }
|
430 | return selection;
|
431 | }
|
432 | function getBoundingRect(node) {
|
433 | const needEvaluate = !("rect" in node) || "rect" in node && node.hasAttribute("width") && node.rect.width !== +node.getAttribute("width");
|
434 | return needEvaluate ? node.rect = node.getBoundingClientRect() : node.rect;
|
435 | }
|
436 | function getRandom(asStr = true, min = 0, max = 1e4) {
|
437 | const crpt = win.crypto || win.msCrypto;
|
438 | const rand = crpt ? min + crpt.getRandomValues(new Uint32Array(1))[0] % (max - min + 1) : Math.floor(Math.random() * (max - min) + min);
|
439 | return asStr ? String(rand) : rand;
|
440 | }
|
441 | function findIndex(arr, v, start, end, isRotated) {
|
442 | if (start > end) {
|
443 | return -1;
|
444 | }
|
445 | const mid = Math.floor((start + end) / 2);
|
446 | let { x, w = 0 } = arr[mid];
|
447 | if (isRotated) {
|
448 | x = arr[mid].y;
|
449 | w = arr[mid].h;
|
450 | }
|
451 | if (v >= x && v <= x + w) {
|
452 | return mid;
|
453 | }
|
454 | return v < x ? findIndex(arr, v, start, mid - 1, isRotated) : findIndex(arr, v, mid + 1, end, isRotated);
|
455 | }
|
456 | function brushEmpty(ctx) {
|
457 | const selection = getBrushSelection(ctx);
|
458 | if (selection) {
|
459 | return selection[0] === selection[1];
|
460 | }
|
461 | return true;
|
462 | }
|
463 | function deepClone(...objectN) {
|
464 | const clone = (v) => {
|
465 | if (isObject(v) && v.constructor) {
|
466 | const r = new v.constructor();
|
467 | for (const k in v) {
|
468 | r[k] = clone(v[k]);
|
469 | }
|
470 | return r;
|
471 | }
|
472 | return v;
|
473 | };
|
474 | return objectN.map((v) => clone(v)).reduce((a, c) => util_spreadValues(util_spreadValues({}, a), c));
|
475 | }
|
476 | function extend(target = {}, source) {
|
477 | if (isArray(source)) {
|
478 | source.forEach((v) => extend(target, v));
|
479 | }
|
480 | for (const p in source) {
|
481 | if (/^\d+$/.test(p) || p in target) {
|
482 | continue;
|
483 | }
|
484 | target[p] = source[p];
|
485 | }
|
486 | return target;
|
487 | }
|
488 | const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
489 | function camelize(str, separator = "-") {
|
490 | return str.split(separator).map((v, i) => i ? v.charAt(0).toUpperCase() + v.slice(1).toLowerCase() : v.toLowerCase()).join("");
|
491 | }
|
492 | const toArray = (v) => [].slice.call(v);
|
493 | function addCssRules(style, selector, prop) {
|
494 | const { rootSelector = "", sheet } = style;
|
495 | const getSelector = (s) => s.replace(/\s?(bb-)/g, ".$1").replace(/\.+/g, ".");
|
496 | const rule = `${rootSelector} ${getSelector(selector)} {${prop.join(";")}}`;
|
497 | return sheet[sheet.insertRule ? "insertRule" : "addRule"](
|
498 | rule,
|
499 | sheet.cssRules.length
|
500 | );
|
501 | }
|
502 | function getCssRules(styleSheets) {
|
503 | let rules = [];
|
504 | styleSheets.forEach((sheet) => {
|
505 | var _a;
|
506 | try {
|
507 | if (sheet.cssRules && sheet.cssRules.length) {
|
508 | rules = rules.concat(toArray(sheet.cssRules));
|
509 | }
|
510 | } catch (e) {
|
511 | (_a = win.console) == null ? void 0 : _a.warn(`Error while reading rules from ${sheet.href}: ${e.toString()}`);
|
512 | }
|
513 | });
|
514 | return rules;
|
515 | }
|
516 | function getScrollPosition(node) {
|
517 | var _a, _b, _c, _d, _e, _f;
|
518 | return {
|
519 | x: ((_b = (_a = win.pageXOffset) != null ? _a : win.scrollX) != null ? _b : 0) + ((_c = node.scrollLeft) != null ? _c : 0),
|
520 | y: ((_e = (_d = win.pageYOffset) != null ? _d : win.scrollY) != null ? _e : 0) + ((_f = node.scrollTop) != null ? _f : 0)
|
521 | };
|
522 | }
|
523 | function getTransformCTM(node, x = 0, y = 0, inverse = true) {
|
524 | const point = new DOMPoint(x, y);
|
525 | const screen = node.getScreenCTM();
|
526 | const res = point.matrixTransform(
|
527 | inverse ? screen == null ? void 0 : screen.inverse() : screen
|
528 | );
|
529 | if (inverse === false) {
|
530 | const rect = node.getBoundingClientRect();
|
531 | res.x -= rect.x;
|
532 | res.y -= rect.y;
|
533 | }
|
534 | return res;
|
535 | }
|
536 | function getTranslation(node) {
|
537 | const transform = node ? node.transform : null;
|
538 | const baseVal = transform && transform.baseVal;
|
539 | return baseVal && baseVal.numberOfItems ? baseVal.getItem(0).matrix : { a: 0, b: 0, c: 0, d: 0, e: 0, f: 0 };
|
540 | }
|
541 | function getUnique(data) {
|
542 | const isDate = data[0] instanceof Date;
|
543 | const d = (isDate ? data.map(Number) : data).filter((v, i, self) => self.indexOf(v) === i);
|
544 | return isDate ? d.map((v) => new Date(v)) : d;
|
545 | }
|
546 | function mergeArray(arr) {
|
547 | return arr && arr.length ? arr.reduce((p, c) => p.concat(c)) : [];
|
548 | }
|
549 | function mergeObj(target, ...objectN) {
|
550 | if (!objectN.length || objectN.length === 1 && !objectN[0]) {
|
551 | return target;
|
552 | }
|
553 | const source = objectN.shift();
|
554 | if (isObject(target) && isObject(source)) {
|
555 | Object.keys(source).forEach((key) => {
|
556 | const value = source[key];
|
557 | if (isObject(value)) {
|
558 | !target[key] && (target[key] = {});
|
559 | target[key] = mergeObj(target[key], value);
|
560 | } else {
|
561 | target[key] = isArray(value) ? value.concat() : value;
|
562 | }
|
563 | });
|
564 | }
|
565 | return mergeObj(target, ...objectN);
|
566 | }
|
567 | function sortValue(data, isAsc = true) {
|
568 | let fn;
|
569 | if (data[0] instanceof Date) {
|
570 | fn = isAsc ? (a, b) => a - b : (a, b) => b - a;
|
571 | } else {
|
572 | if (isAsc && !data.every(isNaN)) {
|
573 | fn = (a, b) => a - b;
|
574 | } else if (!isAsc) {
|
575 | fn = (a, b) => a > b && -1 || a < b && 1 || a === b && 0;
|
576 | }
|
577 | }
|
578 | return data.concat().sort(fn);
|
579 | }
|
580 | function getMinMax(type, data) {
|
581 | let res = data.filter((v) => notEmpty(v));
|
582 | if (res.length) {
|
583 | if (isNumber(res[0])) {
|
584 | res = Math[type](...res);
|
585 | } else if (res[0] instanceof Date) {
|
586 | res = sortValue(res, type === "min")[0];
|
587 | }
|
588 | } else {
|
589 | res = void 0;
|
590 | }
|
591 | return res;
|
592 | }
|
593 | const getRange = (start, end, step = 1) => {
|
594 | const res = [];
|
595 | const n = Math.max(0, Math.ceil((end - start) / step)) | 0;
|
596 | for (let i = start; i < n; i++) {
|
597 | res.push(start + i * step);
|
598 | }
|
599 | return res;
|
600 | };
|
601 | const emulateEvent = {
|
602 | mouse: (() => {
|
603 | const getParams = () => ({
|
604 | bubbles: false,
|
605 | cancelable: false,
|
606 | screenX: 0,
|
607 | screenY: 0,
|
608 | clientX: 0,
|
609 | clientY: 0
|
610 | });
|
611 | try {
|
612 | new MouseEvent("t");
|
613 | return (el, eventType, params = getParams()) => {
|
614 | el.dispatchEvent(new MouseEvent(eventType, params));
|
615 | };
|
616 | } catch (e) {
|
617 | return (el, eventType, params = getParams()) => {
|
618 | const mouseEvent = doc.createEvent("MouseEvent");
|
619 | mouseEvent.initMouseEvent(
|
620 | eventType,
|
621 | params.bubbles,
|
622 | params.cancelable,
|
623 | win,
|
624 | 0,
|
625 |
|
626 | params.screenX,
|
627 | params.screenY,
|
628 | params.clientX,
|
629 | params.clientY,
|
630 | false,
|
631 | false,
|
632 | false,
|
633 | false,
|
634 | 0,
|
635 | null
|
636 | );
|
637 | el.dispatchEvent(mouseEvent);
|
638 | };
|
639 | }
|
640 | })(),
|
641 | touch: (el, eventType, params) => {
|
642 | const touchObj = new Touch(mergeObj({
|
643 | identifier: Date.now(),
|
644 | target: el,
|
645 | radiusX: 2.5,
|
646 | radiusY: 2.5,
|
647 | rotationAngle: 10,
|
648 | force: 0.5
|
649 | }, params));
|
650 | el.dispatchEvent(new TouchEvent(eventType, {
|
651 | cancelable: true,
|
652 | bubbles: true,
|
653 | shiftKey: true,
|
654 | touches: [touchObj],
|
655 | targetTouches: [],
|
656 | changedTouches: [touchObj]
|
657 | }));
|
658 | }
|
659 | };
|
660 | function tplProcess(tpl, data) {
|
661 | let res = tpl;
|
662 | for (const x in data) {
|
663 | res = res.replace(new RegExp(`{=${x}}`, "g"), data[x]);
|
664 | }
|
665 | return res;
|
666 | }
|
667 | function parseDate(date) {
|
668 | var _a;
|
669 | let parsedDate;
|
670 | if (date instanceof Date) {
|
671 | parsedDate = date;
|
672 | } else if (isString(date)) {
|
673 | const { config, format } = this;
|
674 | parsedDate = (_a = format.dataTime(config.data_xFormat)(date)) != null ? _a : new Date(date);
|
675 | } else if (isNumber(date) && !isNaN(date)) {
|
676 | parsedDate = new Date(+date);
|
677 | }
|
678 | if (!parsedDate || isNaN(+parsedDate)) {
|
679 | console && console.error && console.error(`Failed to parse x '${date}' to Date object`);
|
680 | }
|
681 | return parsedDate;
|
682 | }
|
683 | function hasViewBox(svg) {
|
684 | const attr = svg.attr("viewBox");
|
685 | return attr ? /(\d+(\.\d+)?){3}/.test(attr) : false;
|
686 | }
|
687 | function hasStyle(node, condition, all = false) {
|
688 | const isD3Node = !!node.node;
|
689 | let has = false;
|
690 | for (const [key, value] of Object.entries(condition)) {
|
691 | has = isD3Node ? node.style(key) === value : node.style[key] === value;
|
692 | if (all === false && has) {
|
693 | break;
|
694 | }
|
695 | }
|
696 | return has;
|
697 | }
|
698 | function isTabVisible() {
|
699 | var _a, _b;
|
700 | return ((_a = doc) == null ? void 0 : _a.hidden) === false || ((_b = doc) == null ? void 0 : _b.visibilityState) === "visible";
|
701 | }
|
702 | function convertInputType(mouse, touch) {
|
703 | const { DocumentTouch, matchMedia, navigator } = win;
|
704 | const hasPointerCoarse = matchMedia == null ? void 0 : matchMedia("(pointer:coarse)").matches;
|
705 | let hasTouch = false;
|
706 | if (touch) {
|
707 | if (navigator && "maxTouchPoints" in navigator) {
|
708 | hasTouch = navigator.maxTouchPoints > 0;
|
709 | } else if ("ontouchmove" in win || DocumentTouch && doc instanceof DocumentTouch) {
|
710 | hasTouch = true;
|
711 | } else {
|
712 | if (hasPointerCoarse) {
|
713 | hasTouch = true;
|
714 | } else {
|
715 | const UA = navigator.userAgent;
|
716 | hasTouch = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) || /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);
|
717 | }
|
718 | }
|
719 | }
|
720 | const hasMouse = mouse && !hasPointerCoarse && (matchMedia == null ? void 0 : matchMedia("(pointer:fine)").matches);
|
721 | return hasMouse && "mouse" || hasTouch && "touch" || "mouse";
|
722 | }
|
723 | function runUntil(fn, conditionFn) {
|
724 | if (conditionFn() === false) {
|
725 | requestAnimationFrame(() => runUntil(fn, conditionFn));
|
726 | } else {
|
727 | fn();
|
728 | }
|
729 | }
|
730 |
|
731 | ;
|
732 |
|
733 | function loadConfig(config) {
|
734 | const thisConfig = this.config;
|
735 | let target;
|
736 | let keys;
|
737 | let read;
|
738 | const find = () => {
|
739 | const key = keys.shift();
|
740 | if (key && target && isObjectType(target) && key in target) {
|
741 | target = target[key];
|
742 | return find();
|
743 | } else if (!key) {
|
744 | return target;
|
745 | }
|
746 | return void 0;
|
747 | };
|
748 | Object.keys(thisConfig).forEach((key) => {
|
749 | target = config;
|
750 | keys = key.split("_");
|
751 | read = find();
|
752 | if (isDefined(read)) {
|
753 | thisConfig[key] = read;
|
754 | }
|
755 | });
|
756 | if (this.api) {
|
757 | this.state.orgConfig = config;
|
758 | }
|
759 | }
|
760 |
|
761 | ;
|
762 | var Plugin_defProp = Object.defineProperty;
|
763 | var Plugin_defNormalProp = (obj, key, value) => key in obj ? Plugin_defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
764 | var __publicField = (obj, key, value) => Plugin_defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
765 | class Plugin {
|
766 | |
767 |
|
768 |
|
769 |
|
770 |
|
771 | constructor(options = {}) {
|
772 | __publicField(this, "$$");
|
773 | __publicField(this, "options");
|
774 | this.options = options;
|
775 | }
|
776 | |
777 |
|
778 |
|
779 |
|
780 | $beforeInit() {
|
781 | }
|
782 | |
783 |
|
784 |
|
785 |
|
786 | $init() {
|
787 | }
|
788 | |
789 |
|
790 |
|
791 |
|
792 | $afterInit() {
|
793 | }
|
794 | |
795 |
|
796 |
|
797 |
|
798 | $redraw() {
|
799 | }
|
800 | |
801 |
|
802 |
|
803 |
|
804 | $willDestroy() {
|
805 | Object.keys(this).forEach((key) => {
|
806 | this[key] = null;
|
807 | delete this[key];
|
808 | });
|
809 | }
|
810 | }
|
811 | __publicField(Plugin, "version", "3.14.2");
|
812 |
|
813 | ;
|
814 | class Options {
|
815 | constructor() {
|
816 | return {
|
817 | |
818 |
|
819 |
|
820 |
|
821 |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 | selector: void 0
|
828 | };
|
829 | }
|
830 | }
|
831 |
|
832 | ;
|
833 | var sparkline_defProp = Object.defineProperty;
|
834 | var sparkline_defNormalProp = (obj, key, value) => key in obj ? sparkline_defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
835 | var sparkline_publicField = (obj, key, value) => sparkline_defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
836 |
|
837 |
|
838 |
|
839 |
|
840 | class Sparkline extends Plugin {
|
841 | constructor(options) {
|
842 | super(options);
|
843 | sparkline_publicField(this, "config");
|
844 | sparkline_publicField(this, "element");
|
845 | this.config = new Options();
|
846 | return this;
|
847 | }
|
848 | $beforeInit() {
|
849 | loadConfig.call(this, this.options);
|
850 | this.validate();
|
851 | this.element = [].slice.call(document.querySelectorAll(this.config.selector));
|
852 | this.overrideInternals();
|
853 | this.overrideOptions();
|
854 | this.overHandler = this.overHandler.bind(this);
|
855 | this.moveHandler = this.moveHandler.bind(this);
|
856 | this.outHandler = this.outHandler.bind(this);
|
857 | }
|
858 | validate() {
|
859 | const { $$, config } = this;
|
860 | let msg = "";
|
861 | if (!config.selector || !document.querySelector(config.selector)) {
|
862 | msg = "No holder elements found from given selector option.";
|
863 | }
|
864 | if ($$.hasType("bubble") || $$.hasType("scatter") || $$.hasArcType($$.data.targets)) {
|
865 | msg = "Contains non supported chart types.";
|
866 | }
|
867 | if (msg) {
|
868 | throw new Error(`[Sparkline plugin] ${msg}`);
|
869 | }
|
870 | }
|
871 | overrideInternals() {
|
872 | const { $$ } = this;
|
873 | const { getBarW, getIndices } = $$;
|
874 | $$.getIndices = function(indices, d, caller) {
|
875 | return caller === "getShapeX" ? {} : getIndices.call(this, indices, d);
|
876 | };
|
877 | $$.getBarW = function(type, axis) {
|
878 | return getBarW.call(this, type, axis, 1);
|
879 | };
|
880 | }
|
881 | overrideOptions() {
|
882 | const { config } = this.$$;
|
883 | config.legend_show = false;
|
884 | config.resize_auto = false;
|
885 | config.axis_x_show = false;
|
886 | if (config.padding !== false) {
|
887 | const hasOption = (o) => Object.keys(o || {}).length > 0;
|
888 | if (hasOption(config.axis_x_padding)) {
|
889 | config.axis_x_padding = {
|
890 | left: 15,
|
891 | right: 15,
|
892 | unit: "px"
|
893 | };
|
894 | }
|
895 | if (hasOption(config.axis_y_padding)) {
|
896 | config.axis_y_padding = 5;
|
897 | }
|
898 | }
|
899 | config.axis_y_show = false;
|
900 | if (!config.tooltip_position) {
|
901 | config.tooltip_position = function(data, width, height) {
|
902 | const { internal: { state: { event } } } = this;
|
903 | let top = event.pageY - height * 1.35;
|
904 | let left = event.pageX - width / 2;
|
905 | if (top < 0) {
|
906 | top = 0;
|
907 | }
|
908 | if (left < 0) {
|
909 | left = 0;
|
910 | }
|
911 | return { top, left };
|
912 | };
|
913 | }
|
914 | }
|
915 | $init() {
|
916 | var _a;
|
917 | const { $$: { $el } } = this;
|
918 | $el.chart.style("width", "0").style("height", "0").style("pointer-events", "none");
|
919 | ((_a = $el.tooltip) == null ? void 0 : _a.node()) && document.body.appendChild($el.tooltip.node());
|
920 | }
|
921 | $afterInit() {
|
922 | const { $$ } = this;
|
923 | $$.$el.svg.attr("style", null).style("width", "0").style("height", "0");
|
924 | this.bindEvents(true);
|
925 | }
|
926 | |
927 |
|
928 |
|
929 |
|
930 |
|
931 | bindEvents(bind = true) {
|
932 | const { $$: { config } } = this;
|
933 | if (config.interaction_enabled && config.tooltip_show) {
|
934 | const method = `${bind ? "add" : "remove"}EventListener`;
|
935 | this.element.forEach((el) => {
|
936 | const svg = el.querySelector("svg");
|
937 | svg[method]("mouseover", this.overHandler);
|
938 | svg[method]("mousemove", this.moveHandler);
|
939 | svg[method]("mouseout", this.outHandler);
|
940 | });
|
941 | }
|
942 | }
|
943 | overHandler(e) {
|
944 | const { $$ } = this;
|
945 | const { state: { eventReceiver } } = $$;
|
946 | eventReceiver.rect = e.target.getBoundingClientRect();
|
947 | }
|
948 | moveHandler(e) {
|
949 | var _a, _b, _c, _d;
|
950 | const { $$ } = this;
|
951 | const index = $$.getDataIndexFromEvent(e);
|
952 | const data = (_a = $$.api.data(e.target.__id)) == null ? void 0 : _a[0];
|
953 | const d = (_b = data == null ? void 0 : data.values) == null ? void 0 : _b[index];
|
954 | if (d && !d.name) {
|
955 | d.name = d.id;
|
956 | }
|
957 | $$.state.event = e;
|
958 | if (((_c = $$.isPointFocusOnly) == null ? void 0 : _c.call($$)) && d) {
|
959 | (_d = $$.showCircleFocus) == null ? void 0 : _d.call($$, [d]);
|
960 | }
|
961 | $$.setExpand(index, data.id, true);
|
962 | $$.showTooltip([d], e.target);
|
963 | }
|
964 | outHandler(e) {
|
965 | const { $$ } = this;
|
966 | $$.state.event = e;
|
967 | $$.isPointFocusOnly() ? $$.hideCircleFocus() : $$.unexpandCircles();
|
968 | $$.hideTooltip();
|
969 | }
|
970 | $redraw() {
|
971 | var _a;
|
972 | const { $$ } = this;
|
973 | const { $el } = $$;
|
974 | let el = this.element;
|
975 | const data = $$.api.data();
|
976 | const svgWrapper = (_a = $el.chart.html().match(/<svg[^>]*>/)) == null ? void 0 : _a[0];
|
977 | if (el.length < data.length) {
|
978 | const chart = $el.chart.node();
|
979 | for (let i = data.length - el.length; i > 0; i--) {
|
980 | chart.parentNode.insertBefore(el[0].cloneNode(), chart.nextSibling);
|
981 | }
|
982 | this.element = document.querySelectorAll(this.config.selector);
|
983 | el = this.element;
|
984 | }
|
985 | data.map((v) => v.id).forEach((id, i) => {
|
986 | const selector = `.${$COMMON.target}-${id}`;
|
987 | const shape = $el.main.selectAll(selector);
|
988 | let svg = el[i].querySelector("svg");
|
989 | if (!svg) {
|
990 | el[i].innerHTML = `${svgWrapper}</svg>`;
|
991 | svg = el[i].querySelector("svg");
|
992 | svg.__id = id;
|
993 | }
|
994 | if (!svg.querySelector(selector)) {
|
995 | shape.style("opacity", null);
|
996 | }
|
997 | shape.style("fill", "none").style("opacity", null);
|
998 | svg.innerHTML = "";
|
999 | svg.appendChild(shape.node());
|
1000 | });
|
1001 | }
|
1002 | $willDestroy() {
|
1003 | this.bindEvents(false);
|
1004 | this.element.forEach((el) => {
|
1005 | el.innerHTML = "";
|
1006 | });
|
1007 | }
|
1008 | }
|
1009 | sparkline_publicField(Sparkline, "version", `0.0.1`);
|
1010 |
|
1011 | }();
|
1012 | __webpack_exports__ = __webpack_exports__["default"];
|
1013 | return __webpack_exports__;
|
1014 | })()
|
1015 | ;
|
1016 | }); |
\ | No newline at end of file |