UNPKG

9.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-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/assertThisInitialized.js
87function _assertThisInitialized(self) {
88 if (self === void 0) {
89 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
90 }
91
92 return self;
93}
94;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js
95function _setPrototypeOf(o, p) {
96 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
97 o.__proto__ = p;
98 return o;
99 };
100
101 return _setPrototypeOf(o, p);
102}
103;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js
104
105function _inheritsLoose(subClass, superClass) {
106 subClass.prototype = Object.create(superClass.prototype);
107 subClass.prototype.constructor = subClass;
108 _setPrototypeOf(subClass, superClass);
109}
110// EXTERNAL MODULE: external {"commonjs":"d3-selection","commonjs2":"d3-selection","amd":"d3-selection","root":"d3"}
111var external_commonjs_d3_selection_commonjs2_d3_selection_amd_d3_selection_root_d3_ = __webpack_require__(1);
112;// CONCATENATED MODULE: ./src/Plugin/Plugin.ts
113/**
114 * Copyright (c) 2017 ~ present NAVER Corp.
115 * billboard.js project is licensed under the MIT license
116 */
117
118/**
119 * Base class to generate billboard.js plugin
120 * @class Plugin
121 */
122
123/**
124 * Version info string for plugin
125 * @name version
126 * @static
127 * @memberof Plugin
128 * @type {string}
129 * @example
130 * bb.plugin.stanford.version; // ex) 1.9.0
131 */
132var Plugin = /*#__PURE__*/function () {
133 /**
134 * Constructor
135 * @param {Any} options config option object
136 * @private
137 */
138 function Plugin(options) {
139 if (options === void 0) {
140 options = {};
141 }
142
143 this.$$ = void 0;
144 this.options = void 0;
145 this.options = options;
146 }
147 /**
148 * Lifecycle hook for 'beforeInit' phase.
149 * @private
150 */
151
152
153 var _proto = Plugin.prototype;
154
155 _proto.$beforeInit = function $beforeInit() {}
156 /**
157 * Lifecycle hook for 'init' phase.
158 * @private
159 */
160 ;
161
162 _proto.$init = function $init() {}
163 /**
164 * Lifecycle hook for 'afterInit' phase.
165 * @private
166 */
167 ;
168
169 _proto.$afterInit = function $afterInit() {}
170 /**
171 * Lifecycle hook for 'redraw' phase.
172 * @private
173 */
174 ;
175
176 _proto.$redraw = function $redraw() {}
177 /**
178 * Lifecycle hook for 'willDestroy' phase.
179 * @private
180 */
181 ;
182
183 _proto.$willDestroy = function $willDestroy() {
184 var _this = this;
185
186 Object.keys(this).forEach(function (key) {
187 _this[key] = null;
188 delete _this[key];
189 });
190 };
191
192 return Plugin;
193}();
194
195Plugin.version = "3.2.1";
196
197;// CONCATENATED MODULE: ./src/Plugin/bubblecompare/index.ts
198
199
200
201
202/**
203 * Bubble compare diagram plugin.<br>
204 * Compare data 3-dimensional ways: x-axis, y-axis & bubble-size.
205 * - **NOTE:**
206 * - Plugins aren't built-in. Need to be loaded or imported to be used.
207 * - Non required modules from billboard.js core, need to be installed separately.
208 * - **Required modules:**
209 * - [d3-selection](https://github.com/d3/d3-selection)
210 * @class plugin-bubblecompare
211 * @requires d3-selection
212 * @param {object} options bubble compare plugin options
213 * @augments Plugin
214 * @returns {BubbleCompare}
215 * @example
216 * // Plugin must be loaded before the use.
217 * <script src="$YOUR_PATH/plugin/billboardjs-plugin-bubblecompare.js"></script>
218 *
219 * var chart = bb.generate({
220 * data: {
221 * columns: [ ... ],
222 * type: "bubble"
223 * }
224 * ...
225 * plugins: [
226 * new bb.plugin.bubblecompare({
227 * minR: 11,
228 * maxR: 74,
229 * expandScale: 1.1
230 * }),
231 * ]
232 * });
233 * @example
234 * import {bb} from "billboard.js";
235 * import BubbleCompare from "billboard.js/dist/billboardjs-plugin-bubblecompare";
236 *
237 * bb.generate({
238 * plugins: [
239 * new BubbleCompare({ ... })
240 * ]
241 * })
242 */
243
244var BubbleCompare = /*#__PURE__*/function (_Plugin) {
245 _inheritsLoose(BubbleCompare, _Plugin);
246
247 function BubbleCompare(options) {
248 var _this = _Plugin.call(this, options) || this;
249
250 _this.$$ = void 0;
251 return _assertThisInitialized(_this) || _assertThisInitialized(_this);
252 }
253
254 var _proto = BubbleCompare.prototype;
255
256 _proto.$init = function $init() {
257 var $$ = this.$$;
258 $$.findClosest = this.findClosest.bind(this);
259 $$.getBubbleR = this.getBubbleR.bind(this);
260 $$.pointExpandedR = this.pointExpandedR.bind(this);
261 };
262
263 _proto.pointExpandedR = function pointExpandedR(d) {
264 var baseR = this.getBubbleR(d),
265 _this$options$expandS = this.options.expandScale,
266 expandScale = _this$options$expandS === void 0 ? 1 : _this$options$expandS;
267 BubbleCompare.raiseFocusedBubbleLayer(d);
268 this.changeCursorPoint();
269 return baseR * expandScale;
270 };
271
272 BubbleCompare.raiseFocusedBubbleLayer = function raiseFocusedBubbleLayer(d) {
273 d.raise && (0,external_commonjs_d3_selection_commonjs2_d3_selection_amd_d3_selection_root_d3_.select)(d.node().parentNode.parentNode).raise();
274 };
275
276 _proto.changeCursorPoint = function changeCursorPoint() {
277 this.$$.$el.svg.select(".bb-event-rect").style("cursor", "pointer");
278 };
279
280 _proto.findClosest = function findClosest(values, pos) {
281 var _this2 = this,
282 $$ = this.$$;
283
284 return values.filter(function (v) {
285 return v && !$$.isBarType(v.id);
286 }).reduce(function (acc, cur) {
287 var d = $$.dist(cur, pos);
288 return d < _this2.getBubbleR(cur) ? cur : acc;
289 }, 0);
290 };
291
292 _proto.getBubbleR = function getBubbleR(d) {
293 var _this3 = this,
294 _this$options = this.options,
295 minR = _this$options.minR,
296 maxR = _this$options.maxR,
297 curVal = this.getZData(d);
298
299 if (!curVal) return minR;
300
301 var _this$$$$data$targets = this.$$.data.targets.reduce(function (_ref, cur) {
302 var accMin = _ref[0],
303 accMax = _ref[1],
304 val = _this3.getZData(cur.values[0]);
305
306 return [Math.min(accMin, val), Math.max(accMax, val)];
307 }, [1e4, 0]),
308 min = _this$$$$data$targets[0],
309 max = _this$$$$data$targets[1],
310 size = min > 0 && max === min ? 0 : curVal / max;
311
312 return Math.abs(size) * (maxR - minR) + minR;
313 };
314
315 _proto.getZData = function getZData(d) {
316 return this.$$.isBubbleZType(d) ? this.$$.getBubbleZData(d.value, "z") : d.value;
317 };
318
319 return BubbleCompare;
320}(Plugin);
321
322BubbleCompare.version = "0.0.1";
323
324}();
325__webpack_exports__ = __webpack_exports__["default"];
326/******/ return __webpack_exports__;
327/******/ })()
328;
329});
\No newline at end of file