1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | (function webpackUniversalModuleDefinition(root, factory) {
|
13 | if(typeof exports === 'object' && typeof module === 'object')
|
14 | module.exports = factory(require("d3-color"), require("d3-interpolate"), require("d3-scale"), require("d3-brush"), require("d3-selection"), require("d3-axis"), require("d3-format"));
|
15 | else if(typeof define === 'function' && define.amd)
|
16 | define("bb", ["d3-color", "d3-interpolate", "d3-scale", "d3-brush", "d3-selection", "d3-axis", "d3-format"], factory);
|
17 | else if(typeof exports === 'object')
|
18 | exports["bb"] = factory(require("d3-color"), require("d3-interpolate"), require("d3-scale"), require("d3-brush"), require("d3-selection"), require("d3-axis"), require("d3-format"));
|
19 | else
|
20 | root["bb"] = root["bb"] || {}, root["bb"]["plugin"] = root["bb"]["plugin"] || {}, root["bb"]["plugin"]["stanford"] = factory(root["d3"], root["d3"], root["d3"], root["d3"], root["d3"], root["d3"], root["d3"]);
|
21 | })(this, function(__WEBPACK_EXTERNAL_MODULE__5__, __WEBPACK_EXTERNAL_MODULE__6__, __WEBPACK_EXTERNAL_MODULE__7__, __WEBPACK_EXTERNAL_MODULE__3__, __WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__8__, __WEBPACK_EXTERNAL_MODULE__9__) {
|
22 | return (function() {
|
23 | "use strict";
|
24 | var __webpack_modules__ = ([
|
25 | ,
|
26 |
|
27 | (function(module) {
|
28 |
|
29 | module.exports = __WEBPACK_EXTERNAL_MODULE__1__;
|
30 |
|
31 | }),
|
32 | ,
|
33 |
|
34 | (function(module) {
|
35 |
|
36 | module.exports = __WEBPACK_EXTERNAL_MODULE__3__;
|
37 |
|
38 | }),
|
39 | ,
|
40 |
|
41 | (function(module) {
|
42 |
|
43 | module.exports = __WEBPACK_EXTERNAL_MODULE__5__;
|
44 |
|
45 | }),
|
46 |
|
47 | (function(module) {
|
48 |
|
49 | module.exports = __WEBPACK_EXTERNAL_MODULE__6__;
|
50 |
|
51 | }),
|
52 |
|
53 | (function(module) {
|
54 |
|
55 | module.exports = __WEBPACK_EXTERNAL_MODULE__7__;
|
56 |
|
57 | }),
|
58 |
|
59 | (function(module) {
|
60 |
|
61 | module.exports = __WEBPACK_EXTERNAL_MODULE__8__;
|
62 |
|
63 | }),
|
64 |
|
65 | (function(module) {
|
66 |
|
67 | module.exports = __WEBPACK_EXTERNAL_MODULE__9__;
|
68 |
|
69 | })
|
70 | ]);
|
71 |
|
72 |
|
73 | var __webpack_module_cache__ = {};
|
74 |
|
75 |
|
76 | function __webpack_require__(moduleId) {
|
77 |
|
78 | var cachedModule = __webpack_module_cache__[moduleId];
|
79 | if (cachedModule !== undefined) {
|
80 | return cachedModule.exports;
|
81 | }
|
82 |
|
83 | var module = __webpack_module_cache__[moduleId] = {
|
84 |
|
85 |
|
86 | exports: {}
|
87 | };
|
88 |
|
89 |
|
90 | __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
91 |
|
92 |
|
93 | return module.exports;
|
94 | }
|
95 |
|
96 |
|
97 |
|
98 | !function() {
|
99 |
|
100 | __webpack_require__.d = function(exports, definition) {
|
101 | for(var key in definition) {
|
102 | if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
103 | Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
104 | }
|
105 | }
|
106 | };
|
107 | }();
|
108 |
|
109 |
|
110 | !function() {
|
111 | __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
|
112 | }();
|
113 |
|
114 |
|
115 | var __webpack_exports__ = {};
|
116 |
|
117 | !function() {
|
118 |
|
119 |
|
120 | __webpack_require__.d(__webpack_exports__, {
|
121 | "default": function() { return Stanford; }
|
122 | });
|
123 |
|
124 |
|
125 | var external_commonjs_d3_color_commonjs2_d3_color_amd_d3_color_root_d3_ = __webpack_require__(5);
|
126 |
|
127 | var external_commonjs_d3_interpolate_commonjs2_d3_interpolate_amd_d3_interpolate_root_d3_ = __webpack_require__(6);
|
128 |
|
129 | var external_commonjs_d3_scale_commonjs2_d3_scale_amd_d3_scale_root_d3_ = __webpack_require__(7);
|
130 | ;
|
131 | var __defProp = Object.defineProperty;
|
132 | var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
133 | var __hasOwnProp = Object.prototype.hasOwnProperty;
|
134 | var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
135 | var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
136 | var __spreadValues = (a, b) => {
|
137 | for (var prop in b || (b = {}))
|
138 | if (__hasOwnProp.call(b, prop))
|
139 | __defNormalProp(a, prop, b[prop]);
|
140 | if (__getOwnPropSymbols)
|
141 | for (var prop of __getOwnPropSymbols(b)) {
|
142 | if (__propIsEnum.call(b, prop))
|
143 | __defNormalProp(a, prop, b[prop]);
|
144 | }
|
145 | return a;
|
146 | };
|
147 | const $COMMON = {
|
148 | button: "bb-button",
|
149 | chart: "bb-chart",
|
150 | empty: "bb-empty",
|
151 | main: "bb-main",
|
152 | target: "bb-target",
|
153 | EXPANDED: "_expanded_"
|
154 | };
|
155 | const $ARC = {
|
156 | arc: "bb-arc",
|
157 | arcLabelLine: "bb-arc-label-line",
|
158 | arcRange: "bb-arc-range",
|
159 | arcs: "bb-arcs",
|
160 | chartArc: "bb-chart-arc",
|
161 | chartArcs: "bb-chart-arcs",
|
162 | chartArcsBackground: "bb-chart-arcs-background",
|
163 | chartArcsTitle: "bb-chart-arcs-title",
|
164 | needle: "bb-needle"
|
165 | };
|
166 | const $AREA = {
|
167 | area: "bb-area",
|
168 | areas: "bb-areas"
|
169 | };
|
170 | const $AXIS = {
|
171 | axis: "bb-axis",
|
172 | axisX: "bb-axis-x",
|
173 | axisXLabel: "bb-axis-x-label",
|
174 | axisY: "bb-axis-y",
|
175 | axisY2: "bb-axis-y2",
|
176 | axisY2Label: "bb-axis-y2-label",
|
177 | axisYLabel: "bb-axis-y-label",
|
178 | axisXTooltip: "bb-axis-x-tooltip",
|
179 | axisYTooltip: "bb-axis-y-tooltip",
|
180 | axisY2Tooltip: "bb-axis-y2-tooltip"
|
181 | };
|
182 | const $BAR = {
|
183 | bar: "bb-bar",
|
184 | bars: "bb-bars",
|
185 | chartBar: "bb-chart-bar",
|
186 | chartBars: "bb-chart-bars"
|
187 | };
|
188 | const $CANDLESTICK = {
|
189 | candlestick: "bb-candlestick",
|
190 | candlesticks: "bb-candlesticks",
|
191 | chartCandlestick: "bb-chart-candlestick",
|
192 | chartCandlesticks: "bb-chart-candlesticks",
|
193 | valueDown: "bb-value-down",
|
194 | valueUp: "bb-value-up"
|
195 | };
|
196 | const $CIRCLE = {
|
197 | chartCircles: "bb-chart-circles",
|
198 | circle: "bb-circle",
|
199 | circles: "bb-circles"
|
200 | };
|
201 | const $COLOR = {
|
202 | colorPattern: "bb-color-pattern",
|
203 | colorScale: "bb-colorscale"
|
204 | };
|
205 | const $DRAG = {
|
206 | dragarea: "bb-dragarea",
|
207 | INCLUDED: "_included_"
|
208 | };
|
209 | const $FUNNEL = {
|
210 | funnel: "bb-funnel",
|
211 | chartFunnel: "bb-chart-funnel",
|
212 | chartFunnels: "bb-chart-funnels",
|
213 | funnelBackground: "bb-funnel-background"
|
214 | };
|
215 | const $GAUGE = {
|
216 | chartArcsGaugeMax: "bb-chart-arcs-gauge-max",
|
217 | chartArcsGaugeMin: "bb-chart-arcs-gauge-min",
|
218 | chartArcsGaugeUnit: "bb-chart-arcs-gauge-unit",
|
219 | chartArcsGaugeTitle: "bb-chart-arcs-gauge-title",
|
220 | gaugeValue: "bb-gauge-value"
|
221 | };
|
222 | const $LEGEND = {
|
223 | legend: "bb-legend",
|
224 | legendBackground: "bb-legend-background",
|
225 | legendItem: "bb-legend-item",
|
226 | legendItemEvent: "bb-legend-item-event",
|
227 | legendItemHidden: "bb-legend-item-hidden",
|
228 | legendItemPoint: "bb-legend-item-point",
|
229 | legendItemTile: "bb-legend-item-tile"
|
230 | };
|
231 | const $LINE = {
|
232 | chartLine: "bb-chart-line",
|
233 | chartLines: "bb-chart-lines",
|
234 | line: "bb-line",
|
235 | lines: "bb-lines"
|
236 | };
|
237 | const $EVENT = {
|
238 | eventRect: "bb-event-rect",
|
239 | eventRects: "bb-event-rects",
|
240 | eventRectsMultiple: "bb-event-rects-multiple",
|
241 | eventRectsSingle: "bb-event-rects-single"
|
242 | };
|
243 | const $FOCUS = {
|
244 | focused: "bb-focused",
|
245 | defocused: "bb-defocused",
|
246 | legendItemFocused: "bb-legend-item-focused",
|
247 | xgridFocus: "bb-xgrid-focus",
|
248 | ygridFocus: "bb-ygrid-focus"
|
249 | };
|
250 | const $GRID = {
|
251 | grid: "bb-grid",
|
252 | gridLines: "bb-grid-lines",
|
253 | xgrid: "bb-xgrid",
|
254 | xgridLine: "bb-xgrid-line",
|
255 | xgridLines: "bb-xgrid-lines",
|
256 | xgrids: "bb-xgrids",
|
257 | ygrid: "bb-ygrid",
|
258 | ygridLine: "bb-ygrid-line",
|
259 | ygridLines: "bb-ygrid-lines",
|
260 | ygrids: "bb-ygrids"
|
261 | };
|
262 | const $LEVEL = {
|
263 | level: "bb-level",
|
264 | levels: "bb-levels"
|
265 | };
|
266 | const $RADAR = {
|
267 | chartRadar: "bb-chart-radar",
|
268 | chartRadars: "bb-chart-radars"
|
269 | };
|
270 | const $REGION = {
|
271 | region: "bb-region",
|
272 | regions: "bb-regions"
|
273 | };
|
274 | const $SELECT = {
|
275 | selectedCircle: "bb-selected-circle",
|
276 | selectedCircles: "bb-selected-circles",
|
277 | SELECTED: "_selected_"
|
278 | };
|
279 | const $SHAPE = {
|
280 | shape: "bb-shape",
|
281 | shapes: "bb-shapes"
|
282 | };
|
283 | const $SUBCHART = {
|
284 | brush: "bb-brush",
|
285 | subchart: "bb-subchart"
|
286 | };
|
287 | const $TEXT = {
|
288 | chartText: "bb-chart-text",
|
289 | chartTexts: "bb-chart-texts",
|
290 | text: "bb-text",
|
291 | texts: "bb-texts",
|
292 | title: "bb-title",
|
293 | TextOverlapping: "text-overlapping"
|
294 | };
|
295 | const $TOOLTIP = {
|
296 | tooltip: "bb-tooltip",
|
297 | tooltipContainer: "bb-tooltip-container",
|
298 | tooltipName: "bb-tooltip-name"
|
299 | };
|
300 | const $TREEMAP = {
|
301 | treemap: "bb-treemap",
|
302 | chartTreemap: "bb-chart-treemap",
|
303 | chartTreemaps: "bb-chart-treemaps"
|
304 | };
|
305 | const $ZOOM = {
|
306 | buttonZoomReset: "bb-zoom-reset",
|
307 | zoomBrush: "bb-zoom-brush"
|
308 | };
|
309 | var classes = (__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, $COMMON), $ARC), $AREA), $AXIS), $BAR), $CANDLESTICK), $CIRCLE), $COLOR), $DRAG), $GAUGE), $LEGEND), $LINE), $EVENT), $FOCUS), $FUNNEL), $GRID), $RADAR), $REGION), $SELECT), $SHAPE), $SUBCHART), $TEXT), $TOOLTIP), $TREEMAP), $ZOOM));
|
310 |
|
311 |
|
312 | var external_commonjs_d3_brush_commonjs2_d3_brush_amd_d3_brush_root_d3_ = __webpack_require__(3);
|
313 |
|
314 | var external_commonjs_d3_selection_commonjs2_d3_selection_amd_d3_selection_root_d3_ = __webpack_require__(1);
|
315 | ;
|
316 | function getGlobal() {
|
317 | return 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 || Function("return this")();
|
318 | }
|
319 | function getFallback(w) {
|
320 | const hasRAF = typeof (w == null ? void 0 : w.requestAnimationFrame) === "function" && typeof (w == null ? void 0 : w.cancelAnimationFrame) === "function";
|
321 | const hasRIC = typeof (w == null ? void 0 : w.requestIdleCallback) === "function" && typeof (w == null ? void 0 : w.cancelIdleCallback) === "function";
|
322 | const request = (cb) => setTimeout(cb, 1);
|
323 | const cancel = (id) => clearTimeout(id);
|
324 | return [
|
325 | hasRAF ? w.requestAnimationFrame : request,
|
326 | hasRAF ? w.cancelAnimationFrame : cancel,
|
327 | hasRIC ? w.requestIdleCallback : request,
|
328 | hasRIC ? w.cancelIdleCallback : cancel
|
329 | ];
|
330 | }
|
331 | const win = getGlobal();
|
332 | const doc = win == null ? void 0 : win.document;
|
333 | const [
|
334 | requestAnimationFrame,
|
335 | cancelAnimationFrame,
|
336 | requestIdleCallback,
|
337 | cancelIdleCallback
|
338 | ] = getFallback(win);
|
339 |
|
340 |
|
341 | ;
|
342 | var util_defProp = Object.defineProperty;
|
343 | var util_getOwnPropSymbols = Object.getOwnPropertySymbols;
|
344 | var util_hasOwnProp = Object.prototype.hasOwnProperty;
|
345 | var util_propIsEnum = Object.prototype.propertyIsEnumerable;
|
346 | var util_defNormalProp = (obj, key, value) => key in obj ? util_defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
347 | var util_spreadValues = (a, b) => {
|
348 | for (var prop in b || (b = {}))
|
349 | if (util_hasOwnProp.call(b, prop))
|
350 | util_defNormalProp(a, prop, b[prop]);
|
351 | if (util_getOwnPropSymbols)
|
352 | for (var prop of util_getOwnPropSymbols(b)) {
|
353 | if (util_propIsEnum.call(b, prop))
|
354 | util_defNormalProp(a, prop, b[prop]);
|
355 | }
|
356 | return a;
|
357 | };
|
358 |
|
359 |
|
360 |
|
361 |
|
362 | const isValue = (v) => v || v === 0;
|
363 | const isFunction = (v) => typeof v === "function";
|
364 | const isString = (v) => typeof v === "string";
|
365 | const isNumber = (v) => typeof v === "number";
|
366 | const isUndefined = (v) => typeof v === "undefined";
|
367 | const isDefined = (v) => typeof v !== "undefined";
|
368 | const isBoolean = (v) => typeof v === "boolean";
|
369 | const ceil10 = (v) => Math.ceil(v / 10) * 10;
|
370 | const asHalfPixel = (n) => Math.ceil(n) + 0.5;
|
371 | const diffDomain = (d) => d[1] - d[0];
|
372 | const isObjectType = (v) => typeof v === "object";
|
373 | const isEmpty = (o) => isUndefined(o) || o === null || isString(o) && o.length === 0 || isObjectType(o) && !(o instanceof Date) && Object.keys(o).length === 0 || isNumber(o) && isNaN(o);
|
374 | const notEmpty = (o) => !isEmpty(o);
|
375 | const isArray = (arr) => Array.isArray(arr);
|
376 | const isObject = (obj) => obj && !(obj == null ? void 0 : obj.nodeType) && isObjectType(obj) && !isArray(obj);
|
377 | function getOption(options, key, defaultValue) {
|
378 | return isDefined(options[key]) ? options[key] : defaultValue;
|
379 | }
|
380 | function hasValue(dict, value) {
|
381 | let found = false;
|
382 | Object.keys(dict).forEach((key) => dict[key] === value && (found = true));
|
383 | return found;
|
384 | }
|
385 | function callFn(fn, thisArg, ...args) {
|
386 | const isFn = isFunction(fn);
|
387 | isFn && fn.call(thisArg, ...args);
|
388 | return isFn;
|
389 | }
|
390 | function endall(transition, cb) {
|
391 | let n = 0;
|
392 | const end = function(...args) {
|
393 | !--n && cb.apply(this, ...args);
|
394 | };
|
395 | if ("duration" in transition) {
|
396 | transition.each(() => ++n).on("end", end);
|
397 | } else {
|
398 | ++n;
|
399 | transition.call(end);
|
400 | }
|
401 | }
|
402 | function sanitize(str) {
|
403 | return isString(str) ? str.replace(/<(script|img)?/ig, "<").replace(/(script)?>/ig, ">") : str;
|
404 | }
|
405 | function setTextValue(node, text, dy = [-1, 1], toMiddle = false) {
|
406 | if (!node || !isString(text)) {
|
407 | return;
|
408 | }
|
409 | if (text.indexOf("\n") === -1) {
|
410 | node.text(text);
|
411 | } else {
|
412 | const diff = [node.text(), text].map((v) => v.replace(/[\s\n]/g, ""));
|
413 | if (diff[0] !== diff[1]) {
|
414 | const multiline = text.split("\n");
|
415 | const len = toMiddle ? multiline.length - 1 : 1;
|
416 | node.html("");
|
417 | multiline.forEach((v, i) => {
|
418 | node.append("tspan").attr("x", 0).attr("dy", `${i === 0 ? dy[0] * len : dy[1]}em`).text(v);
|
419 | });
|
420 | }
|
421 | }
|
422 | }
|
423 | function getRectSegList(path) {
|
424 | const { x, y, width, height } = path.getBBox();
|
425 | return [
|
426 | { x, y: y + height },
|
427 |
|
428 | { x, y },
|
429 |
|
430 | { x: x + width, y },
|
431 |
|
432 | { x: x + width, y: y + height }
|
433 |
|
434 | ];
|
435 | }
|
436 | function getPathBox(path) {
|
437 | const { width, height } = path.getBoundingClientRect();
|
438 | const items = getRectSegList(path);
|
439 | const x = items[0].x;
|
440 | const y = Math.min(items[0].y, items[1].y);
|
441 | return {
|
442 | x,
|
443 | y,
|
444 | width,
|
445 | height
|
446 | };
|
447 | }
|
448 | function getPointer(event, element) {
|
449 | var _a;
|
450 | const touches = event && ((_a = event.touches || event.sourceEvent && event.sourceEvent.touches) == null ? void 0 : _a[0]);
|
451 | let pointer = [0, 0];
|
452 | try {
|
453 | pointer = (0,external_commonjs_d3_selection_commonjs2_d3_selection_amd_d3_selection_root_d3_.pointer)(touches || event, element);
|
454 | } catch (e) {
|
455 | }
|
456 | return pointer.map((v) => isNaN(v) ? 0 : v);
|
457 | }
|
458 | function getBrushSelection(ctx) {
|
459 | const { event, $el } = ctx;
|
460 | const main = $el.subchart.main || $el.main;
|
461 | let selection;
|
462 | if (event && event.type === "brush") {
|
463 | selection = event.selection;
|
464 | } else if (main && (selection = main.select(".bb-brush").node())) {
|
465 | selection = (0,external_commonjs_d3_brush_commonjs2_d3_brush_amd_d3_brush_root_d3_.brushSelection)(selection);
|
466 | }
|
467 | return selection;
|
468 | }
|
469 | function getBoundingRect(node) {
|
470 | const needEvaluate = !("rect" in node) || "rect" in node && node.hasAttribute("width") && node.rect.width !== +node.getAttribute("width");
|
471 | return needEvaluate ? node.rect = node.getBoundingClientRect() : node.rect;
|
472 | }
|
473 | function getRandom(asStr = true, min = 0, max = 1e4) {
|
474 | const crpt = win.crypto || win.msCrypto;
|
475 | const rand = crpt ? min + crpt.getRandomValues(new Uint32Array(1))[0] % (max - min + 1) : Math.floor(Math.random() * (max - min) + min);
|
476 | return asStr ? String(rand) : rand;
|
477 | }
|
478 | function findIndex(arr, v, start, end, isRotated) {
|
479 | if (start > end) {
|
480 | return -1;
|
481 | }
|
482 | const mid = Math.floor((start + end) / 2);
|
483 | let { x, w = 0 } = arr[mid];
|
484 | if (isRotated) {
|
485 | x = arr[mid].y;
|
486 | w = arr[mid].h;
|
487 | }
|
488 | if (v >= x && v <= x + w) {
|
489 | return mid;
|
490 | }
|
491 | return v < x ? findIndex(arr, v, start, mid - 1, isRotated) : findIndex(arr, v, mid + 1, end, isRotated);
|
492 | }
|
493 | function brushEmpty(ctx) {
|
494 | const selection = getBrushSelection(ctx);
|
495 | if (selection) {
|
496 | return selection[0] === selection[1];
|
497 | }
|
498 | return true;
|
499 | }
|
500 | function deepClone(...objectN) {
|
501 | const clone = (v) => {
|
502 | if (isObject(v) && v.constructor) {
|
503 | const r = new v.constructor();
|
504 | for (const k in v) {
|
505 | r[k] = clone(v[k]);
|
506 | }
|
507 | return r;
|
508 | }
|
509 | return v;
|
510 | };
|
511 | return objectN.map((v) => clone(v)).reduce((a, c) => util_spreadValues(util_spreadValues({}, a), c));
|
512 | }
|
513 | function extend(target = {}, source) {
|
514 | if (isArray(source)) {
|
515 | source.forEach((v) => extend(target, v));
|
516 | }
|
517 | for (const p in source) {
|
518 | if (/^\d+$/.test(p) || p in target) {
|
519 | continue;
|
520 | }
|
521 | target[p] = source[p];
|
522 | }
|
523 | return target;
|
524 | }
|
525 | const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
526 | function camelize(str, separator = "-") {
|
527 | return str.split(separator).map((v, i) => i ? v.charAt(0).toUpperCase() + v.slice(1).toLowerCase() : v.toLowerCase()).join("");
|
528 | }
|
529 | const toArray = (v) => [].slice.call(v);
|
530 | function addCssRules(style, selector, prop) {
|
531 | const { rootSelector = "", sheet } = style;
|
532 | const getSelector = (s) => s.replace(/\s?(bb-)/g, ".$1").replace(/\.+/g, ".");
|
533 | const rule = `${rootSelector} ${getSelector(selector)} {${prop.join(";")}}`;
|
534 | return sheet[sheet.insertRule ? "insertRule" : "addRule"](
|
535 | rule,
|
536 | sheet.cssRules.length
|
537 | );
|
538 | }
|
539 | function getCssRules(styleSheets) {
|
540 | let rules = [];
|
541 | styleSheets.forEach((sheet) => {
|
542 | var _a;
|
543 | try {
|
544 | if (sheet.cssRules && sheet.cssRules.length) {
|
545 | rules = rules.concat(toArray(sheet.cssRules));
|
546 | }
|
547 | } catch (e) {
|
548 | (_a = win.console) == null ? void 0 : _a.warn(`Error while reading rules from ${sheet.href}: ${e.toString()}`);
|
549 | }
|
550 | });
|
551 | return rules;
|
552 | }
|
553 | function getScrollPosition(node) {
|
554 | var _a, _b, _c, _d, _e, _f;
|
555 | return {
|
556 | x: ((_b = (_a = win.pageXOffset) != null ? _a : win.scrollX) != null ? _b : 0) + ((_c = node.scrollLeft) != null ? _c : 0),
|
557 | y: ((_e = (_d = win.pageYOffset) != null ? _d : win.scrollY) != null ? _e : 0) + ((_f = node.scrollTop) != null ? _f : 0)
|
558 | };
|
559 | }
|
560 | function getTransformCTM(node, x = 0, y = 0, inverse = true) {
|
561 | const point = new DOMPoint(x, y);
|
562 | const screen = node.getScreenCTM();
|
563 | const res = point.matrixTransform(
|
564 | inverse ? screen == null ? void 0 : screen.inverse() : screen
|
565 | );
|
566 | if (inverse === false) {
|
567 | const rect = node.getBoundingClientRect();
|
568 | res.x -= rect.x;
|
569 | res.y -= rect.y;
|
570 | }
|
571 | return res;
|
572 | }
|
573 | function getTranslation(node) {
|
574 | const transform = node ? node.transform : null;
|
575 | const baseVal = transform && transform.baseVal;
|
576 | return baseVal && baseVal.numberOfItems ? baseVal.getItem(0).matrix : { a: 0, b: 0, c: 0, d: 0, e: 0, f: 0 };
|
577 | }
|
578 | function getUnique(data) {
|
579 | const isDate = data[0] instanceof Date;
|
580 | const d = (isDate ? data.map(Number) : data).filter((v, i, self) => self.indexOf(v) === i);
|
581 | return isDate ? d.map((v) => new Date(v)) : d;
|
582 | }
|
583 | function mergeArray(arr) {
|
584 | return arr && arr.length ? arr.reduce((p, c) => p.concat(c)) : [];
|
585 | }
|
586 | function mergeObj(target, ...objectN) {
|
587 | if (!objectN.length || objectN.length === 1 && !objectN[0]) {
|
588 | return target;
|
589 | }
|
590 | const source = objectN.shift();
|
591 | if (isObject(target) && isObject(source)) {
|
592 | Object.keys(source).forEach((key) => {
|
593 | const value = source[key];
|
594 | if (isObject(value)) {
|
595 | !target[key] && (target[key] = {});
|
596 | target[key] = mergeObj(target[key], value);
|
597 | } else {
|
598 | target[key] = isArray(value) ? value.concat() : value;
|
599 | }
|
600 | });
|
601 | }
|
602 | return mergeObj(target, ...objectN);
|
603 | }
|
604 | function sortValue(data, isAsc = true) {
|
605 | let fn;
|
606 | if (data[0] instanceof Date) {
|
607 | fn = isAsc ? (a, b) => a - b : (a, b) => b - a;
|
608 | } else {
|
609 | if (isAsc && !data.every(isNaN)) {
|
610 | fn = (a, b) => a - b;
|
611 | } else if (!isAsc) {
|
612 | fn = (a, b) => a > b && -1 || a < b && 1 || a === b && 0;
|
613 | }
|
614 | }
|
615 | return data.concat().sort(fn);
|
616 | }
|
617 | function getMinMax(type, data) {
|
618 | let res = data.filter((v) => notEmpty(v));
|
619 | if (res.length) {
|
620 | if (isNumber(res[0])) {
|
621 | res = Math[type](...res);
|
622 | } else if (res[0] instanceof Date) {
|
623 | res = sortValue(res, type === "min")[0];
|
624 | }
|
625 | } else {
|
626 | res = void 0;
|
627 | }
|
628 | return res;
|
629 | }
|
630 | const getRange = (start, end, step = 1) => {
|
631 | const res = [];
|
632 | const n = Math.max(0, Math.ceil((end - start) / step)) | 0;
|
633 | for (let i = start; i < n; i++) {
|
634 | res.push(start + i * step);
|
635 | }
|
636 | return res;
|
637 | };
|
638 | const emulateEvent = {
|
639 | mouse: (() => {
|
640 | const getParams = () => ({
|
641 | bubbles: false,
|
642 | cancelable: false,
|
643 | screenX: 0,
|
644 | screenY: 0,
|
645 | clientX: 0,
|
646 | clientY: 0
|
647 | });
|
648 | try {
|
649 | new MouseEvent("t");
|
650 | return (el, eventType, params = getParams()) => {
|
651 | el.dispatchEvent(new MouseEvent(eventType, params));
|
652 | };
|
653 | } catch (e) {
|
654 | return (el, eventType, params = getParams()) => {
|
655 | const mouseEvent = doc.createEvent("MouseEvent");
|
656 | mouseEvent.initMouseEvent(
|
657 | eventType,
|
658 | params.bubbles,
|
659 | params.cancelable,
|
660 | win,
|
661 | 0,
|
662 |
|
663 | params.screenX,
|
664 | params.screenY,
|
665 | params.clientX,
|
666 | params.clientY,
|
667 | false,
|
668 | false,
|
669 | false,
|
670 | false,
|
671 | 0,
|
672 | null
|
673 | );
|
674 | el.dispatchEvent(mouseEvent);
|
675 | };
|
676 | }
|
677 | })(),
|
678 | touch: (el, eventType, params) => {
|
679 | const touchObj = new Touch(mergeObj({
|
680 | identifier: Date.now(),
|
681 | target: el,
|
682 | radiusX: 2.5,
|
683 | radiusY: 2.5,
|
684 | rotationAngle: 10,
|
685 | force: 0.5
|
686 | }, params));
|
687 | el.dispatchEvent(new TouchEvent(eventType, {
|
688 | cancelable: true,
|
689 | bubbles: true,
|
690 | shiftKey: true,
|
691 | touches: [touchObj],
|
692 | targetTouches: [],
|
693 | changedTouches: [touchObj]
|
694 | }));
|
695 | }
|
696 | };
|
697 | function tplProcess(tpl, data) {
|
698 | let res = tpl;
|
699 | for (const x in data) {
|
700 | res = res.replace(new RegExp(`{=${x}}`, "g"), data[x]);
|
701 | }
|
702 | return res;
|
703 | }
|
704 | function parseDate(date) {
|
705 | var _a;
|
706 | let parsedDate;
|
707 | if (date instanceof Date) {
|
708 | parsedDate = date;
|
709 | } else if (isString(date)) {
|
710 | const { config, format } = this;
|
711 | parsedDate = (_a = format.dataTime(config.data_xFormat)(date)) != null ? _a : new Date(date);
|
712 | } else if (isNumber(date) && !isNaN(date)) {
|
713 | parsedDate = new Date(+date);
|
714 | }
|
715 | if (!parsedDate || isNaN(+parsedDate)) {
|
716 | console && console.error && console.error(`Failed to parse x '${date}' to Date object`);
|
717 | }
|
718 | return parsedDate;
|
719 | }
|
720 | function hasViewBox(svg) {
|
721 | const attr = svg.attr("viewBox");
|
722 | return attr ? /(\d+(\.\d+)?){3}/.test(attr) : false;
|
723 | }
|
724 | function hasStyle(node, condition, all = false) {
|
725 | const isD3Node = !!node.node;
|
726 | let has = false;
|
727 | for (const [key, value] of Object.entries(condition)) {
|
728 | has = isD3Node ? node.style(key) === value : node.style[key] === value;
|
729 | if (all === false && has) {
|
730 | break;
|
731 | }
|
732 | }
|
733 | return has;
|
734 | }
|
735 | function isTabVisible() {
|
736 | var _a, _b;
|
737 | return ((_a = doc) == null ? void 0 : _a.hidden) === false || ((_b = doc) == null ? void 0 : _b.visibilityState) === "visible";
|
738 | }
|
739 | function convertInputType(mouse, touch) {
|
740 | const { DocumentTouch, matchMedia, navigator } = win;
|
741 | const hasPointerCoarse = matchMedia == null ? void 0 : matchMedia("(pointer:coarse)").matches;
|
742 | let hasTouch = false;
|
743 | if (touch) {
|
744 | if (navigator && "maxTouchPoints" in navigator) {
|
745 | hasTouch = navigator.maxTouchPoints > 0;
|
746 | } else if ("ontouchmove" in win || DocumentTouch && doc instanceof DocumentTouch) {
|
747 | hasTouch = true;
|
748 | } else {
|
749 | if (hasPointerCoarse) {
|
750 | hasTouch = true;
|
751 | } else {
|
752 | const UA = navigator.userAgent;
|
753 | hasTouch = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) || /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);
|
754 | }
|
755 | }
|
756 | }
|
757 | const hasMouse = mouse && !hasPointerCoarse && (matchMedia == null ? void 0 : matchMedia("(pointer:fine)").matches);
|
758 | return hasMouse && "mouse" || hasTouch && "touch" || "mouse";
|
759 | }
|
760 | function runUntil(fn, conditionFn) {
|
761 | if (conditionFn() === false) {
|
762 | requestAnimationFrame(() => runUntil(fn, conditionFn));
|
763 | } else {
|
764 | fn();
|
765 | }
|
766 | }
|
767 |
|
768 | ;
|
769 |
|
770 | function loadConfig(config) {
|
771 | const thisConfig = this.config;
|
772 | let target;
|
773 | let keys;
|
774 | let read;
|
775 | const find = () => {
|
776 | const key = keys.shift();
|
777 | if (key && target && isObjectType(target) && key in target) {
|
778 | target = target[key];
|
779 | return find();
|
780 | } else if (!key) {
|
781 | return target;
|
782 | }
|
783 | return void 0;
|
784 | };
|
785 | Object.keys(thisConfig).forEach((key) => {
|
786 | target = config;
|
787 | keys = key.split("_");
|
788 | read = find();
|
789 | if (isDefined(read)) {
|
790 | thisConfig[key] = read;
|
791 | }
|
792 | });
|
793 | if (this.api) {
|
794 | this.state.orgConfig = config;
|
795 | }
|
796 | }
|
797 |
|
798 | ;
|
799 | var Plugin_defProp = Object.defineProperty;
|
800 | var Plugin_defNormalProp = (obj, key, value) => key in obj ? Plugin_defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
801 | var __publicField = (obj, key, value) => Plugin_defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
802 | class Plugin {
|
803 | |
804 |
|
805 |
|
806 |
|
807 |
|
808 | constructor(options = {}) {
|
809 | __publicField(this, "$$");
|
810 | __publicField(this, "options");
|
811 | this.options = options;
|
812 | }
|
813 | |
814 |
|
815 |
|
816 |
|
817 | $beforeInit() {
|
818 | }
|
819 | |
820 |
|
821 |
|
822 |
|
823 | $init() {
|
824 | }
|
825 | |
826 |
|
827 |
|
828 |
|
829 | $afterInit() {
|
830 | }
|
831 | |
832 |
|
833 |
|
834 |
|
835 | $redraw() {
|
836 | }
|
837 | |
838 |
|
839 |
|
840 |
|
841 | $willDestroy() {
|
842 | Object.keys(this).forEach((key) => {
|
843 | this[key] = null;
|
844 | delete this[key];
|
845 | });
|
846 | }
|
847 | }
|
848 | __publicField(Plugin, "version", "3.14.2");
|
849 |
|
850 |
|
851 | var external_commonjs_d3_axis_commonjs2_d3_axis_amd_d3_axis_root_d3_ = __webpack_require__(8);
|
852 |
|
853 | var external_commonjs_d3_format_commonjs2_d3_format_amd_d3_format_root_d3_ = __webpack_require__(9);
|
854 | ;
|
855 | var stanford_classes = ({
|
856 | colorScale: "bb-colorscale",
|
857 | stanfordElements: "bb-stanford-elements",
|
858 | stanfordLine: "bb-stanford-line",
|
859 | stanfordLines: "bb-stanford-lines",
|
860 | stanfordRegion: "bb-stanford-region",
|
861 | stanfordRegions: "bb-stanford-regions"
|
862 | });
|
863 |
|
864 | ;
|
865 | var ColorScale_defProp = Object.defineProperty;
|
866 | var ColorScale_defNormalProp = (obj, key, value) => key in obj ? ColorScale_defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
867 | var ColorScale_publicField = (obj, key, value) => ColorScale_defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
868 |
|
869 |
|
870 |
|
871 |
|
872 |
|
873 | class ColorScale {
|
874 | constructor(owner) {
|
875 | ColorScale_publicField(this, "owner");
|
876 | ColorScale_publicField(this, "colorScale");
|
877 | this.owner = owner;
|
878 | }
|
879 | drawColorScale() {
|
880 | const { $$, config } = this.owner;
|
881 | const target = $$.data.targets[0];
|
882 | const height = $$.state.height - config.padding_bottom - config.padding_top;
|
883 | const barWidth = config.scale_width;
|
884 | const barHeight = 5;
|
885 | const points = getRange(config.padding_bottom, height, barHeight);
|
886 | const inverseScale = (0,external_commonjs_d3_scale_commonjs2_d3_scale_amd_d3_scale_root_d3_.scaleSequential)(target.colors).domain([points[points.length - 1], points[0]]);
|
887 | if (this.colorScale) {
|
888 | this.colorScale.remove();
|
889 | }
|
890 | this.colorScale = $$.$el.svg.append("g").attr("width", 50).attr("height", height).attr("class", stanford_classes.colorScale);
|
891 | this.colorScale.append("g").attr("transform", `translate(0, ${config.padding_top})`).selectAll("bars").data(points).enter().append("rect").attr("y", (d, i) => i * barHeight).attr("x", 0).attr("width", barWidth).attr("height", barHeight).attr("fill", (d) => inverseScale(d));
|
892 | const axisScale = (0,external_commonjs_d3_scale_commonjs2_d3_scale_amd_d3_scale_root_d3_.scaleSymlog)().domain([target.minEpochs, target.maxEpochs]).range([
|
893 | points[0] + config.padding_top + points[points.length - 1] + barHeight - 1,
|
894 | points[0] + config.padding_top
|
895 | ]);
|
896 | const legendAxis = (0,external_commonjs_d3_axis_commonjs2_d3_axis_amd_d3_axis_root_d3_.axisRight)(axisScale);
|
897 | const scaleFormat = config.scale_format;
|
898 | if (scaleFormat === "pow10") {
|
899 | legendAxis.tickValues([1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7]);
|
900 | } else if (isFunction(scaleFormat)) {
|
901 | legendAxis.tickFormat(scaleFormat);
|
902 | } else {
|
903 | legendAxis.tickFormat((0,external_commonjs_d3_format_commonjs2_d3_format_amd_d3_format_root_d3_.format)("d"));
|
904 | }
|
905 | const axis = this.colorScale.append("g").attr("class", "legend axis").attr("transform", `translate(${barWidth},0)`).call(legendAxis);
|
906 | if (scaleFormat === "pow10") {
|
907 | axis.selectAll(".tick text").text(null).filter((d) => d / Math.pow(10, Math.ceil(Math.log(d) / Math.LN10 - 1e-12)) === 1).text(10).append("tspan").attr("dy", "-.7em").text((d) => Math.round(Math.log(d) / Math.LN10));
|
908 | }
|
909 | this.colorScale.attr(
|
910 | "transform",
|
911 | `translate(${$$.state.current.width - this.xForColorScale()}, 0)`
|
912 | );
|
913 | }
|
914 | xForColorScale() {
|
915 | return this.owner.config.padding_right + this.colorScale.node().getBBox().width;
|
916 | }
|
917 | getColorScalePadding() {
|
918 | return this.xForColorScale() + this.owner.config.padding_left + 20;
|
919 | }
|
920 | }
|
921 |
|
922 | ;
|
923 |
|
924 | function pointInRegion(point, region) {
|
925 | const x = point.x;
|
926 | const y = point.value;
|
927 | let inside = false;
|
928 | for (let i = 0, j = region.length - 1; i < region.length; j = i++) {
|
929 | const xi = region[i].x;
|
930 | const yi = region[i].y;
|
931 | const xj = region[j].x;
|
932 | const yj = region[j].y;
|
933 | const intersect = yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
|
934 | if (intersect) {
|
935 | inside = !inside;
|
936 | }
|
937 | }
|
938 | return inside;
|
939 | }
|
940 | function compareEpochs(a, b) {
|
941 | if (a.epochs < b.epochs) {
|
942 | return -1;
|
943 | }
|
944 | if (a.epochs > b.epochs) {
|
945 | return 1;
|
946 | }
|
947 | return 0;
|
948 | }
|
949 | function getRegionArea(points) {
|
950 | let area = 0;
|
951 | let point1;
|
952 | let point2;
|
953 | for (let i = 0, l = points.length, j = l - 1; i < l; j = i, i++) {
|
954 | point1 = points[i];
|
955 | point2 = points[j];
|
956 | area += point1.x * point2.y;
|
957 | area -= point1.y * point2.x;
|
958 | }
|
959 | area /= 2;
|
960 | return area;
|
961 | }
|
962 | function getCentroid(points) {
|
963 | const area = getRegionArea(points);
|
964 | let x = 0;
|
965 | let y = 0;
|
966 | let f;
|
967 | for (let i = 0, l = points.length, j = l - 1; i < l; j = i, i++) {
|
968 | const point1 = points[i];
|
969 | const point2 = points[j];
|
970 | f = point1.x * point2.y - point2.x * point1.y;
|
971 | x += (point1.x + point2.x) * f;
|
972 | y += (point1.y + point2.y) * f;
|
973 | }
|
974 | f = area * 6;
|
975 | return {
|
976 | x: x / f,
|
977 | y: y / f
|
978 | };
|
979 | }
|
980 |
|
981 |
|
982 | ;
|
983 | var Elements_defProp = Object.defineProperty;
|
984 | var Elements_defNormalProp = (obj, key, value) => key in obj ? Elements_defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
985 | var Elements_publicField = (obj, key, value) => Elements_defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
986 |
|
987 |
|
988 | class Elements {
|
989 | constructor(owner) {
|
990 | Elements_publicField(this, "owner");
|
991 | this.owner = owner;
|
992 | const elements = owner.$$.$el.main.select(".bb-chart").append("g").attr("class", stanford_classes.stanfordElements);
|
993 | elements.append("g").attr("class", stanford_classes.stanfordLines);
|
994 | elements.append("g").attr("class", stanford_classes.stanfordRegions);
|
995 | }
|
996 | updateStanfordLines(duration) {
|
997 | const { $$ } = this.owner;
|
998 | const { config, $el: { main } } = $$;
|
999 | const isRotated = config.axis_rotated;
|
1000 | const xvCustom = this.xvCustom.bind($$);
|
1001 | const yvCustom = this.yvCustom.bind($$);
|
1002 | const stanfordLine = main.select(`.${stanford_classes.stanfordLines}`).style("shape-rendering", "geometricprecision").selectAll(`.${stanford_classes.stanfordLine}`).data(this.owner.config.lines);
|
1003 | stanfordLine.exit().transition().duration(duration).style("opacity", "0").remove();
|
1004 | const stanfordLineEnter = stanfordLine.enter().append("g");
|
1005 | stanfordLineEnter.append("line").style("opacity", "0");
|
1006 | stanfordLineEnter.merge(stanfordLine).attr("class", (d) => stanford_classes.stanfordLine + (d.class ? ` ${d.class}` : "")).select("line").transition().duration(duration).attr("x1", (d) => {
|
1007 | const v = isRotated ? yvCustom(d, "y1") : xvCustom(d, "x1");
|
1008 | return v;
|
1009 | }).attr("x2", (d) => isRotated ? yvCustom(d, "y2") : xvCustom(d, "x2")).attr("y1", (d) => {
|
1010 | const v = isRotated ? xvCustom(d, "x1") : yvCustom(d, "y1");
|
1011 | return v;
|
1012 | }).attr("y2", (d) => isRotated ? xvCustom(d, "x2") : yvCustom(d, "y2")).transition().style("opacity", null);
|
1013 | }
|
1014 | updateStanfordRegions(duration) {
|
1015 | const { $$ } = this.owner;
|
1016 | const { config, $el: { main } } = $$;
|
1017 | const isRotated = config.axis_rotated;
|
1018 | const xvCustom = this.xvCustom.bind($$);
|
1019 | const yvCustom = this.yvCustom.bind($$);
|
1020 | const countPointsInRegion = this.owner.countEpochsInRegion.bind($$);
|
1021 | let stanfordRegion = main.select(`.${stanford_classes.stanfordRegions}`).selectAll(`.${stanford_classes.stanfordRegion}`).data(this.owner.config.regions);
|
1022 | stanfordRegion.exit().transition().duration(duration).style("opacity", "0").remove();
|
1023 | const stanfordRegionEnter = stanfordRegion.enter().append("g");
|
1024 | stanfordRegionEnter.append("polygon").style("opacity", "0");
|
1025 | stanfordRegionEnter.append("text").attr("transform", isRotated ? "rotate(-90)" : "").style("opacity", "0");
|
1026 | stanfordRegion = stanfordRegionEnter.merge(stanfordRegion);
|
1027 | stanfordRegion.attr("class", (d) => stanford_classes.stanfordRegion + (d.class ? ` ${d.class}` : "")).select("polygon").transition().duration(duration).attr("points", (d) => d.points.map(
|
1028 | (value) => [
|
1029 | isRotated ? yvCustom(value, "y") : xvCustom(value, "x"),
|
1030 | isRotated ? xvCustom(value, "x") : yvCustom(value, "y")
|
1031 | ].join(",")
|
1032 | ).join(" ")).transition().style("opacity", (d) => String(d.opacity ? d.opacity : 0.2));
|
1033 | stanfordRegion.select("text").transition().duration(duration).attr(
|
1034 | "x",
|
1035 | (d) => isRotated ? yvCustom(getCentroid(d.points), "y") : xvCustom(getCentroid(d.points), "x")
|
1036 | ).attr(
|
1037 | "y",
|
1038 | (d) => isRotated ? xvCustom(getCentroid(d.points), "x") : yvCustom(getCentroid(d.points), "y")
|
1039 | ).text((d) => {
|
1040 | if (d.text) {
|
1041 | const { value, percentage } = countPointsInRegion(d.points);
|
1042 | return d.text(value, percentage);
|
1043 | }
|
1044 | return "";
|
1045 | }).attr("text-anchor", "middle").attr("dominant-baseline", "middle").transition().style("opacity", null);
|
1046 | }
|
1047 | updateStanfordElements(duration = 0) {
|
1048 | this.updateStanfordLines(duration);
|
1049 | this.updateStanfordRegions(duration);
|
1050 | }
|
1051 | xvCustom(d, xyValue) {
|
1052 | const $$ = this;
|
1053 | const { axis, config } = $$;
|
1054 | let value = xyValue ? d[xyValue] : $$.getBaseValue(d);
|
1055 | if (axis.isTimeSeries()) {
|
1056 | value = parseDate.call($$, value);
|
1057 | } else if (axis.isCategorized() && isString(value)) {
|
1058 | value = config.axis_x_categories.indexOf(d.value);
|
1059 | }
|
1060 | return $$.scale.x(value);
|
1061 | }
|
1062 | yvCustom(d, xyValue) {
|
1063 | const $$ = this;
|
1064 | const yScale = d.axis && d.axis === "y2" ? $$.scale.y2 : $$.scale.y;
|
1065 | const value = xyValue ? d[xyValue] : $$.getBaseValue(d);
|
1066 | return yScale(value);
|
1067 | }
|
1068 | }
|
1069 |
|
1070 | ;
|
1071 | class Options {
|
1072 | constructor() {
|
1073 | return {
|
1074 | |
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 | colors: void 0,
|
1086 | |
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 | epochs: [],
|
1096 | |
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 |
|
1106 |
|
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 | lines: [],
|
1117 | |
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 |
|
1123 |
|
1124 |
|
1125 |
|
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 | scale_min: void 0,
|
1143 | scale_max: void 0,
|
1144 | scale_width: 20,
|
1145 | scale_format: void 0,
|
1146 | |
1147 |
|
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 |
|
1153 |
|
1154 |
|
1155 |
|
1156 |
|
1157 |
|
1158 |
|
1159 |
|
1160 |
|
1161 |
|
1162 |
|
1163 |
|
1164 | padding_top: 0,
|
1165 | padding_right: 0,
|
1166 | padding_bottom: 0,
|
1167 | padding_left: 0,
|
1168 | |
1169 |
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 |
|
1178 |
|
1179 |
|
1180 |
|
1181 |
|
1182 |
|
1183 |
|
1184 |
|
1185 |
|
1186 |
|
1187 |
|
1188 |
|
1189 |
|
1190 |
|
1191 |
|
1192 |
|
1193 |
|
1194 |
|
1195 |
|
1196 |
|
1197 |
|
1198 |
|
1199 | regions: []
|
1200 | };
|
1201 | }
|
1202 | }
|
1203 |
|
1204 | ;
|
1205 | var stanford_defProp = Object.defineProperty;
|
1206 | var stanford_defNormalProp = (obj, key, value) => key in obj ? stanford_defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
1207 | var stanford_publicField = (obj, key, value) => stanford_defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
1208 |
|
1209 |
|
1210 |
|
1211 |
|
1212 |
|
1213 |
|
1214 |
|
1215 |
|
1216 |
|
1217 |
|
1218 | class Stanford extends Plugin {
|
1219 | constructor(options) {
|
1220 | super(options);
|
1221 | stanford_publicField(this, "config");
|
1222 | stanford_publicField(this, "colorScale");
|
1223 | stanford_publicField(this, "elements");
|
1224 | this.config = new Options();
|
1225 | return this;
|
1226 | }
|
1227 | $beforeInit() {
|
1228 | const { $$ } = this;
|
1229 | $$.config.data_xSort = false;
|
1230 | $$.isMultipleX = () => true;
|
1231 | $$.showGridFocus = () => {
|
1232 | };
|
1233 | $$.labelishData = (d) => d.values;
|
1234 | $$.opacityForCircle = () => 1;
|
1235 | const getCurrentPadding = $$.getCurrentPadding.bind($$);
|
1236 | $$.getCurrentPadding = () => {
|
1237 | const padding = getCurrentPadding();
|
1238 | padding.right += this.colorScale ? this.colorScale.getColorScalePadding() : 0;
|
1239 | return padding;
|
1240 | };
|
1241 | }
|
1242 | $init() {
|
1243 | const { $$ } = this;
|
1244 | loadConfig.call(this, this.options);
|
1245 | $$.color = this.getStanfordPointColor.bind($$);
|
1246 | this.colorScale = new ColorScale(this);
|
1247 | this.elements = new Elements(this);
|
1248 | this.convertData();
|
1249 | this.initStanfordData();
|
1250 | this.setStanfordTooltip();
|
1251 | this.colorScale.drawColorScale();
|
1252 | $$.right += this.colorScale ? this.colorScale.getColorScalePadding() : 0;
|
1253 | this.$redraw();
|
1254 | }
|
1255 | $redraw(duration) {
|
1256 | var _a, _b;
|
1257 | (_a = this.colorScale) == null ? void 0 : _a.drawColorScale();
|
1258 | (_b = this.elements) == null ? void 0 : _b.updateStanfordElements(duration);
|
1259 | }
|
1260 | getOptions() {
|
1261 | return new Options();
|
1262 | }
|
1263 | convertData() {
|
1264 | const data = this.$$.data.targets;
|
1265 | const epochs = this.options.epochs;
|
1266 | data.forEach((d) => {
|
1267 | d.values.forEach((v, i) => {
|
1268 | v.epochs = epochs[i];
|
1269 | });
|
1270 | d.minEpochs = void 0;
|
1271 | d.maxEpochs = void 0;
|
1272 | d.colors = void 0;
|
1273 | d.colorscale = void 0;
|
1274 | });
|
1275 | }
|
1276 | initStanfordData() {
|
1277 | const { config } = this;
|
1278 | const target = this.$$.data.targets[0];
|
1279 | target.values.sort(compareEpochs);
|
1280 | const epochs = target.values.map((a) => a.epochs);
|
1281 | target.minEpochs = !isNaN(config.scale_min) ? config.scale_min : Math.min(...epochs);
|
1282 | target.maxEpochs = !isNaN(config.scale_max) ? config.scale_max : Math.max(...epochs);
|
1283 | target.colors = isFunction(config.colors) ? config.colors : (0,external_commonjs_d3_interpolate_commonjs2_d3_interpolate_amd_d3_interpolate_root_d3_.interpolateHslLong)((0,external_commonjs_d3_color_commonjs2_d3_color_amd_d3_color_root_d3_.hsl)(250, 1, 0.5), (0,external_commonjs_d3_color_commonjs2_d3_color_amd_d3_color_root_d3_.hsl)(0, 1, 0.5));
|
1284 | target.colorscale = (0,external_commonjs_d3_scale_commonjs2_d3_scale_amd_d3_scale_root_d3_.scaleSequentialLog)(target.colors).domain([target.minEpochs, target.maxEpochs]);
|
1285 | }
|
1286 | getStanfordPointColor(d) {
|
1287 | const target = this.data.targets[0];
|
1288 | return target.colorscale(d.epochs);
|
1289 | }
|
1290 | setStanfordTooltip() {
|
1291 | const { config } = this.$$;
|
1292 | if (isEmpty(config.tooltip_contents)) {
|
1293 | config.tooltip_contents = function(d, defaultTitleFormat, defaultValueFormat, color) {
|
1294 | const { data_x } = config;
|
1295 | let html = `<table class="${$TOOLTIP.tooltip}"><tbody>`;
|
1296 | d.forEach((v) => {
|
1297 | const { id = "", value = 0, epochs = 0, x = "" } = v;
|
1298 | html += `<tr>
|
1299 | <th>${data_x || ""}</th>
|
1300 | <th class="value">${defaultTitleFormat(x)}</th>
|
1301 | </tr>
|
1302 | <tr>
|
1303 | <th>${v.id}</th>
|
1304 | <th class="value">${defaultValueFormat(value)}</th>
|
1305 | </tr>
|
1306 | <tr class="${$TOOLTIP.tooltipName}-${id}">
|
1307 | <td class="name"><span style="background-color:${color(v)}"></span>Epochs</td>
|
1308 | <td class="value">${defaultValueFormat(epochs)}</td>
|
1309 | </tr>`;
|
1310 | });
|
1311 | return `${html}</tbody></table>`;
|
1312 | };
|
1313 | }
|
1314 | }
|
1315 | countEpochsInRegion(region) {
|
1316 | const $$ = this;
|
1317 | const target = $$.data.targets[0];
|
1318 | const total = target.values.reduce(
|
1319 | (accumulator, currentValue) => accumulator + Number(currentValue.epochs),
|
1320 | 0
|
1321 | );
|
1322 | const value = target.values.reduce((accumulator, currentValue) => {
|
1323 | if (pointInRegion(currentValue, region)) {
|
1324 | return accumulator + Number(currentValue.epochs);
|
1325 | }
|
1326 | return accumulator;
|
1327 | }, 0);
|
1328 | return {
|
1329 | value,
|
1330 | percentage: value !== 0 ? +(value / total * 100).toFixed(1) : 0
|
1331 | };
|
1332 | }
|
1333 | }
|
1334 |
|
1335 | }();
|
1336 | __webpack_exports__ = __webpack_exports__["default"];
|
1337 | return __webpack_exports__;
|
1338 | })()
|
1339 | ;
|
1340 | }); |
\ | No newline at end of file |