UNPKG

40.3 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.6.3
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-delaunay"), require("d3-polygon"), require("d3-selection"), require("d3-brush"));
15 else if(typeof define === 'function' && define.amd)
16 define("bb", ["d3-delaunay", "d3-polygon", "d3-selection", "d3-brush"], factory);
17 else if(typeof exports === 'object')
18 exports["bb"] = factory(require("d3-delaunay"), require("d3-polygon"), require("d3-selection"), require("d3-brush"));
19 else
20 root["bb"] = root["bb"] || {}, root["bb"]["plugin"] = root["bb"]["plugin"] || {}, root["bb"]["plugin"]["textoverlap"] = factory(root["d3"], root["d3"], root["d3"], root["d3"]);
21})(this, function(__WEBPACK_EXTERNAL_MODULE__12__, __WEBPACK_EXTERNAL_MODULE__13__, __WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__3__) {
22return /******/ (function() { // webpackBootstrap
23/******/ "use strict";
24/******/ var __webpack_modules__ = ({
25
26/***/ 3:
27/***/ (function(module) {
28
29module.exports = __WEBPACK_EXTERNAL_MODULE__3__;
30
31/***/ }),
32
33/***/ 12:
34/***/ (function(module) {
35
36module.exports = __WEBPACK_EXTERNAL_MODULE__12__;
37
38/***/ }),
39
40/***/ 13:
41/***/ (function(module) {
42
43module.exports = __WEBPACK_EXTERNAL_MODULE__13__;
44
45/***/ }),
46
47/***/ 1:
48/***/ (function(module) {
49
50module.exports = __WEBPACK_EXTERNAL_MODULE__1__;
51
52/***/ })
53
54/******/ });
55/************************************************************************/
56/******/ // The module cache
57/******/ var __webpack_module_cache__ = {};
58/******/
59/******/ // The require function
60/******/ function __webpack_require__(moduleId) {
61/******/ // Check if module is in cache
62/******/ var cachedModule = __webpack_module_cache__[moduleId];
63/******/ if (cachedModule !== undefined) {
64/******/ return cachedModule.exports;
65/******/ }
66/******/ // Create a new module (and put it into the cache)
67/******/ var module = __webpack_module_cache__[moduleId] = {
68/******/ // no module.id needed
69/******/ // no module.loaded needed
70/******/ exports: {}
71/******/ };
72/******/
73/******/ // Execute the module function
74/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
75/******/
76/******/ // Return the exports of the module
77/******/ return module.exports;
78/******/ }
79/******/
80/************************************************************************/
81/******/ /* webpack/runtime/define property getters */
82/******/ !function() {
83/******/ // define getter functions for harmony exports
84/******/ __webpack_require__.d = function(exports, definition) {
85/******/ for(var key in definition) {
86/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
87/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
88/******/ }
89/******/ }
90/******/ };
91/******/ }();
92/******/
93/******/ /* webpack/runtime/hasOwnProperty shorthand */
94/******/ !function() {
95/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
96/******/ }();
97/******/
98/************************************************************************/
99var __webpack_exports__ = {};
100// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
101!function() {
102
103// EXPORTS
104__webpack_require__.d(__webpack_exports__, {
105 "default": function() { return /* binding */ TextOverlap; }
106});
107
108;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/newArrowCheck.js
109function _newArrowCheck(innerThis, boundThis) {
110 if (innerThis !== boundThis) {
111 throw new TypeError("Cannot instantiate an arrow function");
112 }
113}
114;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js
115function _assertThisInitialized(self) {
116 if (self === void 0) {
117 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
118 }
119 return self;
120}
121;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js
122function _setPrototypeOf(o, p) {
123 _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
124 o.__proto__ = p;
125 return o;
126 };
127 return _setPrototypeOf(o, p);
128}
129;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js
130
131function _inheritsLoose(subClass, superClass) {
132 subClass.prototype = Object.create(superClass.prototype);
133 subClass.prototype.constructor = subClass;
134 _setPrototypeOf(subClass, superClass);
135}
136// EXTERNAL MODULE: external {"commonjs":"d3-delaunay","commonjs2":"d3-delaunay","amd":"d3-delaunay","root":"d3"}
137var external_commonjs_d3_delaunay_commonjs2_d3_delaunay_amd_d3_delaunay_root_d3_ = __webpack_require__(12);
138// EXTERNAL MODULE: external {"commonjs":"d3-polygon","commonjs2":"d3-polygon","amd":"d3-polygon","root":"d3"}
139var external_commonjs_d3_polygon_commonjs2_d3_polygon_amd_d3_polygon_root_d3_ = __webpack_require__(13);
140;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js
141function _defineProperty(obj, key, value) {
142 if (key in obj) {
143 Object.defineProperty(obj, key, {
144 value: value,
145 enumerable: true,
146 configurable: true,
147 writable: true
148 });
149 } else {
150 obj[key] = value;
151 }
152 return obj;
153}
154// EXTERNAL MODULE: external {"commonjs":"d3-selection","commonjs2":"d3-selection","amd":"d3-selection","root":"d3"}
155var external_commonjs_d3_selection_commonjs2_d3_selection_amd_d3_selection_root_d3_ = __webpack_require__(1);
156// EXTERNAL MODULE: external {"commonjs":"d3-brush","commonjs2":"d3-brush","amd":"d3-brush","root":"d3"}
157var external_commonjs_d3_brush_commonjs2_d3_brush_amd_d3_brush_root_d3_ = __webpack_require__(3);
158;// CONCATENATED MODULE: ./src/module/browser.ts
159
160var _this = undefined;
161/**
162 * Copyright (c) 2017 ~ present NAVER Corp.
163 * billboard.js project is licensed under the MIT license
164 */
165/**
166 * Window object
167 * @private
168 */
169/* eslint-disable no-new-func, no-undef */
170
171var win = function () {
172 _newArrowCheck(this, _this);
173 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;
174 return root || Function("return this")();
175}.bind(undefined)();
176/* eslint-enable no-new-func, no-undef */
177
178// fallback for non-supported environments
179win.requestIdleCallback = win.requestIdleCallback || function (cb) {
180 _newArrowCheck(this, _this);
181 return setTimeout(cb, 1);
182}.bind(undefined);
183// win.cancelIdleCallback = win.cancelIdleCallback || (id => clearTimeout(id));
184win.requestAnimationFrame = win.requestAnimationFrame || function (cb) {
185 _newArrowCheck(this, _this);
186 return setTimeout(cb, 1);
187}.bind(undefined);
188var doc = win == null ? void 0 : win.document;
189;// CONCATENATED MODULE: ./src/module/util.ts
190
191
192var util_this = undefined;
193function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
194function _objectSpread(target) { for (var i = 1, source; i < arguments.length; i++) { source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
195/**
196 * Copyright (c) 2017 ~ present NAVER Corp.
197 * billboard.js project is licensed under the MIT license
198 * @ignore
199 */
200
201
202
203
204var isValue = function (v) {
205 _newArrowCheck(this, util_this);
206 return v || v === 0;
207 }.bind(undefined),
208 isFunction = function (v) {
209 _newArrowCheck(this, util_this);
210 return typeof v === "function";
211 }.bind(undefined),
212 isString = function (v) {
213 _newArrowCheck(this, util_this);
214 return typeof v === "string";
215 }.bind(undefined),
216 isNumber = function (v) {
217 _newArrowCheck(this, util_this);
218 return typeof v === "number";
219 }.bind(undefined),
220 isUndefined = function (v) {
221 _newArrowCheck(this, util_this);
222 return typeof v === "undefined";
223 }.bind(undefined),
224 isDefined = function (v) {
225 _newArrowCheck(this, util_this);
226 return typeof v !== "undefined";
227 }.bind(undefined),
228 isboolean = function (v) {
229 _newArrowCheck(this, util_this);
230 return typeof v === "boolean";
231 }.bind(undefined),
232 ceil10 = function (v) {
233 _newArrowCheck(this, util_this);
234 return Math.ceil(v / 10) * 10;
235 }.bind(undefined),
236 asHalfPixel = function (n) {
237 _newArrowCheck(this, util_this);
238 return Math.ceil(n) + .5;
239 }.bind(undefined),
240 diffDomain = function (d) {
241 _newArrowCheck(this, util_this);
242 return d[1] - d[0];
243 }.bind(undefined),
244 isObjectType = function (v) {
245 _newArrowCheck(this, util_this);
246 return typeof v === "object";
247 }.bind(undefined),
248 isEmpty = function (o) {
249 _newArrowCheck(this, util_this);
250 return isUndefined(o) || o === null || isString(o) && o.length === 0 || isObjectType(o) && !(o instanceof Date) && Object.keys(o).length === 0 || isNumber(o) && isNaN(o);
251 }.bind(undefined),
252 notEmpty = function (o) {
253 _newArrowCheck(this, util_this);
254 return !isEmpty(o);
255 }.bind(undefined),
256 isArray = function (arr) {
257 _newArrowCheck(this, util_this);
258 return Array.isArray(arr);
259 }.bind(undefined),
260 isObject = function (obj) {
261 _newArrowCheck(this, util_this);
262 return obj && !(obj != null && obj.nodeType) && isObjectType(obj) && !isArray(obj);
263 }.bind(undefined);
264/**
265 * Get specified key value from object
266 * If default value is given, will return if given key value not found
267 * @param {object} options Source object
268 * @param {string} key Key value
269 * @param {*} defaultValue Default value
270 * @returns {*}
271 * @private
272 */
273function getOption(options, key, defaultValue) {
274 return isDefined(options[key]) ? options[key] : defaultValue;
275}
276
277/**
278 * Check if value exist in the given object
279 * @param {object} dict Target object to be checked
280 * @param {*} value Value to be checked
281 * @returns {boolean}
282 * @private
283 */
284function hasValue(dict, value) {
285 var _this2 = this,
286 found = !1;
287 Object.keys(dict).forEach(function (key) {
288 _newArrowCheck(this, _this2);
289 return dict[key] === value && (found = !0);
290 }.bind(this));
291 return found;
292}
293
294/**
295 * Call function with arguments
296 * @param {Function} fn Function to be called
297 * @param {*} thisArg "this" value for fn
298 * @param {*} args Arguments for fn
299 * @returns {boolean} true: fn is function, false: fn is not function
300 * @private
301 */
302function callFn(fn, thisArg) {
303 for (var isFn = isFunction(fn), _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
304 args[_key - 2] = arguments[_key];
305 }
306 isFn && fn.call.apply(fn, [thisArg].concat(args));
307 return isFn;
308}
309
310/**
311 * Call function after all transitions ends
312 * @param {d3.transition} transition Transition
313 * @param {Fucntion} cb Callback function
314 * @private
315 */
316function endall(transition, cb) {
317 var _this3 = this,
318 n = 0,
319 end = function () {
320 for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
321 args[_key2] = arguments[_key2];
322 }
323 --n || cb.apply.apply(cb, [this].concat(args));
324 };
325 // if is transition selection
326 if ("duration" in transition) {
327 transition.each(function () {
328 _newArrowCheck(this, _this3);
329 return ++n;
330 }.bind(this)).on("end", end);
331 } else {
332 ++n;
333 transition.call(end);
334 }
335}
336
337/**
338 * Replace tag sign to html entity
339 * @param {string} str Target string value
340 * @returns {string}
341 * @private
342 */
343function sanitise(str) {
344 return isString(str) ? str.replace(/</g, "&lt;").replace(/>/g, "&gt;") : str;
345}
346
347/**
348 * Set text value. If there's multiline add nodes.
349 * @param {d3Selection} node Text node
350 * @param {string} text Text value string
351 * @param {Array} dy dy value for multilined text
352 * @param {boolean} toMiddle To be alingned vertically middle
353 * @private
354 */
355function setTextValue(node, text, dy, toMiddle) {
356 var _this4 = this;
357 if (dy === void 0) {
358 dy = [-1, 1];
359 }
360 if (toMiddle === void 0) {
361 toMiddle = !1;
362 }
363 if (!node || !isString(text)) {
364 return;
365 }
366 if (text.indexOf("\n") === -1) {
367 node.text(text);
368 } else {
369 var diff = [node.text(), text].map(function (v) {
370 _newArrowCheck(this, _this4);
371 return v.replace(/[\s\n]/g, "");
372 }.bind(this));
373 if (diff[0] !== diff[1]) {
374 var multiline = text.split("\n"),
375 len = toMiddle ? multiline.length - 1 : 1;
376 // reset possible text
377 node.html("");
378 multiline.forEach(function (v, i) {
379 _newArrowCheck(this, _this4);
380 node.append("tspan").attr("x", 0).attr("dy", (i === 0 ? dy[0] * len : dy[1]) + "em").text(v);
381 }.bind(this));
382 }
383 }
384}
385
386/**
387 * Substitution of SVGPathSeg API polyfill
388 * @param {SVGGraphicsElement} path Target svg element
389 * @returns {Array}
390 * @private
391 */
392function getRectSegList(path) {
393 /*
394 * seg1 ---------- seg2
395 * | |
396 * | |
397 * | |
398 * seg0 ---------- seg3
399 * */
400 var _path$getBBox = path.getBBox(),
401 x = _path$getBBox.x,
402 y = _path$getBBox.y,
403 width = _path$getBBox.width,
404 height = _path$getBBox.height;
405 return [{
406 x: x,
407 y: y + height
408 },
409 // seg0
410 {
411 x: x,
412 y: y
413 },
414 // seg1
415 {
416 x: x + width,
417 y: y
418 },
419 // seg2
420 {
421 x: x + width,
422 y: y + height
423 } // seg3
424 ];
425}
426
427/**
428 * Get svg bounding path box dimension
429 * @param {SVGGraphicsElement} path Target svg element
430 * @returns {object}
431 * @private
432 */
433function getPathBox(path) {
434 var _path$getBoundingClie = path.getBoundingClientRect(),
435 width = _path$getBoundingClie.width,
436 height = _path$getBoundingClie.height,
437 items = getRectSegList(path),
438 x = items[0].x,
439 y = Math.min(items[0].y, items[1].y);
440 return {
441 x: x,
442 y: y,
443 width: width,
444 height: height
445 };
446}
447
448/**
449 * Get event's current position coordinates
450 * @param {object} event Event object
451 * @param {SVGElement|HTMLElement} element Target element
452 * @returns {Array} [x, y] Coordinates x, y array
453 * @private
454 */
455function getPointer(event, element) {
456 var _ref,
457 touches = event && ((_ref = event.touches || event.sourceEvent && event.sourceEvent.touches) == null ? void 0 : _ref[0]),
458 pointer = (0,external_commonjs_d3_selection_commonjs2_d3_selection_amd_d3_selection_root_d3_.pointer)(touches || event, element),
459 _this5 = this;
460 return pointer.map(function (v) {
461 _newArrowCheck(this, _this5);
462 return isNaN(v) ? 0 : v;
463 }.bind(this));
464}
465
466/**
467 * Return brush selection array
468 * @param {object} ctx Current instance
469 * @returns {d3.brushSelection}
470 * @private
471 */
472function getBrushSelection(ctx) {
473 var event = ctx.event,
474 $el = ctx.$el,
475 main = $el.subchart.main || $el.main,
476 selection;
477 // check from event
478 if (event && event.type === "brush") {
479 selection = event.selection;
480 // check from brush area selection
481 } else if (main && (selection = main.select(".bb-brush").node())) {
482 selection = (0,external_commonjs_d3_brush_commonjs2_d3_brush_amd_d3_brush_root_d3_.brushSelection)(selection);
483 }
484 return selection;
485}
486
487/**
488 * Get boundingClientRect.
489 * Cache the evaluated value once it was called.
490 * @param {HTMLElement} node Target element
491 * @returns {object}
492 * @private
493 */
494function getBoundingRect(node) {
495 var needEvaluate = !("rect" in node) || "rect" in node && node.hasAttribute("width") && node.rect.width !== +node.getAttribute("width");
496 return needEvaluate ? node.rect = node.getBoundingClientRect() : node.rect;
497}
498
499/**
500 * Retrun random number
501 * @param {boolean} asStr Convert returned value as string
502 * @param {number} min Minimum value
503 * @param {number} max Maximum value
504 * @returns {number|string}
505 * @private
506 */
507function getRandom(asStr, min, max) {
508 if (asStr === void 0) {
509 asStr = !0;
510 }
511 if (min === void 0) {
512 min = 0;
513 }
514 if (max === void 0) {
515 max = 1e4;
516 }
517 var rand = Math.floor(Math.random() * (max - min) + min);
518 return asStr ? rand + "" : rand;
519}
520
521/**
522 * Find index based on binary search
523 * @param {Array} arr Data array
524 * @param {number} v Target number to find
525 * @param {number} start Start index of data array
526 * @param {number} end End index of data arr
527 * @param {boolean} isRotated Weather is roted axis
528 * @returns {number} Index number
529 * @private
530 */
531function findIndex(arr, v, start, end, isRotated) {
532 if (start > end) {
533 return -1;
534 }
535 var mid = Math.floor((start + end) / 2),
536 _arr$mid = arr[mid],
537 x = _arr$mid.x,
538 _arr$mid$w = _arr$mid.w,
539 w = _arr$mid$w === void 0 ? 0 : _arr$mid$w;
540 if (isRotated) {
541 x = arr[mid].y;
542 w = arr[mid].h;
543 }
544 if (v >= x && v <= x + w) {
545 return mid;
546 }
547 return v < x ? findIndex(arr, v, start, mid - 1, isRotated) : findIndex(arr, v, mid + 1, end, isRotated);
548}
549
550/**
551 * Check if brush is empty
552 * @param {object} ctx Bursh context
553 * @returns {boolean}
554 * @private
555 */
556function brushEmpty(ctx) {
557 var selection = getBrushSelection(ctx);
558 if (selection) {
559 // brush selected area
560 // two-dimensional: [[x0, y0], [x1, y1]]
561 // one-dimensional: [x0, x1] or [y0, y1]
562 return selection[0] === selection[1];
563 }
564 return !0;
565}
566
567/**
568 * Deep copy object
569 * @param {object} objectN Source object
570 * @returns {object} Cloned object
571 * @private
572 */
573function deepClone() {
574 for (var _this6 = this, clone = function (v) {
575 _newArrowCheck(this, _this6);
576 if (isObject(v) && v.constructor) {
577 var r = new v.constructor();
578 for (var k in v) {
579 r[k] = clone(v[k]);
580 }
581 return r;
582 }
583 return v;
584 }.bind(this), _len3 = arguments.length, objectN = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
585 objectN[_key3] = arguments[_key3];
586 }
587 return objectN.map(function (v) {
588 _newArrowCheck(this, _this6);
589 return clone(v);
590 }.bind(this)).reduce(function (a, c) {
591 _newArrowCheck(this, _this6);
592 return _objectSpread(_objectSpread({}, a), c);
593 }.bind(this));
594}
595
596/**
597 * Extend target from source object
598 * @param {object} target Target object
599 * @param {object|Array} source Source object
600 * @returns {object}
601 * @private
602 */
603function extend(target, source) {
604 var _this7 = this;
605 if (target === void 0) {
606 target = {};
607 }
608 if (isArray(source)) {
609 source.forEach(function (v) {
610 _newArrowCheck(this, _this7);
611 return extend(target, v);
612 }.bind(this));
613 }
614
615 // exclude name with only numbers
616 for (var p in source) {
617 if (/^\d+$/.test(p) || p in target) {
618 continue;
619 }
620 target[p] = source[p];
621 }
622 return target;
623}
624
625/**
626 * Return first letter capitalized
627 * @param {string} str Target string
628 * @returns {string} capitalized string
629 * @private
630 */
631var capitalize = function (str) {
632 _newArrowCheck(this, util_this);
633 return str.charAt(0).toUpperCase() + str.slice(1);
634}.bind(undefined);
635
636/**
637 * Camelize from kebob style string
638 * @param {string} str Target string
639 * @param {string} separator Separator string
640 * @returns {string} camelized string
641 * @private
642 */
643function camelize(str, separator) {
644 var _this8 = this;
645 if (separator === void 0) {
646 separator = "-";
647 }
648 return str.split(separator).map(function (v, i) {
649 _newArrowCheck(this, _this8);
650 return i ? v.charAt(0).toUpperCase() + v.slice(1).toLowerCase() : v.toLowerCase();
651 }.bind(this)).join("");
652}
653
654/**
655 * Convert to array
656 * @param {object} v Target to be converted
657 * @returns {Array}
658 * @private
659 */
660var toArray = function (v) {
661 _newArrowCheck(this, util_this);
662 return [].slice.call(v);
663}.bind(undefined);
664
665/**
666 * Add CSS rules
667 * @param {object} style Style object
668 * @param {string} selector Selector string
669 * @param {Array} prop Prps arrary
670 * @returns {number} Newely added rule index
671 * @private
672 */
673function addCssRules(style, selector, prop) {
674 var _this9 = this,
675 rootSelctor = style.rootSelctor,
676 sheet = style.sheet,
677 getSelector = function (s) {
678 _newArrowCheck(this, _this9);
679 return s.replace(/\s?(bb-)/g, ".$1").replace(/\.+/g, ".");
680 }.bind(this),
681 rule = rootSelctor + " " + getSelector(selector) + " {" + prop.join(";") + "}";
682 return sheet[sheet.insertRule ? "insertRule" : "addRule"](rule, sheet.cssRules.length);
683}
684
685/**
686 * Get css rules for specified stylesheets
687 * @param {Array} styleSheets The stylesheets to get the rules from
688 * @returns {Array}
689 * @private
690 */
691function getCssRules(styleSheets) {
692 var _this10 = this,
693 rules = [];
694 styleSheets.forEach(function (sheet) {
695 _newArrowCheck(this, _this10);
696 try {
697 if (sheet.cssRules && sheet.cssRules.length) {
698 rules = rules.concat(toArray(sheet.cssRules));
699 }
700 } catch (e) {
701 console.error("Error while reading rules from " + sheet.href + ": " + e.toString());
702 }
703 }.bind(this));
704 return rules;
705}
706
707/**
708 * Gets the SVGMatrix of an SVGGElement
709 * @param {SVGElement} node Node element
710 * @returns {SVGMatrix} matrix
711 * @private
712 */
713function getTranslation(node) {
714 var transform = node ? node.transform : null,
715 baseVal = transform && transform.baseVal;
716 return baseVal && baseVal.numberOfItems ? baseVal.getItem(0).matrix : {
717 a: 0,
718 b: 0,
719 c: 0,
720 d: 0,
721 e: 0,
722 f: 0
723 };
724}
725
726/**
727 * Get unique value from array
728 * @param {Array} data Source data
729 * @returns {Array} Unique array value
730 * @private
731 */
732function getUnique(data) {
733 var _this11 = this,
734 isDate = data[0] instanceof Date,
735 d = (isDate ? data.map(Number) : data).filter(function (v, i, self) {
736 _newArrowCheck(this, _this11);
737 return self.indexOf(v) === i;
738 }.bind(this));
739 return isDate ? d.map(function (v) {
740 _newArrowCheck(this, _this11);
741 return new Date(v);
742 }.bind(this)) : d;
743}
744
745/**
746 * Merge array
747 * @param {Array} arr Source array
748 * @returns {Array}
749 * @private
750 */
751function mergeArray(arr) {
752 var _this12 = this;
753 return arr && arr.length ? arr.reduce(function (p, c) {
754 _newArrowCheck(this, _this12);
755 return p.concat(c);
756 }.bind(this)) : [];
757}
758
759/**
760 * Merge object returning new object
761 * @param {object} target Target object
762 * @param {object} objectN Source object
763 * @returns {object} merged target object
764 * @private
765 */
766function mergeObj(target) {
767 for (var _this13 = this, _len4 = arguments.length, objectN = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
768 objectN[_key4 - 1] = arguments[_key4];
769 }
770 if (!objectN.length || objectN.length === 1 && !objectN[0]) {
771 return target;
772 }
773 var source = objectN.shift();
774 if (isObject(target) && isObject(source)) {
775 Object.keys(source).forEach(function (key) {
776 _newArrowCheck(this, _this13);
777 var value = source[key];
778 if (isObject(value)) {
779 target[key] || (target[key] = {});
780 target[key] = mergeObj(target[key], value);
781 } else {
782 target[key] = isArray(value) ? value.concat() : value;
783 }
784 }.bind(this));
785 }
786 return mergeObj.apply(void 0, [target].concat(objectN));
787}
788
789/**
790 * Sort value
791 * @param {Array} data value to be sorted
792 * @param {boolean} isAsc true: asc, false: desc
793 * @returns {number|string|Date} sorted date
794 * @private
795 */
796function sortValue(data, isAsc) {
797 var _this14 = this;
798 if (isAsc === void 0) {
799 isAsc = !0;
800 }
801 var fn;
802 if (data[0] instanceof Date) {
803 fn = isAsc ? function (a, b) {
804 _newArrowCheck(this, _this14);
805 return a - b;
806 }.bind(this) : function (a, b) {
807 _newArrowCheck(this, _this14);
808 return b - a;
809 }.bind(this);
810 } else {
811 if (isAsc && !data.every(isNaN)) {
812 fn = function (a, b) {
813 _newArrowCheck(this, _this14);
814 return a - b;
815 }.bind(this);
816 } else if (!isAsc) {
817 fn = function (a, b) {
818 _newArrowCheck(this, _this14);
819 return a > b && -1 || a < b && 1 || a === b && 0;
820 }.bind(this);
821 }
822 }
823 return data.concat().sort(fn);
824}
825
826/**
827 * Get min/max value
828 * @param {string} type 'min' or 'max'
829 * @param {Array} data Array data value
830 * @returns {number|Date|undefined}
831 * @private
832 */
833function getMinMax(type, data) {
834 var _this15 = this,
835 res = data.filter(function (v) {
836 _newArrowCheck(this, _this15);
837 return notEmpty(v);
838 }.bind(this));
839 if (res.length) {
840 if (isNumber(res[0])) {
841 res = Math[type].apply(Math, res);
842 } else if (res[0] instanceof Date) {
843 res = sortValue(res, type === "min")[0];
844 }
845 } else {
846 res = undefined;
847 }
848 return res;
849}
850
851/**
852 * Get range
853 * @param {number} start Start number
854 * @param {number} end End number
855 * @param {number} step Step number
856 * @returns {Array}
857 * @private
858 */
859var getRange = function (start, end, step) {
860 if (step === void 0) {
861 step = 1;
862 }
863 _newArrowCheck(this, util_this);
864 var res = [],
865 n = Math.max(0, Math.ceil((end - start) / step)) | 0;
866 for (var i = start; i < n; i++) {
867 res.push(start + i * step);
868 }
869 return res;
870 }.bind(undefined),
871 emulateEvent = {
872 mouse: function () {
873 var _this16 = this;
874 _newArrowCheck(this, util_this);
875 var getParams = function () {
876 _newArrowCheck(this, _this16);
877 return {
878 bubbles: !1,
879 cancelable: !1,
880 screenX: 0,
881 screenY: 0,
882 clientX: 0,
883 clientY: 0
884 };
885 }.bind(this);
886 try {
887 // eslint-disable-next-line no-new
888 new MouseEvent("t");
889 return function (el, eventType, params) {
890 if (params === void 0) {
891 params = getParams();
892 }
893 _newArrowCheck(this, _this16);
894 el.dispatchEvent(new MouseEvent(eventType, params));
895 }.bind(this);
896 } catch (e) {
897 // Polyfills DOM4 MouseEvent
898 return function (el, eventType, params) {
899 if (params === void 0) {
900 params = getParams();
901 }
902 _newArrowCheck(this, _this16);
903 var mouseEvent = doc.createEvent("MouseEvent");
904
905 // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/initMouseEvent
906 mouseEvent.initMouseEvent(eventType, params.bubbles, params.cancelable, win, 0,
907 // the event's mouse click count
908 params.screenX, params.screenY, params.clientX, params.clientY, !1, !1, !1, !1, 0, null);
909 el.dispatchEvent(mouseEvent);
910 }.bind(this);
911 }
912 }.bind(undefined)(),
913 touch: function touch(el, eventType, params) {
914 _newArrowCheck(this, util_this);
915 var touchObj = new Touch(mergeObj({
916 identifier: Date.now(),
917 target: el,
918 radiusX: 2.5,
919 radiusY: 2.5,
920 rotationAngle: 10,
921 force: .5
922 }, params));
923 el.dispatchEvent(new TouchEvent(eventType, {
924 cancelable: !0,
925 bubbles: !0,
926 shiftKey: !0,
927 touches: [touchObj],
928 targetTouches: [],
929 changedTouches: [touchObj]
930 }));
931 }.bind(undefined)
932 }; // emulate event
933/**
934 * Process the template & return bound string
935 * @param {string} tpl Template string
936 * @param {object} data Data value to be replaced
937 * @returns {string}
938 * @private
939 */
940function tplProcess(tpl, data) {
941 var res = tpl;
942 for (var x in data) {
943 res = res.replace(new RegExp("{=" + x + "}", "g"), data[x]);
944 }
945 return res;
946}
947
948/**
949 * Get parsed date value
950 * (It must be called in 'ChartInternal' context)
951 * @param {Date|string|number} date Value of date to be parsed
952 * @returns {Date}
953 * @private
954 */
955function parseDate(date) {
956 var parsedDate;
957 if (date instanceof Date) {
958 parsedDate = date;
959 } else if (isString(date)) {
960 var _format$dataTime,
961 config = this.config,
962 format = this.format;
963 // if fails to parse, try by new Date()
964 // https://github.com/naver/billboard.js/issues/1714
965 parsedDate = (_format$dataTime = format.dataTime(config.data_xFormat)(date)) != null ? _format$dataTime : new Date(date);
966 } else if (isNumber(date) && !isNaN(date)) {
967 parsedDate = new Date(+date);
968 }
969 if (!parsedDate || isNaN(+parsedDate)) {
970 console && console.error && console.error("Failed to parse x '" + date + "' to Date object");
971 }
972 return parsedDate;
973}
974
975/**
976 * Return if the current doc is visible or not
977 * @returns {boolean}
978 * @private
979 */
980function isTabVisible() {
981 return (doc == null ? void 0 : doc.hidden) === !1 || (doc == null ? void 0 : doc.visibilityState) === "visible";
982}
983
984/**
985 * Get the current input type
986 * @param {boolean} mouse Config value: interaction.inputType.mouse
987 * @param {boolean} touch Config value: interaction.inputType.touch
988 * @returns {string} "mouse" | "touch" | null
989 * @private
990 */
991function convertInputType(mouse, touch) {
992 var _this17 = this,
993 DocumentTouch = win.DocumentTouch,
994 matchMedia = win.matchMedia,
995 navigator = win.navigator,
996 hasTouch = !1;
997 if (touch) {
998 // Some Edge desktop return true: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/20417074/
999 if (navigator && "maxTouchPoints" in navigator) {
1000 hasTouch = navigator.maxTouchPoints > 0;
1001
1002 // Ref: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
1003 // On IE11 with IE9 emulation mode, ('ontouchstart' in window) is returning true
1004 } else if ("ontouchmove" in win || DocumentTouch && doc instanceof DocumentTouch) {
1005 hasTouch = !0;
1006 } else {
1007 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent#avoiding_user_agent_detection
1008 if (matchMedia != null && matchMedia("(pointer:coarse)").matches) {
1009 hasTouch = !0;
1010 } else {
1011 // Only as a last resort, fall back to user agent sniffing
1012 var UA = navigator.userAgent;
1013 hasTouch = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) || /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);
1014 }
1015 }
1016 }
1017
1018 // Check if agent has mouse using any-hover, touch devices (e.g iPad) with external mouse will return true as long as mouse is connected
1019 // https://css-tricks.com/interaction-media-features-and-their-potential-for-incorrect-assumptions/#aa-testing-the-capabilities-of-all-inputs
1020 // Demo: https://patrickhlauke.github.io/touch/pointer-hover-any-pointer-any-hover/
1021 var hasMouse = mouse && ["any-hover:hover", "any-pointer:fine"].some(function (v) {
1022 _newArrowCheck(this, _this17);
1023 return matchMedia == null ? void 0 : matchMedia("(" + v + ")").matches;
1024 }.bind(this));
1025
1026 // fallback to 'mouse' if no input type is detected.
1027 return hasMouse && "mouse" || hasTouch && "touch" || "mouse";
1028}
1029
1030/**
1031 * Run function until given condition function return true
1032 * @param {Function} fn Function to be executed when condition is true
1033 * @param {Function} conditionFn Condition function to check if condition is true
1034 * @private
1035 */
1036function runUntil(fn, conditionFn) {
1037 var _this18 = this;
1038 if (conditionFn() === !1) {
1039 win.requestAnimationFrame(function () {
1040 _newArrowCheck(this, _this18);
1041 return runUntil(fn, conditionFn);
1042 }.bind(this));
1043 } else {
1044 fn();
1045 }
1046}
1047;// CONCATENATED MODULE: ./src/config/config.ts
1048
1049/**
1050 * Copyright (c) 2017 ~ present NAVER Corp.
1051 * billboard.js project is licensed under the MIT license
1052 */
1053
1054/**
1055 * Load configuration option
1056 * @param {object} config User's generation config value
1057 * @private
1058 */
1059function loadConfig(config) {
1060 var _this = this,
1061 thisConfig = this.config,
1062 target,
1063 keys,
1064 read,
1065 find = function () {
1066 _newArrowCheck(this, _this);
1067 var key = keys.shift();
1068 if (key && target && isObjectType(target) && key in target) {
1069 target = target[key];
1070 return find();
1071 } else if (!key) {
1072 return target;
1073 }
1074 return undefined;
1075 }.bind(this);
1076 Object.keys(thisConfig).forEach(function (key) {
1077 _newArrowCheck(this, _this);
1078 target = config;
1079 keys = key.split("_");
1080 read = find();
1081 if (isDefined(read)) {
1082 thisConfig[key] = read;
1083 }
1084 }.bind(this));
1085
1086 // only should run in the ChartInternal context
1087 if (this.api) {
1088 this.state.orgConfig = config;
1089 }
1090}
1091;// CONCATENATED MODULE: ./src/Plugin/Plugin.ts
1092
1093/**
1094 * Copyright (c) 2017 ~ present NAVER Corp.
1095 * billboard.js project is licensed under the MIT license
1096 */
1097/**
1098 * Base class to generate billboard.js plugin
1099 * @class Plugin
1100 */
1101/**
1102 * Version info string for plugin
1103 * @name version
1104 * @static
1105 * @memberof Plugin
1106 * @type {string}
1107 * @example
1108 * bb.plugin.stanford.version; // ex) 1.9.0
1109 */
1110var Plugin = /*#__PURE__*/function () {
1111 /**
1112 * Constructor
1113 * @param {Any} options config option object
1114 * @private
1115 */
1116 function Plugin(options) {
1117 if (options === void 0) {
1118 options = {};
1119 }
1120 this.$$ = void 0;
1121 this.options = void 0;
1122 this.options = options;
1123 }
1124
1125 /**
1126 * Lifecycle hook for 'beforeInit' phase.
1127 * @private
1128 */
1129 var _proto = Plugin.prototype;
1130 _proto.$beforeInit = function $beforeInit() {}
1131
1132 /**
1133 * Lifecycle hook for 'init' phase.
1134 * @private
1135 */;
1136 _proto.$init = function $init() {}
1137
1138 /**
1139 * Lifecycle hook for 'afterInit' phase.
1140 * @private
1141 */;
1142 _proto.$afterInit = function $afterInit() {}
1143
1144 /**
1145 * Lifecycle hook for 'redraw' phase.
1146 * @private
1147 */;
1148 _proto.$redraw = function $redraw() {}
1149
1150 /**
1151 * Lifecycle hook for 'willDestroy' phase.
1152 * @private
1153 */;
1154 _proto.$willDestroy = function $willDestroy() {
1155 var _this = this;
1156 Object.keys(this).forEach(function (key) {
1157 _newArrowCheck(this, _this);
1158 this[key] = null;
1159 delete this[key];
1160 }.bind(this));
1161 };
1162 return Plugin;
1163}();
1164Plugin.version = "3.6.3";
1165
1166;// CONCATENATED MODULE: ./src/Plugin/textoverlap/Options.ts
1167/**
1168 * Copyright (c) 2017 ~ present NAVER Corp.
1169 * billboard.js project is licensed under the MIT license
1170 */
1171/**
1172 * TextOverlap plugin option class
1173 * @class TextOverlapOptions
1174 * @param {Options} options TextOverlap plugin options
1175 * @augments Plugin
1176 * @returns {TextOverlapOptions}
1177 * @private
1178 */
1179var Options = function () {
1180 return {
1181 /**
1182 * Selector string for target text nodes within chart element.
1183 * - **NOTE:** If no value is given, defaults to data label text elements.
1184 * @name selector
1185 * @memberof plugin-textoverlap
1186 * @type {string}
1187 * @default undefined
1188 * @example
1189 * // selector for data label text nodes
1190 * selector: ".bb-texts text"
1191 */
1192 selector: undefined,
1193 /**
1194 * Extent of label overlap prevention.
1195 * @name extent
1196 * @memberof plugin-textoverlap
1197 * @type {number}
1198 * @default 1
1199 * @example
1200 * extent: 1
1201 */
1202 extent: 1,
1203 /**
1204 * Minimum area needed to show a data label.
1205 * @name area
1206 * @memberof plugin-textoverlap
1207 * @type {number}
1208 * @default 0
1209 * @example
1210 * area: 0
1211 */
1212 area: 0
1213 };
1214};
1215
1216;// CONCATENATED MODULE: ./src/Plugin/textoverlap/index.ts
1217
1218
1219
1220/**
1221 * Copyright (c) 2017 ~ present NAVER Corp.
1222 * billboard.js project is licensed under the MIT license
1223 */
1224
1225
1226
1227
1228
1229
1230
1231/**
1232 * TextOverlap plugin<br>
1233 * Prevents label overlap using [Voronoi layout](https://en.wikipedia.org/wiki/Voronoi_diagram).
1234 * - **NOTE:**
1235 * - Plugins aren't built-in. Need to be loaded or imported to be used.
1236 * - Non required modules from billboard.js core, need to be installed separately.
1237 * - Appropriate and works for axis based chart.
1238 * - **Required modules:**
1239 * - [d3-polygon](https://github.com/d3/d3-polygon)
1240 * - [d3-delaunay](https://github.com/d3/d3-delaunay)
1241 * @class plugin-textoverlap
1242 * @requires d3-polygon
1243 * @requires d3-delaunay
1244 * @param {object} options TextOverlap plugin options
1245 * @augments Plugin
1246 * @returns {TextOverlap}
1247 * @example
1248 * // Plugin must be loaded before the use.
1249 * <script src="$YOUR_PATH/plugin/billboardjs-plugin-textoverlap.js"></script>
1250 *
1251 * var chart = bb.generate({
1252 * data: {
1253 * columns: [ ... ]
1254 * },
1255 * ...
1256 * plugins: [
1257 * new bb.plugin.textoverlap({
1258 * selector: ".bb-texts text",
1259 * extent: 8,
1260 * area: 3
1261 * })
1262 * ]
1263 * });
1264 * @example
1265 * import {bb} from "billboard.js";
1266 * import TextOverlap from "billboard.js/dist/billboardjs-plugin-textoverlap";
1267 *
1268 * bb.generate({
1269 * plugins: [
1270 * new TextOverlap({ ... })
1271 * ]
1272 * })
1273 */
1274var TextOverlap = /*#__PURE__*/function (_Plugin) {
1275 _inheritsLoose(TextOverlap, _Plugin);
1276 function TextOverlap(options) {
1277 var _this = _Plugin.call(this, options) || this;
1278 _this.config = void 0;
1279 _this.config = new Options();
1280 return _assertThisInitialized(_this) || _assertThisInitialized(_this);
1281 }
1282 var _proto = TextOverlap.prototype;
1283 _proto.$init = function $init() {
1284 loadConfig.call(this, this.options);
1285 };
1286 _proto.$redraw = function $redraw() {
1287 var $el = this.$$.$el,
1288 selector = this.config.selector,
1289 text = selector ? $el.main.selectAll(selector) : $el.text;
1290 text.empty() || this.preventLabelOverlap(text);
1291 }
1292
1293 /**
1294 * Generates the voronoi layout for data labels
1295 * @param {Array} points Indices values
1296 * @returns {object} Voronoi layout points and corresponding Data points
1297 * @private
1298 */;
1299 _proto.generateVoronoi = function generateVoronoi(points) {
1300 var _this2 = this,
1301 $$ = this.$$,
1302 scale = $$.scale,
1303 _map = ["x", "y"].map(function (v) {
1304 _newArrowCheck(this, _this2);
1305 return scale[v].domain();
1306 }.bind(this)),
1307 min = _map[0],
1308 max = _map[1],
1309 _ref = [max[0], min[1]];
1310 min[1] = _ref[0];
1311 max[0] = _ref[1];
1312 return external_commonjs_d3_delaunay_commonjs2_d3_delaunay_amd_d3_delaunay_root_d3_.Delaunay.from(points).voronoi([].concat(min, max)); // bounds = [xmin, ymin, xmax, ymax], default value: [0, 0, 960, 500]
1313 }
1314
1315 /**
1316 * Set text label's position to preventg overlap.
1317 * @param {d3Selection} text target text selection
1318 * @private
1319 */;
1320 _proto.preventLabelOverlap = function preventLabelOverlap(text) {
1321 var _this3 = this,
1322 _this$config = this.config,
1323 extent = _this$config.extent,
1324 area = _this$config.area,
1325 points = text.data().map(function (v) {
1326 _newArrowCheck(this, _this3);
1327 return [v.index, v.value];
1328 }.bind(this)),
1329 voronoi = this.generateVoronoi(points),
1330 i = 0;
1331 text.each(function () {
1332 var cell = voronoi.cellPolygon(i);
1333 if (cell && this) {
1334 var _points$i = points[i],
1335 x = _points$i[0],
1336 y = _points$i[1],
1337 _d3PolygonCentroid = (0,external_commonjs_d3_polygon_commonjs2_d3_polygon_amd_d3_polygon_root_d3_.polygonCentroid)(cell),
1338 cx = _d3PolygonCentroid[0],
1339 cy = _d3PolygonCentroid[1],
1340 polygonArea = Math.abs((0,external_commonjs_d3_polygon_commonjs2_d3_polygon_amd_d3_polygon_root_d3_.polygonArea)(cell)),
1341 angle = Math.round(Math.atan2(cy - y, cx - x) / Math.PI * 2),
1342 xTranslate = extent * (angle === 0 ? 1 : -1),
1343 yTranslate = angle === -1 ? -extent : extent + 5,
1344 txtAnchor = Math.abs(angle) === 1 ? "middle" : angle === 0 ? "start" : "end"; // @ts-ignore wrong type definiton for d3PolygonCentroid
1345 this.style.display = polygonArea < area ? "none" : "";
1346 this.setAttribute("text-anchor", txtAnchor);
1347 this.setAttribute("dy", "0." + (angle === 1 ? 71 : 35) + "em");
1348 this.setAttribute("transform", "translate(" + xTranslate + ", " + yTranslate + ")");
1349 }
1350 i++;
1351 });
1352 };
1353 return TextOverlap;
1354}(Plugin);
1355
1356}();
1357__webpack_exports__ = __webpack_exports__["default"];
1358/******/ return __webpack_exports__;
1359/******/ })()
1360;
1361});
\No newline at end of file