UNPKG

9.98 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-selection"));
15 else if(typeof define === 'function' && define.amd)
16 define("bb", ["d3-selection"], factory);
17 else if(typeof exports === 'object')
18 exports["bb"] = 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__1__) {
22return /******/ (function() { // webpackBootstrap
23/******/ "use strict";
24/******/ var __webpack_modules__ = ([
25/* 0 */,
26/* 1 */
27/***/ (function(module) {
28
29module.exports = __WEBPACK_EXTERNAL_MODULE__1__;
30
31/***/ })
32/******/ ]);
33/************************************************************************/
34/******/ // The module cache
35/******/ var __webpack_module_cache__ = {};
36/******/
37/******/ // The require function
38/******/ function __webpack_require__(moduleId) {
39/******/ // Check if module is in cache
40/******/ var cachedModule = __webpack_module_cache__[moduleId];
41/******/ if (cachedModule !== undefined) {
42/******/ return cachedModule.exports;
43/******/ }
44/******/ // Create a new module (and put it into the cache)
45/******/ var module = __webpack_module_cache__[moduleId] = {
46/******/ // no module.id needed
47/******/ // no module.loaded needed
48/******/ exports: {}
49/******/ };
50/******/
51/******/ // Execute the module function
52/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
53/******/
54/******/ // Return the exports of the module
55/******/ return module.exports;
56/******/ }
57/******/
58/************************************************************************/
59/******/ /* webpack/runtime/define property getters */
60/******/ !function() {
61/******/ // define getter functions for harmony exports
62/******/ __webpack_require__.d = function(exports, definition) {
63/******/ for(var key in definition) {
64/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
65/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
66/******/ }
67/******/ }
68/******/ };
69/******/ }();
70/******/
71/******/ /* webpack/runtime/hasOwnProperty shorthand */
72/******/ !function() {
73/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
74/******/ }();
75/******/
76/************************************************************************/
77var __webpack_exports__ = {};
78// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
79!function() {
80
81// EXPORTS
82__webpack_require__.d(__webpack_exports__, {
83 "default": function() { return /* binding */ BubbleCompare; }
84});
85
86;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/newArrowCheck.js
87function _newArrowCheck(innerThis, boundThis) {
88 if (innerThis !== boundThis) {
89 throw new TypeError("Cannot instantiate an arrow function");
90 }
91}
92;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js
93function _assertThisInitialized(self) {
94 if (self === void 0) {
95 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
96 }
97 return self;
98}
99;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js
100function _setPrototypeOf(o, p) {
101 _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
102 o.__proto__ = p;
103 return o;
104 };
105 return _setPrototypeOf(o, p);
106}
107;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js
108
109function _inheritsLoose(subClass, superClass) {
110 subClass.prototype = Object.create(superClass.prototype);
111 subClass.prototype.constructor = subClass;
112 _setPrototypeOf(subClass, superClass);
113}
114// EXTERNAL MODULE: external {"commonjs":"d3-selection","commonjs2":"d3-selection","amd":"d3-selection","root":"d3"}
115var external_commonjs_d3_selection_commonjs2_d3_selection_amd_d3_selection_root_d3_ = __webpack_require__(1);
116;// CONCATENATED MODULE: ./src/Plugin/Plugin.ts
117
118/**
119 * Copyright (c) 2017 ~ present NAVER Corp.
120 * billboard.js project is licensed under the MIT license
121 */
122/**
123 * Base class to generate billboard.js plugin
124 * @class Plugin
125 */
126/**
127 * Version info string for plugin
128 * @name version
129 * @static
130 * @memberof Plugin
131 * @type {string}
132 * @example
133 * bb.plugin.stanford.version; // ex) 1.9.0
134 */
135var Plugin = /*#__PURE__*/function () {
136 /**
137 * Constructor
138 * @param {Any} options config option object
139 * @private
140 */
141 function Plugin(options) {
142 if (options === void 0) {
143 options = {};
144 }
145 this.$$ = void 0;
146 this.options = void 0;
147 this.options = options;
148 }
149
150 /**
151 * Lifecycle hook for 'beforeInit' phase.
152 * @private
153 */
154 var _proto = Plugin.prototype;
155 _proto.$beforeInit = function $beforeInit() {}
156
157 /**
158 * Lifecycle hook for 'init' phase.
159 * @private
160 */;
161 _proto.$init = function $init() {}
162
163 /**
164 * Lifecycle hook for 'afterInit' phase.
165 * @private
166 */;
167 _proto.$afterInit = function $afterInit() {}
168
169 /**
170 * Lifecycle hook for 'redraw' phase.
171 * @private
172 */;
173 _proto.$redraw = function $redraw() {}
174
175 /**
176 * Lifecycle hook for 'willDestroy' phase.
177 * @private
178 */;
179 _proto.$willDestroy = function $willDestroy() {
180 var _this = this;
181 Object.keys(this).forEach(function (key) {
182 _newArrowCheck(this, _this);
183 this[key] = null;
184 delete this[key];
185 }.bind(this));
186 };
187 return Plugin;
188}();
189Plugin.version = "3.6.3";
190
191;// CONCATENATED MODULE: ./src/Plugin/bubblecompare/index.ts
192
193
194
195
196
197
198/**
199 * Bubble compare diagram plugin.<br>
200 * Compare data 3-dimensional ways: x-axis, y-axis & bubble-size.
201 * - **NOTE:**
202 * - Plugins aren't built-in. Need to be loaded or imported to be used.
203 * - Non required modules from billboard.js core, need to be installed separately.
204 * - **Required modules:**
205 * - [d3-selection](https://github.com/d3/d3-selection)
206 * @class plugin-bubblecompare
207 * @requires d3-selection
208 * @param {object} options bubble compare plugin options
209 * @augments Plugin
210 * @returns {BubbleCompare}
211 * @example
212 * // Plugin must be loaded before the use.
213 * <script src="$YOUR_PATH/plugin/billboardjs-plugin-bubblecompare.js"></script>
214 *
215 * var chart = bb.generate({
216 * data: {
217 * columns: [ ... ],
218 * type: "bubble"
219 * }
220 * ...
221 * plugins: [
222 * new bb.plugin.bubblecompare({
223 * minR: 11,
224 * maxR: 74,
225 * expandScale: 1.1
226 * }),
227 * ]
228 * });
229 * @example
230 * import {bb} from "billboard.js";
231 * import BubbleCompare from "billboard.js/dist/billboardjs-plugin-bubblecompare";
232 *
233 * bb.generate({
234 * plugins: [
235 * new BubbleCompare({ ... })
236 * ]
237 * })
238 */
239var BubbleCompare = /*#__PURE__*/function (_Plugin) {
240 _inheritsLoose(BubbleCompare, _Plugin);
241 function BubbleCompare(options) {
242 var _this = _Plugin.call(this, options) || this;
243 _this.$$ = void 0;
244 return _assertThisInitialized(_this) || _assertThisInitialized(_this);
245 }
246 var _proto = BubbleCompare.prototype;
247 _proto.$init = function $init() {
248 var $$ = this.$$;
249 $$.findClosest = this.findClosest.bind(this);
250 $$.getBubbleR = this.getBubbleR.bind(this);
251 $$.pointExpandedR = this.pointExpandedR.bind(this);
252 };
253 _proto.pointExpandedR = function pointExpandedR(d) {
254 var baseR = this.getBubbleR(d),
255 _this$options$expandS = this.options.expandScale,
256 expandScale = _this$options$expandS === void 0 ? 1 : _this$options$expandS;
257 BubbleCompare.raiseFocusedBubbleLayer(d);
258 this.changeCursorPoint();
259 return baseR * expandScale;
260 };
261 BubbleCompare.raiseFocusedBubbleLayer = function raiseFocusedBubbleLayer(d) {
262 d.raise && (0,external_commonjs_d3_selection_commonjs2_d3_selection_amd_d3_selection_root_d3_.select)(d.node().parentNode.parentNode).raise();
263 };
264 _proto.changeCursorPoint = function changeCursorPoint() {
265 this.$$.$el.svg.select(".bb-event-rect").style("cursor", "pointer");
266 };
267 _proto.findClosest = function findClosest(values, pos) {
268 var _this2 = this,
269 $$ = this.$$;
270 return values.filter(function (v) {
271 _newArrowCheck(this, _this2);
272 return v && !$$.isBarType(v.id);
273 }.bind(this)).reduce(function (acc, cur) {
274 _newArrowCheck(this, _this2);
275 var d = $$.dist(cur, pos);
276 return d < this.getBubbleR(cur) ? cur : acc;
277 }.bind(this), 0);
278 };
279 _proto.getBubbleR = function getBubbleR(d) {
280 var _this3 = this,
281 _this$options = this.options,
282 minR = _this$options.minR,
283 maxR = _this$options.maxR,
284 curVal = this.getZData(d);
285 if (!curVal) return minR;
286 var _this$$$$data$targets = this.$$.data.targets.reduce(function (_ref, cur) {
287 var accMin = _ref[0],
288 accMax = _ref[1];
289 _newArrowCheck(this, _this3);
290 var val = this.getZData(cur.values[0]);
291 return [Math.min(accMin, val), Math.max(accMax, val)];
292 }.bind(this), [1e4, 0]),
293 min = _this$$$$data$targets[0],
294 max = _this$$$$data$targets[1],
295 size = min > 0 && max === min ? 0 : curVal / max;
296 return Math.abs(size) * (maxR - minR) + minR;
297 };
298 _proto.getZData = function getZData(d) {
299 return this.$$.isBubbleZType(d) ? this.$$.getBubbleZData(d.value, "z") : d.value;
300 };
301 return BubbleCompare;
302}(Plugin);
303BubbleCompare.version = "0.0.1";
304
305}();
306__webpack_exports__ = __webpack_exports__["default"];
307/******/ return __webpack_exports__;
308/******/ })()
309;
310});
\No newline at end of file