UNPKG

19.8 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 * http://naver.github.io/billboard.js/
7 *
8 * @version 1.12.1
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-selection"));
15 else if(typeof define === 'function' && define.amd)
16 define("bubblecompare", ["d3-selection"], factory);
17 else if(typeof exports === 'object')
18 exports["bubblecompare"] = factory(require("d3-selection"));
19 else
20 root["bb"] = root["bb"] || {}, root["bb"]["plugin"] = root["bb"]["plugin"] || {}, root["bb"]["plugin"]["bubblecompare"] = factory(root["d3"]);
21})(this, function(__WEBPACK_EXTERNAL_MODULE__8__) {
22return /******/ (function(modules) { // webpackBootstrap
23/******/ // The module cache
24/******/ var installedModules = {};
25/******/
26/******/ // The require function
27/******/ function __webpack_require__(moduleId) {
28/******/
29/******/ // Check if module is in cache
30/******/ if(installedModules[moduleId]) {
31/******/ return installedModules[moduleId].exports;
32/******/ }
33/******/ // Create a new module (and put it into the cache)
34/******/ var module = installedModules[moduleId] = {
35/******/ i: moduleId,
36/******/ l: false,
37/******/ exports: {}
38/******/ };
39/******/
40/******/ // Execute the module function
41/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
42/******/
43/******/ // Flag the module as loaded
44/******/ module.l = true;
45/******/
46/******/ // Return the exports of the module
47/******/ return module.exports;
48/******/ }
49/******/
50/******/
51/******/ // expose the modules object (__webpack_modules__)
52/******/ __webpack_require__.m = modules;
53/******/
54/******/ // expose the module cache
55/******/ __webpack_require__.c = installedModules;
56/******/
57/******/ // define getter function for harmony exports
58/******/ __webpack_require__.d = function(exports, name, getter) {
59/******/ if(!__webpack_require__.o(exports, name)) {
60/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
61/******/ }
62/******/ };
63/******/
64/******/ // define __esModule on exports
65/******/ __webpack_require__.r = function(exports) {
66/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
67/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
68/******/ }
69/******/ Object.defineProperty(exports, '__esModule', { value: true });
70/******/ };
71/******/
72/******/ // create a fake namespace object
73/******/ // mode & 1: value is a module id, require it
74/******/ // mode & 2: merge all properties of value into the ns
75/******/ // mode & 4: return value when already ns object
76/******/ // mode & 8|1: behave like require
77/******/ __webpack_require__.t = function(value, mode) {
78/******/ if(mode & 1) value = __webpack_require__(value);
79/******/ if(mode & 8) return value;
80/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
81/******/ var ns = Object.create(null);
82/******/ __webpack_require__.r(ns);
83/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
84/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
85/******/ return ns;
86/******/ };
87/******/
88/******/ // getDefaultExport function for compatibility with non-harmony modules
89/******/ __webpack_require__.n = function(module) {
90/******/ var getter = module && module.__esModule ?
91/******/ function getDefault() { return module['default']; } :
92/******/ function getModuleExports() { return module; };
93/******/ __webpack_require__.d(getter, 'a', getter);
94/******/ return getter;
95/******/ };
96/******/
97/******/ // Object.prototype.hasOwnProperty.call
98/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
99/******/
100/******/ // __webpack_public_path__
101/******/ __webpack_require__.p = "";
102/******/
103/******/
104/******/ // Load entry module and return exports
105/******/ return __webpack_require__(__webpack_require__.s = 0);
106/******/ })
107/************************************************************************/
108/******/ ([
109/* 0 */
110/***/ (function(module, __webpack_exports__, __webpack_require__) {
111
112"use strict";
113__webpack_require__.r(__webpack_exports__);
114/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return BubbleCompare; });
115/* harmony import */ var _babel_runtime_helpers_esm_slicedToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(20);
116/* harmony import */ var _babel_runtime_helpers_esm_classCallCheck__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
117/* harmony import */ var _babel_runtime_helpers_esm_createClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2);
118/* harmony import */ var _babel_runtime_helpers_esm_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(3);
119/* harmony import */ var _babel_runtime_helpers_esm_getPrototypeOf__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6);
120/* harmony import */ var _babel_runtime_helpers_esm_assertThisInitialized__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(5);
121/* harmony import */ var _babel_runtime_helpers_esm_inherits__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(22);
122/* harmony import */ var _babel_runtime_helpers_esm_defineProperty__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(7);
123/* harmony import */ var d3_selection__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(8);
124/* harmony import */ var d3_selection__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(d3_selection__WEBPACK_IMPORTED_MODULE_8__);
125/* harmony import */ var _Plugin__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(9);
126
127
128
129
130
131
132
133
134
135
136/**
137 * Bubble compare diagram plugin.<br>
138 * Compare data 3-dimensional ways: x-axis, y-axis & bubble-size.
139 * - **NOTE:**
140 * - Plugins aren't built-in. Need to be loaded or imported to be used.
141 * - Non required modules from billboard.js core, need to be installed separately.
142 * - **Required modules:**
143 * - [d3-selection](https://github.com/d3/d3-selection)
144 * @class plugin-bubblecompare
145 * @requires d3-selection
146 * @param {Object} options bubble compare plugin options
147 * @extends Plugin
148 * @return {BubbleCompare}
149 * @example
150 * var chart = bb.generate({
151 * data: {
152 * columns: [ ... ],
153 * type: "bubble"
154 * }
155 * ...
156 * plugins: [
157 * new bb.plugin.bubblecompare({
158 * minR: 11,
159 * maxR: 74,
160 * expandScale: 1.1
161 * }),
162 * ]
163 * });
164 * @example
165 * import {bb} from "billboard.js";
166 * import BubbleCompare from "billboard.js/dist/billboardjs-plugin-bubblecompare";
167 *
168 * bb.generate({
169 * plugins: [
170 * new BubbleCompare({ ... })
171 * ]
172 * })
173 */
174
175var BubbleCompare = /*#__PURE__*/function (_Plugin) {
176 function BubbleCompare(options) {
177 var _this;
178
179 return Object(_babel_runtime_helpers_esm_classCallCheck__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"])(this, BubbleCompare), _this = Object(_babel_runtime_helpers_esm_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_3__[/* default */ "a"])(this, Object(_babel_runtime_helpers_esm_getPrototypeOf__WEBPACK_IMPORTED_MODULE_4__[/* default */ "a"])(BubbleCompare).call(this, options)), Object(_babel_runtime_helpers_esm_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_3__[/* default */ "a"])(_this, Object(_babel_runtime_helpers_esm_assertThisInitialized__WEBPACK_IMPORTED_MODULE_5__[/* default */ "a"])(_this));
180 }
181
182 return Object(_babel_runtime_helpers_esm_inherits__WEBPACK_IMPORTED_MODULE_6__[/* default */ "a"])(BubbleCompare, _Plugin), Object(_babel_runtime_helpers_esm_createClass__WEBPACK_IMPORTED_MODULE_2__[/* default */ "a"])(BubbleCompare, [{
183 key: "$init",
184 value: function $init() {
185 var $$ = this.$$;
186 $$.findClosest = this.findClosest.bind(this), $$.getBubbleR = this.getBubbleR.bind(this), $$.pointExpandedR = this.pointExpandedR.bind(this);
187 }
188 }, {
189 key: "pointExpandedR",
190 value: function pointExpandedR(d) {
191 var baseR = this.getBubbleR(d),
192 _this$options$expandS = this.options.expandScale,
193 expandScale = _this$options$expandS === void 0 ? 1 : _this$options$expandS;
194 return BubbleCompare.raiseFocusedBubbleLayer(d), this.changeCursorPoint(), baseR * expandScale;
195 }
196 }, {
197 key: "changeCursorPoint",
198 value: function changeCursorPoint() {
199 this.$$.svg.select(".bb-event-rect").style("cursor", "pointer");
200 }
201 }, {
202 key: "findClosest",
203 value: function findClosest(values, pos) {
204 var _this2 = this,
205 $$ = this.$$;
206
207 return values.filter(function (v) {
208 return v && !$$.isBarType(v.id);
209 }).reduce(function (acc, cur) {
210 var d = $$.dist(cur, pos);
211 return d < _this2.getBubbleR(cur) ? cur : acc;
212 }, 0);
213 }
214 }, {
215 key: "getBubbleR",
216 value: function getBubbleR(d) {
217 var _this3 = this,
218 _this$options = this.options,
219 minR = _this$options.minR,
220 maxR = _this$options.maxR,
221 curVal = this.getZData(d);
222
223 if (!curVal) return minR;
224
225 var _this$$$$data$targets = this.$$.data.targets.reduce(function (_ref, cur) {
226 var _ref2 = Object(_babel_runtime_helpers_esm_slicedToArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(_ref, 2),
227 accMin = _ref2[0],
228 accMax = _ref2[1],
229 val = _this3.getZData(cur.values[0]);
230
231 return [Math.min(accMin, val), Math.max(accMax, val)];
232 }, [1e4, 0]),
233 _this$$$$data$targets2 = Object(_babel_runtime_helpers_esm_slicedToArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(_this$$$$data$targets, 2),
234 min = _this$$$$data$targets2[0],
235 max = _this$$$$data$targets2[1],
236 size = min > 0 && max === min ? 0 : curVal / max;
237
238 return Math.abs(size) * (maxR - minR) + minR;
239 }
240 }, {
241 key: "getZData",
242 value: function getZData(d) {
243 return this.$$.isBubbleZType(d) ? this.$$.getBubbleZData(d.value, "z") : d.value;
244 }
245 }], [{
246 key: "raiseFocusedBubbleLayer",
247 value: function raiseFocusedBubbleLayer(d) {
248 d.raise && Object(d3_selection__WEBPACK_IMPORTED_MODULE_8__["select"])(d.node().parentNode.parentNode).raise();
249 }
250 }]), BubbleCompare;
251}(_Plugin__WEBPACK_IMPORTED_MODULE_9__[/* default */ "a"]);
252
253Object(_babel_runtime_helpers_esm_defineProperty__WEBPACK_IMPORTED_MODULE_7__[/* default */ "a"])(BubbleCompare, "version", "0.0.1");
254
255
256
257/***/ }),
258/* 1 */
259/***/ (function(module, __webpack_exports__, __webpack_require__) {
260
261"use strict";
262/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _classCallCheck; });
263function _classCallCheck(instance, Constructor) {
264 if (!(instance instanceof Constructor)) {
265 throw new TypeError("Cannot call a class as a function");
266 }
267}
268
269/***/ }),
270/* 2 */
271/***/ (function(module, __webpack_exports__, __webpack_require__) {
272
273"use strict";
274/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _createClass; });
275function _defineProperties(target, props) {
276 for (var i = 0; i < props.length; i++) {
277 var descriptor = props[i];
278 descriptor.enumerable = descriptor.enumerable || false;
279 descriptor.configurable = true;
280 if ("value" in descriptor) descriptor.writable = true;
281 Object.defineProperty(target, descriptor.key, descriptor);
282 }
283}
284
285function _createClass(Constructor, protoProps, staticProps) {
286 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
287 if (staticProps) _defineProperties(Constructor, staticProps);
288 return Constructor;
289}
290
291/***/ }),
292/* 3 */
293/***/ (function(module, __webpack_exports__, __webpack_require__) {
294
295"use strict";
296/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _possibleConstructorReturn; });
297/* harmony import */ var _helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4);
298/* harmony import */ var _assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
299
300
301function _possibleConstructorReturn(self, call) {
302 if (call && (Object(_helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(call) === "object" || typeof call === "function")) {
303 return call;
304 }
305
306 return Object(_assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"])(self);
307}
308
309/***/ }),
310/* 4 */
311/***/ (function(module, __webpack_exports__, __webpack_require__) {
312
313"use strict";
314/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _typeof; });
315function _typeof(obj) {
316 "@babel/helpers - typeof";
317
318 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
319 _typeof = function _typeof(obj) {
320 return typeof obj;
321 };
322 } else {
323 _typeof = function _typeof(obj) {
324 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
325 };
326 }
327
328 return _typeof(obj);
329}
330
331/***/ }),
332/* 5 */
333/***/ (function(module, __webpack_exports__, __webpack_require__) {
334
335"use strict";
336/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _assertThisInitialized; });
337function _assertThisInitialized(self) {
338 if (self === void 0) {
339 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
340 }
341
342 return self;
343}
344
345/***/ }),
346/* 6 */
347/***/ (function(module, __webpack_exports__, __webpack_require__) {
348
349"use strict";
350/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _getPrototypeOf; });
351function _getPrototypeOf(o) {
352 _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
353 return o.__proto__ || Object.getPrototypeOf(o);
354 };
355 return _getPrototypeOf(o);
356}
357
358/***/ }),
359/* 7 */
360/***/ (function(module, __webpack_exports__, __webpack_require__) {
361
362"use strict";
363/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _defineProperty; });
364function _defineProperty(obj, key, value) {
365 if (key in obj) {
366 Object.defineProperty(obj, key, {
367 value: value,
368 enumerable: true,
369 configurable: true,
370 writable: true
371 });
372 } else {
373 obj[key] = value;
374 }
375
376 return obj;
377}
378
379/***/ }),
380/* 8 */
381/***/ (function(module, exports) {
382
383module.exports = __WEBPACK_EXTERNAL_MODULE__8__;
384
385/***/ }),
386/* 9 */
387/***/ (function(module, __webpack_exports__, __webpack_require__) {
388
389"use strict";
390/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Plugin; });
391/* harmony import */ var _babel_runtime_helpers_esm_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
392/* harmony import */ var _babel_runtime_helpers_esm_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
393/* harmony import */ var _babel_runtime_helpers_esm_defineProperty__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(7);
394
395
396
397
398/**
399 * Copyright (c) 2017 ~ present NAVER Corp.
400 * billboard.js project is licensed under the MIT license
401 */
402
403/**
404 * Base class to generate billboard.js plugin
405 * @class Plugin
406 */
407var Plugin = /*#__PURE__*/function () {
408 /**
409 * Version info string for plugin
410 * @name version
411 * @static
412 * @memberof Plugin
413 * @type {String}
414 * @example
415 * bb.plugin.stanford.version; // ex) 1.9.0
416 */
417
418 /**
419 * Constructor
420 * @param {Any} config config option object
421 * @private
422 */
423 function Plugin() {
424 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
425 Object(_babel_runtime_helpers_esm_classCallCheck__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(this, Plugin), this.options = options;
426 }
427 /**
428 * Lifecycle hook for 'beforeInit' phase.
429 * @private
430 */
431
432
433 return Object(_babel_runtime_helpers_esm_createClass__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"])(Plugin, [{
434 key: "$beforeInit",
435 value: function $beforeInit() {}
436 /**
437 * Lifecycle hook for 'init' phase.
438 * @private
439 */
440
441 }, {
442 key: "$init",
443 value: function $init() {}
444 /**
445 * Lifecycle hook for 'afterInit' phase.
446 * @private
447 */
448
449 }, {
450 key: "$afterInit",
451 value: function $afterInit() {}
452 /**
453 * Lifecycle hook for 'redraw' phase.
454 * @private
455 */
456
457 }, {
458 key: "$redraw",
459 value: function $redraw() {}
460 /**
461 * Lifecycle hook for 'willDestroy' phase.
462 * @private
463 */
464
465 }, {
466 key: "$willDestroy",
467 value: function $willDestroy() {
468 var _this = this;
469
470 Object.keys(this).forEach(function (key) {
471 _this[key] = null, delete _this[key];
472 });
473 }
474 }]), Plugin;
475}();
476
477Object(_babel_runtime_helpers_esm_defineProperty__WEBPACK_IMPORTED_MODULE_2__[/* default */ "a"])(Plugin, "version", "1.12.1");
478
479
480
481/***/ }),
482/* 10 */,
483/* 11 */,
484/* 12 */,
485/* 13 */,
486/* 14 */,
487/* 15 */,
488/* 16 */,
489/* 17 */,
490/* 18 */,
491/* 19 */,
492/* 20 */
493/***/ (function(module, __webpack_exports__, __webpack_require__) {
494
495"use strict";
496
497// EXPORTS
498__webpack_require__.d(__webpack_exports__, "a", function() { return /* binding */ _slicedToArray; });
499
500// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js
501function _arrayWithHoles(arr) {
502 if (Array.isArray(arr)) return arr;
503}
504// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js
505function _iterableToArrayLimit(arr, i) {
506 if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
507 return;
508 }
509
510 var _arr = [];
511 var _n = true;
512 var _d = false;
513 var _e = undefined;
514
515 try {
516 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
517 _arr.push(_s.value);
518
519 if (i && _arr.length === i) break;
520 }
521 } catch (err) {
522 _d = true;
523 _e = err;
524 } finally {
525 try {
526 if (!_n && _i["return"] != null) _i["return"]();
527 } finally {
528 if (_d) throw _e;
529 }
530 }
531
532 return _arr;
533}
534// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/nonIterableRest.js
535function _nonIterableRest() {
536 throw new TypeError("Invalid attempt to destructure non-iterable instance");
537}
538// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js
539
540
541
542function _slicedToArray(arr, i) {
543 return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
544}
545
546/***/ }),
547/* 21 */,
548/* 22 */
549/***/ (function(module, __webpack_exports__, __webpack_require__) {
550
551"use strict";
552
553// EXPORTS
554__webpack_require__.d(__webpack_exports__, "a", function() { return /* binding */ _inherits; });
555
556// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js
557function _setPrototypeOf(o, p) {
558 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
559 o.__proto__ = p;
560 return o;
561 };
562
563 return _setPrototypeOf(o, p);
564}
565// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/inherits.js
566
567function _inherits(subClass, superClass) {
568 if (typeof superClass !== "function" && superClass !== null) {
569 throw new TypeError("Super expression must either be null or a function");
570 }
571
572 subClass.prototype = Object.create(superClass && superClass.prototype, {
573 constructor: {
574 value: subClass,
575 writable: true,
576 configurable: true
577 }
578 });
579 if (superClass) _setPrototypeOf(subClass, superClass);
580}
581
582/***/ })
583/******/ ])["default"];
584});
\No newline at end of file