|
| 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.17.2 |
| 9 | + * @requires billboard.js |
| 10 | + * @summary billboard.js plugin |
| 11 | +*/ |
| 12 | +import { select } from 'd3-selection'; |
| 13 | + |
| 14 | +/****************************************************************************** |
| 15 | +Copyright (c) Microsoft Corporation. |
| 16 | +
|
| 17 | +Permission to use, copy, modify, and/or distribute this software for any |
| 18 | +purpose with or without fee is hereby granted. |
| 19 | +
|
| 20 | +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH |
| 21 | +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
| 22 | +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, |
| 23 | +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
| 24 | +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
| 25 | +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 26 | +PERFORMANCE OF THIS SOFTWARE. |
| 27 | +***************************************************************************** */ |
| 28 | +/* global Reflect, Promise, SuppressedError, Symbol, Iterator */ |
| 29 | + |
| 30 | +var extendStatics = function(d, b) { |
| 31 | + extendStatics = Object.setPrototypeOf || |
| 32 | + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
| 33 | + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; |
| 34 | + return extendStatics(d, b); |
| 35 | +}; |
| 36 | + |
| 37 | +function __extends(d, b) { |
| 38 | + if (typeof b !== "function" && b !== null) |
| 39 | + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); |
| 40 | + extendStatics(d, b); |
| 41 | + function __() { this.constructor = d; } |
| 42 | + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
| 43 | +} |
| 44 | + |
| 45 | +/** |
| 46 | + * Copyright (c) 2017 ~ present NAVER Corp. |
| 47 | + * billboard.js project is licensed under the MIT license |
| 48 | + */ |
| 49 | +/** |
| 50 | + * Base class to generate billboard.js plugin |
| 51 | + * @class Plugin |
| 52 | + */ |
| 53 | +/** |
| 54 | + * Version info string for plugin |
| 55 | + * @name version |
| 56 | + * @static |
| 57 | + * @memberof Plugin |
| 58 | + * @type {string} |
| 59 | + * @example |
| 60 | + * bb.plugin.stanford.version; // ex) 1.9.0 |
| 61 | + */ |
| 62 | +var Plugin = /** @class */ (function () { |
| 63 | + /** |
| 64 | + * Constructor |
| 65 | + * @param {Any} options config option object |
| 66 | + * @private |
| 67 | + */ |
| 68 | + function Plugin(options) { |
| 69 | + if (options === void 0) { options = {}; } |
| 70 | + this.options = options; |
| 71 | + } |
| 72 | + /** |
| 73 | + * Lifecycle hook for 'beforeInit' phase. |
| 74 | + * @private |
| 75 | + */ |
| 76 | + Plugin.prototype.$beforeInit = function () { }; |
| 77 | + /** |
| 78 | + * Lifecycle hook for 'init' phase. |
| 79 | + * @private |
| 80 | + */ |
| 81 | + Plugin.prototype.$init = function () { }; |
| 82 | + /** |
| 83 | + * Lifecycle hook for 'afterInit' phase. |
| 84 | + * @private |
| 85 | + */ |
| 86 | + Plugin.prototype.$afterInit = function () { }; |
| 87 | + /** |
| 88 | + * Lifecycle hook for 'redraw' phase. |
| 89 | + * @private |
| 90 | + */ |
| 91 | + Plugin.prototype.$redraw = function () { }; |
| 92 | + /** |
| 93 | + * Lifecycle hook for 'willDestroy' phase. |
| 94 | + * @private |
| 95 | + */ |
| 96 | + Plugin.prototype.$willDestroy = function () { |
| 97 | + var _this = this; |
| 98 | + Object.keys(this).forEach(function (key) { |
| 99 | + _this[key] = null; |
| 100 | + delete _this[key]; |
| 101 | + }); |
| 102 | + }; |
| 103 | + Plugin.version = "3.17.2"; |
| 104 | + return Plugin; |
| 105 | +}()); |
| 106 | + |
| 107 | +/** |
| 108 | + * Bubble compare diagram plugin.<br> |
| 109 | + * Compare data 3-dimensional ways: x-axis, y-axis & bubble-size. |
| 110 | + * - **NOTE:** |
| 111 | + * - Plugins aren't built-in. Need to be loaded or imported to be used. |
| 112 | + * - Non required modules from billboard.js core, need to be installed separately. |
| 113 | + * - **Required modules:** |
| 114 | + * - [d3-selection](https://github.com/d3/d3-selection) |
| 115 | + * @class plugin-bubblecompare |
| 116 | + * @requires d3-selection |
| 117 | + * @param {object} options bubble compare plugin options |
| 118 | + * @augments Plugin |
| 119 | + * @returns {BubbleCompare} |
| 120 | + * @example |
| 121 | + * // Plugin must be loaded before the use. |
| 122 | + * <script src="$YOUR_PATH/plugin/billboardjs-plugin-bubblecompare.js"></script> |
| 123 | + * |
| 124 | + * var chart = bb.generate({ |
| 125 | + * data: { |
| 126 | + * columns: [ ... ], |
| 127 | + * type: "bubble" |
| 128 | + * } |
| 129 | + * ... |
| 130 | + * plugins: [ |
| 131 | + * new bb.plugin.bubblecompare({ |
| 132 | + * minR: 11, |
| 133 | + * maxR: 74, |
| 134 | + * expandScale: 1.1 |
| 135 | + * }), |
| 136 | + * ] |
| 137 | + * }); |
| 138 | + * @example |
| 139 | + * import {bb} from "billboard.js"; |
| 140 | + * import BubbleCompare from "billboard.js/dist/billboardjs-plugin-bubblecompare"; |
| 141 | + * |
| 142 | + * bb.generate({ |
| 143 | + * plugins: [ |
| 144 | + * new BubbleCompare({ ... }) |
| 145 | + * ] |
| 146 | + * }) |
| 147 | + */ |
| 148 | +var BubbleCompare = /** @class */ (function (_super) { |
| 149 | + __extends(BubbleCompare, _super); |
| 150 | + function BubbleCompare(options) { |
| 151 | + var _this = _super.call(this, options) || this; |
| 152 | + return _this; |
| 153 | + } |
| 154 | + BubbleCompare.prototype.$init = function () { |
| 155 | + var $$ = this.$$; |
| 156 | + $$.findClosest = this.findClosest.bind(this); |
| 157 | + $$.getBubbleR = this.getBubbleR.bind(this); |
| 158 | + $$.pointExpandedR = this.pointExpandedR.bind(this); |
| 159 | + }; |
| 160 | + BubbleCompare.prototype.pointExpandedR = function (d) { |
| 161 | + var baseR = this.getBubbleR(d); |
| 162 | + var _a = this.options.expandScale, expandScale = _a === void 0 ? 1 : _a; |
| 163 | + BubbleCompare.raiseFocusedBubbleLayer(d); |
| 164 | + this.changeCursorPoint(); |
| 165 | + return baseR * expandScale; |
| 166 | + }; |
| 167 | + BubbleCompare.raiseFocusedBubbleLayer = function (d) { |
| 168 | + d.raise && select(d.node().parentNode.parentNode).raise(); |
| 169 | + }; |
| 170 | + BubbleCompare.prototype.changeCursorPoint = function () { |
| 171 | + this.$$.$el.eventRect.style("cursor", "pointer"); |
| 172 | + }; |
| 173 | + BubbleCompare.prototype.findClosest = function (values, pos) { |
| 174 | + var _this = this; |
| 175 | + var $$ = this.$$; |
| 176 | + return values |
| 177 | + .filter(function (v) { return v && !$$.isBarType(v.id); }) |
| 178 | + .reduce(function (acc, cur) { |
| 179 | + var d = $$.dist(cur, pos); |
| 180 | + return d < _this.getBubbleR(cur) ? cur : acc; |
| 181 | + }, 0); |
| 182 | + }; |
| 183 | + BubbleCompare.prototype.getBubbleR = function (d) { |
| 184 | + var _this = this; |
| 185 | + var _a = this.options, minR = _a.minR, maxR = _a.maxR; |
| 186 | + var curVal = this.getZData(d); |
| 187 | + if (!curVal) |
| 188 | + return minR; |
| 189 | + var _b = this.$$.data.targets.reduce(function (_a, cur) { |
| 190 | + var accMin = _a[0], accMax = _a[1]; |
| 191 | + var val = _this.getZData(cur.values[0]); |
| 192 | + return [Math.min(accMin, val), Math.max(accMax, val)]; |
| 193 | + }, [10000, 0]), min = _b[0], max = _b[1]; |
| 194 | + var size = min > 0 && max === min ? 0 : curVal / max; |
| 195 | + return Math.abs(size) * (maxR - minR) + minR; |
| 196 | + }; |
| 197 | + BubbleCompare.prototype.getZData = function (d) { |
| 198 | + return this.$$.isBubbleZType(d) ? this.$$.getBubbleZData(d.value, "z") : d.value; |
| 199 | + }; |
| 200 | + BubbleCompare.version = "0.0.1"; |
| 201 | + return BubbleCompare; |
| 202 | +}(Plugin)); |
| 203 | + |
| 204 | +export { BubbleCompare as default }; |
0 commit comments