UNPKG

58 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.2.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-interpolate"), require("d3-color"), require("d3-scale"), require("d3-selection"), require("d3-brush"), require("d3-axis"), require("d3-format"));
15 else if(typeof define === 'function' && define.amd)
16 define("bb", ["d3-interpolate", "d3-color", "d3-scale", "d3-selection", "d3-brush", "d3-axis", "d3-format"], factory);
17 else if(typeof exports === 'object')
18 exports["bb"] = factory(require("d3-interpolate"), require("d3-color"), require("d3-scale"), require("d3-selection"), require("d3-brush"), require("d3-axis"), require("d3-format"));
19 else
20 root["bb"] = root["bb"] || {}, root["bb"]["plugin"] = root["bb"]["plugin"] || {}, root["bb"]["plugin"]["stanford"] = factory(root["d3"], root["d3"], root["d3"], root["d3"], root["d3"], root["d3"], root["d3"]);
21})(this, function(__WEBPACK_EXTERNAL_MODULE__5__, __WEBPACK_EXTERNAL_MODULE__6__, __WEBPACK_EXTERNAL_MODULE__7__, __WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__3__, __WEBPACK_EXTERNAL_MODULE__8__, __WEBPACK_EXTERNAL_MODULE__9__) {
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/* 4 */,
40/* 5 */
41/***/ (function(module) {
42
43module.exports = __WEBPACK_EXTERNAL_MODULE__5__;
44
45/***/ }),
46/* 6 */
47/***/ (function(module) {
48
49module.exports = __WEBPACK_EXTERNAL_MODULE__6__;
50
51/***/ }),
52/* 7 */
53/***/ (function(module) {
54
55module.exports = __WEBPACK_EXTERNAL_MODULE__7__;
56
57/***/ }),
58/* 8 */
59/***/ (function(module) {
60
61module.exports = __WEBPACK_EXTERNAL_MODULE__8__;
62
63/***/ }),
64/* 9 */
65/***/ (function(module) {
66
67module.exports = __WEBPACK_EXTERNAL_MODULE__9__;
68
69/***/ })
70/******/ ]);
71/************************************************************************/
72/******/ // The module cache
73/******/ var __webpack_module_cache__ = {};
74/******/
75/******/ // The require function
76/******/ function __webpack_require__(moduleId) {
77/******/ // Check if module is in cache
78/******/ var cachedModule = __webpack_module_cache__[moduleId];
79/******/ if (cachedModule !== undefined) {
80/******/ return cachedModule.exports;
81/******/ }
82/******/ // Create a new module (and put it into the cache)
83/******/ var module = __webpack_module_cache__[moduleId] = {
84/******/ // no module.id needed
85/******/ // no module.loaded needed
86/******/ exports: {}
87/******/ };
88/******/
89/******/ // Execute the module function
90/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
91/******/
92/******/ // Return the exports of the module
93/******/ return module.exports;
94/******/ }
95/******/
96/************************************************************************/
97/******/ /* webpack/runtime/define property getters */
98/******/ !function() {
99/******/ // define getter functions for harmony exports
100/******/ __webpack_require__.d = function(exports, definition) {
101/******/ for(var key in definition) {
102/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
103/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
104/******/ }
105/******/ }
106/******/ };
107/******/ }();
108/******/
109/******/ /* webpack/runtime/hasOwnProperty shorthand */
110/******/ !function() {
111/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
112/******/ }();
113/******/
114/************************************************************************/
115var __webpack_exports__ = {};
116// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
117!function() {
118
119// EXPORTS
120__webpack_require__.d(__webpack_exports__, {
121 "default": function() { return /* binding */ Stanford; }
122});
123
124;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js
125function _assertThisInitialized(self) {
126 if (self === void 0) {
127 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
128 }
129
130 return self;
131}
132;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js
133function _setPrototypeOf(o, p) {
134 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
135 o.__proto__ = p;
136 return o;
137 };
138
139 return _setPrototypeOf(o, p);
140}
141;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js
142
143function _inheritsLoose(subClass, superClass) {
144 subClass.prototype = Object.create(superClass.prototype);
145 subClass.prototype.constructor = subClass;
146 _setPrototypeOf(subClass, superClass);
147}
148// EXTERNAL MODULE: external {"commonjs":"d3-interpolate","commonjs2":"d3-interpolate","amd":"d3-interpolate","root":"d3"}
149var external_commonjs_d3_interpolate_commonjs2_d3_interpolate_amd_d3_interpolate_root_d3_ = __webpack_require__(5);
150// EXTERNAL MODULE: external {"commonjs":"d3-color","commonjs2":"d3-color","amd":"d3-color","root":"d3"}
151var external_commonjs_d3_color_commonjs2_d3_color_amd_d3_color_root_d3_ = __webpack_require__(6);
152// EXTERNAL MODULE: external {"commonjs":"d3-scale","commonjs2":"d3-scale","amd":"d3-scale","root":"d3"}
153var external_commonjs_d3_scale_commonjs2_d3_scale_amd_d3_scale_root_d3_ = __webpack_require__(7);
154;// CONCATENATED MODULE: ./src/config/classes.ts
155/**
156 * Copyright (c) 2017 ~ present NAVER Corp.
157 * billboard.js project is licensed under the MIT license
158 */
159
160/**
161 * CSS class names definition
162 * @private
163 */
164/* harmony default export */ var classes = ({
165 arc: "bb-arc",
166 arcLabelLine: "bb-arc-label-line",
167 arcs: "bb-arcs",
168 area: "bb-area",
169 areas: "bb-areas",
170 axis: "bb-axis",
171 axisX: "bb-axis-x",
172 axisXLabel: "bb-axis-x-label",
173 axisY: "bb-axis-y",
174 axisY2: "bb-axis-y2",
175 axisY2Label: "bb-axis-y2-label",
176 axisYLabel: "bb-axis-y-label",
177 bar: "bb-bar",
178 bars: "bb-bars",
179 brush: "bb-brush",
180 button: "bb-button",
181 buttonZoomReset: "bb-zoom-reset",
182 candlestick: "bb-candlestick",
183 candlesticks: "bb-candlesticks",
184 chart: "bb-chart",
185 chartArc: "bb-chart-arc",
186 chartArcs: "bb-chart-arcs",
187 chartArcsBackground: "bb-chart-arcs-background",
188 chartArcsGaugeMax: "bb-chart-arcs-gauge-max",
189 chartArcsGaugeMin: "bb-chart-arcs-gauge-min",
190 chartArcsGaugeUnit: "bb-chart-arcs-gauge-unit",
191 chartArcsTitle: "bb-chart-arcs-title",
192 chartArcsGaugeTitle: "bb-chart-arcs-gauge-title",
193 chartBar: "bb-chart-bar",
194 chartBars: "bb-chart-bars",
195 chartCandlestick: "bb-chart-candlestick",
196 chartCandlesticks: "bb-chart-candlesticks",
197 chartCircles: "bb-chart-circles",
198 chartLine: "bb-chart-line",
199 chartLines: "bb-chart-lines",
200 chartRadar: "bb-chart-radar",
201 chartRadars: "bb-chart-radars",
202 chartText: "bb-chart-text",
203 chartTexts: "bb-chart-texts",
204 circle: "bb-circle",
205 circles: "bb-circles",
206 colorPattern: "bb-color-pattern",
207 colorScale: "bb-colorscale",
208 defocused: "bb-defocused",
209 dragarea: "bb-dragarea",
210 empty: "bb-empty",
211 eventRect: "bb-event-rect",
212 eventRects: "bb-event-rects",
213 eventRectsMultiple: "bb-event-rects-multiple",
214 eventRectsSingle: "bb-event-rects-single",
215 focused: "bb-focused",
216 gaugeValue: "bb-gauge-value",
217 grid: "bb-grid",
218 gridLines: "bb-grid-lines",
219 legend: "bb-legend",
220 legendBackground: "bb-legend-background",
221 legendItem: "bb-legend-item",
222 legendItemEvent: "bb-legend-item-event",
223 legendItemFocused: "bb-legend-item-focused",
224 legendItemHidden: "bb-legend-item-hidden",
225 legendItemPoint: "bb-legend-item-point",
226 legendItemTile: "bb-legend-item-tile",
227 level: "bb-level",
228 levels: "bb-levels",
229 line: "bb-line",
230 lines: "bb-lines",
231 main: "bb-main",
232 region: "bb-region",
233 regions: "bb-regions",
234 selectedCircle: "bb-selected-circle",
235 selectedCircles: "bb-selected-circles",
236 shape: "bb-shape",
237 shapes: "bb-shapes",
238 stanfordElements: "bb-stanford-elements",
239 stanfordLine: "bb-stanford-line",
240 stanfordLines: "bb-stanford-lines",
241 stanfordRegion: "bb-stanford-region",
242 stanfordRegions: "bb-stanford-regions",
243 subchart: "bb-subchart",
244 target: "bb-target",
245 text: "bb-text",
246 texts: "bb-texts",
247 title: "bb-title",
248 tooltip: "bb-tooltip",
249 tooltipContainer: "bb-tooltip-container",
250 tooltipName: "bb-tooltip-name",
251 valueDown: "bb-value-down",
252 valueUp: "bb-value-up",
253 xgrid: "bb-xgrid",
254 xgridFocus: "bb-xgrid-focus",
255 xgridLine: "bb-xgrid-line",
256 xgridLines: "bb-xgrid-lines",
257 xgrids: "bb-xgrids",
258 ygrid: "bb-ygrid",
259 ygridFocus: "bb-ygrid-focus",
260 ygridLine: "bb-ygrid-line",
261 ygridLines: "bb-ygrid-lines",
262 ygrids: "bb-ygrids",
263 zoomBrush: "bb-zoom-brush",
264 EXPANDED: "_expanded_",
265 SELECTED: "_selected_",
266 INCLUDED: "_included_",
267 TextOverlapping: "text-overlapping"
268});
269;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js
270function _defineProperty(obj, key, value) {
271 if (key in obj) {
272 Object.defineProperty(obj, key, {
273 value: value,
274 enumerable: true,
275 configurable: true,
276 writable: true
277 });
278 } else {
279 obj[key] = value;
280 }
281
282 return obj;
283}
284// EXTERNAL MODULE: external {"commonjs":"d3-selection","commonjs2":"d3-selection","amd":"d3-selection","root":"d3"}
285var external_commonjs_d3_selection_commonjs2_d3_selection_amd_d3_selection_root_d3_ = __webpack_require__(1);
286// EXTERNAL MODULE: external {"commonjs":"d3-brush","commonjs2":"d3-brush","amd":"d3-brush","root":"d3"}
287var external_commonjs_d3_brush_commonjs2_d3_brush_amd_d3_brush_root_d3_ = __webpack_require__(3);
288;// CONCATENATED MODULE: ./src/module/browser.ts
289/**
290 * Copyright (c) 2017 ~ present NAVER Corp.
291 * billboard.js project is licensed under the MIT license
292 */
293
294/**
295 * Window object
296 * @private
297 */
298
299/* eslint-disable no-new-func, no-undef */
300
301
302var win = function () {
303 var root = 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;
304 return root || Function("return this")();
305}();
306/* eslint-enable no-new-func, no-undef */
307// fallback for non-supported environments
308
309
310win.requestIdleCallback = win.requestIdleCallback || function (cb) {
311 return setTimeout(cb, 1);
312};
313
314win.cancelIdleCallback = win.cancelIdleCallback || function (id) {
315 return clearTimeout(id);
316};
317
318var doc = win == null ? void 0 : win.document;
319;// CONCATENATED MODULE: ./src/module/util.ts
320
321
322function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
323
324function _objectSpread(target) { for (var i = 1, source; i < arguments.length; i++) { source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
325
326/**
327 * Copyright (c) 2017 ~ present NAVER Corp.
328 * billboard.js project is licensed under the MIT license
329 * @ignore
330 */
331
332
333
334
335
336
337var isValue = function (v) {
338 return v || v === 0;
339},
340 isFunction = function (v) {
341 return typeof v === "function";
342},
343 isString = function (v) {
344 return typeof v === "string";
345},
346 isNumber = function (v) {
347 return typeof v === "number";
348},
349 isUndefined = function (v) {
350 return typeof v === "undefined";
351},
352 isDefined = function (v) {
353 return typeof v !== "undefined";
354},
355 isboolean = function (v) {
356 return typeof v === "boolean";
357},
358 ceil10 = function (v) {
359 return Math.ceil(v / 10) * 10;
360},
361 asHalfPixel = function (n) {
362 return Math.ceil(n) + .5;
363},
364 diffDomain = function (d) {
365 return d[1] - d[0];
366},
367 isObjectType = function (v) {
368 return typeof v === "object";
369},
370 isEmpty = function (o) {
371 return isUndefined(o) || o === null || isString(o) && o.length === 0 || isObjectType(o) && !(o instanceof Date) && Object.keys(o).length === 0 || isNumber(o) && isNaN(o);
372},
373 notEmpty = function (o) {
374 return !isEmpty(o);
375},
376 isArray = function (arr) {
377 return Array.isArray(arr);
378},
379 isObject = function (obj) {
380 return obj && !(obj != null && obj.nodeType) && isObjectType(obj) && !isArray(obj);
381};
382
383/**
384 * Get specified key value from object
385 * If default value is given, will return if given key value not found
386 * @param {object} options Source object
387 * @param {string} key Key value
388 * @param {*} defaultValue Default value
389 * @returns {*}
390 * @private
391 */
392function getOption(options, key, defaultValue) {
393 return isDefined(options[key]) ? options[key] : defaultValue;
394}
395/**
396 * Check if value exist in the given object
397 * @param {object} dict Target object to be checked
398 * @param {*} value Value to be checked
399 * @returns {boolean}
400 * @private
401 */
402
403
404function hasValue(dict, value) {
405 var found = !1;
406 Object.keys(dict).forEach(function (key) {
407 return dict[key] === value && (found = !0);
408 });
409 return found;
410}
411/**
412 * Call function with arguments
413 * @param {Function} fn Function to be called
414 * @param {*} args Arguments
415 * @returns {boolean} true: fn is function, false: fn is not function
416 * @private
417 */
418
419
420function callFn(fn) {
421 for (var isFn = isFunction(fn), _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
422 args[_key - 1] = arguments[_key];
423 }
424
425 isFn && fn.call.apply(fn, args);
426 return isFn;
427}
428/**
429 * Call function after all transitions ends
430 * @param {d3.transition} transition Transition
431 * @param {Fucntion} cb Callback function
432 * @private
433 */
434
435
436function endall(transition, cb) {
437 var n = 0,
438 end = function () {
439 for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
440 args[_key2] = arguments[_key2];
441 }
442
443 --n || cb.apply.apply(cb, [this].concat(args));
444 };
445
446 // if is transition selection
447 if ("duration" in transition) {
448 transition.each(function () {
449 return ++n;
450 }).on("end", end);
451 } else {
452 ++n;
453 transition.call(end);
454 }
455}
456/**
457 * Replace tag sign to html entity
458 * @param {string} str Target string value
459 * @returns {string}
460 * @private
461 */
462
463
464function sanitise(str) {
465 return isString(str) ? str.replace(/</g, "&lt;").replace(/>/g, "&gt;") : str;
466}
467/**
468 * Set text value. If there's multiline add nodes.
469 * @param {d3Selection} node Text node
470 * @param {string} text Text value string
471 * @param {Array} dy dy value for multilined text
472 * @param {boolean} toMiddle To be alingned vertically middle
473 * @private
474 */
475
476
477function setTextValue(node, text, dy, toMiddle) {
478 if (dy === void 0) {
479 dy = [-1, 1];
480 }
481
482 if (toMiddle === void 0) {
483 toMiddle = !1;
484 }
485
486 if (!node || !isString(text)) {
487 return;
488 }
489
490 if (text.indexOf("\n") === -1) {
491 node.text(text);
492 } else {
493 var diff = [node.text(), text].map(function (v) {
494 return v.replace(/[\s\n]/g, "");
495 });
496
497 if (diff[0] !== diff[1]) {
498 var multiline = text.split("\n"),
499 len = toMiddle ? multiline.length - 1 : 1;
500 // reset possible text
501 node.html("");
502 multiline.forEach(function (v, i) {
503 node.append("tspan").attr("x", 0).attr("dy", (i === 0 ? dy[0] * len : dy[1]) + "em").text(v);
504 });
505 }
506 }
507}
508/**
509 * Substitution of SVGPathSeg API polyfill
510 * @param {SVGGraphicsElement} path Target svg element
511 * @returns {Array}
512 * @private
513 */
514
515
516function getRectSegList(path) {
517 /*
518 * seg1 ---------- seg2
519 * | |
520 * | |
521 * | |
522 * seg0 ---------- seg3
523 * */
524 var _path$getBBox = path.getBBox(),
525 x = _path$getBBox.x,
526 y = _path$getBBox.y,
527 width = _path$getBBox.width,
528 height = _path$getBBox.height;
529
530 return [{
531 x: x,
532 y: y + height
533 }, // seg0
534 {
535 x: x,
536 y: y
537 }, // seg1
538 {
539 x: x + width,
540 y: y
541 }, // seg2
542 {
543 x: x + width,
544 y: y + height
545 } // seg3
546 ];
547}
548/**
549 * Get svg bounding path box dimension
550 * @param {SVGGraphicsElement} path Target svg element
551 * @returns {object}
552 * @private
553 */
554
555
556function getPathBox(path) {
557 var _path$getBoundingClie = path.getBoundingClientRect(),
558 width = _path$getBoundingClie.width,
559 height = _path$getBoundingClie.height,
560 items = getRectSegList(path),
561 x = items[0].x,
562 y = Math.min(items[0].y, items[1].y);
563
564 return {
565 x: x,
566 y: y,
567 width: width,
568 height: height
569 };
570}
571/**
572 * Get event's current position coordinates
573 * @param {object} event Event object
574 * @param {SVGElement|HTMLElement} element Target element
575 * @returns {Array} [x, y] Coordinates x, y array
576 * @private
577 */
578
579
580function getPointer(event, element) {
581 var _ref,
582 touches = event && ((_ref = event.touches || event.sourceEvent && event.sourceEvent.touches) == null ? void 0 : _ref[0]),
583 pointer = (0,external_commonjs_d3_selection_commonjs2_d3_selection_amd_d3_selection_root_d3_.pointer)(touches || event, element);
584
585 return pointer.map(function (v) {
586 return isNaN(v) ? 0 : v;
587 });
588}
589/**
590 * Return brush selection array
591 * @param {object} ctx Current instance
592 * @returns {d3.brushSelection}
593 * @private
594 */
595
596
597function getBrushSelection(ctx) {
598 var event = ctx.event,
599 $el = ctx.$el,
600 main = $el.subchart.main || $el.main,
601 selection;
602
603 // check from event
604 if (event && event.type === "brush") {
605 selection = event.selection; // check from brush area selection
606 } else if (main && (selection = main.select("." + classes.brush).node())) {
607 selection = (0,external_commonjs_d3_brush_commonjs2_d3_brush_amd_d3_brush_root_d3_.brushSelection)(selection);
608 }
609
610 return selection;
611}
612/**
613 * Get boundingClientRect.
614 * Cache the evaluated value once it was called.
615 * @param {HTMLElement} node Target element
616 * @returns {object}
617 * @private
618 */
619
620
621function getBoundingRect(node) {
622 var needEvaluate = !("rect" in node) || "rect" in node && node.hasAttribute("width") && node.rect.width !== +node.getAttribute("width");
623 return needEvaluate ? node.rect = node.getBoundingClientRect() : node.rect;
624}
625/**
626 * Retrun random number
627 * @param {boolean} asStr Convert returned value as string
628 * @returns {number|string}
629 * @private
630 */
631
632
633function getRandom(asStr) {
634 if (asStr === void 0) {
635 asStr = !0;
636 }
637
638 var rand = Math.random();
639 return asStr ? rand + "" : rand;
640}
641/**
642 * Find index based on binary search
643 * @param {Array} arr Data array
644 * @param {number} v Target number to find
645 * @param {number} start Start index of data array
646 * @param {number} end End index of data arr
647 * @param {boolean} isRotated Weather is roted axis
648 * @returns {number} Index number
649 * @private
650 */
651
652
653function findIndex(arr, v, start, end, isRotated) {
654 if (start > end) {
655 return -1;
656 }
657
658 var mid = Math.floor((start + end) / 2),
659 _arr$mid = arr[mid],
660 x = _arr$mid.x,
661 _arr$mid$w = _arr$mid.w,
662 w = _arr$mid$w === void 0 ? 0 : _arr$mid$w;
663
664 if (isRotated) {
665 x = arr[mid].y;
666 w = arr[mid].h;
667 }
668
669 if (v >= x && v <= x + w) {
670 return mid;
671 }
672
673 return v < x ? findIndex(arr, v, start, mid - 1, isRotated) : findIndex(arr, v, mid + 1, end, isRotated);
674}
675/**
676 * Check if brush is empty
677 * @param {object} ctx Bursh context
678 * @returns {boolean}
679 * @private
680 */
681
682
683function brushEmpty(ctx) {
684 var selection = getBrushSelection(ctx);
685
686 if (selection) {
687 // brush selected area
688 // two-dimensional: [[x0, y0], [x1, y1]]
689 // one-dimensional: [x0, x1] or [y0, y1]
690 return selection[0] === selection[1];
691 }
692
693 return !0;
694}
695/**
696 * Deep copy object
697 * @param {object} objectN Source object
698 * @returns {object} Cloned object
699 * @private
700 */
701
702
703function deepClone() {
704 for (var clone = function (v) {
705 if (isObject(v) && v.constructor) {
706 var r = new v.constructor();
707
708 for (var k in v) {
709 r[k] = clone(v[k]);
710 }
711
712 return r;
713 }
714
715 return v;
716 }, _len3 = arguments.length, objectN = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
717 objectN[_key3] = arguments[_key3];
718 }
719
720 return objectN.map(function (v) {
721 return clone(v);
722 }).reduce(function (a, c) {
723 return _objectSpread(_objectSpread({}, a), c);
724 });
725}
726/**
727 * Extend target from source object
728 * @param {object} target Target object
729 * @param {object|Array} source Source object
730 * @returns {object}
731 * @private
732 */
733
734
735function extend(target, source) {
736 if (target === void 0) {
737 target = {};
738 }
739
740 if (isArray(source)) {
741 source.forEach(function (v) {
742 return extend(target, v);
743 });
744 } // exclude name with only numbers
745
746
747 for (var p in source) {
748 if (/^\d+$/.test(p) || p in target) {
749 continue;
750 }
751
752 target[p] = source[p];
753 }
754
755 return target;
756}
757/**
758 * Return first letter capitalized
759 * @param {string} str Target string
760 * @returns {string} capitalized string
761 * @private
762 */
763
764
765var capitalize = function (str) {
766 return str.charAt(0).toUpperCase() + str.slice(1);
767};
768/**
769 * Camelize from kebob style string
770 * @param {string} str Target string
771 * @param {string} separator Separator string
772 * @returns {string} camelized string
773 * @private
774 */
775
776
777function camelize(str, separator) {
778 if (separator === void 0) {
779 separator = "-";
780 }
781
782 return str.split(separator).map(function (v, i) {
783 return i ? v.charAt(0).toUpperCase() + v.slice(1).toLowerCase() : v.toLowerCase();
784 }).join("");
785}
786/**
787 * Convert to array
788 * @param {object} v Target to be converted
789 * @returns {Array}
790 * @private
791 */
792
793
794var toArray = function (v) {
795 return [].slice.call(v);
796};
797/**
798 * Get css rules for specified stylesheets
799 * @param {Array} styleSheets The stylesheets to get the rules from
800 * @returns {Array}
801 * @private
802 */
803
804
805function getCssRules(styleSheets) {
806 var rules = [];
807 styleSheets.forEach(function (sheet) {
808 try {
809 if (sheet.cssRules && sheet.cssRules.length) {
810 rules = rules.concat(toArray(sheet.cssRules));
811 }
812 } catch (e) {
813 console.error("Error while reading rules from " + sheet.href + ": " + e.toString());
814 }
815 });
816 return rules;
817}
818/**
819 * Gets the SVGMatrix of an SVGGElement
820 * @param {SVGElement} node Node element
821 * @returns {SVGMatrix} matrix
822 * @private
823 */
824
825
826function getTranslation(node) {
827 var transform = node ? node.transform : null,
828 baseVal = transform && transform.baseVal;
829 return baseVal && baseVal.numberOfItems ? baseVal.getItem(0).matrix : {
830 a: 0,
831 b: 0,
832 c: 0,
833 d: 0,
834 e: 0,
835 f: 0
836 };
837}
838/**
839 * Get unique value from array
840 * @param {Array} data Source data
841 * @returns {Array} Unique array value
842 * @private
843 */
844
845
846function getUnique(data) {
847 var isDate = data[0] instanceof Date,
848 d = (isDate ? data.map(Number) : data).filter(function (v, i, self) {
849 return self.indexOf(v) === i;
850 });
851 return isDate ? d.map(function (v) {
852 return new Date(v);
853 }) : d;
854}
855/**
856 * Merge array
857 * @param {Array} arr Source array
858 * @returns {Array}
859 * @private
860 */
861
862
863function mergeArray(arr) {
864 return arr && arr.length ? arr.reduce(function (p, c) {
865 return p.concat(c);
866 }) : [];
867}
868/**
869 * Merge object returning new object
870 * @param {object} target Target object
871 * @param {object} objectN Source object
872 * @returns {object} merged target object
873 * @private
874 */
875
876
877function mergeObj(target) {
878 for (var _len4 = arguments.length, objectN = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
879 objectN[_key4 - 1] = arguments[_key4];
880 }
881
882 if (!objectN.length || objectN.length === 1 && !objectN[0]) {
883 return target;
884 }
885
886 var source = objectN.shift();
887
888 if (isObject(target) && isObject(source)) {
889 Object.keys(source).forEach(function (key) {
890 var value = source[key];
891
892 if (isObject(value)) {
893 target[key] || (target[key] = {});
894 target[key] = mergeObj(target[key], value);
895 } else {
896 target[key] = isArray(value) ? value.concat() : value;
897 }
898 });
899 }
900
901 return mergeObj.apply(void 0, [target].concat(objectN));
902}
903/**
904 * Sort value
905 * @param {Array} data value to be sorted
906 * @param {boolean} isAsc true: asc, false: desc
907 * @returns {number|string|Date} sorted date
908 * @private
909 */
910
911
912function sortValue(data, isAsc) {
913 if (isAsc === void 0) {
914 isAsc = !0;
915 }
916
917 var fn;
918
919 if (data[0] instanceof Date) {
920 fn = isAsc ? function (a, b) {
921 return a - b;
922 } : function (a, b) {
923 return b - a;
924 };
925 } else {
926 if (isAsc && !data.every(isNaN)) {
927 fn = function (a, b) {
928 return a - b;
929 };
930 } else if (!isAsc) {
931 fn = function (a, b) {
932 return a > b && -1 || a < b && 1 || a === b && 0;
933 };
934 }
935 }
936
937 return data.concat().sort(fn);
938}
939/**
940 * Get min/max value
941 * @param {string} type 'min' or 'max'
942 * @param {Array} data Array data value
943 * @returns {number|Date|undefined}
944 * @private
945 */
946
947
948function getMinMax(type, data) {
949 var res = data.filter(function (v) {
950 return notEmpty(v);
951 });
952
953 if (res.length) {
954 if (isNumber(res[0])) {
955 res = Math[type].apply(Math, res);
956 } else if (res[0] instanceof Date) {
957 res = sortValue(res, type === "min")[0];
958 }
959 } else {
960 res = undefined;
961 }
962
963 return res;
964}
965/**
966 * Get range
967 * @param {number} start Start number
968 * @param {number} end End number
969 * @param {number} step Step number
970 * @returns {Array}
971 * @private
972 */
973
974
975var getRange = function (start, end, step) {
976 if (step === void 0) {
977 step = 1;
978 }
979
980 var res = [],
981 n = Math.max(0, Math.ceil((end - start) / step)) | 0;
982
983 for (var i = start; i < n; i++) {
984 res.push(start + i * step);
985 }
986
987 return res;
988},
989 emulateEvent = {
990 mouse: function () {
991 var getParams = function () {
992 return {
993 bubbles: !1,
994 cancelable: !1,
995 screenX: 0,
996 screenY: 0,
997 clientX: 0,
998 clientY: 0
999 };
1000 };
1001
1002 try {
1003 // eslint-disable-next-line no-new
1004 new MouseEvent("t");
1005 return function (el, eventType, params) {
1006 if (params === void 0) {
1007 params = getParams();
1008 }
1009
1010 el.dispatchEvent(new MouseEvent(eventType, params));
1011 };
1012 } catch (e) {
1013 // Polyfills DOM4 MouseEvent
1014 return function (el, eventType, params) {
1015 if (params === void 0) {
1016 params = getParams();
1017 }
1018
1019 var mouseEvent = doc.createEvent("MouseEvent"); // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/initMouseEvent
1020
1021 mouseEvent.initMouseEvent(eventType, params.bubbles, params.cancelable, win, 0, // the event's mouse click count
1022 params.screenX, params.screenY, params.clientX, params.clientY, !1, !1, !1, !1, 0, null);
1023 el.dispatchEvent(mouseEvent);
1024 };
1025 }
1026 }(),
1027 touch: function touch(el, eventType, params) {
1028 var touchObj = new Touch(mergeObj({
1029 identifier: Date.now(),
1030 target: el,
1031 radiusX: 2.5,
1032 radiusY: 2.5,
1033 rotationAngle: 10,
1034 force: .5
1035 }, params));
1036 el.dispatchEvent(new TouchEvent(eventType, {
1037 cancelable: !0,
1038 bubbles: !0,
1039 shiftKey: !0,
1040 touches: [touchObj],
1041 targetTouches: [],
1042 changedTouches: [touchObj]
1043 }));
1044 }
1045}; // emulate event
1046
1047
1048/**
1049 * Process the template & return bound string
1050 * @param {string} tpl Template string
1051 * @param {object} data Data value to be replaced
1052 * @returns {string}
1053 * @private
1054 */
1055function tplProcess(tpl, data) {
1056 var res = tpl;
1057
1058 for (var x in data) {
1059 res = res.replace(new RegExp("{=" + x + "}", "g"), data[x]);
1060 }
1061
1062 return res;
1063}
1064/**
1065 * Get parsed date value
1066 * (It must be called in 'ChartInternal' context)
1067 * @param {Date|string|number} date Value of date to be parsed
1068 * @returns {Date}
1069 * @private
1070 */
1071
1072
1073function parseDate(date) {
1074 var parsedDate;
1075
1076 if (date instanceof Date) {
1077 parsedDate = date;
1078 } else if (isString(date)) {
1079 var config = this.config,
1080 format = this.format;
1081 parsedDate = format.dataTime(config.data_xFormat)(date);
1082 } else if (isNumber(date) && !isNaN(date)) {
1083 parsedDate = new Date(+date);
1084 }
1085
1086 if (!parsedDate || isNaN(+parsedDate)) {
1087 console && console.error && console.error("Failed to parse x '" + date + "' to Date object");
1088 }
1089
1090 return parsedDate;
1091}
1092/**
1093 * Return if the current doc is visible or not
1094 * @returns {boolean}
1095 * @private
1096 */
1097
1098
1099function isTabVisible() {
1100 return !doc.hidden;
1101}
1102/**
1103 * Get the current input type
1104 * @param {boolean} mouse Config value: interaction.inputType.mouse
1105 * @param {boolean} touch Config value: interaction.inputType.touch
1106 * @returns {string} "mouse" | "touch" | null
1107 * @private
1108 */
1109
1110
1111function convertInputType(mouse, touch) {
1112 var isMobile = !1; // https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent#Mobile_Tablet_or_Desktop
1113
1114 if (/Mobi/.test(win.navigator.userAgent) && touch) {
1115 // Some Edge desktop return true: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/20417074/
1116 var hasTouchPoints = win.navigator && "maxTouchPoints" in win.navigator && win.navigator.maxTouchPoints > 0,
1117 hasTouch = "ontouchmove" in win || win.DocumentTouch && doc instanceof win.DocumentTouch; // Ref: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
1118 // On IE11 with IE9 emulation mode, ('ontouchstart' in window) is returning true
1119
1120 isMobile = hasTouchPoints || hasTouch;
1121 }
1122
1123 var hasMouse = mouse && !isMobile ? "onmouseover" in win : !1;
1124 return hasMouse && "mouse" || isMobile && "touch" || null;
1125}
1126;// CONCATENATED MODULE: ./src/config/config.ts
1127/**
1128 * Copyright (c) 2017 ~ present NAVER Corp.
1129 * billboard.js project is licensed under the MIT license
1130 */
1131
1132
1133/**
1134 * Load configuration option
1135 * @param {object} config User's generation config value
1136 * @private
1137 */
1138function loadConfig(config) {
1139 var thisConfig = this.config,
1140 target,
1141 keys,
1142 read,
1143 find = function () {
1144 var key = keys.shift();
1145
1146 if (key && target && isObjectType(target) && key in target) {
1147 target = target[key];
1148 return find();
1149 } else if (!key) {
1150 return target;
1151 }
1152
1153 return undefined;
1154 };
1155
1156 Object.keys(thisConfig).forEach(function (key) {
1157 target = config;
1158 keys = key.split("_");
1159 read = find();
1160
1161 if (isDefined(read)) {
1162 thisConfig[key] = read;
1163 }
1164 });
1165}
1166;// CONCATENATED MODULE: ./src/Plugin/Plugin.ts
1167/**
1168 * Copyright (c) 2017 ~ present NAVER Corp.
1169 * billboard.js project is licensed under the MIT license
1170 */
1171
1172/**
1173 * Base class to generate billboard.js plugin
1174 * @class Plugin
1175 */
1176
1177/**
1178 * Version info string for plugin
1179 * @name version
1180 * @static
1181 * @memberof Plugin
1182 * @type {string}
1183 * @example
1184 * bb.plugin.stanford.version; // ex) 1.9.0
1185 */
1186var Plugin = /*#__PURE__*/function () {
1187 /**
1188 * Constructor
1189 * @param {Any} options config option object
1190 * @private
1191 */
1192 function Plugin(options) {
1193 if (options === void 0) {
1194 options = {};
1195 }
1196
1197 this.$$ = void 0;
1198 this.options = void 0;
1199 this.options = options;
1200 }
1201 /**
1202 * Lifecycle hook for 'beforeInit' phase.
1203 * @private
1204 */
1205
1206
1207 var _proto = Plugin.prototype;
1208
1209 _proto.$beforeInit = function $beforeInit() {}
1210 /**
1211 * Lifecycle hook for 'init' phase.
1212 * @private
1213 */
1214 ;
1215
1216 _proto.$init = function $init() {}
1217 /**
1218 * Lifecycle hook for 'afterInit' phase.
1219 * @private
1220 */
1221 ;
1222
1223 _proto.$afterInit = function $afterInit() {}
1224 /**
1225 * Lifecycle hook for 'redraw' phase.
1226 * @private
1227 */
1228 ;
1229
1230 _proto.$redraw = function $redraw() {}
1231 /**
1232 * Lifecycle hook for 'willDestroy' phase.
1233 * @private
1234 */
1235 ;
1236
1237 _proto.$willDestroy = function $willDestroy() {
1238 var _this = this;
1239
1240 Object.keys(this).forEach(function (key) {
1241 _this[key] = null;
1242 delete _this[key];
1243 });
1244 };
1245
1246 return Plugin;
1247}();
1248
1249Plugin.version = "3.2.1";
1250
1251;// CONCATENATED MODULE: ./src/Plugin/stanford/Options.ts
1252/**
1253 * Copyright (c) 2017 ~ present NAVER Corp.
1254 * billboard.js project is licensed under the MIT license
1255 */
1256
1257/**
1258 * Stanford diagram plugin option class
1259 * @class StanfordOptions
1260 * @param {Options} options Stanford plugin options
1261 * @augments Plugin
1262 * @returns {StanfordOptions}
1263 * @private
1264 */
1265var Options = function () {
1266 return {
1267 /**
1268 * Set the color of the color scale. This function receives a value between 0 and 1, and should return a color.
1269 * @name colors
1270 * @memberof plugin-stanford
1271 * @type {Function}
1272 * @default undefined
1273 * @example
1274 * colors: d3.interpolateHslLong(
1275 * d3.hsl(250, 1, 0.5), d3.hsl(0, 1, 0.5)
1276 * )
1277 */
1278 colors: undefined,
1279
1280 /**
1281 * Specify the key of epochs values in the data.
1282 * @name epochs
1283 * @memberof plugin-stanford
1284 * @type {Array}
1285 * @default []
1286 * @example
1287 * epochs: [ 1, 1, 2, 2, ... ]
1288 */
1289 epochs: [],
1290
1291 /**
1292 * Show additional lines anywhere on the chart.
1293 * - Each line object should consist with following options:
1294 *
1295 * | Key | Type | Description |
1296 * | --- | --- | --- |
1297 * | x1 | Number | Starting position on the x axis |
1298 * | y1 | Number | Starting position on the y axis |
1299 * | x2 | Number | Ending position on the x axis |
1300 * | y2 | Number | Ending position on the y axis |
1301 * | class | String | Optional value. Set a custom css class to this line. |
1302 * @type {Array}
1303 * @memberof plugin-stanford
1304 * @default []
1305 * @example
1306 * lines: [
1307 * { x1: 0, y1: 0, x2: 65, y2: 65, class: "line1" },
1308 * { x1: 0, x2: 65, y1: 40, y2: 40, class: "line2" }
1309 * ]
1310 */
1311 lines: [],
1312
1313 /**
1314 * Set scale values
1315 * @name scale
1316 * @memberof plugin-stanford
1317 * @type {object}
1318 * @property {object} [scale] scale object
1319 * @property {number} [scale.min=undefined] Minimum value of the color scale. Default: lowest value in epochs
1320 * @property {number} [scale.max=undefined] Maximum value of the color scale. Default: highest value in epochs
1321 * @property {number} [scale.width=20] Width of the color scale
1322 * @property {string|Function} [scale.format=undefined] Format of the axis of the color scale. Use 'pow10' to format as powers of 10 or a custom function. Example: d3.format("d")
1323 * @example
1324 * scale: {
1325 * max: 10000,
1326 * min: 1,
1327 * width: 500,
1328 *
1329 * // specify 'pow10' to format as powers of 10
1330 * format: "pow10",
1331 *
1332 * // or specify a format function
1333 * format: function(x) {
1334 * return x +"%";
1335 * }
1336 * },
1337 */
1338 scale_min: undefined,
1339 scale_max: undefined,
1340 scale_width: 20,
1341 scale_format: undefined,
1342
1343 /**
1344 * The padding for color scale element
1345 * @name padding
1346 * @memberof plugin-stanford
1347 * @type {object}
1348 * @property {object} [padding] padding object
1349 * @property {number} [padding.top=0] Top padding value.
1350 * @property {number} [padding.right=0] Right padding value.
1351 * @property {number} [padding.bottom=0] Bottom padding value.
1352 * @property {number} [padding.left=0] Left padding value.
1353 * @example
1354 * padding: {
1355 * top: 15,
1356 * right: 0,
1357 * bottom: 0,
1358 * left: 0
1359 * },
1360 */
1361 padding_top: 0,
1362 padding_right: 0,
1363 padding_bottom: 0,
1364 padding_left: 0,
1365
1366 /**
1367 * Show additional regions anywhere on the chart.
1368 * - Each region object should consist with following options:
1369 *
1370 * | Key | Type | Default | Attributes | Description |
1371 * | --- | --- | --- | --- | --- |
1372 * | points | Array | | | Accepts a group of objects that has x and y.<br>These points should be added in a counter-clockwise fashion to make a closed polygon. |
1373 * | opacity | Number | `0.2` | &lt;optional> | Sets the opacity of the region as value between 0 and 1 |
1374 * | text | Function | | &lt;optional> | This function receives a value and percentage of the number of epochs in this region.<br>Return a string to place text in the middle of the region. |
1375 * | class | String | | &lt;optional> | Se a custom css class to this region, use the fill property in css to set a background color. |
1376 * @name regions
1377 * @memberof plugin-stanford
1378 * @type {Array}
1379 * @default []
1380 * @example
1381 * regions: [
1382 * {
1383 * points: [ // add points counter-clockwise
1384 * { x: 0, y: 0 },
1385 * { x: 40, y: 40 },
1386 * { x: 0, y: 40 },
1387 * ],
1388 * text: function (value, percentage) {
1389 * return `Normal Operations: ${value} (${percentage}%)`;
1390 * },
1391 * opacity: 0.2, // 0 to 1
1392 * class: "test-polygon1"
1393 * },
1394 * ...
1395 * ]
1396 */
1397 regions: []
1398 };
1399};
1400
1401
1402;// CONCATENATED MODULE: ./src/Plugin/stanford/classes.ts
1403/**
1404 * Copyright (c) 2017 ~ present NAVER Corp.
1405 * billboard.js project is licensed under the MIT license
1406 */
1407
1408/**
1409 * CSS class names definition
1410 * @private
1411 */
1412/* harmony default export */ var stanford_classes = ({
1413 colorScale: "bb-colorscale",
1414 stanfordElements: "bb-stanford-elements",
1415 stanfordLine: "bb-stanford-line",
1416 stanfordLines: "bb-stanford-lines",
1417 stanfordRegion: "bb-stanford-region",
1418 stanfordRegions: "bb-stanford-regions"
1419});
1420;// CONCATENATED MODULE: ./src/Plugin/stanford/util.ts
1421/**
1422 * Copyright (c) 2017 ~ present NAVER Corp.
1423 * billboard.js project is licensed under the MIT license
1424 * @ignore
1425 */
1426
1427/**
1428 * Check if point is in region
1429 * @param {object} point Point
1430 * @param {Array} region Region
1431 * @returns {boolean}
1432 * @private
1433 */
1434
1435function pointInRegion(point, region) {
1436 // thanks to: http://bl.ocks.org/bycoffe/5575904
1437 // ray-casting algorithm based on
1438 // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
1439 var x = point.x,
1440 y = point.value,
1441 inside = !1;
1442
1443 for (var i = 0, j = region.length - 1; i < region.length; j = i++) {
1444 var xi = region[i].x,
1445 yi = region[i].y,
1446 xj = region[j].x,
1447 yj = region[j].y;
1448
1449 if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) {
1450 inside = !inside;
1451 }
1452 }
1453
1454 return inside;
1455}
1456/**
1457 * Compare epochs
1458 * @param {object} a Target
1459 * @param {object} b Source
1460 * @returns {number}
1461 * @private
1462 */
1463
1464
1465function compareEpochs(a, b) {
1466 if (a.epochs < b.epochs) {
1467 return -1;
1468 }
1469
1470 if (a.epochs > b.epochs) {
1471 return 1;
1472 }
1473
1474 return 0;
1475}
1476/**
1477 * Get region area
1478 * @param {Array} points Points
1479 * @returns {number}
1480 * @private
1481 */
1482
1483
1484function getRegionArea(points) {
1485 // thanks to: https://stackoverflow.com/questions/16282330/find-centerpoint-of-polygon-in-javascript
1486 var area = 0,
1487 point1,
1488 point2;
1489
1490 for (var i = 0, l = points.length, j = l - 1; i < l; j = i, i++) {
1491 point1 = points[i];
1492 point2 = points[j];
1493 area += point1.x * point2.y;
1494 area -= point1.y * point2.x;
1495 }
1496
1497 area /= 2;
1498 return area;
1499}
1500/**
1501 * Get centroid
1502 * @param {Array} points Points
1503 * @returns {object}
1504 * @private
1505 */
1506
1507
1508function getCentroid(points) {
1509 var area = getRegionArea(points),
1510 x = 0,
1511 y = 0,
1512 f;
1513
1514 for (var i = 0, l = points.length, j = l - 1; i < l; j = i, i++) {
1515 var point1 = points[i],
1516 point2 = points[j];
1517 f = point1.x * point2.y - point2.x * point1.y;
1518 x += (point1.x + point2.x) * f;
1519 y += (point1.y + point2.y) * f;
1520 }
1521
1522 f = area * 6;
1523 return {
1524 x: x / f,
1525 y: y / f
1526 };
1527}
1528
1529
1530;// CONCATENATED MODULE: ./src/Plugin/stanford/Elements.ts
1531/**
1532 * Copyright (c) 2017 ~ present NAVER Corp.
1533 * billboard.js project is licensed under the MIT license
1534 */
1535// @ts-nocheck
1536
1537
1538/**
1539 * Stanford diagram plugin element class
1540 * @class ColorScale
1541 * @param {Stanford} owner Stanford instance
1542 * @private
1543 */
1544
1545var Elements = /*#__PURE__*/function () {
1546 function Elements(owner) {
1547 this.owner = void 0;
1548 this.owner = owner; // MEMO: Avoid blocking eventRect
1549
1550 var elements = owner.$$.$el.main.select(".bb-chart").append("g").attr("class", stanford_classes.stanfordElements);
1551 elements.append("g").attr("class", stanford_classes.stanfordLines);
1552 elements.append("g").attr("class", stanford_classes.stanfordRegions);
1553 }
1554
1555 var _proto = Elements.prototype;
1556
1557 _proto.updateStanfordLines = function updateStanfordLines(duration) {
1558 var $$ = this.owner.$$,
1559 config = $$.config,
1560 main = $$.$el.main,
1561 isRotated = config.axis_rotated,
1562 xvCustom = this.xvCustom.bind($$),
1563 yvCustom = this.yvCustom.bind($$),
1564 stanfordLine = main.select("." + stanford_classes.stanfordLines).style("shape-rendering", "geometricprecision").selectAll("." + stanford_classes.stanfordLine).data(this.owner.config.lines);
1565 // exit
1566 stanfordLine.exit().transition().duration(duration).style("opacity", "0").remove(); // enter
1567
1568 var stanfordLineEnter = stanfordLine.enter().append("g");
1569 stanfordLineEnter.append("line").style("opacity", "0");
1570 stanfordLineEnter.merge(stanfordLine).attr("class", function (d) {
1571 return stanford_classes.stanfordLine + (d.class ? " " + d.class : "");
1572 }).select("line").transition().duration(duration).attr("x1", function (d) {
1573 return isRotated ? yvCustom(d, "y1") : xvCustom(d, "x1");
1574 }).attr("x2", function (d) {
1575 return isRotated ? yvCustom(d, "y2") : xvCustom(d, "x2");
1576 }).attr("y1", function (d) {
1577 return isRotated ? xvCustom(d, "x1") : yvCustom(d, "y1");
1578 }).attr("y2", function (d) {
1579 return isRotated ? xvCustom(d, "x2") : yvCustom(d, "y2");
1580 }).transition().style("opacity", null);
1581 };
1582
1583 _proto.updateStanfordRegions = function updateStanfordRegions(duration) {
1584 var $$ = this.owner.$$,
1585 config = $$.config,
1586 main = $$.$el.main,
1587 isRotated = config.axis_rotated,
1588 xvCustom = this.xvCustom.bind($$),
1589 yvCustom = this.yvCustom.bind($$),
1590 countPointsInRegion = this.owner.countEpochsInRegion.bind($$),
1591 stanfordRegion = main.select("." + stanford_classes.stanfordRegions).selectAll("." + stanford_classes.stanfordRegion).data(this.owner.config.regions);
1592 // exit
1593 stanfordRegion.exit().transition().duration(duration).style("opacity", "0").remove(); // enter
1594
1595 var stanfordRegionEnter = stanfordRegion.enter().append("g");
1596 stanfordRegionEnter.append("polygon").style("opacity", "0");
1597 stanfordRegionEnter.append("text").attr("transform", isRotated ? "rotate(-90)" : "").style("opacity", "0");
1598 stanfordRegion = stanfordRegionEnter.merge(stanfordRegion); // update
1599
1600 stanfordRegion.attr("class", function (d) {
1601 return stanford_classes.stanfordRegion + (d.class ? " " + d.class : "");
1602 }).select("polygon").transition().duration(duration).attr("points", function (d) {
1603 return d.points.map(function (value) {
1604 return [isRotated ? yvCustom(value, "y") : xvCustom(value, "x"), isRotated ? xvCustom(value, "x") : yvCustom(value, "y")].join(",");
1605 }).join(" ");
1606 }).transition().style("opacity", function (d) {
1607 return (d.opacity ? d.opacity : .2) + "";
1608 });
1609 stanfordRegion.select("text").transition().duration(duration).attr("x", function (d) {
1610 return isRotated ? yvCustom(getCentroid(d.points), "y") : xvCustom(getCentroid(d.points), "x");
1611 }).attr("y", function (d) {
1612 return isRotated ? xvCustom(getCentroid(d.points), "x") : yvCustom(getCentroid(d.points), "y");
1613 }).text(function (d) {
1614 if (d.text) {
1615 var _countPointsInRegion = countPointsInRegion(d.points),
1616 value = _countPointsInRegion.value,
1617 percentage = _countPointsInRegion.percentage;
1618
1619 return d.text(value, percentage);
1620 }
1621
1622 return "";
1623 }).attr("text-anchor", "middle").attr("dominant-baseline", "middle").transition().style("opacity", null);
1624 };
1625
1626 _proto.updateStanfordElements = function updateStanfordElements(duration) {
1627 if (duration === void 0) {
1628 duration = 0;
1629 }
1630
1631 this.updateStanfordLines(duration);
1632 this.updateStanfordRegions(duration);
1633 };
1634
1635 _proto.xvCustom = function xvCustom(d, xyValue) {
1636 var $$ = this,
1637 axis = $$.axis,
1638 config = $$.config,
1639 value = xyValue ? d[xyValue] : $$.getBaseValue(d);
1640
1641 if (axis.isTimeSeries()) {
1642 value = parseDate.call($$, value);
1643 } else if (axis.isCategorized() && isString(value)) {
1644 value = config.axis_x_categories.indexOf(d.value);
1645 }
1646
1647 return Math.ceil($$.scale.x(value));
1648 };
1649
1650 _proto.yvCustom = function yvCustom(d, xyValue) {
1651 var $$ = this,
1652 yScale = d.axis && d.axis === "y2" ? $$.scale.y2 : $$.scale.y,
1653 value = xyValue ? d[xyValue] : $$.getBaseValue(d);
1654 return Math.ceil(yScale(value));
1655 };
1656
1657 return Elements;
1658}();
1659
1660
1661// EXTERNAL MODULE: external {"commonjs":"d3-axis","commonjs2":"d3-axis","amd":"d3-axis","root":"d3"}
1662var external_commonjs_d3_axis_commonjs2_d3_axis_amd_d3_axis_root_d3_ = __webpack_require__(8);
1663// EXTERNAL MODULE: external {"commonjs":"d3-format","commonjs2":"d3-format","amd":"d3-format","root":"d3"}
1664var external_commonjs_d3_format_commonjs2_d3_format_amd_d3_format_root_d3_ = __webpack_require__(9);
1665;// CONCATENATED MODULE: ./src/Plugin/stanford/ColorScale.ts
1666/**
1667 * Copyright (c) 2017 ~ present NAVER Corp.
1668 * billboard.js project is licensed under the MIT license
1669 */
1670
1671
1672
1673
1674
1675/**
1676 * Stanford diagram plugin color scale class
1677 * @class ColorScale
1678 * @param {Stanford} owner Stanford instance
1679 * @private
1680 */
1681
1682var ColorScale = /*#__PURE__*/function () {
1683 function ColorScale(owner) {
1684 this.owner = void 0;
1685 this.colorScale = void 0;
1686 this.owner = owner;
1687 }
1688
1689 var _proto = ColorScale.prototype;
1690
1691 _proto.drawColorScale = function drawColorScale() {
1692 var _this$owner = this.owner,
1693 $$ = _this$owner.$$,
1694 config = _this$owner.config,
1695 target = $$.data.targets[0],
1696 height = $$.state.height - config.padding_bottom - config.padding_top,
1697 barWidth = config.scale_width,
1698 barHeight = 5,
1699 points = getRange(config.padding_bottom, height, barHeight),
1700 inverseScale = (0,external_commonjs_d3_scale_commonjs2_d3_scale_amd_d3_scale_root_d3_.scaleSequential)(target.colors).domain([points[points.length - 1], points[0]]);
1701
1702 if (this.colorScale) {
1703 this.colorScale.remove();
1704 }
1705
1706 this.colorScale = $$.$el.svg.append("g").attr("width", 50).attr("height", height).attr("class", stanford_classes.colorScale);
1707 this.colorScale.append("g").attr("transform", "translate(0, " + config.padding_top + ")").selectAll("bars").data(points).enter().append("rect").attr("y", function (d, i) {
1708 return i * barHeight;
1709 }).attr("x", 0).attr("width", barWidth).attr("height", barHeight).attr("fill", function (d) {
1710 return inverseScale(d);
1711 }); // Legend Axis
1712
1713 var axisScale = (0,external_commonjs_d3_scale_commonjs2_d3_scale_amd_d3_scale_root_d3_.scaleLog)().domain([target.minEpochs, target.maxEpochs]).range([points[0] + config.padding_top + points[points.length - 1] + barHeight - 1, points[0] + config.padding_top]),
1714 legendAxis = (0,external_commonjs_d3_axis_commonjs2_d3_axis_amd_d3_axis_root_d3_.axisRight)(axisScale),
1715 scaleFormat = config.scale_format;
1716
1717 if (scaleFormat === "pow10") {
1718 legendAxis.tickValues([1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7]);
1719 } else if (isFunction(scaleFormat)) {
1720 legendAxis.tickFormat(scaleFormat);
1721 } else {
1722 legendAxis.tickFormat((0,external_commonjs_d3_format_commonjs2_d3_format_amd_d3_format_root_d3_.format)("d"));
1723 } // Draw Axis
1724
1725
1726 var axis = this.colorScale.append("g").attr("class", "legend axis").attr("transform", "translate(" + barWidth + ",0)").call(legendAxis);
1727
1728 if (scaleFormat === "pow10") {
1729 axis.selectAll(".tick text").text(null).filter(function (d) {
1730 return d / Math.pow(10, Math.ceil(Math.log(d) / Math.LN10 - 1e-12)) === 1;
1731 }) // Power of Ten
1732 .text(10).append("tspan").attr("dy", "-.7em") // https://bl.ocks.org/mbostock/6738229
1733 .text(function (d) {
1734 return Math.round(Math.log(d) / Math.LN10);
1735 });
1736 }
1737
1738 this.colorScale.attr("transform", "translate(" + ($$.state.current.width - this.xForColorScale()) + ", 0)");
1739 };
1740
1741 _proto.xForColorScale = function xForColorScale() {
1742 return this.owner.config.padding_right + this.colorScale.node().getBBox().width;
1743 };
1744
1745 _proto.getColorScalePadding = function getColorScalePadding() {
1746 return this.xForColorScale() + this.owner.config.padding_left + 20;
1747 };
1748
1749 return ColorScale;
1750}();
1751
1752
1753;// CONCATENATED MODULE: ./src/Plugin/stanford/index.ts
1754
1755
1756
1757/**
1758 * Copyright (c) 2017 ~ present NAVER Corp.
1759 * billboard.js project is licensed under the MIT license
1760 */
1761// @ts-nocheck
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772/**
1773 * Stanford diagram plugin
1774 * - **NOTE:**
1775 * - Plugins aren't built-in. Need to be loaded or imported to be used.
1776 * - Non required modules from billboard.js core, need to be installed separately.
1777 * - Is preferable use `scatter` as data.type
1778 * - **Required modules:**
1779 * - [d3-selection](https://github.com/d3/d3-selection)
1780 * - [d3-interpolate](https://github.com/d3/d3-interpolate)
1781 * - [d3-color](https://github.com/d3/d3-color)
1782 * - [d3-scale](https://github.com/d3/d3-scale)
1783 * - [d3-brush](https://github.com/d3/d3-brush)
1784 * - [d3-axis](https://github.com/d3/d3-axis)
1785 * - [d3-format](https://github.com/d3/d3-format)
1786 * @class plugin-stanford
1787 * @requires d3-selection
1788 * @requires d3-interpolate
1789 * @requires d3-color
1790 * @requires d3-scale
1791 * @requires d3-brush
1792 * @requires d3-axis
1793 * @requires d3-format
1794 * @param {object} options Stanford plugin options
1795 * @augments Plugin
1796 * @returns {Stanford}
1797 * @example
1798 * // Plugin must be loaded before the use.
1799 * <script src="$YOUR_PATH/plugin/billboardjs-plugin-stanford.js"></script>
1800 *
1801 * var chart = bb.generate({
1802 * data: {
1803 * columns: [ ... ],
1804 * type: "scatter"
1805 * }
1806 * ...
1807 * plugins: [
1808 * new bb.plugin.stanford({
1809 * colors: d3.interpolateHslLong(
1810 * d3.hsl(250, 1, 0.5), d3.hsl(0, 1, 0.5)
1811 * ),
1812 * epochs: [ 1, 1, 2, 2, ... ],
1813 * lines: [
1814 * { x1: 0, y1: 0, x2: 65, y2: 65, class: "line1" },
1815 * { x1: 0, x2: 65, y1: 40, y2: 40, class: "line2" }
1816 * ],
1817 * scale: {
1818 * max: 10000,
1819 * min: 1,
1820 * width: 500,
1821 * format: 'pow10',
1822 * },
1823 * padding: {
1824 * top: 15,
1825 * right: 0,
1826 * bottom: 0,
1827 * left: 0
1828 * },
1829 * regions: [
1830 * {
1831 * points: [ // add points counter-clockwise
1832 * { x: 0, y: 0 },
1833 * { x: 40, y: 40 },
1834 * { x: 0, y: 40 }
1835 * ],
1836 * text: function (value, percentage) {
1837 * return `Normal Operations: ${value} (${percentage}%)`;
1838 * },
1839 * opacity: 0.2, // 0 to 1
1840 * class: "test-polygon1"
1841 * },
1842 * ...
1843 * ]
1844 * }
1845 * ]
1846 * });
1847 * @example
1848 * import {bb} from "billboard.js";
1849 * import Stanford from "billboard.js/dist/billboardjs-plugin-stanford";
1850 *
1851 * bb.generate({
1852 * plugins: [
1853 * new Stanford({ ... })
1854 * ]
1855 * })
1856 */
1857
1858var Stanford = /*#__PURE__*/function (_Plugin) {
1859 _inheritsLoose(Stanford, _Plugin);
1860
1861 function Stanford(options) {
1862 var _this = _Plugin.call(this, options) || this;
1863
1864 _this.config = void 0;
1865 _this.colorScale = void 0;
1866 _this.elements = void 0;
1867 _this.config = new Options();
1868 return _assertThisInitialized(_this) || _assertThisInitialized(_this);
1869 }
1870
1871 var _proto = Stanford.prototype;
1872
1873 _proto.$beforeInit = function $beforeInit() {
1874 var _this2 = this,
1875 $$ = this.$$;
1876
1877 // override on config values & methods
1878 $$.config.data_xSort = !1;
1879
1880 $$.isMultipleX = function () {
1881 return !0;
1882 };
1883
1884 $$.showGridFocus = function () {};
1885
1886 $$.labelishData = function (d) {
1887 return d.values;
1888 };
1889
1890 $$.opacityForCircle = function () {
1891 return 1;
1892 };
1893
1894 var getCurrentPaddingRight = $$.getCurrentPaddingRight.bind($$);
1895
1896 $$.getCurrentPaddingRight = function () {
1897 return getCurrentPaddingRight() + (_this2.colorScale ? _this2.colorScale.getColorScalePadding() : 0);
1898 };
1899 };
1900
1901 _proto.$init = function $init() {
1902 var $$ = this.$$;
1903 loadConfig.call(this, this.options);
1904 $$.color = this.getStanfordPointColor.bind($$);
1905 this.colorScale = new ColorScale(this);
1906 this.elements = new Elements(this);
1907 this.convertData();
1908 this.initStanfordData();
1909 this.setStanfordTooltip();
1910 this.colorScale.drawColorScale();
1911 this.$redraw();
1912 };
1913
1914 _proto.$redraw = function $redraw(duration) {
1915 var _this$colorScale, _this$elements;
1916
1917 (_this$colorScale = this.colorScale) == null ? void 0 : _this$colorScale.drawColorScale();
1918 (_this$elements = this.elements) == null ? void 0 : _this$elements.updateStanfordElements(duration);
1919 };
1920
1921 _proto.getOptions = function getOptions() {
1922 return new Options();
1923 };
1924
1925 _proto.convertData = function convertData() {
1926 var data = this.$$.data.targets,
1927 epochs = this.options.epochs;
1928 data.forEach(function (d) {
1929 d.values.forEach(function (v, i) {
1930 v.epochs = epochs[i];
1931 });
1932 d.minEpochs = undefined;
1933 d.maxEpochs = undefined;
1934 d.colors = undefined;
1935 d.colorscale = undefined;
1936 });
1937 };
1938
1939 _proto.xvCustom = function xvCustom(d, xyValue) {
1940 var $$ = this,
1941 axis = $$.axis,
1942 config = $$.config,
1943 value = xyValue ? d[xyValue] : $$.getBaseValue(d);
1944
1945 if (axis.isTimeSeries()) {
1946 value = parseDate.call($$, value);
1947 } else if (axis.isCategorized() && isString(value)) {
1948 value = config.axis_x_categories.indexOf(d.value);
1949 }
1950
1951 return Math.ceil($$.scale.x(value));
1952 };
1953
1954 _proto.yvCustom = function yvCustom(d, xyValue) {
1955 var $$ = this,
1956 scale = $$.scale,
1957 yScale = d.axis && d.axis === "y2" ? scale.y2 : scale.y,
1958 value = xyValue ? d[xyValue] : $$.getBaseValue(d);
1959 return Math.ceil(yScale(value));
1960 };
1961
1962 _proto.initStanfordData = function initStanfordData() {
1963 var config = this.config,
1964 target = this.$$.data.targets[0];
1965 // TODO STANFORD see if (data.js -> orderTargets)+ can be used instead
1966 // Make larger values appear on top
1967 target.values.sort(compareEpochs); // Get array of epochs
1968
1969 var epochs = target.values.map(function (a) {
1970 return a.epochs;
1971 });
1972 target.minEpochs = !isNaN(config.scale_min) ? config.scale_min : Math.min.apply(Math, epochs);
1973 target.maxEpochs = !isNaN(config.scale_max) ? config.scale_max : Math.max.apply(Math, epochs);
1974 target.colors = isFunction(config.colors) ? config.colors : (0,external_commonjs_d3_interpolate_commonjs2_d3_interpolate_amd_d3_interpolate_root_d3_.interpolateHslLong)((0,external_commonjs_d3_color_commonjs2_d3_color_amd_d3_color_root_d3_.hsl)(250, 1, .5), (0,external_commonjs_d3_color_commonjs2_d3_color_amd_d3_color_root_d3_.hsl)(0, 1, .5));
1975 target.colorscale = (0,external_commonjs_d3_scale_commonjs2_d3_scale_amd_d3_scale_root_d3_.scaleSequentialLog)(target.colors).domain([target.minEpochs, target.maxEpochs]);
1976 };
1977
1978 _proto.getStanfordPointColor = function getStanfordPointColor(d) {
1979 var target = this.data.targets[0];
1980 return target.colorscale(d.epochs);
1981 };
1982
1983 _proto.setStanfordTooltip = function setStanfordTooltip() {
1984 var config = this.$$.config;
1985
1986 if (isEmpty(config.tooltip_contents)) {
1987 config.tooltip_contents = function (d, defaultTitleFormat, defaultValueFormat, color) {
1988 var html = "<table class=\"" + classes.tooltip + "\"><tbody>";
1989 d.forEach(function (v) {
1990 html += "<tr>\n\t\t\t\t\t\t\t<th>" + defaultTitleFormat(config.data_x) + "</th>\n\t\t\t\t\t\t\t<th class=\"value\">" + defaultValueFormat(v.x) + "</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>" + defaultTitleFormat(v.id) + "</th>\n\t\t\t\t\t\t\t<th class=\"value\">" + defaultValueFormat(v.value) + "</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class=\"" + classes.tooltipName + "-" + v.id + "\">\n\t\t\t\t\t\t\t<td class=\"name\"><span style=\"background-color:" + color(v) + "\"></span>" + defaultTitleFormat("Epochs") + "</td>\n\t\t\t\t\t\t\t<td class=\"value\">" + defaultValueFormat(v.epochs) + "</td>\n\t\t\t\t\t\t</tr>";
1991 });
1992 return html + "</tbody></table>";
1993 };
1994 }
1995 };
1996
1997 _proto.countEpochsInRegion = function countEpochsInRegion(region) {
1998 var $$ = this,
1999 target = $$.data.targets[0],
2000 total = target.values.reduce(function (accumulator, currentValue) {
2001 return accumulator + +currentValue.epochs;
2002 }, 0),
2003 value = target.values.reduce(function (accumulator, currentValue) {
2004 if (pointInRegion(currentValue, region)) {
2005 return accumulator + +currentValue.epochs;
2006 }
2007
2008 return accumulator;
2009 }, 0);
2010 return {
2011 value: value,
2012 percentage: value !== 0 ? +(value / total * 100).toFixed(1) : 0
2013 };
2014 };
2015
2016 return Stanford;
2017}(Plugin);
2018
2019
2020}();
2021__webpack_exports__ = __webpack_exports__["default"];
2022/******/ return __webpack_exports__;
2023/******/ })()
2024;
2025});
\No newline at end of file