UNPKG

31.9 kBJavaScriptView Raw
1/*!
2 * Copyright (c) 2017 ~ present NAVER Corp.
3 * billboard.js project is licensed under the MIT license
4 *
5 * billboard.js, JavaScript chart library
6 * https://naver.github.io/billboard.js/
7 *
8 * @version 3.14.2
9 * @requires billboard.js
10 * @summary billboard.js plugin
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__) {
22return /******/ (function() { // webpackBootstrap
23/******/ "use strict";
24/******/ var __webpack_modules__ = ([
25/* 0 */,
26/* 1 */
27/***/ (function(module) {
28
29module.exports = __WEBPACK_EXTERNAL_MODULE__1__;
30
31/***/ }),
32/* 2 */,
33/* 3 */
34/***/ (function(module) {
35
36module.exports = __WEBPACK_EXTERNAL_MODULE__3__;
37
38/***/ })
39/******/ ]);
40/************************************************************************/
41/******/ // The module cache
42/******/ var __webpack_module_cache__ = {};
43/******/
44/******/ // The require function
45/******/ function __webpack_require__(moduleId) {
46/******/ // Check if module is in cache
47/******/ var cachedModule = __webpack_module_cache__[moduleId];
48/******/ if (cachedModule !== undefined) {
49/******/ return cachedModule.exports;
50/******/ }
51/******/ // Create a new module (and put it into the cache)
52/******/ var module = __webpack_module_cache__[moduleId] = {
53/******/ // no module.id needed
54/******/ // no module.loaded needed
55/******/ exports: {}
56/******/ };
57/******/
58/******/ // Execute the module function
59/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
60/******/
61/******/ // Return the exports of the module
62/******/ return module.exports;
63/******/ }
64/******/
65/************************************************************************/
66/******/ /* webpack/runtime/define property getters */
67/******/ !function() {
68/******/ // define getter functions for harmony exports
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/******/ /* webpack/runtime/hasOwnProperty shorthand */
79/******/ !function() {
80/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
81/******/ }();
82/******/
83/************************************************************************/
84var __webpack_exports__ = {};
85// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
86!function() {
87
88// EXPORTS
89__webpack_require__.d(__webpack_exports__, {
90 "default": function() { return /* binding */ Sparkline; }
91});
92
93;// ./src/config/classes.ts
94var __defProp = Object.defineProperty;
95var __getOwnPropSymbols = Object.getOwnPropertySymbols;
96var __hasOwnProp = Object.prototype.hasOwnProperty;
97var __propIsEnum = Object.prototype.propertyIsEnumerable;
98var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
99var __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};
110const $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};
118const $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};
129const $AREA = {
130 area: "bb-area",
131 areas: "bb-areas"
132};
133const $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};
145const $BAR = {
146 bar: "bb-bar",
147 bars: "bb-bars",
148 chartBar: "bb-chart-bar",
149 chartBars: "bb-chart-bars"
150};
151const $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};
159const $CIRCLE = {
160 chartCircles: "bb-chart-circles",
161 circle: "bb-circle",
162 circles: "bb-circles"
163};
164const $COLOR = {
165 colorPattern: "bb-color-pattern",
166 colorScale: "bb-colorscale"
167};
168const $DRAG = {
169 dragarea: "bb-dragarea",
170 INCLUDED: "_included_"
171};
172const $FUNNEL = {
173 funnel: "bb-funnel",
174 chartFunnel: "bb-chart-funnel",
175 chartFunnels: "bb-chart-funnels",
176 funnelBackground: "bb-funnel-background"
177};
178const $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};
185const $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};
194const $LINE = {
195 chartLine: "bb-chart-line",
196 chartLines: "bb-chart-lines",
197 line: "bb-line",
198 lines: "bb-lines"
199};
200const $EVENT = {
201 eventRect: "bb-event-rect",
202 eventRects: "bb-event-rects",
203 eventRectsMultiple: "bb-event-rects-multiple",
204 eventRectsSingle: "bb-event-rects-single"
205};
206const $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};
213const $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};
225const $LEVEL = {
226 level: "bb-level",
227 levels: "bb-levels"
228};
229const $RADAR = {
230 chartRadar: "bb-chart-radar",
231 chartRadars: "bb-chart-radars"
232};
233const $REGION = {
234 region: "bb-region",
235 regions: "bb-regions"
236};
237const $SELECT = {
238 selectedCircle: "bb-selected-circle",
239 selectedCircles: "bb-selected-circles",
240 SELECTED: "_selected_"
241};
242const $SHAPE = {
243 shape: "bb-shape",
244 shapes: "bb-shapes"
245};
246const $SUBCHART = {
247 brush: "bb-brush",
248 subchart: "bb-subchart"
249};
250const $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};
258const $TOOLTIP = {
259 tooltip: "bb-tooltip",
260 tooltipContainer: "bb-tooltip-container",
261 tooltipName: "bb-tooltip-name"
262};
263const $TREEMAP = {
264 treemap: "bb-treemap",
265 chartTreemap: "bb-chart-treemap",
266 chartTreemaps: "bb-chart-treemaps"
267};
268const $ZOOM = {
269 buttonZoomReset: "bb-zoom-reset",
270 zoomBrush: "bb-zoom-brush"
271};
272/* harmony default export */ 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// EXTERNAL MODULE: external {"commonjs":"d3-brush","commonjs2":"d3-brush","amd":"d3-brush","root":"d3"}
275var external_commonjs_d3_brush_commonjs2_d3_brush_amd_d3_brush_root_d3_ = __webpack_require__(3);
276// EXTERNAL MODULE: external {"commonjs":"d3-selection","commonjs2":"d3-selection","amd":"d3-selection","root":"d3"}
277var external_commonjs_d3_selection_commonjs2_d3_selection_amd_d3_selection_root_d3_ = __webpack_require__(1);
278;// ./src/module/browser.ts
279function 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}
282function 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}
294const win = getGlobal();
295const doc = win == null ? void 0 : win.document;
296const [
297 requestAnimationFrame,
298 cancelAnimationFrame,
299 requestIdleCallback,
300 cancelIdleCallback
301] = getFallback(win);
302
303
304;// ./src/module/util.ts
305var util_defProp = Object.defineProperty;
306var util_getOwnPropSymbols = Object.getOwnPropertySymbols;
307var util_hasOwnProp = Object.prototype.hasOwnProperty;
308var util_propIsEnum = Object.prototype.propertyIsEnumerable;
309var util_defNormalProp = (obj, key, value) => key in obj ? util_defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
310var 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
325const isValue = (v) => v || v === 0;
326const isFunction = (v) => typeof v === "function";
327const isString = (v) => typeof v === "string";
328const isNumber = (v) => typeof v === "number";
329const isUndefined = (v) => typeof v === "undefined";
330const isDefined = (v) => typeof v !== "undefined";
331const isBoolean = (v) => typeof v === "boolean";
332const ceil10 = (v) => Math.ceil(v / 10) * 10;
333const asHalfPixel = (n) => Math.ceil(n) + 0.5;
334const diffDomain = (d) => d[1] - d[0];
335const isObjectType = (v) => typeof v === "object";
336const 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);
337const notEmpty = (o) => !isEmpty(o);
338const isArray = (arr) => Array.isArray(arr);
339const isObject = (obj) => obj && !(obj == null ? void 0 : obj.nodeType) && isObjectType(obj) && !isArray(obj);
340function getOption(options, key, defaultValue) {
341 return isDefined(options[key]) ? options[key] : defaultValue;
342}
343function hasValue(dict, value) {
344 let found = false;
345 Object.keys(dict).forEach((key) => dict[key] === value && (found = true));
346 return found;
347}
348function callFn(fn, thisArg, ...args) {
349 const isFn = isFunction(fn);
350 isFn && fn.call(thisArg, ...args);
351 return isFn;
352}
353function 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}
365function sanitize(str) {
366 return isString(str) ? str.replace(/<(script|img)?/ig, "&lt;").replace(/(script)?>/ig, "&gt;") : str;
367}
368function 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}
386function getRectSegList(path) {
387 const { x, y, width, height } = path.getBBox();
388 return [
389 { x, y: y + height },
390 // seg0
391 { x, y },
392 // seg1
393 { x: x + width, y },
394 // seg2
395 { x: x + width, y: y + height }
396 // seg3
397 ];
398}
399function 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}
411function 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}
421function 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}
432function 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}
436function 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}
441function 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}
456function brushEmpty(ctx) {
457 const selection = getBrushSelection(ctx);
458 if (selection) {
459 return selection[0] === selection[1];
460 }
461 return true;
462}
463function 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}
476function 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}
488const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
489function camelize(str, separator = "-") {
490 return str.split(separator).map((v, i) => i ? v.charAt(0).toUpperCase() + v.slice(1).toLowerCase() : v.toLowerCase()).join("");
491}
492const toArray = (v) => [].slice.call(v);
493function 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}
502function 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}
516function 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}
523function 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}
536function 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}
541function 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}
546function mergeArray(arr) {
547 return arr && arr.length ? arr.reduce((p, c) => p.concat(c)) : [];
548}
549function 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}
567function 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}
580function 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}
593const 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};
601const 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 // the event's mouse click count
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};
660function 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}
667function 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 = /* @__PURE__ */ 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}
683function hasViewBox(svg) {
684 const attr = svg.attr("viewBox");
685 return attr ? /(\d+(\.\d+)?){3}/.test(attr) : false;
686}
687function 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}
698function isTabVisible() {
699 var _a, _b;
700 return ((_a = doc) == null ? void 0 : _a.hidden) === false || ((_b = doc) == null ? void 0 : _b.visibilityState) === "visible";
701}
702function 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}
723function runUntil(fn, conditionFn) {
724 if (conditionFn() === false) {
725 requestAnimationFrame(() => runUntil(fn, conditionFn));
726 } else {
727 fn();
728 }
729}
730
731;// ./src/config/config.ts
732
733function 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;// ./src/Plugin/Plugin.ts
762var Plugin_defProp = Object.defineProperty;
763var Plugin_defNormalProp = (obj, key, value) => key in obj ? Plugin_defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
764var __publicField = (obj, key, value) => Plugin_defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
765class Plugin {
766 /**
767 * Constructor
768 * @param {Any} options config option object
769 * @private
770 */
771 constructor(options = {}) {
772 __publicField(this, "$$");
773 __publicField(this, "options");
774 this.options = options;
775 }
776 /**
777 * Lifecycle hook for 'beforeInit' phase.
778 * @private
779 */
780 $beforeInit() {
781 }
782 /**
783 * Lifecycle hook for 'init' phase.
784 * @private
785 */
786 $init() {
787 }
788 /**
789 * Lifecycle hook for 'afterInit' phase.
790 * @private
791 */
792 $afterInit() {
793 }
794 /**
795 * Lifecycle hook for 'redraw' phase.
796 * @private
797 */
798 $redraw() {
799 }
800 /**
801 * Lifecycle hook for 'willDestroy' phase.
802 * @private
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;// ./src/Plugin/sparkline/Options.ts
814class Options {
815 constructor() {
816 return {
817 /**
818 * Specify sparkline charts holder selector.
819 * - **NOTE:** The amount of holder should match with the amount of data. If has less, will append necessaray amount nodes as sibling of main chart.
820 * @name selector
821 * @memberof plugin-sparkline
822 * @type {string}
823 * @default undefined
824 * @example
825 * selector: ".sparkline"
826 */
827 selector: void 0
828 };
829 }
830}
831
832;// ./src/Plugin/sparkline/index.ts
833var sparkline_defProp = Object.defineProperty;
834var sparkline_defNormalProp = (obj, key, value) => key in obj ? sparkline_defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
835var sparkline_publicField = (obj, key, value) => sparkline_defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
836
837
838
839
840class 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 * Bind tooltip event handlers for each sparkline elements.
928 * @param {boolean} bind or unbind
929 * @private
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}
1009sparkline_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