1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | import { timeParse, utcParse, timeFormat, utcFormat } from 'd3-time-format';
|
11 | import { pointer, select, namespaces, selectAll } from 'd3-selection';
|
12 | import { brushSelection, brushY, brushX } from 'd3-brush';
|
13 | import { csvParseRows, csvParse, tsvParseRows, tsvParse } from 'd3-dsv';
|
14 | import { drag as drag$1 } from 'd3-drag';
|
15 | import { scaleOrdinal, scaleLinear, scaleSymlog, scaleLog, scaleTime } from 'd3-scale';
|
16 | import { transition } from 'd3-transition';
|
17 | import { curveBasis, curveBasisClosed, curveBasisOpen, curveBundle, curveCardinal, curveCardinalClosed, curveCardinalOpen, curveCatmullRom, curveCatmullRomClosed, curveCatmullRomOpen, curveMonotoneX, curveMonotoneY, curveNatural, curveLinearClosed, curveLinear, curveStep, curveStepAfter, curveStepBefore, pie as pie$1, arc, area as area$1, line as line$1 } from 'd3-shape';
|
18 | import { axisLeft, axisBottom, axisTop, axisRight } from 'd3-axis';
|
19 | import { easeLinear } from 'd3-ease';
|
20 | import { interpolate } from 'd3-interpolate';
|
21 | import { zoomIdentity, zoomTransform, zoom as zoom$2 } from 'd3-zoom';
|
22 | import { rgb } from 'd3-color';
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | var CLASS = {
|
33 | arc: "bb-arc",
|
34 | arcLabelLine: "bb-arc-label-line",
|
35 | arcs: "bb-arcs",
|
36 | area: "bb-area",
|
37 | areas: "bb-areas",
|
38 | axis: "bb-axis",
|
39 | axisX: "bb-axis-x",
|
40 | axisXLabel: "bb-axis-x-label",
|
41 | axisY: "bb-axis-y",
|
42 | axisY2: "bb-axis-y2",
|
43 | axisY2Label: "bb-axis-y2-label",
|
44 | axisYLabel: "bb-axis-y-label",
|
45 | bar: "bb-bar",
|
46 | bars: "bb-bars",
|
47 | brush: "bb-brush",
|
48 | button: "bb-button",
|
49 | buttonZoomReset: "bb-zoom-reset",
|
50 | candlestick: "bb-candlestick",
|
51 | candlesticks: "bb-candlesticks",
|
52 | chart: "bb-chart",
|
53 | chartArc: "bb-chart-arc",
|
54 | chartArcs: "bb-chart-arcs",
|
55 | chartArcsBackground: "bb-chart-arcs-background",
|
56 | chartArcsGaugeMax: "bb-chart-arcs-gauge-max",
|
57 | chartArcsGaugeMin: "bb-chart-arcs-gauge-min",
|
58 | chartArcsGaugeUnit: "bb-chart-arcs-gauge-unit",
|
59 | chartArcsTitle: "bb-chart-arcs-title",
|
60 | chartArcsGaugeTitle: "bb-chart-arcs-gauge-title",
|
61 | chartBar: "bb-chart-bar",
|
62 | chartBars: "bb-chart-bars",
|
63 | chartCandlestick: "bb-chart-candlestick",
|
64 | chartCandlesticks: "bb-chart-candlesticks",
|
65 | chartCircles: "bb-chart-circles",
|
66 | chartLine: "bb-chart-line",
|
67 | chartLines: "bb-chart-lines",
|
68 | chartRadar: "bb-chart-radar",
|
69 | chartRadars: "bb-chart-radars",
|
70 | chartText: "bb-chart-text",
|
71 | chartTexts: "bb-chart-texts",
|
72 | circle: "bb-circle",
|
73 | circles: "bb-circles",
|
74 | colorPattern: "bb-color-pattern",
|
75 | colorScale: "bb-colorscale",
|
76 | defocused: "bb-defocused",
|
77 | dragarea: "bb-dragarea",
|
78 | empty: "bb-empty",
|
79 | eventRect: "bb-event-rect",
|
80 | eventRects: "bb-event-rects",
|
81 | eventRectsMultiple: "bb-event-rects-multiple",
|
82 | eventRectsSingle: "bb-event-rects-single",
|
83 | focused: "bb-focused",
|
84 | gaugeValue: "bb-gauge-value",
|
85 | grid: "bb-grid",
|
86 | gridLines: "bb-grid-lines",
|
87 | legend: "bb-legend",
|
88 | legendBackground: "bb-legend-background",
|
89 | legendItem: "bb-legend-item",
|
90 | legendItemEvent: "bb-legend-item-event",
|
91 | legendItemFocused: "bb-legend-item-focused",
|
92 | legendItemHidden: "bb-legend-item-hidden",
|
93 | legendItemPoint: "bb-legend-item-point",
|
94 | legendItemTile: "bb-legend-item-tile",
|
95 | level: "bb-level",
|
96 | levels: "bb-levels",
|
97 | line: "bb-line",
|
98 | lines: "bb-lines",
|
99 | main: "bb-main",
|
100 | region: "bb-region",
|
101 | regions: "bb-regions",
|
102 | selectedCircle: "bb-selected-circle",
|
103 | selectedCircles: "bb-selected-circles",
|
104 | shape: "bb-shape",
|
105 | shapes: "bb-shapes",
|
106 | stanfordElements: "bb-stanford-elements",
|
107 | stanfordLine: "bb-stanford-line",
|
108 | stanfordLines: "bb-stanford-lines",
|
109 | stanfordRegion: "bb-stanford-region",
|
110 | stanfordRegions: "bb-stanford-regions",
|
111 | subchart: "bb-subchart",
|
112 | target: "bb-target",
|
113 | text: "bb-text",
|
114 | texts: "bb-texts",
|
115 | title: "bb-title",
|
116 | tooltip: "bb-tooltip",
|
117 | tooltipContainer: "bb-tooltip-container",
|
118 | tooltipName: "bb-tooltip-name",
|
119 | valueDown: "bb-value-down",
|
120 | valueUp: "bb-value-up",
|
121 | xgrid: "bb-xgrid",
|
122 | xgridFocus: "bb-xgrid-focus",
|
123 | xgridLine: "bb-xgrid-line",
|
124 | xgridLines: "bb-xgrid-lines",
|
125 | xgrids: "bb-xgrids",
|
126 | ygrid: "bb-ygrid",
|
127 | ygridFocus: "bb-ygrid-focus",
|
128 | ygridLine: "bb-ygrid-line",
|
129 | ygridLines: "bb-ygrid-lines",
|
130 | ygrids: "bb-ygrids",
|
131 | zoomBrush: "bb-zoom-brush",
|
132 | EXPANDED: "_expanded_",
|
133 | SELECTED: "_selected_",
|
134 | INCLUDED: "_included_",
|
135 | TextOverlapping: "text-overlapping"
|
136 | };
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 | var Element = (function () {
|
145 | function Element() {
|
146 | var element = {
|
147 | chart: null,
|
148 | main: null,
|
149 | svg: null,
|
150 | axis: {
|
151 | x: null,
|
152 | y: null,
|
153 | y2: null,
|
154 | subX: null
|
155 | },
|
156 | defs: null,
|
157 | tooltip: null,
|
158 | legend: null,
|
159 | title: null,
|
160 | subchart: {
|
161 | main: null,
|
162 | bar: null,
|
163 | line: null,
|
164 | area: null
|
165 | },
|
166 | arcs: null,
|
167 | bar: null,
|
168 | candlestick: null,
|
169 | line: null,
|
170 | area: null,
|
171 | circle: null,
|
172 | radar: null,
|
173 | text: null,
|
174 | grid: {
|
175 | main: null,
|
176 | x: null,
|
177 | y: null
|
178 | },
|
179 | gridLines: {
|
180 | main: null,
|
181 | x: null,
|
182 | y: null
|
183 | },
|
184 | region: {
|
185 | main: null,
|
186 | list: null
|
187 | },
|
188 | eventRect: null
|
189 | };
|
190 | return element;
|
191 | }
|
192 | return Element;
|
193 | }());
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 | var State = (function () {
|
206 | function State() {
|
207 | return {
|
208 | width: 0,
|
209 | width2: 0,
|
210 | height: 0,
|
211 | height2: 0,
|
212 | margin: {
|
213 | top: 0,
|
214 | bottom: 0,
|
215 | left: 0,
|
216 | right: 0
|
217 | },
|
218 | margin2: {
|
219 | top: 0,
|
220 | bottom: 0,
|
221 | left: 0,
|
222 | right: 0
|
223 | },
|
224 | margin3: {
|
225 | top: 0,
|
226 | bottom: 0,
|
227 | left: 0,
|
228 | right: 0
|
229 | },
|
230 | arcWidth: 0,
|
231 | arcHeight: 0,
|
232 | xAxisHeight: 0,
|
233 | hasAxis: false,
|
234 | hasRadar: false,
|
235 | current: {
|
236 | width: 0,
|
237 | height: 0,
|
238 | dataMax: 0,
|
239 | maxTickWidths: {
|
240 | x: { size: 0, ticks: [], clipPath: 0, domain: "" },
|
241 | y: { size: 0, domain: "" },
|
242 | y2: { size: 0, domain: "" }
|
243 | },
|
244 |
|
245 | types: []
|
246 | },
|
247 |
|
248 | isLegendRight: false,
|
249 | isLegendInset: false,
|
250 | isLegendTop: false,
|
251 | isLegendLeft: false,
|
252 | legendStep: 0,
|
253 | legendItemWidth: 0,
|
254 | legendItemHeight: 0,
|
255 | legendHasRendered: false,
|
256 | eventReceiver: {
|
257 | currentIdx: -1,
|
258 | rect: {},
|
259 | data: [],
|
260 | coords: []
|
261 | },
|
262 | axis: {
|
263 | x: {
|
264 | padding: { left: 0, right: 0 },
|
265 | tickCount: 0
|
266 | }
|
267 | },
|
268 | rotatedPadding: {
|
269 | left: 30,
|
270 | right: 0,
|
271 | top: 5
|
272 | },
|
273 | withoutFadeIn: {},
|
274 | inputType: "",
|
275 | datetimeId: "",
|
276 |
|
277 | clip: {
|
278 | id: "",
|
279 | idXAxis: "",
|
280 | idYAxis: "",
|
281 | idXAxisTickTexts: "",
|
282 | idGrid: "",
|
283 | idSubchart: "",
|
284 | path: "",
|
285 | pathXAxis: "",
|
286 | pathYAxis: "",
|
287 | pathXAxisTickTexts: "",
|
288 | pathGrid: ""
|
289 | },
|
290 |
|
291 | event: null,
|
292 | dragStart: null,
|
293 | dragging: false,
|
294 | flowing: false,
|
295 | cancelClick: false,
|
296 | mouseover: false,
|
297 | rendered: false,
|
298 | transiting: false,
|
299 | redrawing: false,
|
300 | resizing: false,
|
301 | toggling: false,
|
302 | zooming: false,
|
303 | hasNegativeValue: false,
|
304 | hasPositiveValue: true,
|
305 | orgAreaOpacity: "0.2",
|
306 |
|
307 | hiddenTargetIds: [],
|
308 | hiddenLegendIds: [],
|
309 | focusedTargetIds: [],
|
310 | defocusedTargetIds: [],
|
311 |
|
312 | radius: 0,
|
313 | innerRadius: 0,
|
314 | outerRadius: undefined,
|
315 | innerRadiusRatio: 0,
|
316 | gaugeArcWidth: 0,
|
317 | radiusExpanded: 0,
|
318 |
|
319 | xgridAttr: {
|
320 | x1: null,
|
321 | x2: null,
|
322 | y1: null,
|
323 | y2: null
|
324 | }
|
325 | };
|
326 | }
|
327 | return State;
|
328 | }());
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 | var classes = {
|
336 | element: Element,
|
337 | state: State
|
338 | };
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 | var Store = (function () {
|
346 | function Store() {
|
347 | var _this = this;
|
348 | Object.keys(classes).forEach(function (v) {
|
349 | _this[v] = new classes[v]();
|
350 | });
|
351 | }
|
352 | Store.prototype.getStore = function (name) {
|
353 | return this[name];
|
354 | };
|
355 | return Store;
|
356 | }());
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 | var _assign = function __assign() {
|
374 | return _assign = Object.assign || function (t) {
|
375 | for (var s, i = 1, n = arguments.length; i < n; i++) for (var p in s = arguments[i], s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
|
376 |
|
377 | return t;
|
378 | }, _assign.apply(this, arguments);
|
379 | };
|
380 | function __spreadArray(to, from) {
|
381 | for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i];
|
382 |
|
383 | return to;
|
384 | }
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 | var main = {
|
394 | |
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 | bindto: "#chart",
|
421 | |
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 | background: {},
|
441 | |
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 | clipPath: true,
|
456 | |
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 | svg_classname: undefined,
|
469 | |
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 | size_width: undefined,
|
486 | size_height: undefined,
|
487 | |
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 | padding_left: undefined,
|
506 | padding_right: undefined,
|
507 | padding_top: undefined,
|
508 | padding_bottom: undefined,
|
509 | |
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 | resize_auto: true,
|
522 | |
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 |
|
534 | onover: undefined,
|
535 | |
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 | onout: undefined,
|
548 | |
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 | onresize: undefined,
|
561 | |
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 | onresized: undefined,
|
574 | |
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 | onbeforeinit: undefined,
|
587 | |
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 | oninit: undefined,
|
600 | |
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 | onafterinit: undefined,
|
613 | |
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 | onrendered: undefined,
|
626 | |
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 | transition_duration: 350,
|
640 | |
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 | plugins: [],
|
653 | |
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 | render: {},
|
694 | |
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 | regions: []
|
717 | };
|
718 |
|
719 |
|
720 |
|
721 |
|
722 | var data$2 = {
|
723 | |
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 | data_x: undefined,
|
736 | |
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 |
|
754 |
|
755 | data_idConverter: function (id) { return id; },
|
756 | |
757 |
|
758 |
|
759 |
|
760 |
|
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 |
|
768 |
|
769 |
|
770 |
|
771 | data_names: {},
|
772 | |
773 |
|
774 |
|
775 |
|
776 |
|
777 |
|
778 |
|
779 |
|
780 |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 | data_classes: {},
|
788 | |
789 |
|
790 |
|
791 |
|
792 |
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 |
|
828 |
|
829 |
|
830 |
|
831 |
|
832 |
|
833 |
|
834 |
|
835 |
|
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 | data_type: undefined,
|
846 | |
847 |
|
848 |
|
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 |
|
856 |
|
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 |
|
869 |
|
870 |
|
871 |
|
872 |
|
873 |
|
874 |
|
875 |
|
876 |
|
877 |
|
878 |
|
879 |
|
880 |
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 | data_types: {},
|
894 | |
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 |
|
919 |
|
920 |
|
921 |
|
922 |
|
923 |
|
924 |
|
925 |
|
926 |
|
927 |
|
928 |
|
929 |
|
930 |
|
931 |
|
932 |
|
933 |
|
934 |
|
935 |
|
936 |
|
937 |
|
938 |
|
939 |
|
940 |
|
941 |
|
942 |
|
943 |
|
944 | data_order: "desc",
|
945 | |
946 |
|
947 |
|
948 |
|
949 |
|
950 |
|
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 |
|
958 |
|
959 | data_groups: [],
|
960 | |
961 |
|
962 |
|
963 |
|
964 |
|
965 |
|
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 |
|
972 |
|
973 | data_color: undefined,
|
974 | |
975 |
|
976 |
|
977 |
|
978 |
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 |
|
985 |
|
986 |
|
987 |
|
988 |
|
989 |
|
990 |
|
991 | data_colors: {},
|
992 | |
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 |
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 |
|
1051 |
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 | data_labels: {},
|
1075 | data_labels_colors: undefined,
|
1076 | data_labels_position: {},
|
1077 | |
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 | data_hide: false,
|
1094 | |
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 |
|
1106 |
|
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 | data_filter: undefined,
|
1113 | |
1114 |
|
1115 |
|
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 |
|
1123 |
|
1124 |
|
1125 |
|
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 | data_onclick: function () { },
|
1133 | |
1134 |
|
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 |
|
1143 |
|
1144 |
|
1145 |
|
1146 |
|
1147 |
|
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 | data_onover: function () { },
|
1153 | |
1154 |
|
1155 |
|
1156 |
|
1157 |
|
1158 |
|
1159 |
|
1160 |
|
1161 |
|
1162 |
|
1163 |
|
1164 |
|
1165 |
|
1166 |
|
1167 |
|
1168 |
|
1169 |
|
1170 |
|
1171 |
|
1172 | data_onout: function () { },
|
1173 | |
1174 |
|
1175 |
|
1176 |
|
1177 |
|
1178 |
|
1179 |
|
1180 |
|
1181 |
|
1182 |
|
1183 |
|
1184 |
|
1185 |
|
1186 |
|
1187 | data_onmin: undefined,
|
1188 | |
1189 |
|
1190 |
|
1191 |
|
1192 |
|
1193 |
|
1194 |
|
1195 |
|
1196 |
|
1197 |
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 | data_onmax: undefined,
|
1203 | |
1204 |
|
1205 |
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 |
|
1211 |
|
1212 |
|
1213 |
|
1214 |
|
1215 | data_url: undefined,
|
1216 | |
1217 |
|
1218 |
|
1219 |
|
1220 |
|
1221 |
|
1222 |
|
1223 |
|
1224 |
|
1225 |
|
1226 |
|
1227 |
|
1228 |
|
1229 |
|
1230 |
|
1231 |
|
1232 |
|
1233 | data_headers: undefined,
|
1234 | |
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 |
|
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 |
|
1248 |
|
1249 |
|
1250 |
|
1251 |
|
1252 |
|
1253 |
|
1254 |
|
1255 |
|
1256 | data_json: undefined,
|
1257 | |
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 |
|
1268 |
|
1269 |
|
1270 |
|
1271 |
|
1272 |
|
1273 |
|
1274 |
|
1275 |
|
1276 |
|
1277 |
|
1278 |
|
1279 |
|
1280 |
|
1281 |
|
1282 |
|
1283 |
|
1284 |
|
1285 |
|
1286 |
|
1287 |
|
1288 |
|
1289 |
|
1290 |
|
1291 |
|
1292 |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 |
|
1298 |
|
1299 |
|
1300 |
|
1301 |
|
1302 |
|
1303 |
|
1304 |
|
1305 |
|
1306 |
|
1307 |
|
1308 |
|
1309 |
|
1310 |
|
1311 |
|
1312 |
|
1313 |
|
1314 |
|
1315 |
|
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 |
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 |
|
1334 |
|
1335 | data_rows: undefined,
|
1336 | |
1337 |
|
1338 |
|
1339 |
|
1340 |
|
1341 |
|
1342 |
|
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 |
|
1348 |
|
1349 |
|
1350 |
|
1351 |
|
1352 |
|
1353 |
|
1354 |
|
1355 |
|
1356 |
|
1357 |
|
1358 |
|
1359 |
|
1360 |
|
1361 |
|
1362 |
|
1363 |
|
1364 |
|
1365 |
|
1366 |
|
1367 |
|
1368 |
|
1369 |
|
1370 |
|
1371 |
|
1372 |
|
1373 |
|
1374 |
|
1375 |
|
1376 |
|
1377 |
|
1378 |
|
1379 |
|
1380 |
|
1381 |
|
1382 |
|
1383 |
|
1384 |
|
1385 |
|
1386 |
|
1387 |
|
1388 |
|
1389 |
|
1390 |
|
1391 |
|
1392 |
|
1393 |
|
1394 | data_columns: undefined,
|
1395 | |
1396 |
|
1397 |
|
1398 |
|
1399 |
|
1400 |
|
1401 |
|
1402 |
|
1403 |
|
1404 |
|
1405 |
|
1406 |
|
1407 |
|
1408 |
|
1409 |
|
1410 | data_mimeType: "csv",
|
1411 | |
1412 |
|
1413 |
|
1414 |
|
1415 |
|
1416 |
|
1417 |
|
1418 |
|
1419 |
|
1420 |
|
1421 |
|
1422 |
|
1423 |
|
1424 |
|
1425 |
|
1426 |
|
1427 |
|
1428 |
|
1429 |
|
1430 |
|
1431 |
|
1432 | data_keys: undefined,
|
1433 | |
1434 |
|
1435 |
|
1436 |
|
1437 |
|
1438 |
|
1439 |
|
1440 |
|
1441 |
|
1442 |
|
1443 |
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 | data_empty_label_text: ""
|
1450 | };
|
1451 |
|
1452 |
|
1453 |
|
1454 |
|
1455 |
|
1456 |
|
1457 |
|
1458 |
|
1459 | var color$1 = {
|
1460 | |
1461 |
|
1462 |
|
1463 |
|
1464 |
|
1465 |
|
1466 |
|
1467 |
|
1468 |
|
1469 |
|
1470 |
|
1471 |
|
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 |
|
1477 |
|
1478 |
|
1479 |
|
1480 |
|
1481 |
|
1482 |
|
1483 |
|
1484 |
|
1485 |
|
1486 |
|
1487 |
|
1488 |
|
1489 |
|
1490 |
|
1491 |
|
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 |
|
1500 |
|
1501 |
|
1502 |
|
1503 |
|
1504 |
|
1505 |
|
1506 |
|
1507 |
|
1508 |
|
1509 |
|
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 | color_pattern: [],
|
1535 | color_tiles: undefined,
|
1536 | color_threshold: {},
|
1537 | color_onover: undefined
|
1538 | };
|
1539 |
|
1540 |
|
1541 |
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 |
|
1547 | var interaction$1 = {
|
1548 | |
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 |
|
1558 |
|
1559 |
|
1560 |
|
1561 |
|
1562 |
|
1563 |
|
1564 |
|
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 |
|
1570 |
|
1571 |
|
1572 |
|
1573 |
|
1574 |
|
1575 |
|
1576 |
|
1577 |
|
1578 |
|
1579 |
|
1580 | interaction_enabled: true,
|
1581 | interaction_brighten: true,
|
1582 | interaction_inputType_mouse: true,
|
1583 | interaction_inputType_touch: {}
|
1584 | };
|
1585 |
|
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 |
|
1592 |
|
1593 | var legend$2 = {
|
1594 | |
1595 |
|
1596 |
|
1597 |
|
1598 |
|
1599 |
|
1600 |
|
1601 |
|
1602 |
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 |
|
1611 |
|
1612 |
|
1613 |
|
1614 |
|
1615 |
|
1616 |
|
1617 |
|
1618 |
|
1619 |
|
1620 |
|
1621 |
|
1622 |
|
1623 |
|
1624 |
|
1625 |
|
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 |
|
1631 |
|
1632 |
|
1633 |
|
1634 |
|
1635 |
|
1636 |
|
1637 |
|
1638 |
|
1639 |
|
1640 |
|
1641 |
|
1642 |
|
1643 |
|
1644 |
|
1645 |
|
1646 |
|
1647 |
|
1648 |
|
1649 |
|
1650 |
|
1651 |
|
1652 |
|
1653 |
|
1654 |
|
1655 |
|
1656 |
|
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 |
|
1663 |
|
1664 |
|
1665 |
|
1666 |
|
1667 |
|
1668 |
|
1669 |
|
1670 |
|
1671 |
|
1672 |
|
1673 |
|
1674 |
|
1675 |
|
1676 |
|
1677 |
|
1678 |
|
1679 | legend_show: true,
|
1680 | legend_hide: false,
|
1681 | legend_contents_bindto: undefined,
|
1682 | legend_contents_template: undefined,
|
1683 | legend_position: "bottom",
|
1684 | legend_inset_anchor: "top-left",
|
1685 | legend_inset_x: 10,
|
1686 | legend_inset_y: 0,
|
1687 | legend_inset_step: undefined,
|
1688 | legend_item_onclick: undefined,
|
1689 | legend_item_onover: undefined,
|
1690 | legend_item_onout: undefined,
|
1691 | legend_equally: false,
|
1692 | legend_padding: 0,
|
1693 | legend_item_tile_width: 10,
|
1694 | legend_item_tile_height: 10,
|
1695 | legend_usePoint: false
|
1696 | };
|
1697 |
|
1698 |
|
1699 |
|
1700 |
|
1701 |
|
1702 |
|
1703 |
|
1704 |
|
1705 | var title$1 = {
|
1706 | |
1707 |
|
1708 |
|
1709 |
|
1710 |
|
1711 |
|
1712 |
|
1713 |
|
1714 |
|
1715 |
|
1716 |
|
1717 |
|
1718 |
|
1719 |
|
1720 |
|
1721 |
|
1722 |
|
1723 |
|
1724 |
|
1725 |
|
1726 |
|
1727 |
|
1728 |
|
1729 |
|
1730 |
|
1731 |
|
1732 |
|
1733 |
|
1734 |
|
1735 | title_text: undefined,
|
1736 | title_padding: {
|
1737 | top: 0,
|
1738 | right: 0,
|
1739 | bottom: 0,
|
1740 | left: 0
|
1741 | },
|
1742 | title_position: "center"
|
1743 | };
|
1744 |
|
1745 |
|
1746 |
|
1747 |
|
1748 |
|
1749 |
|
1750 |
|
1751 |
|
1752 | var tooltip$2 = {
|
1753 | |
1754 |
|
1755 |
|
1756 |
|
1757 |
|
1758 |
|
1759 |
|
1760 |
|
1761 |
|
1762 |
|
1763 |
|
1764 |
|
1765 |
|
1766 |
|
1767 |
|
1768 |
|
1769 |
|
1770 |
|
1771 |
|
1772 |
|
1773 |
|
1774 |
|
1775 |
|
1776 |
|
1777 |
|
1778 |
|
1779 |
|
1780 |
|
1781 |
|
1782 |
|
1783 |
|
1784 |
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 |
|
1795 |
|
1796 |
|
1797 |
|
1798 |
|
1799 |
|
1800 |
|
1801 |
|
1802 |
|
1803 |
|
1804 |
|
1805 |
|
1806 |
|
1807 |
|
1808 |
|
1809 |
|
1810 |
|
1811 |
|
1812 |
|
1813 |
|
1814 |
|
1815 |
|
1816 |
|
1817 |
|
1818 |
|
1819 |
|
1820 |
|
1821 |
|
1822 |
|
1823 |
|
1824 |
|
1825 |
|
1826 |
|
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 |
|
1833 |
|
1834 |
|
1835 |
|
1836 |
|
1837 |
|
1838 |
|
1839 |
|
1840 |
|
1841 |
|
1842 |
|
1843 |
|
1844 |
|
1845 |
|
1846 |
|
1847 |
|
1848 |
|
1849 |
|
1850 |
|
1851 |
|
1852 |
|
1853 |
|
1854 |
|
1855 |
|
1856 |
|
1857 |
|
1858 |
|
1859 |
|
1860 |
|
1861 |
|
1862 |
|
1863 |
|
1864 |
|
1865 |
|
1866 |
|
1867 |
|
1868 |
|
1869 |
|
1870 |
|
1871 |
|
1872 |
|
1873 |
|
1874 |
|
1875 |
|
1876 |
|
1877 |
|
1878 |
|
1879 |
|
1880 |
|
1881 |
|
1882 |
|
1883 |
|
1884 |
|
1885 |
|
1886 |
|
1887 |
|
1888 |
|
1889 |
|
1890 |
|
1891 |
|
1892 |
|
1893 |
|
1894 |
|
1895 |
|
1896 |
|
1897 |
|
1898 |
|
1899 |
|
1900 |
|
1901 |
|
1902 |
|
1903 |
|
1904 |
|
1905 |
|
1906 |
|
1907 |
|
1908 |
|
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 |
|
1914 |
|
1915 |
|
1916 |
|
1917 |
|
1918 |
|
1919 |
|
1920 | tooltip_show: true,
|
1921 | tooltip_doNotHide: false,
|
1922 | tooltip_grouped: true,
|
1923 | tooltip_format_title: undefined,
|
1924 | tooltip_format_name: undefined,
|
1925 | tooltip_format_value: undefined,
|
1926 | tooltip_position: undefined,
|
1927 | tooltip_contents: {},
|
1928 | tooltip_init_show: false,
|
1929 | tooltip_init_x: 0,
|
1930 | tooltip_init_position: {
|
1931 | top: "0px",
|
1932 | left: "50px"
|
1933 | },
|
1934 | tooltip_linked: false,
|
1935 | tooltip_linked_name: "",
|
1936 | tooltip_onshow: function () { },
|
1937 | tooltip_onhide: function () { },
|
1938 | tooltip_onshown: function () { },
|
1939 | tooltip_onhidden: function () { },
|
1940 | tooltip_order: null
|
1941 | };
|
1942 |
|
1943 |
|
1944 |
|
1945 |
|
1946 |
|
1947 | var win = (function () {
|
1948 | var root = (typeof globalThis === "object" && globalThis !== null && globalThis.Object === Object && globalThis) ||
|
1949 | (typeof global === "object" && global !== null && global.Object === Object && global) ||
|
1950 | (typeof self === "object" && self !== null && self.Object === Object && self);
|
1951 | return root || Function("return this")();
|
1952 | })();
|
1953 |
|
1954 | var doc = win && win.document;
|
1955 |
|
1956 | var isValue = function (v) { return v || v === 0; };
|
1957 | var isFunction = function (v) { return typeof v === "function"; };
|
1958 | var isString = function (v) { return typeof v === "string"; };
|
1959 | var isNumber = function (v) { return typeof v === "number"; };
|
1960 | var isUndefined = function (v) { return typeof v === "undefined"; };
|
1961 | var isDefined = function (v) { return typeof v !== "undefined"; };
|
1962 | var isboolean = function (v) { return typeof v === "boolean"; };
|
1963 | var ceil10 = function (v) { return Math.ceil(v / 10) * 10; };
|
1964 | var asHalfPixel = function (n) { return Math.ceil(n) + 0.5; };
|
1965 | var diffDomain = function (d) { return d[1] - d[0]; };
|
1966 | var isObjectType = function (v) { return typeof v === "object"; };
|
1967 | var isEmpty = function (o) { return (isUndefined(o) || o === null ||
|
1968 | (isString(o) && o.length === 0) ||
|
1969 | (isObjectType(o) && !(o instanceof Date) && Object.keys(o).length === 0) ||
|
1970 | (isNumber(o) && isNaN(o))); };
|
1971 | var notEmpty = function (o) { return !isEmpty(o); };
|
1972 |
|
1973 |
|
1974 |
|
1975 |
|
1976 |
|
1977 |
|
1978 | var isArray = function (arr) { return Array.isArray(arr); };
|
1979 |
|
1980 |
|
1981 |
|
1982 |
|
1983 |
|
1984 |
|
1985 | var isObject = function (obj) { return obj && !obj.nodeType && isObjectType(obj) && !isArray(obj); };
|
1986 |
|
1987 |
|
1988 |
|
1989 |
|
1990 |
|
1991 |
|
1992 |
|
1993 |
|
1994 |
|
1995 | function getOption(options, key, defaultValue) {
|
1996 | return isDefined(options[key]) ? options[key] : defaultValue;
|
1997 | }
|
1998 |
|
1999 |
|
2000 |
|
2001 |
|
2002 |
|
2003 |
|
2004 |
|
2005 | function hasValue(dict, value) {
|
2006 | var found = false;
|
2007 | Object.keys(dict).forEach(function (key) { return (dict[key] === value) && (found = true); });
|
2008 | return found;
|
2009 | }
|
2010 |
|
2011 |
|
2012 |
|
2013 |
|
2014 |
|
2015 |
|
2016 |
|
2017 | function callFn(fn) {
|
2018 | var args = [];
|
2019 | for (var _i = 1; _i < arguments.length; _i++) {
|
2020 | args[_i - 1] = arguments[_i];
|
2021 | }
|
2022 | var isFn = isFunction(fn);
|
2023 | isFn && fn.call.apply(fn, args);
|
2024 | return isFn;
|
2025 | }
|
2026 |
|
2027 |
|
2028 |
|
2029 |
|
2030 |
|
2031 |
|
2032 | function endall(transition, cb) {
|
2033 | var n = 0;
|
2034 | transition
|
2035 | .each(function () { return ++n; })
|
2036 | .on("end", function () {
|
2037 | var args = [];
|
2038 | for (var _i = 0; _i < arguments.length; _i++) {
|
2039 | args[_i] = arguments[_i];
|
2040 | }
|
2041 | !--n && cb.apply.apply(cb, __spreadArray([this], args));
|
2042 | });
|
2043 | }
|
2044 |
|
2045 |
|
2046 |
|
2047 |
|
2048 |
|
2049 |
|
2050 | function sanitise(str) {
|
2051 | return isString(str) ?
|
2052 | str.replace(/</g, "<").replace(/>/g, ">") : str;
|
2053 | }
|
2054 |
|
2055 |
|
2056 |
|
2057 |
|
2058 |
|
2059 |
|
2060 |
|
2061 |
|
2062 | function setTextValue(node, text, dy, toMiddle) {
|
2063 | if (dy === void 0) { dy = [-1, 1]; }
|
2064 | if (toMiddle === void 0) { toMiddle = false; }
|
2065 | if (!node || !isString(text)) {
|
2066 | return;
|
2067 | }
|
2068 | if (text.indexOf("\n") === -1) {
|
2069 | node.text(text);
|
2070 | }
|
2071 | else {
|
2072 | var diff = [node.text(), text].map(function (v) { return v.replace(/[\s\n]/g, ""); });
|
2073 | if (diff[0] !== diff[1]) {
|
2074 | var multiline = text.split("\n");
|
2075 | var len_1 = toMiddle ? multiline.length - 1 : 1;
|
2076 |
|
2077 | node.html("");
|
2078 | multiline.forEach(function (v, i) {
|
2079 | node.append("tspan")
|
2080 | .attr("x", 0)
|
2081 | .attr("dy", (i === 0 ? dy[0] * len_1 : dy[1]) + "em")
|
2082 | .text(v);
|
2083 | });
|
2084 | }
|
2085 | }
|
2086 | }
|
2087 |
|
2088 |
|
2089 |
|
2090 |
|
2091 |
|
2092 |
|
2093 | function getRectSegList(path) {
|
2094 | |
2095 |
|
2096 |
|
2097 |
|
2098 |
|
2099 |
|
2100 |
|
2101 | var _a = path.getBBox(), x = _a.x, y = _a.y, width = _a.width, height = _a.height;
|
2102 | return [
|
2103 | { x: x, y: y + height },
|
2104 | { x: x, y: y },
|
2105 | { x: x + width, y: y },
|
2106 | { x: x + width, y: y + height }
|
2107 | ];
|
2108 | }
|
2109 |
|
2110 |
|
2111 |
|
2112 |
|
2113 |
|
2114 |
|
2115 | function getPathBox(path) {
|
2116 | var _a = path.getBoundingClientRect(), width = _a.width, height = _a.height;
|
2117 | var items = getRectSegList(path);
|
2118 | var x = items[0].x;
|
2119 | var y = Math.min(items[0].y, items[1].y);
|
2120 | return {
|
2121 | x: x, y: y, width: width, height: height
|
2122 | };
|
2123 | }
|
2124 |
|
2125 |
|
2126 |
|
2127 |
|
2128 |
|
2129 |
|
2130 |
|
2131 | function getPointer(event, element) {
|
2132 | var touches = event && (event.touches || (event.sourceEvent && event.sourceEvent.touches));
|
2133 | var pointer$1 = event ?
|
2134 | pointer(touches ? touches[0] : event, element) :
|
2135 | [0, 0];
|
2136 | return pointer$1;
|
2137 | }
|
2138 |
|
2139 |
|
2140 |
|
2141 |
|
2142 |
|
2143 |
|
2144 | function getBrushSelection(ctx) {
|
2145 | var event = ctx.event, $el = ctx.$el;
|
2146 | var main = $el.subchart.main || $el.main;
|
2147 | var selection;
|
2148 |
|
2149 | if (event && event.type === "brush") {
|
2150 | selection = event.selection;
|
2151 |
|
2152 | }
|
2153 | else if (main && (selection = main.select("." + CLASS.brush).node())) {
|
2154 | selection = brushSelection(selection);
|
2155 | }
|
2156 | return selection;
|
2157 | }
|
2158 |
|
2159 |
|
2160 |
|
2161 |
|
2162 |
|
2163 |
|
2164 |
|
2165 | function getBoundingRect(node) {
|
2166 | var needEvaluate = !("rect" in node) || ("rect" in node && node.hasAttribute("width") && node.rect.width !== +node.getAttribute("width"));
|
2167 | return needEvaluate ?
|
2168 | (node.rect = node.getBoundingClientRect()) : node.rect;
|
2169 | }
|
2170 |
|
2171 |
|
2172 |
|
2173 |
|
2174 |
|
2175 |
|
2176 | function getRandom(asStr) {
|
2177 | if (asStr === void 0) { asStr = true; }
|
2178 | var rand = Math.random();
|
2179 | return asStr ? String(rand) : rand;
|
2180 | }
|
2181 |
|
2182 |
|
2183 |
|
2184 |
|
2185 |
|
2186 |
|
2187 |
|
2188 |
|
2189 |
|
2190 |
|
2191 | function findIndex(arr, v, start, end, isRotated) {
|
2192 | if (start > end) {
|
2193 | return -1;
|
2194 | }
|
2195 | var mid = Math.floor((start + end) / 2);
|
2196 | var _a = arr[mid], x = _a.x, _b = _a.w, w = _b === void 0 ? 0 : _b;
|
2197 | if (isRotated) {
|
2198 | x = arr[mid].y;
|
2199 | w = arr[mid].h;
|
2200 | }
|
2201 | if (v >= x && v <= x + w) {
|
2202 | return mid;
|
2203 | }
|
2204 | return v < x ?
|
2205 | findIndex(arr, v, start, mid - 1, isRotated) :
|
2206 | findIndex(arr, v, mid + 1, end, isRotated);
|
2207 | }
|
2208 |
|
2209 |
|
2210 |
|
2211 |
|
2212 |
|
2213 |
|
2214 | function brushEmpty(ctx) {
|
2215 | var selection = getBrushSelection(ctx);
|
2216 | if (selection) {
|
2217 |
|
2218 |
|
2219 |
|
2220 | return selection[0] === selection[1];
|
2221 | }
|
2222 | return true;
|
2223 | }
|
2224 |
|
2225 |
|
2226 |
|
2227 |
|
2228 |
|
2229 |
|
2230 | function deepClone() {
|
2231 | var objectN = [];
|
2232 | for (var _i = 0; _i < arguments.length; _i++) {
|
2233 | objectN[_i] = arguments[_i];
|
2234 | }
|
2235 | var clone = function (v) {
|
2236 | if (isObject(v) && v.constructor) {
|
2237 | var r = new v.constructor();
|
2238 | for (var k in v) {
|
2239 | r[k] = clone(v[k]);
|
2240 | }
|
2241 | return r;
|
2242 | }
|
2243 | return v;
|
2244 | };
|
2245 | return objectN.map(function (v) { return clone(v); })
|
2246 | .reduce(function (a, c) { return (_assign(_assign({}, a), c)); });
|
2247 | }
|
2248 |
|
2249 |
|
2250 |
|
2251 |
|
2252 |
|
2253 |
|
2254 |
|
2255 | function extend(target, source) {
|
2256 | if (target === void 0) { target = {}; }
|
2257 | if (isArray(source)) {
|
2258 | source.forEach(function (v) { return extend(target, v); });
|
2259 | }
|
2260 |
|
2261 | for (var p in source) {
|
2262 | if (/^\d+$/.test(p) || p in target) {
|
2263 | continue;
|
2264 | }
|
2265 | target[p] = source[p];
|
2266 | }
|
2267 | return target;
|
2268 | }
|
2269 |
|
2270 |
|
2271 |
|
2272 |
|
2273 |
|
2274 |
|
2275 | var capitalize = function (str) { return str.charAt(0).toUpperCase() + str.slice(1); };
|
2276 |
|
2277 |
|
2278 |
|
2279 |
|
2280 |
|
2281 |
|
2282 | var toArray = function (v) { return [].slice.call(v); };
|
2283 |
|
2284 |
|
2285 |
|
2286 |
|
2287 |
|
2288 |
|
2289 | function getCssRules(styleSheets) {
|
2290 | var rules = [];
|
2291 | styleSheets.forEach(function (sheet) {
|
2292 | try {
|
2293 | if (sheet.cssRules && sheet.cssRules.length) {
|
2294 | rules = rules.concat(toArray(sheet.cssRules));
|
2295 | }
|
2296 | }
|
2297 | catch (e) {
|
2298 | console.error("Error while reading rules from " + sheet.href + ": " + e.toString());
|
2299 | }
|
2300 | });
|
2301 | return rules;
|
2302 | }
|
2303 |
|
2304 |
|
2305 |
|
2306 |
|
2307 |
|
2308 |
|
2309 | var getTranslation = function (node) {
|
2310 | var transform = node ? node.transform : null;
|
2311 | var baseVal = transform && transform.baseVal;
|
2312 | return baseVal && baseVal.numberOfItems ?
|
2313 | baseVal.getItem(0).matrix :
|
2314 | { a: 0, b: 0, c: 0, d: 0, e: 0, f: 0 };
|
2315 | };
|
2316 |
|
2317 |
|
2318 |
|
2319 |
|
2320 |
|
2321 |
|
2322 | function getUnique(data) {
|
2323 | var isDate = data[0] instanceof Date;
|
2324 | var d = (isDate ? data.map(Number) : data)
|
2325 | .filter(function (v, i, self) { return self.indexOf(v) === i; });
|
2326 | return isDate ? d.map(function (v) { return new Date(v); }) : d;
|
2327 | }
|
2328 |
|
2329 |
|
2330 |
|
2331 |
|
2332 |
|
2333 |
|
2334 | function mergeArray(arr) {
|
2335 | return arr && arr.length ? arr.reduce(function (p, c) { return p.concat(c); }) : [];
|
2336 | }
|
2337 |
|
2338 |
|
2339 |
|
2340 |
|
2341 |
|
2342 |
|
2343 |
|
2344 | function mergeObj(target) {
|
2345 | var objectN = [];
|
2346 | for (var _i = 1; _i < arguments.length; _i++) {
|
2347 | objectN[_i - 1] = arguments[_i];
|
2348 | }
|
2349 | if (!objectN.length || (objectN.length === 1 && !objectN[0])) {
|
2350 | return target;
|
2351 | }
|
2352 | var source = objectN.shift();
|
2353 | if (isObject(target) && isObject(source)) {
|
2354 | Object.keys(source).forEach(function (key) {
|
2355 | var value = source[key];
|
2356 | if (isObject(value)) {
|
2357 | !target[key] && (target[key] = {});
|
2358 | target[key] = mergeObj(target[key], value);
|
2359 | }
|
2360 | else {
|
2361 | target[key] = isArray(value) ?
|
2362 | value.concat() : value;
|
2363 | }
|
2364 | });
|
2365 | }
|
2366 | return mergeObj.apply(void 0, __spreadArray([target], objectN));
|
2367 | }
|
2368 |
|
2369 |
|
2370 |
|
2371 |
|
2372 |
|
2373 |
|
2374 |
|
2375 | function sortValue(data, isAsc) {
|
2376 | if (isAsc === void 0) { isAsc = true; }
|
2377 | var fn;
|
2378 | if (data[0] instanceof Date) {
|
2379 | fn = isAsc ? function (a, b) { return a - b; } : function (a, b) { return b - a; };
|
2380 | }
|
2381 | else {
|
2382 | if (isAsc && !data.every(isNaN)) {
|
2383 | fn = function (a, b) { return a - b; };
|
2384 | }
|
2385 | else if (!isAsc) {
|
2386 | fn = function (a, b) { return (a > b && -1) || (a < b && 1) || (a === b && 0); };
|
2387 | }
|
2388 | }
|
2389 | return data.concat().sort(fn);
|
2390 | }
|
2391 |
|
2392 |
|
2393 |
|
2394 |
|
2395 |
|
2396 |
|
2397 |
|
2398 | function getMinMax$1(type, data) {
|
2399 | var res = data.filter(function (v) { return notEmpty(v); });
|
2400 | if (res.length) {
|
2401 | if (isNumber(res[0])) {
|
2402 | res = Math[type].apply(Math, res);
|
2403 | }
|
2404 | else if (res[0] instanceof Date) {
|
2405 | res = sortValue(res, type === "min")[0];
|
2406 | }
|
2407 | }
|
2408 | else {
|
2409 | res = undefined;
|
2410 | }
|
2411 | return res;
|
2412 | }
|
2413 |
|
2414 |
|
2415 |
|
2416 |
|
2417 |
|
2418 |
|
2419 |
|
2420 |
|
2421 | var getRange = function (start, end, step) {
|
2422 | if (step === void 0) { step = 1; }
|
2423 | var res = [];
|
2424 | var n = Math.max(0, Math.ceil((end - start) / step)) | 0;
|
2425 | for (var i = start; i < n; i++) {
|
2426 | res.push(start + i * step);
|
2427 | }
|
2428 | return res;
|
2429 | };
|
2430 |
|
2431 | var emulateEvent = {
|
2432 | mouse: (function () {
|
2433 | var getParams = function () { return ({
|
2434 | bubbles: false, cancelable: false, screenX: 0, screenY: 0, clientX: 0, clientY: 0
|
2435 | }); };
|
2436 | try {
|
2437 |
|
2438 | new MouseEvent("t");
|
2439 | return function (el, eventType, params) {
|
2440 | if (params === void 0) { params = getParams(); }
|
2441 | el.dispatchEvent(new MouseEvent(eventType, params));
|
2442 | };
|
2443 | }
|
2444 | catch (e) {
|
2445 |
|
2446 | return function (el, eventType, params) {
|
2447 | if (params === void 0) { params = getParams(); }
|
2448 | var mouseEvent = doc.createEvent("MouseEvent");
|
2449 |
|
2450 | mouseEvent.initMouseEvent(eventType, params.bubbles, params.cancelable, win, 0,
|
2451 | params.screenX, params.screenY, params.clientX, params.clientY, false, false, false, false, 0, null);
|
2452 | el.dispatchEvent(mouseEvent);
|
2453 | };
|
2454 | }
|
2455 | })(),
|
2456 | touch: function (el, eventType, params) {
|
2457 | var touchObj = new Touch(mergeObj({
|
2458 | identifier: Date.now(),
|
2459 | target: el,
|
2460 | radiusX: 2.5,
|
2461 | radiusY: 2.5,
|
2462 | rotationAngle: 10,
|
2463 | force: 0.5
|
2464 | }, params));
|
2465 | el.dispatchEvent(new TouchEvent(eventType, {
|
2466 | cancelable: true,
|
2467 | bubbles: true,
|
2468 | shiftKey: true,
|
2469 | touches: [touchObj],
|
2470 | targetTouches: [],
|
2471 | changedTouches: [touchObj]
|
2472 | }));
|
2473 | }
|
2474 | };
|
2475 |
|
2476 |
|
2477 |
|
2478 |
|
2479 |
|
2480 |
|
2481 |
|
2482 | function tplProcess(tpl, data) {
|
2483 | var res = tpl;
|
2484 | for (var x in data) {
|
2485 | res = res.replace(new RegExp("{=" + x + "}", "g"), data[x]);
|
2486 | }
|
2487 | return res;
|
2488 | }
|
2489 |
|
2490 |
|
2491 |
|
2492 |
|
2493 |
|
2494 |
|
2495 |
|
2496 | function parseDate(date) {
|
2497 | var parsedDate;
|
2498 | if (date instanceof Date) {
|
2499 | parsedDate = date;
|
2500 | }
|
2501 | else if (isString(date)) {
|
2502 | var _a = this, config = _a.config, format = _a.format;
|
2503 | parsedDate = format.dataTime(config.data_xFormat)(date);
|
2504 | }
|
2505 | else if (isNumber(date) && !isNaN(date)) {
|
2506 | parsedDate = new Date(+date);
|
2507 | }
|
2508 | if (!parsedDate || isNaN(+parsedDate)) {
|
2509 | console && console.error &&
|
2510 | console.error("Failed to parse x '" + date + "' to Date object");
|
2511 | }
|
2512 | return parsedDate;
|
2513 | }
|
2514 |
|
2515 |
|
2516 |
|
2517 |
|
2518 |
|
2519 | function isTabVisible() {
|
2520 | return !doc.hidden;
|
2521 | }
|
2522 |
|
2523 |
|
2524 |
|
2525 |
|
2526 |
|
2527 |
|
2528 |
|
2529 | function convertInputType(mouse, touch) {
|
2530 | var isMobile = false;
|
2531 |
|
2532 | if (/Mobi/.test(win.navigator.userAgent) && touch) {
|
2533 |
|
2534 | var hasTouchPoints = win.navigator && "maxTouchPoints" in win.navigator && win.navigator.maxTouchPoints > 0;
|
2535 |
|
2536 |
|
2537 | var hasTouch = ("ontouchmove" in win || (win.DocumentTouch && doc instanceof win.DocumentTouch));
|
2538 | isMobile = hasTouchPoints || hasTouch;
|
2539 | }
|
2540 | var hasMouse = mouse && !isMobile ? ("onmouseover" in win) : false;
|
2541 | return (hasMouse && "mouse") || (isMobile && "touch") || null;
|
2542 | }
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 | var Options = (function () {
|
2551 | function Options() {
|
2552 | return deepClone(main, data$2, color$1, interaction$1, legend$2, title$1, tooltip$2, Options.data);
|
2553 | }
|
2554 | Options.setOptions = function (options) {
|
2555 | this.data = options
|
2556 | .reduce(function (a, c) { return (_assign(_assign({}, a), c)); }, this.data);
|
2557 | };
|
2558 | Options.data = {};
|
2559 | return Options;
|
2560 | }());
|
2561 |
|
2562 |
|
2563 |
|
2564 |
|
2565 |
|
2566 |
|
2567 |
|
2568 |
|
2569 |
|
2570 |
|
2571 | var KEY = {
|
2572 | bubbleBaseLength: "$baseLength",
|
2573 | colorPattern: "__colorPattern__",
|
2574 | dataMinMax: "$dataMinMax",
|
2575 | dataTotalSum: "$dataTotalSum",
|
2576 | dataTotalPerIndex: "$totalPerIndex",
|
2577 | legendItemTextBox: "legendItemTextBox",
|
2578 | radarPoints: "$radarPoints",
|
2579 | setOverOut: "setOverOut",
|
2580 | callOverOutForTouch: "callOverOutForTouch",
|
2581 | textRect: "textRect"
|
2582 | };
|
2583 | var Cache = (function () {
|
2584 | function Cache() {
|
2585 | this.cache = {};
|
2586 | }
|
2587 | |
2588 |
|
2589 |
|
2590 |
|
2591 |
|
2592 |
|
2593 |
|
2594 |
|
2595 | Cache.prototype.add = function (key, value, isDataType) {
|
2596 | if (isDataType === void 0) { isDataType = false; }
|
2597 | this.cache[key] = isDataType ? this.cloneTarget(value) : value;
|
2598 | return this.cache[key];
|
2599 | };
|
2600 | |
2601 |
|
2602 |
|
2603 |
|
2604 |
|
2605 | Cache.prototype.remove = function (key) {
|
2606 | var _this = this;
|
2607 | toArray(key).forEach(function (v) { return delete _this.cache[v]; });
|
2608 | };
|
2609 | |
2610 |
|
2611 |
|
2612 |
|
2613 |
|
2614 |
|
2615 |
|
2616 | Cache.prototype.get = function (key, isDataType) {
|
2617 | if (isDataType === void 0) { isDataType = false; }
|
2618 | if (isDataType) {
|
2619 | var targets = [];
|
2620 | for (var i = 0, id = void 0; (id = key[i]); i++) {
|
2621 | if (id in this.cache) {
|
2622 | targets.push(this.cloneTarget(this.cache[id]));
|
2623 | }
|
2624 | }
|
2625 | return targets;
|
2626 | }
|
2627 | else {
|
2628 | var value = this.cache[key];
|
2629 | return isValue(value) ? value : null;
|
2630 | }
|
2631 | };
|
2632 | |
2633 |
|
2634 |
|
2635 |
|
2636 |
|
2637 | Cache.prototype.reset = function (all) {
|
2638 | var $$ = this;
|
2639 | for (var x in $$.cache) {
|
2640 |
|
2641 | if (all || /^\$/.test(x)) {
|
2642 | $$.cache[x] = null;
|
2643 | }
|
2644 | }
|
2645 | };
|
2646 | |
2647 |
|
2648 |
|
2649 |
|
2650 |
|
2651 |
|
2652 |
|
2653 | Cache.prototype.cloneTarget = function (target) {
|
2654 | return {
|
2655 | id: target.id,
|
2656 | id_org: target.id_org,
|
2657 | values: target.values.map(function (d) { return ({ x: d.x, value: d.value, id: d.id }); })
|
2658 | };
|
2659 | };
|
2660 | return Cache;
|
2661 | }());
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 |
|
2667 | var setTimeout$1 = win.setTimeout, clearTimeout$1 = win.clearTimeout;
|
2668 |
|
2669 |
|
2670 |
|
2671 |
|
2672 |
|
2673 | function generateResize() {
|
2674 | var fn = [];
|
2675 | var timeout;
|
2676 | var callResizeFn = function () {
|
2677 |
|
2678 | callResizeFn.clear();
|
2679 | timeout = setTimeout$1(function () {
|
2680 | fn.forEach(function (f) { return f(); });
|
2681 | }, 200);
|
2682 | };
|
2683 | callResizeFn.clear = function () {
|
2684 | if (timeout) {
|
2685 | clearTimeout$1(timeout);
|
2686 | timeout = null;
|
2687 | }
|
2688 | };
|
2689 | callResizeFn.add = function (f) { return fn.push(f); };
|
2690 | callResizeFn.remove = function (f) { return fn.splice(fn.indexOf(f), 1); };
|
2691 | return callResizeFn;
|
2692 | }
|
2693 |
|
2694 |
|
2695 |
|
2696 |
|
2697 |
|
2698 | function generateWait() {
|
2699 | var transitionsToWait = [];
|
2700 | var f = function (t, callback) {
|
2701 | var timer;
|
2702 |
|
2703 | function loop() {
|
2704 | var done = 0;
|
2705 | for (var i = 0, t_1; (t_1 = transitionsToWait[i]); i++) {
|
2706 | if (t_1 === true || (t_1.empty && t_1.empty())) {
|
2707 | done++;
|
2708 | continue;
|
2709 | }
|
2710 | try {
|
2711 | t_1.transition();
|
2712 | }
|
2713 | catch (e) {
|
2714 | done++;
|
2715 | }
|
2716 | }
|
2717 | timer && clearTimeout$1(timer);
|
2718 | if (done === transitionsToWait.length) {
|
2719 | callback && callback();
|
2720 | }
|
2721 | else {
|
2722 | timer = setTimeout$1(loop, 50);
|
2723 | }
|
2724 | }
|
2725 | loop();
|
2726 | };
|
2727 | f.add = function (t) {
|
2728 | isArray(t) ?
|
2729 | (transitionsToWait = transitionsToWait.concat(t)) :
|
2730 | transitionsToWait.push(t);
|
2731 | };
|
2732 | return f;
|
2733 | }
|
2734 |
|
2735 |
|
2736 |
|
2737 |
|
2738 |
|
2739 |
|
2740 |
|
2741 |
|
2742 |
|
2743 |
|
2744 | var dataConvert = {
|
2745 | |
2746 |
|
2747 |
|
2748 |
|
2749 |
|
2750 |
|
2751 |
|
2752 | convertData: function (args, callback) {
|
2753 | var data;
|
2754 | if (args.bindto) {
|
2755 | data = {};
|
2756 | ["url", "mimeType", "headers", "keys", "json", "keys", "rows", "columns"]
|
2757 | .forEach(function (v) {
|
2758 | var key = "data_" + v;
|
2759 | if (key in args) {
|
2760 | data[v] = args[key];
|
2761 | }
|
2762 | });
|
2763 | }
|
2764 | else {
|
2765 | data = args;
|
2766 | }
|
2767 | if (data.url && callback) {
|
2768 | this.convertUrlToData(data.url, data.mimeType, data.headers, data.keys, callback);
|
2769 | }
|
2770 | else if (data.json) {
|
2771 | data = this.convertJsonToData(data.json, data.keys);
|
2772 | }
|
2773 | else if (data.rows) {
|
2774 | data = this.convertRowsToData(data.rows);
|
2775 | }
|
2776 | else if (data.columns) {
|
2777 | data = this.convertColumnsToData(data.columns);
|
2778 | }
|
2779 | else if (args.bindto) {
|
2780 | throw Error("url or json or rows or columns is required.");
|
2781 | }
|
2782 | return isArray(data) && data;
|
2783 | },
|
2784 | |
2785 |
|
2786 |
|
2787 |
|
2788 |
|
2789 |
|
2790 |
|
2791 |
|
2792 |
|
2793 | convertUrlToData: function (url, mimeType, headers, keys, done) {
|
2794 | var _this = this;
|
2795 | if (mimeType === void 0) { mimeType = "csv"; }
|
2796 | var req = new XMLHttpRequest();
|
2797 | req.open("GET", url);
|
2798 | if (headers) {
|
2799 | Object.keys(headers).forEach(function (key) {
|
2800 | req.setRequestHeader(key, headers[key]);
|
2801 | });
|
2802 | }
|
2803 | req.onreadystatechange = function () {
|
2804 | if (req.readyState === 4) {
|
2805 | if (req.status === 200) {
|
2806 | var response = req.responseText;
|
2807 | response && done.call(_this, _this["convert" + capitalize(mimeType) + "ToData"](mimeType === "json" ? JSON.parse(response) : response, keys));
|
2808 | }
|
2809 | else {
|
2810 | throw new Error(url + ": Something went wrong loading!");
|
2811 | }
|
2812 | }
|
2813 | };
|
2814 | req.send();
|
2815 | },
|
2816 | |
2817 |
|
2818 |
|
2819 |
|
2820 |
|
2821 |
|
2822 |
|
2823 | convertCsvTsvToData: function (parser, xsv) {
|
2824 | var rows = parser.rows(xsv);
|
2825 | var d;
|
2826 | if (rows.length === 1) {
|
2827 | d = [{}];
|
2828 | rows[0].forEach(function (id) {
|
2829 | d[0][id] = null;
|
2830 | });
|
2831 | }
|
2832 | else {
|
2833 | d = parser.parse(xsv);
|
2834 | }
|
2835 | return d;
|
2836 | },
|
2837 | convertCsvToData: function (xsv) {
|
2838 | return this.convertCsvTsvToData({
|
2839 | rows: csvParseRows,
|
2840 | parse: csvParse
|
2841 | }, xsv);
|
2842 | },
|
2843 | convertTsvToData: function (tsv) {
|
2844 | return this.convertCsvTsvToData({
|
2845 | rows: tsvParseRows,
|
2846 | parse: tsvParse
|
2847 | }, tsv);
|
2848 | },
|
2849 | convertJsonToData: function (json, keysParam) {
|
2850 | var _this = this;
|
2851 | var config = this.config;
|
2852 | var newRows = [];
|
2853 | var targetKeys;
|
2854 | var data;
|
2855 | if (isArray(json)) {
|
2856 | var keys = keysParam || config.data_keys;
|
2857 | if (keys.x) {
|
2858 | targetKeys = keys.value.concat(keys.x);
|
2859 | config.data_x = keys.x;
|
2860 | }
|
2861 | else {
|
2862 | targetKeys = keys.value;
|
2863 | }
|
2864 | newRows.push(targetKeys);
|
2865 | json.forEach(function (o) {
|
2866 | var newRow = targetKeys.map(function (key) {
|
2867 |
|
2868 | var v = _this.findValueInJson(o, key);
|
2869 | if (isUndefined(v)) {
|
2870 | v = null;
|
2871 | }
|
2872 | return v;
|
2873 | });
|
2874 | newRows.push(newRow);
|
2875 | });
|
2876 | data = this.convertRowsToData(newRows);
|
2877 | }
|
2878 | else {
|
2879 | Object.keys(json).forEach(function (key) {
|
2880 | var tmp = json[key].concat();
|
2881 | tmp.unshift(key);
|
2882 | newRows.push(tmp);
|
2883 | });
|
2884 | data = this.convertColumnsToData(newRows);
|
2885 | }
|
2886 | return data;
|
2887 | },
|
2888 | findValueInJson: function (object, path) {
|
2889 | if (object[path] !== undefined) {
|
2890 | return object[path];
|
2891 | }
|
2892 | var convertedPath = path.replace(/\[(\w+)\]/g, ".$1");
|
2893 | var pathArray = convertedPath.replace(/^\./, "").split(".");
|
2894 | var target = object;
|
2895 | pathArray.some(function (k) { return !(target = target && k in target ?
|
2896 | target[k] : undefined); });
|
2897 | return target;
|
2898 | },
|
2899 | convertRowsToData: function (rows) {
|
2900 | var keys = rows[0];
|
2901 | var newRows = [];
|
2902 | rows.forEach(function (row, i) {
|
2903 | if (i > 0) {
|
2904 | var newRow_1 = {};
|
2905 | row.forEach(function (v, j) {
|
2906 | if (isUndefined(v)) {
|
2907 | throw new Error("Source data is missing a component at (" + i + ", " + j + ")!");
|
2908 | }
|
2909 | newRow_1[keys[j]] = v;
|
2910 | });
|
2911 | newRows.push(newRow_1);
|
2912 | }
|
2913 | });
|
2914 | return newRows;
|
2915 | },
|
2916 | convertColumnsToData: function (columns) {
|
2917 | var newRows = [];
|
2918 | columns.forEach(function (col, i) {
|
2919 | var key = col[0];
|
2920 | col.forEach(function (v, j) {
|
2921 | if (j > 0) {
|
2922 | if (isUndefined(newRows[j - 1])) {
|
2923 | newRows[j - 1] = {};
|
2924 | }
|
2925 | if (isUndefined(v)) {
|
2926 | throw new Error("Source data is missing a component at (" + i + ", " + j + ")!");
|
2927 | }
|
2928 | newRows[j - 1][key] = v;
|
2929 | }
|
2930 | });
|
2931 | });
|
2932 | return newRows;
|
2933 | },
|
2934 | convertDataToTargets: function (data, appendXs) {
|
2935 | var _this = this;
|
2936 | var $$ = this;
|
2937 | var axis = $$.axis, config = $$.config, state = $$.state;
|
2938 | var isCategorized = false;
|
2939 | var isTimeSeries = false;
|
2940 | var isCustomX = false;
|
2941 | if (axis) {
|
2942 | isCategorized = axis.isCategorized();
|
2943 | isTimeSeries = axis.isTimeSeries();
|
2944 | isCustomX = axis.isCustomX();
|
2945 | }
|
2946 | var dataKeys = Object.keys(data[0] || {});
|
2947 | var ids = dataKeys.length ? dataKeys.filter($$.isNotX, $$) : [];
|
2948 | var xs = dataKeys.length ? dataKeys.filter($$.isX, $$) : [];
|
2949 | var xsData;
|
2950 |
|
2951 | ids.forEach(function (id) {
|
2952 | var xKey = _this.getXKey(id);
|
2953 | if (isCustomX || isTimeSeries) {
|
2954 |
|
2955 | if (xs.indexOf(xKey) >= 0) {
|
2956 | xsData = ((appendXs && $$.data.xs[id]) || [])
|
2957 | .concat(data.map(function (d) { return d[xKey]; })
|
2958 | .filter(isValue)
|
2959 | .map(function (rawX, i) { return $$.generateTargetX(rawX, id, i); }));
|
2960 | }
|
2961 | else if (config.data_x) {
|
2962 |
|
2963 | xsData = _this.getOtherTargetXs();
|
2964 | }
|
2965 | else if (notEmpty(config.data_xs)) {
|
2966 |
|
2967 | xsData = $$.getXValuesOfXKey(xKey, $$.data.targets);
|
2968 | }
|
2969 |
|
2970 | }
|
2971 | else {
|
2972 | xsData = data.map(function (d, i) { return i; });
|
2973 | }
|
2974 | xsData && (_this.data.xs[id] = xsData);
|
2975 | });
|
2976 |
|
2977 | ids.forEach(function (id) {
|
2978 | if (!_this.data.xs[id]) {
|
2979 | throw new Error("x is not defined for id = \"" + id + "\".");
|
2980 | }
|
2981 | });
|
2982 |
|
2983 | var targets = ids.map(function (id, index) {
|
2984 | var convertedId = config.data_idConverter.bind($$.api)(id);
|
2985 | var xKey = $$.getXKey(id);
|
2986 | var isCategory = isCustomX && isCategorized;
|
2987 | var hasCategory = isCategory && data.map(function (v) { return v.x; })
|
2988 | .every(function (v) { return config.axis_x_categories.indexOf(v) > -1; });
|
2989 | return {
|
2990 | id: convertedId,
|
2991 | id_org: id,
|
2992 | values: data.map(function (d, i) {
|
2993 | var rawX = d[xKey];
|
2994 | var value = d[id];
|
2995 | var x;
|
2996 | value = value !== null && !isNaN(value) && !isObject(value) ?
|
2997 | +value : (isArray(value) || isObject(value) ? value : null);
|
2998 |
|
2999 | if ((isCategory || state.hasRadar) && index === 0 && !isUndefined(rawX)) {
|
3000 | if (!hasCategory && index === 0 && i === 0) {
|
3001 | config.axis_x_categories = [];
|
3002 | }
|
3003 | x = config.axis_x_categories.indexOf(rawX);
|
3004 | if (x === -1) {
|
3005 | x = config.axis_x_categories.length;
|
3006 | config.axis_x_categories.push(rawX);
|
3007 | }
|
3008 | }
|
3009 | else {
|
3010 | x = $$.generateTargetX(rawX, id, i);
|
3011 | }
|
3012 |
|
3013 | if (isUndefined(value) || $$.data.xs[id].length <= i) {
|
3014 | x = undefined;
|
3015 | }
|
3016 | return { x: x, value: value, id: convertedId };
|
3017 | }).filter(function (v) { return isDefined(v.x); })
|
3018 | };
|
3019 | });
|
3020 |
|
3021 | targets.forEach(function (t) {
|
3022 |
|
3023 | if (config.data_xSort) {
|
3024 | t.values = t.values.sort(function (v1, v2) {
|
3025 | var x1 = v1.x || v1.x === 0 ? v1.x : Infinity;
|
3026 | var x2 = v2.x || v2.x === 0 ? v2.x : Infinity;
|
3027 | return x1 - x2;
|
3028 | });
|
3029 | }
|
3030 |
|
3031 | t.values.forEach(function (v, i) { return (v.index = i); });
|
3032 |
|
3033 | $$.data.xs[t.id].sort(function (v1, v2) { return v1 - v2; });
|
3034 | });
|
3035 |
|
3036 | state.hasNegativeValue = $$.hasNegativeValueInTargets(targets);
|
3037 | state.hasPositiveValue = $$.hasPositiveValueInTargets(targets);
|
3038 |
|
3039 | if (config.data_type) {
|
3040 | $$.setTargetType($$.mapToIds(targets)
|
3041 | .filter(function (id) { return !(id in config.data_types); }), config.data_type);
|
3042 | }
|
3043 |
|
3044 | targets.forEach(function (d) { return $$.cache.add(d.id_org, d, true); });
|
3045 | return targets;
|
3046 | }
|
3047 | };
|
3048 |
|
3049 | var data$1 = {
|
3050 | isX: function (key) {
|
3051 | var $$ = this;
|
3052 | var config = $$.config;
|
3053 | var dataKey = config.data_x && key === config.data_x;
|
3054 | var existValue = notEmpty(config.data_xs) && hasValue(config.data_xs, key);
|
3055 | return dataKey || existValue;
|
3056 | },
|
3057 | isNotX: function (key) {
|
3058 | return !this.isX(key);
|
3059 | },
|
3060 | isStackNormalized: function () {
|
3061 | var config = this.config;
|
3062 | return !!(config.data_stack_normalize && config.data_groups.length);
|
3063 | },
|
3064 | isGrouped: function (id) {
|
3065 | var groups = this.config.data_groups;
|
3066 | return id ?
|
3067 | groups.some(function (v) { return v.indexOf(id) >= 0 && v.length > 1; }) :
|
3068 | groups.length > 0;
|
3069 | },
|
3070 | getXKey: function (id) {
|
3071 | var $$ = this;
|
3072 | var config = $$.config;
|
3073 | return config.data_x ?
|
3074 | config.data_x : (notEmpty(config.data_xs) ? config.data_xs[id] : null);
|
3075 | },
|
3076 | getXValuesOfXKey: function (key, targets) {
|
3077 | var $$ = this;
|
3078 | var ids = targets && notEmpty(targets) ? $$.mapToIds(targets) : [];
|
3079 | var xValues;
|
3080 | ids.forEach(function (id) {
|
3081 | if ($$.getXKey(id) === key) {
|
3082 | xValues = $$.data.xs[id];
|
3083 | }
|
3084 | });
|
3085 | return xValues;
|
3086 | },
|
3087 | |
3088 |
|
3089 |
|
3090 |
|
3091 |
|
3092 |
|
3093 |
|
3094 | getIndexByX: function (x, basedX) {
|
3095 | var $$ = this;
|
3096 | return basedX ?
|
3097 | basedX.indexOf(isString(x) ? x : +x) :
|
3098 | ($$.filterByX($$.data.targets, x)[0] || { index: null }).index;
|
3099 | },
|
3100 | getXValue: function (id, i) {
|
3101 | var $$ = this;
|
3102 | return id in $$.data.xs &&
|
3103 | $$.data.xs[id] &&
|
3104 | isValue($$.data.xs[id][i]) ? $$.data.xs[id][i] : i;
|
3105 | },
|
3106 | getOtherTargetXs: function () {
|
3107 | var $$ = this;
|
3108 | var idsForX = Object.keys($$.data.xs);
|
3109 | return idsForX.length ? $$.data.xs[idsForX[0]] : null;
|
3110 | },
|
3111 | getOtherTargetX: function (index) {
|
3112 | var xs = this.getOtherTargetXs();
|
3113 | return xs && index < xs.length ? xs[index] : null;
|
3114 | },
|
3115 | addXs: function (xs) {
|
3116 | var $$ = this;
|
3117 | var config = $$.config;
|
3118 | Object.keys(xs).forEach(function (id) {
|
3119 | config.data_xs[id] = xs[id];
|
3120 | });
|
3121 | },
|
3122 | isMultipleX: function () {
|
3123 | return notEmpty(this.config.data_xs) ||
|
3124 | !this.config.data_xSort ||
|
3125 | this.hasType("bubble") ||
|
3126 | this.hasType("scatter");
|
3127 | },
|
3128 | addName: function (data) {
|
3129 | var $$ = this;
|
3130 | var config = $$.config;
|
3131 | var name;
|
3132 | if (data) {
|
3133 | name = config.data_names[data.id];
|
3134 | data.name = name !== undefined ? name : data.id;
|
3135 | }
|
3136 | return data;
|
3137 | },
|
3138 | |
3139 |
|
3140 |
|
3141 |
|
3142 |
|
3143 |
|
3144 |
|
3145 | getAllValuesOnIndex: function (index, filterNull) {
|
3146 | if (filterNull === void 0) { filterNull = false; }
|
3147 | var $$ = this;
|
3148 | var value = $$.filterTargetsToShow($$.data.targets)
|
3149 | .map(function (t) { return $$.addName($$.getValueOnIndex(t.values, index)); });
|
3150 | if (filterNull) {
|
3151 | value = value.filter(function (v) { return isValue(v.value); });
|
3152 | }
|
3153 | return value;
|
3154 | },
|
3155 | getValueOnIndex: function (values, index) {
|
3156 | var valueOnIndex = values.filter(function (v) { return v.index === index; });
|
3157 | return valueOnIndex.length ? valueOnIndex[0] : null;
|
3158 | },
|
3159 | updateTargetX: function (targets, x) {
|
3160 | var $$ = this;
|
3161 | targets.forEach(function (t) {
|
3162 | t.values.forEach(function (v, i) {
|
3163 | v.x = $$.generateTargetX(x[i], t.id, i);
|
3164 | });
|
3165 | $$.data.xs[t.id] = x;
|
3166 | });
|
3167 | },
|
3168 | updateTargetXs: function (targets, xs) {
|
3169 | var $$ = this;
|
3170 | targets.forEach(function (t) {
|
3171 | xs[t.id] && $$.updateTargetX([t], xs[t.id]);
|
3172 | });
|
3173 | },
|
3174 | generateTargetX: function (rawX, id, index) {
|
3175 | var $$ = this;
|
3176 | var axis = $$.axis;
|
3177 | var x = axis && axis.isCategorized() ? index : (rawX || index);
|
3178 | if (axis && axis.isTimeSeries()) {
|
3179 | var fn = parseDate.bind($$);
|
3180 | x = rawX ? fn(rawX) : fn($$.getXValue(id, index));
|
3181 | }
|
3182 | else if (axis && axis.isCustomX() && !axis.isCategorized()) {
|
3183 | x = isValue(rawX) ? +rawX : $$.getXValue(id, index);
|
3184 | }
|
3185 | return x;
|
3186 | },
|
3187 | updateXs: function (values) {
|
3188 | if (values.length) {
|
3189 | this.axis.xs = values.map(function (v) { return v.x; });
|
3190 | }
|
3191 | },
|
3192 | getPrevX: function (i) {
|
3193 | var x = this.axis.xs[i - 1];
|
3194 | return isDefined(x) ? x : null;
|
3195 | },
|
3196 | getNextX: function (i) {
|
3197 | var x = this.axis.xs[i + 1];
|
3198 | return isDefined(x) ? x : null;
|
3199 | },
|
3200 | |
3201 |
|
3202 |
|
3203 |
|
3204 |
|
3205 |
|
3206 | getBaseValue: function (data) {
|
3207 | var $$ = this;
|
3208 | var hasAxis = $$.state.hasAxis;
|
3209 | var value = data.value;
|
3210 |
|
3211 |
|
3212 | if (value && hasAxis) {
|
3213 | if ($$.isAreaRangeType(data)) {
|
3214 | value = $$.getRangedData(data, "mid");
|
3215 | }
|
3216 | else if ($$.isBubbleZType(data)) {
|
3217 | value = $$.getBubbleZData(value, "y");
|
3218 | }
|
3219 | }
|
3220 | return value;
|
3221 | },
|
3222 | |
3223 |
|
3224 |
|
3225 |
|
3226 |
|
3227 |
|
3228 | getMinMaxValue: function (data) {
|
3229 | var getBaseValue = this.getBaseValue.bind(this);
|
3230 | var min;
|
3231 | var max;
|
3232 | (data || this.data.targets.map(function (t) { return t.values; }))
|
3233 | .forEach(function (v, i) {
|
3234 | var value = v.map(getBaseValue).filter(isNumber);
|
3235 | min = Math.min.apply(Math, __spreadArray([i ? min : Infinity], value));
|
3236 | max = Math.max.apply(Math, __spreadArray([i ? max : -Infinity], value));
|
3237 | });
|
3238 | return { min: min, max: max };
|
3239 | },
|
3240 | |
3241 |
|
3242 |
|
3243 |
|
3244 |
|
3245 | getMinMaxData: function () {
|
3246 | var $$ = this;
|
3247 | var cacheKey = KEY.dataMinMax;
|
3248 | var minMaxData = $$.cache.get(cacheKey);
|
3249 | if (!minMaxData) {
|
3250 | var data = $$.data.targets.map(function (t) { return t.values; });
|
3251 | var minMax_1 = $$.getMinMaxValue(data);
|
3252 | var min_1 = [];
|
3253 | var max_1 = [];
|
3254 | data.forEach(function (v) {
|
3255 | var minData = $$.getFilteredDataByValue(v, minMax_1.min);
|
3256 | var maxData = $$.getFilteredDataByValue(v, minMax_1.max);
|
3257 | if (minData.length) {
|
3258 | min_1 = min_1.concat(minData);
|
3259 | }
|
3260 | if (maxData.length) {
|
3261 | max_1 = max_1.concat(maxData);
|
3262 | }
|
3263 | });
|
3264 |
|
3265 | $$.cache.add(cacheKey, minMaxData = { min: min_1, max: max_1 });
|
3266 | }
|
3267 | return minMaxData;
|
3268 | },
|
3269 | |
3270 |
|
3271 |
|
3272 |
|
3273 |
|
3274 | getTotalPerIndex: function () {
|
3275 | var $$ = this;
|
3276 | var cacheKey = KEY.dataTotalPerIndex;
|
3277 | var sum = $$.cache.get(cacheKey);
|
3278 | if ($$.isStackNormalized() && !sum) {
|
3279 | sum = [];
|
3280 | $$.data.targets.forEach(function (row) {
|
3281 | row.values.forEach(function (v, i) {
|
3282 | if (!sum[i]) {
|
3283 | sum[i] = 0;
|
3284 | }
|
3285 | sum[i] += isNumber(v.value) ? v.value : 0;
|
3286 | });
|
3287 | });
|
3288 | }
|
3289 | return sum;
|
3290 | },
|
3291 | |
3292 |
|
3293 |
|
3294 |
|
3295 |
|
3296 |
|
3297 | getTotalDataSum: function (subtractHidden) {
|
3298 | var $$ = this;
|
3299 | var cacheKey = KEY.dataTotalSum;
|
3300 | var total = $$.cache.get(cacheKey);
|
3301 | if (!isNumber(total)) {
|
3302 | var sum = mergeArray($$.data.targets.map(function (t) { return t.values; }))
|
3303 | .map(function (v) { return v.value; })
|
3304 | .reduce(function (p, c) { return p + c; });
|
3305 | $$.cache.add(cacheKey, total = sum);
|
3306 | }
|
3307 | if (subtractHidden) {
|
3308 | total -= $$.getHiddenTotalDataSum();
|
3309 | }
|
3310 | return total;
|
3311 | },
|
3312 | |
3313 |
|
3314 |
|
3315 |
|
3316 |
|
3317 | getHiddenTotalDataSum: function () {
|
3318 | var $$ = this;
|
3319 | var api = $$.api, hiddenTargetIds = $$.state.hiddenTargetIds;
|
3320 | var total = 0;
|
3321 | if (hiddenTargetIds.length) {
|
3322 | total = api.data.values.bind(api)(hiddenTargetIds)
|
3323 | .reduce(function (p, c) { return p + c; });
|
3324 | }
|
3325 | return total;
|
3326 | },
|
3327 | |
3328 |
|
3329 |
|
3330 |
|
3331 |
|
3332 |
|
3333 |
|
3334 | getFilteredDataByValue: function (data, value) {
|
3335 | var _this = this;
|
3336 | return data.filter(function (t) { return _this.getBaseValue(t) === value; });
|
3337 | },
|
3338 | |
3339 |
|
3340 |
|
3341 |
|
3342 |
|
3343 | getMaxDataCount: function () {
|
3344 | return Math.max.apply(Math, this.data.targets.map(function (t) { return t.values.length; }));
|
3345 | },
|
3346 | getMaxDataCountTarget: function () {
|
3347 | var target = this.filterTargetsToShow() || [];
|
3348 | var length = target.length;
|
3349 | if (length > 1) {
|
3350 | target = target.map(function (t) { return t.values; })
|
3351 | .reduce(function (a, b) { return a.concat(b); })
|
3352 | .map(function (v) { return v.x; });
|
3353 | target = sortValue(getUnique(target))
|
3354 | .map(function (x, index) { return ({ x: x, index: index }); });
|
3355 | }
|
3356 | else if (length) {
|
3357 | target = target[0].values;
|
3358 | }
|
3359 | return target;
|
3360 | },
|
3361 | mapToIds: function (targets) {
|
3362 | return targets.map(function (d) { return d.id; });
|
3363 | },
|
3364 | mapToTargetIds: function (ids) {
|
3365 | var $$ = this;
|
3366 | return ids ? (isArray(ids) ? ids.concat() : [ids]) : $$.mapToIds($$.data.targets);
|
3367 | },
|
3368 | hasTarget: function (targets, id) {
|
3369 | var ids = this.mapToIds(targets);
|
3370 | for (var i = 0, val = void 0; (val = ids[i]); i++) {
|
3371 | if (val === id) {
|
3372 | return true;
|
3373 | }
|
3374 | }
|
3375 | return false;
|
3376 | },
|
3377 | isTargetToShow: function (targetId) {
|
3378 | return this.state.hiddenTargetIds.indexOf(targetId) < 0;
|
3379 | },
|
3380 | isLegendToShow: function (targetId) {
|
3381 | return this.state.hiddenLegendIds.indexOf(targetId) < 0;
|
3382 | },
|
3383 | filterTargetsToShow: function (targets) {
|
3384 | var $$ = this;
|
3385 | return (targets || $$.data.targets).filter(function (t) { return $$.isTargetToShow(t.id); });
|
3386 | },
|
3387 | mapTargetsToUniqueXs: function (targets) {
|
3388 | var $$ = this;
|
3389 | var axis = $$.axis;
|
3390 | var xs = [];
|
3391 | if (targets && targets.length) {
|
3392 | xs = getUnique(mergeArray(targets.map(function (t) { return t.values.map(function (v) { return +v.x; }); })));
|
3393 | xs = axis && axis.isTimeSeries() ? xs.map(function (x) { return new Date(+x); }) : xs.map(function (x) { return +x; });
|
3394 | }
|
3395 | return sortValue(xs);
|
3396 | },
|
3397 | addHiddenTargetIds: function (targetIds) {
|
3398 | this.state.hiddenTargetIds = this.state.hiddenTargetIds.concat(targetIds);
|
3399 | },
|
3400 | removeHiddenTargetIds: function (targetIds) {
|
3401 | this.state.hiddenTargetIds = this.state.hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; });
|
3402 | },
|
3403 | addHiddenLegendIds: function (targetIds) {
|
3404 | this.state.hiddenLegendIds = this.state.hiddenLegendIds.concat(targetIds);
|
3405 | },
|
3406 | removeHiddenLegendIds: function (targetIds) {
|
3407 | this.state.hiddenLegendIds = this.state.hiddenLegendIds.filter(function (id) { return targetIds.indexOf(id) < 0; });
|
3408 | },
|
3409 | getValuesAsIdKeyed: function (targets) {
|
3410 | var $$ = this;
|
3411 | var hasAxis = $$.state.hasAxis;
|
3412 | var ys = {};
|
3413 | var isMultipleX = $$.isMultipleX();
|
3414 | var xs = isMultipleX ? $$.mapTargetsToUniqueXs(targets)
|
3415 | .map(function (v) { return (isString(v) ? v : +v); }) : null;
|
3416 | targets.forEach(function (t) {
|
3417 | var data = [];
|
3418 | t.values
|
3419 | .filter(function (v) { return isValue(v.value); })
|
3420 | .forEach(function (v) {
|
3421 | var value = v.value;
|
3422 |
|
3423 | if ($$.isCandlestickType(v)) {
|
3424 | value = isArray(value) ? value.slice(0, 4) : [value.open, value.high, value.low, value.close];
|
3425 | }
|
3426 | if (isArray(value)) {
|
3427 | data.push.apply(data, value);
|
3428 | }
|
3429 | else if (isObject(value) && "high" in value) {
|
3430 | data.push.apply(data, Object.values(value));
|
3431 | }
|
3432 | else if ($$.isBubbleZType(v)) {
|
3433 | data.push(hasAxis && $$.getBubbleZData(value, "y"));
|
3434 | }
|
3435 | else {
|
3436 | if (isMultipleX) {
|
3437 | data[$$.getIndexByX(v.x, xs)] = value;
|
3438 | }
|
3439 | else {
|
3440 | data.push(value);
|
3441 | }
|
3442 | }
|
3443 | });
|
3444 | ys[t.id] = data;
|
3445 | });
|
3446 | return ys;
|
3447 | },
|
3448 | checkValueInTargets: function (targets, checker) {
|
3449 | var ids = Object.keys(targets);
|
3450 | var values;
|
3451 | for (var i = 0; i < ids.length; i++) {
|
3452 | values = targets[ids[i]].values;
|
3453 | for (var j = 0; j < values.length; j++) {
|
3454 | if (checker(values[j].value)) {
|
3455 | return true;
|
3456 | }
|
3457 | }
|
3458 | }
|
3459 | return false;
|
3460 | },
|
3461 | hasMultiTargets: function () {
|
3462 | return this.filterTargetsToShow().length > 1;
|
3463 | },
|
3464 | hasNegativeValueInTargets: function (targets) {
|
3465 | return this.checkValueInTargets(targets, function (v) { return v < 0; });
|
3466 | },
|
3467 | hasPositiveValueInTargets: function (targets) {
|
3468 | return this.checkValueInTargets(targets, function (v) { return v > 0; });
|
3469 | },
|
3470 | _checkOrder: function (type) {
|
3471 | var config = this.config;
|
3472 | var order = config.data_order;
|
3473 | return isString(order) && order.toLowerCase() === type;
|
3474 | },
|
3475 | isOrderDesc: function () {
|
3476 | return this._checkOrder("desc");
|
3477 | },
|
3478 | isOrderAsc: function () {
|
3479 | return this._checkOrder("asc");
|
3480 | },
|
3481 | |
3482 |
|
3483 |
|
3484 |
|
3485 |
|
3486 |
|
3487 | orderTargets: function (targetsValue) {
|
3488 | var $$ = this;
|
3489 | var targets = __spreadArray([], targetsValue);
|
3490 | var fn = $$.getSortCompareFn();
|
3491 | fn && targets.sort(fn);
|
3492 | return targets;
|
3493 | },
|
3494 | |
3495 |
|
3496 |
|
3497 |
|
3498 |
|
3499 |
|
3500 | getSortCompareFn: function (isArc) {
|
3501 | if (isArc === void 0) { isArc = false; }
|
3502 | var $$ = this;
|
3503 | var config = $$.config;
|
3504 | var orderAsc = $$.isOrderAsc();
|
3505 | var orderDesc = $$.isOrderDesc();
|
3506 | var fn;
|
3507 | if (orderAsc || orderDesc) {
|
3508 | fn = function (t1, t2) {
|
3509 | var reducer = function (p, c) { return p + Math.abs(c.value); };
|
3510 | var t1Sum = t1.values.reduce(reducer, 0);
|
3511 | var t2Sum = t2.values.reduce(reducer, 0);
|
3512 | return isArc ?
|
3513 | (orderAsc ? t1Sum - t2Sum : t2Sum - t1Sum) :
|
3514 | (orderAsc ? t2Sum - t1Sum : t1Sum - t2Sum);
|
3515 | };
|
3516 | }
|
3517 | else if (isFunction(config.data_order)) {
|
3518 | fn = config.data_order.bind($$.api);
|
3519 | }
|
3520 | return fn || null;
|
3521 | },
|
3522 | filterByX: function (targets, x) {
|
3523 | return mergeArray(targets.map(function (t) { return t.values; })).filter(function (v) { return v.x - x === 0; });
|
3524 | },
|
3525 | filterRemoveNull: function (data) {
|
3526 | var _this = this;
|
3527 | return data.filter(function (d) { return isValue(_this.getBaseValue(d)); });
|
3528 | },
|
3529 | filterByXDomain: function (targets, xDomain) {
|
3530 | return targets.map(function (t) { return ({
|
3531 | id: t.id,
|
3532 | id_org: t.id_org,
|
3533 | values: t.values.filter(function (v) { return xDomain[0] <= v.x && v.x <= xDomain[1]; })
|
3534 | }); });
|
3535 | },
|
3536 | hasDataLabel: function () {
|
3537 | var dataLabels = this.config.data_labels;
|
3538 | return (isboolean(dataLabels) && dataLabels) ||
|
3539 | (isObjectType(dataLabels) && notEmpty(dataLabels));
|
3540 | },
|
3541 | |
3542 |
|
3543 |
|
3544 |
|
3545 |
|
3546 | getDataIndexFromEvent: function (event) {
|
3547 | var $$ = this;
|
3548 | var config = $$.config, _a = $$.state, inputType = _a.inputType, _b = _a.eventReceiver, coords = _b.coords, rect = _b.rect;
|
3549 | var isRotated = config.axis_rotated;
|
3550 |
|
3551 | var e = inputType === "touch" && event.changedTouches ? event.changedTouches[0] : event;
|
3552 | var index = findIndex(coords, isRotated ? e.clientY - rect.top : e.clientX - rect.left, 0, coords.length - 1, isRotated);
|
3553 | return index;
|
3554 | },
|
3555 | getDataLabelLength: function (min, max, key) {
|
3556 | var $$ = this;
|
3557 | var lengths = [0, 0];
|
3558 | var paddingCoef = 1.3;
|
3559 | $$.$el.chart.select("svg").selectAll(".dummy")
|
3560 | .data([min, max])
|
3561 | .enter()
|
3562 | .append("text")
|
3563 | .text(function (d) { return $$.dataLabelFormat(d.id)(d); })
|
3564 | .each(function (d, i) {
|
3565 | lengths[i] = this.getBoundingClientRect()[key] * paddingCoef;
|
3566 | })
|
3567 | .remove();
|
3568 | return lengths;
|
3569 | },
|
3570 | isNoneArc: function (d) {
|
3571 | return this.hasTarget(this.data.targets, d.id);
|
3572 | },
|
3573 | isArc: function (d) {
|
3574 | return "data" in d && this.hasTarget(this.data.targets, d.data.id);
|
3575 | },
|
3576 | findSameXOfValues: function (values, index) {
|
3577 | var targetX = values[index].x;
|
3578 | var sames = [];
|
3579 | var i;
|
3580 | for (i = index - 1; i >= 0; i--) {
|
3581 | if (targetX !== values[i].x) {
|
3582 | break;
|
3583 | }
|
3584 | sames.push(values[i]);
|
3585 | }
|
3586 | for (i = index; i < values.length; i++) {
|
3587 | if (targetX !== values[i].x) {
|
3588 | break;
|
3589 | }
|
3590 | sames.push(values[i]);
|
3591 | }
|
3592 | return sames;
|
3593 | },
|
3594 | findClosestFromTargets: function (targets, pos) {
|
3595 | var $$ = this;
|
3596 | var candidates = targets.map(function (target) { return $$.findClosest(target.values, pos); });
|
3597 |
|
3598 | return $$.findClosest(candidates, pos);
|
3599 | },
|
3600 | findClosest: function (values, pos) {
|
3601 | var $$ = this;
|
3602 | var config = $$.config, main = $$.$el.main;
|
3603 | var data = values.filter(function (v) { return v && isValue(v.value); });
|
3604 | var minDist = config.point_sensitivity;
|
3605 | var closest;
|
3606 |
|
3607 | data
|
3608 | .filter(function (v) { return $$.isBarType(v.id); })
|
3609 | .forEach(function (v) {
|
3610 | var shape = main.select("." + CLASS.bars + $$.getTargetSelectorSuffix(v.id) + " ." + CLASS.bar + "-" + v.index).node();
|
3611 | if (!closest && $$.isWithinBar(shape)) {
|
3612 | closest = v;
|
3613 | }
|
3614 | });
|
3615 |
|
3616 | data
|
3617 | .filter(function (v) { return !$$.isBarType(v.id); })
|
3618 | .forEach(function (v) {
|
3619 | var d = $$.dist(v, pos);
|
3620 | if (d < minDist) {
|
3621 | minDist = d;
|
3622 | closest = v;
|
3623 | }
|
3624 | });
|
3625 | return closest;
|
3626 | },
|
3627 | dist: function (data, pos) {
|
3628 | var $$ = this;
|
3629 | var isRotated = $$.config.axis_rotated, scale = $$.scale;
|
3630 | var xIndex = isRotated ? 1 : 0;
|
3631 | var yIndex = isRotated ? 0 : 1;
|
3632 | var y = $$.circleY(data, data.index);
|
3633 | var x = (scale.zoom || scale.x)(data.x);
|
3634 | return Math.sqrt(Math.pow(x - pos[xIndex], 2) + Math.pow(y - pos[yIndex], 2));
|
3635 | },
|
3636 | |
3637 |
|
3638 |
|
3639 |
|
3640 |
|
3641 |
|
3642 | convertValuesToStep: function (values) {
|
3643 | var $$ = this;
|
3644 | var axis = $$.axis, config = $$.config;
|
3645 | var stepType = config.line_step_type;
|
3646 | var isCategorized = axis ? axis.isCategorized() : false;
|
3647 | var converted = isArray(values) ? values.concat() : [values];
|
3648 | if (!(isCategorized || /step\-(after|before)/.test(stepType))) {
|
3649 | return values;
|
3650 | }
|
3651 |
|
3652 | var head = converted[0];
|
3653 | var tail = converted[converted.length - 1];
|
3654 | var id = head.id;
|
3655 | var x = head.x;
|
3656 |
|
3657 | converted.unshift({ x: --x, value: head.value, id: id });
|
3658 | isCategorized && stepType === "step-after" &&
|
3659 | converted.unshift({ x: --x, value: head.value, id: id });
|
3660 |
|
3661 | x = tail.x;
|
3662 | converted.push({ x: ++x, value: tail.value, id: id });
|
3663 | isCategorized && stepType === "step-before" &&
|
3664 | converted.push({ x: ++x, value: tail.value, id: id });
|
3665 | return converted;
|
3666 | },
|
3667 | convertValuesToRange: function (values) {
|
3668 | var converted = isArray(values) ? values.concat() : [values];
|
3669 | var ranges = [];
|
3670 | converted.forEach(function (range) {
|
3671 | var x = range.x, id = range.id;
|
3672 | ranges.push({
|
3673 | x: x,
|
3674 | id: id,
|
3675 | value: range.value[0]
|
3676 | });
|
3677 | ranges.push({
|
3678 | x: x,
|
3679 | id: id,
|
3680 | value: range.value[2]
|
3681 | });
|
3682 | });
|
3683 | return ranges;
|
3684 | },
|
3685 | updateDataAttributes: function (name, attrs) {
|
3686 | var $$ = this;
|
3687 | var config = $$.config;
|
3688 | var current = config["data_" + name];
|
3689 | if (isUndefined(attrs)) {
|
3690 | return current;
|
3691 | }
|
3692 | Object.keys(attrs).forEach(function (id) {
|
3693 | current[id] = attrs[id];
|
3694 | });
|
3695 | $$.redraw({ withLegend: true });
|
3696 | return current;
|
3697 | },
|
3698 | getRangedData: function (d, key, type) {
|
3699 | if (key === void 0) { key = ""; }
|
3700 | if (type === void 0) { type = "areaRange"; }
|
3701 | var value = d === null || d === void 0 ? void 0 : d.value;
|
3702 | if (isArray(value)) {
|
3703 |
|
3704 | var index = {
|
3705 | areaRange: ["high", "mid", "low"],
|
3706 | candlestick: ["open", "high", "low", "close", "volume"]
|
3707 | }[type].indexOf(key);
|
3708 | return index >= 0 && value ? value[index] : undefined;
|
3709 | }
|
3710 | else if (value) {
|
3711 | return value[key];
|
3712 | }
|
3713 | return value;
|
3714 | },
|
3715 | |
3716 |
|
3717 |
|
3718 |
|
3719 |
|
3720 |
|
3721 |
|
3722 |
|
3723 | getRatio: function (type, d, asPercent) {
|
3724 | var $$ = this;
|
3725 | var config = $$.config, state = $$.state;
|
3726 | var api = $$.api;
|
3727 | var ratio = 0;
|
3728 | if (d && api.data.shown().length) {
|
3729 | ratio = d.ratio || d.value;
|
3730 | if (type === "arc") {
|
3731 |
|
3732 | if ($$.pie.padAngle()()) {
|
3733 | ratio = d.value / $$.getTotalDataSum(true);
|
3734 |
|
3735 | }
|
3736 | else {
|
3737 | var gaugeArcLength = config.gauge_fullCircle ? $$.getArcLength() : $$.getStartAngle() * -2;
|
3738 | var arcLength = $$.hasType("gauge") ? gaugeArcLength : Math.PI * 2;
|
3739 | ratio = (d.endAngle - d.startAngle) / arcLength;
|
3740 | }
|
3741 | }
|
3742 | else if (type === "index") {
|
3743 | var dataValues = api.data.values.bind(api);
|
3744 | var total = this.getTotalPerIndex();
|
3745 | if (state.hiddenTargetIds.length) {
|
3746 | var hiddenSum_1 = dataValues(state.hiddenTargetIds, false);
|
3747 | if (hiddenSum_1.length) {
|
3748 | hiddenSum_1 = hiddenSum_1
|
3749 | .reduce(function (acc, curr) { return acc.map(function (v, i) { return (isNumber(v) ? v : 0) + curr[i]; }); });
|
3750 | total = total.map(function (v, i) { return v - hiddenSum_1[i]; });
|
3751 | }
|
3752 | }
|
3753 | d.ratio = isNumber(d.value) && total && total[d.index] > 0 ?
|
3754 | d.value / total[d.index] : 0;
|
3755 | ratio = d.ratio;
|
3756 | }
|
3757 | else if (type === "radar") {
|
3758 | ratio = (parseFloat(String(Math.max(d.value, 0))) / state.current.dataMax) * config.radar_size_ratio;
|
3759 | }
|
3760 | else if (type === "bar") {
|
3761 | var yScale = $$.getYScaleById.bind($$)(d.id);
|
3762 | var max = yScale.domain().reduce(function (a, c) { return c - a; });
|
3763 | ratio = Math.abs(d.value) / max;
|
3764 | }
|
3765 | }
|
3766 | return asPercent && ratio ? ratio * 100 : ratio;
|
3767 | },
|
3768 | |
3769 |
|
3770 |
|
3771 |
|
3772 |
|
3773 | updateDataIndexByX: function (tickValues) {
|
3774 | var $$ = this;
|
3775 | var tickValueMap = tickValues.reduce(function (out, tick, index) {
|
3776 | out[Number(tick.x)] = index;
|
3777 | return out;
|
3778 | }, {});
|
3779 | $$.data.targets.forEach(function (t) {
|
3780 | t.values.forEach(function (value, valueIndex) {
|
3781 | var index = tickValueMap[Number(value.x)];
|
3782 | if (index === undefined) {
|
3783 | index = valueIndex;
|
3784 | }
|
3785 | value.index = index;
|
3786 | });
|
3787 | });
|
3788 | },
|
3789 | |
3790 |
|
3791 |
|
3792 |
|
3793 |
|
3794 |
|
3795 | isBubbleZType: function (d) {
|
3796 | var $$ = this;
|
3797 | return $$.isBubbleType(d) && ((isObject(d.value) && ("z" in d.value || "y" in d.value)) ||
|
3798 | (isArray(d.value) && d.value.length === 2));
|
3799 | },
|
3800 | |
3801 |
|
3802 |
|
3803 |
|
3804 |
|
3805 |
|
3806 | getDataById: function (id) {
|
3807 | var d = this.cache.get(id) || this.api.data(id);
|
3808 | return isArray(d) ? d[0] : d;
|
3809 | }
|
3810 | };
|
3811 |
|
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 | var dataLoad = {
|
3817 | load: function (rawTargets, args) {
|
3818 | var $$ = this;
|
3819 | var targets = rawTargets;
|
3820 | if (targets) {
|
3821 |
|
3822 | if (args.filter) {
|
3823 | targets = targets.filter(args.filter);
|
3824 | }
|
3825 |
|
3826 | if (args.type || args.types) {
|
3827 | targets.forEach(function (t) {
|
3828 | var type = (args.types && args.types[t.id]) || args.type;
|
3829 | $$.setTargetType(t.id, type);
|
3830 | });
|
3831 | }
|
3832 |
|
3833 | $$.data.targets.forEach(function (d) {
|
3834 | for (var i = 0; i < targets.length; i++) {
|
3835 | if (d.id === targets[i].id) {
|
3836 | d.values = targets[i].values;
|
3837 | targets.splice(i, 1);
|
3838 | break;
|
3839 | }
|
3840 | }
|
3841 | });
|
3842 | $$.data.targets = $$.data.targets.concat(targets);
|
3843 | }
|
3844 |
|
3845 | $$.updateTargets($$.data.targets);
|
3846 |
|
3847 | $$.redraw({
|
3848 | withUpdateOrgXDomain: true,
|
3849 | withUpdateXDomain: true,
|
3850 | withLegend: true
|
3851 | });
|
3852 |
|
3853 | $$.updateTypesElements();
|
3854 | args.done && args.done.call($$.api);
|
3855 | },
|
3856 | loadFromArgs: function (args) {
|
3857 | var $$ = this;
|
3858 |
|
3859 | if (!$$.config) {
|
3860 | return;
|
3861 | }
|
3862 |
|
3863 | $$.cache.reset();
|
3864 | var data = args.data || $$.convertData(args, function (d) { return $$.load($$.convertDataToTargets(d), args); });
|
3865 | data && $$.load($$.convertDataToTargets(data), args);
|
3866 | },
|
3867 | unload: function (rawTargetIds, customDoneCb) {
|
3868 | var $$ = this;
|
3869 | var state = $$.state, $el = $$.$el;
|
3870 | var done = customDoneCb;
|
3871 | var targetIds = rawTargetIds;
|
3872 |
|
3873 | $$.cache.reset();
|
3874 | if (!done) {
|
3875 | done = function () { };
|
3876 | }
|
3877 |
|
3878 | targetIds = targetIds.filter(function (id) { return $$.hasTarget($$.data.targets, id); });
|
3879 |
|
3880 | if (!targetIds || targetIds.length === 0) {
|
3881 | done();
|
3882 | return;
|
3883 | }
|
3884 | $el.svg.selectAll(targetIds.map(function (id) { return $$.selectorTarget(id); }))
|
3885 | .transition()
|
3886 | .style("opacity", "0")
|
3887 | .remove()
|
3888 | .call(endall, done);
|
3889 | targetIds.forEach(function (id) {
|
3890 |
|
3891 | state.withoutFadeIn[id] = false;
|
3892 |
|
3893 | if ($el.legend) {
|
3894 | $el.legend.selectAll("." + CLASS.legendItem + $$.getTargetSelectorSuffix(id)).remove();
|
3895 | }
|
3896 |
|
3897 | $$.data.targets = $$.data.targets.filter(function (t) { return t.id !== id; });
|
3898 | });
|
3899 |
|
3900 | $$.updateTypesElements();
|
3901 | }
|
3902 | };
|
3903 |
|
3904 |
|
3905 |
|
3906 |
|
3907 |
|
3908 | var interaction = {
|
3909 | selectRectForSingle: function (context, eventRect, index) {
|
3910 | var $$ = this;
|
3911 | var config = $$.config, main = $$.$el.main;
|
3912 | var isSelectionEnabled = config.data_selection_enabled;
|
3913 | var isSelectionGrouped = config.data_selection_grouped;
|
3914 | var isSelectable = config.data_selection_isselectable;
|
3915 | var isTooltipGrouped = config.tooltip_grouped;
|
3916 | var selectedData = $$.getAllValuesOnIndex(index);
|
3917 | if (isTooltipGrouped) {
|
3918 | $$.showTooltip(selectedData, context);
|
3919 | $$.showGridFocus && $$.showGridFocus(selectedData);
|
3920 | if (!isSelectionEnabled || isSelectionGrouped) {
|
3921 | return;
|
3922 | }
|
3923 | }
|
3924 | main.selectAll("." + CLASS.shape + "-" + index)
|
3925 | .each(function () {
|
3926 | select(this).classed(CLASS.EXPANDED, true);
|
3927 | if (isSelectionEnabled) {
|
3928 | eventRect.style("cursor", isSelectionGrouped ? "pointer" : null);
|
3929 | }
|
3930 | if (!isTooltipGrouped) {
|
3931 | $$.hideGridFocus && $$.hideGridFocus();
|
3932 | $$.hideTooltip();
|
3933 | !isSelectionGrouped && $$.expandCirclesBars(index);
|
3934 | }
|
3935 | })
|
3936 | .filter(function (d) {
|
3937 | return $$.isWithinShape(this, d);
|
3938 | })
|
3939 | .call(function (selected) {
|
3940 | var d = selected.data();
|
3941 | if (isSelectionEnabled &&
|
3942 | (isSelectionGrouped || (isSelectable && isSelectable.bind($$.api)(d)))) {
|
3943 | eventRect.style("cursor", "pointer");
|
3944 | }
|
3945 | if (!isTooltipGrouped) {
|
3946 | $$.showTooltip(d, context);
|
3947 | $$.showGridFocus && $$.showGridFocus(d);
|
3948 | $$.unexpandCircles && $$.unexpandCircles();
|
3949 | selected.each(function (d) { return $$.expandCirclesBars(index, d.id); });
|
3950 | }
|
3951 | });
|
3952 | },
|
3953 | expandCirclesBars: function (index, id, reset) {
|
3954 | var $$ = this;
|
3955 | var config = $$.config, _a = $$.$el, bar = _a.bar, circle = _a.circle;
|
3956 | circle && config.point_focus_expand_enabled &&
|
3957 | $$.expandCircles(index, id, reset);
|
3958 | bar && $$.expandBars(index, id, reset);
|
3959 | },
|
3960 | |
3961 |
|
3962 |
|
3963 |
|
3964 |
|
3965 |
|
3966 | setOverOut: function (isOver, d) {
|
3967 | var $$ = this;
|
3968 | var config = $$.config, hasRadar = $$.state.hasRadar, main = $$.$el.main;
|
3969 | var isArc = isObject(d);
|
3970 |
|
3971 | if (isArc || d !== -1) {
|
3972 | var callback_1 = config[isOver ? "data_onover" : "data_onout"].bind($$.api);
|
3973 | config.color_onover && $$.setOverColor(isOver, d, isArc);
|
3974 | if (isArc) {
|
3975 | callback_1(d, main.select("." + CLASS.arc + $$.getTargetSelectorSuffix(d.id)).node());
|
3976 | }
|
3977 | else if (!config.tooltip_grouped) {
|
3978 | var last_1 = $$.cache.get(KEY.setOverOut) || [];
|
3979 | var shape = main.selectAll("." + CLASS.shape + "-" + d)
|
3980 | .filter(function (d) {
|
3981 | return $$.isWithinShape(this, d);
|
3982 | });
|
3983 | shape
|
3984 | .each(function (d) {
|
3985 | var _this = this;
|
3986 | if (last_1.length === 0 || last_1.every(function (v) { return v !== _this; })) {
|
3987 | callback_1(d, this);
|
3988 | last_1.push(this);
|
3989 | }
|
3990 | });
|
3991 | if (last_1.length > 0 && shape.empty()) {
|
3992 | callback_1 = config.data_onout.bind($$.api);
|
3993 | last_1.forEach(function (v) { return callback_1(select(v).datum(), v); });
|
3994 | last_1 = [];
|
3995 | }
|
3996 | $$.cache.add(KEY.setOverOut, last_1);
|
3997 | }
|
3998 | else {
|
3999 | if (isOver) {
|
4000 | config.point_focus_only && hasRadar ?
|
4001 | $$.showCircleFocus($$.getAllValuesOnIndex(d, true)) :
|
4002 | $$.expandCirclesBars(d, null, true);
|
4003 | }
|
4004 | !$$.isMultipleX() && main.selectAll("." + CLASS.shape + "-" + d)
|
4005 | .each(function (d) {
|
4006 | callback_1(d, this);
|
4007 | });
|
4008 | }
|
4009 | }
|
4010 | },
|
4011 | |
4012 |
|
4013 |
|
4014 |
|
4015 |
|
4016 | callOverOutForTouch: function (d) {
|
4017 | var $$ = this;
|
4018 | var last = $$.cache.get(KEY.callOverOutForTouch);
|
4019 | if (isObject(d) && last ? d.id !== last.id : (d !== last)) {
|
4020 | (last || isNumber(last)) && $$.setOverOut(false, last);
|
4021 | (d || isNumber(d)) && $$.setOverOut(true, d);
|
4022 | $$.cache.add(KEY.callOverOutForTouch, d);
|
4023 | }
|
4024 | },
|
4025 | |
4026 |
|
4027 |
|
4028 |
|
4029 |
|
4030 | getDraggableSelection: function () {
|
4031 | var $$ = this;
|
4032 | var config = $$.config, state = $$.state;
|
4033 | return config.interaction_enabled && config.data_selection_draggable && $$.drag ?
|
4034 | drag$1()
|
4035 | .on("drag", function (event) {
|
4036 | state.event = event;
|
4037 | $$.drag(getPointer(event, this));
|
4038 | })
|
4039 | .on("start", function (event) {
|
4040 | state.event = event;
|
4041 | $$.dragstart(getPointer(event, this));
|
4042 | })
|
4043 | .on("end", function (event) {
|
4044 | state.event = event;
|
4045 | $$.dragend();
|
4046 | }) : function () { };
|
4047 | },
|
4048 | |
4049 |
|
4050 |
|
4051 |
|
4052 |
|
4053 |
|
4054 |
|
4055 | dispatchEvent: function (type, index, mouse) {
|
4056 | var $$ = this;
|
4057 | var config = $$.config, _a = $$.state, eventReceiver = _a.eventReceiver, hasAxis = _a.hasAxis, hasRadar = _a.hasRadar, _b = $$.$el, eventRect = _b.eventRect, arcs = _b.arcs, radar = _b.radar;
|
4058 | var isMultipleX = $$.isMultipleX();
|
4059 | var element = (hasRadar ? radar.axes.select("." + CLASS.axis + "-" + index + " text") : (eventRect || arcs.selectAll("." + CLASS.target + " path").filter(function (d, i) { return i === index; }))).node();
|
4060 | var _c = element.getBoundingClientRect(), width = _c.width, left = _c.left, top = _c.top;
|
4061 | if (hasAxis && !hasRadar && !isMultipleX) {
|
4062 | var coords = eventReceiver.coords[index];
|
4063 | width = coords.w;
|
4064 | left += coords.x;
|
4065 | top += coords.y;
|
4066 | }
|
4067 | var x = left + (mouse ? mouse[0] : 0) + (isMultipleX || config.axis_rotated ? 0 : (width / 2));
|
4068 | var y = top + (mouse ? mouse[1] : 0);
|
4069 | var params = {
|
4070 | screenX: x,
|
4071 | screenY: y,
|
4072 | clientX: x,
|
4073 | clientY: y
|
4074 | };
|
4075 | emulateEvent[/^(mouse|click)/.test(type) ? "mouse" : "touch"](element, type, params);
|
4076 | },
|
4077 | setDragStatus: function (isDragging) {
|
4078 | this.state.dragging = isDragging;
|
4079 | }
|
4080 | };
|
4081 |
|
4082 |
|
4083 |
|
4084 |
|
4085 |
|
4086 | var classModule = {
|
4087 | generateClass: function (prefix, targetId) {
|
4088 | return " " + prefix + " " + (prefix + this.getTargetSelectorSuffix(targetId));
|
4089 | },
|
4090 | |
4091 |
|
4092 |
|
4093 |
|
4094 |
|
4095 |
|
4096 |
|
4097 | getClass: function (type, withShape) {
|
4098 | var _this = this;
|
4099 | var isPlural = /s$/.test(type);
|
4100 | var useIdKey = /^(area|arc|line)s?$/.test(type);
|
4101 | var key = isPlural ? "id" : "index";
|
4102 | return function (d) {
|
4103 | var data = d.data || d;
|
4104 | var result = (withShape ? _this.generateClass(CLASS[isPlural ? "shapes" : "shape"], data[key]) : "") + _this.generateClass(CLASS[type], data[useIdKey ? "id" : key]);
|
4105 | return result.trim();
|
4106 | };
|
4107 | },
|
4108 | |
4109 |
|
4110 |
|
4111 |
|
4112 |
|
4113 |
|
4114 | getChartClass: function (type) {
|
4115 | var _this = this;
|
4116 | return function (d) { return CLASS["chart" + type] + _this.classTarget((d.data ? d.data : d).id); };
|
4117 | },
|
4118 | generateExtraLineClass: function () {
|
4119 | var $$ = this;
|
4120 | var classes = $$.config.line_classes || [];
|
4121 | var ids = [];
|
4122 | return function (d) {
|
4123 | var id = d.id || (d.data && d.data.id) || d;
|
4124 | if (ids.indexOf(id) < 0) {
|
4125 | ids.push(id);
|
4126 | }
|
4127 | return classes[ids.indexOf(id) % classes.length];
|
4128 | };
|
4129 | },
|
4130 | classRegion: function (d, i) {
|
4131 | return this.generateClass(CLASS.region, i) + " " + ("class" in d ? d["class"] : "");
|
4132 | },
|
4133 | classTarget: function (id) {
|
4134 | var additionalClassSuffix = this.config.data_classes[id];
|
4135 | var additionalClass = "";
|
4136 | if (additionalClassSuffix) {
|
4137 | additionalClass = " " + CLASS.target + "-" + additionalClassSuffix;
|
4138 | }
|
4139 | return this.generateClass(CLASS.target, id) + additionalClass;
|
4140 | },
|
4141 | classFocus: function (d) {
|
4142 | return this.classFocused(d) + this.classDefocused(d);
|
4143 | },
|
4144 | classFocused: function (d) {
|
4145 | return " " + (this.state.focusedTargetIds.indexOf(d.id) >= 0 ? CLASS.focused : "");
|
4146 | },
|
4147 | classDefocused: function (d) {
|
4148 | return " " + (this.state.defocusedTargetIds.indexOf(d.id) >= 0 ? CLASS.defocused : "");
|
4149 | },
|
4150 | getTargetSelectorSuffix: function (targetId) {
|
4151 | return targetId || targetId === 0 ?
|
4152 | ("-" + targetId).replace(/[\s?!@#$%^&*()_=+,.<>'":;\[\]\/|~`{}\\]/g, "-") : "";
|
4153 | },
|
4154 | selectorTarget: function (id, prefix) {
|
4155 | var pfx = prefix || "";
|
4156 | var target = this.getTargetSelectorSuffix(id);
|
4157 |
|
4158 | return pfx + "." + (CLASS.target + target) + ", " + pfx + "." + (CLASS.circles + target);
|
4159 | },
|
4160 | selectorTargets: function (idsValue, prefix) {
|
4161 | var _this = this;
|
4162 | var ids = idsValue || [];
|
4163 | return ids.length ?
|
4164 | ids.map(function (id) { return _this.selectorTarget(id, prefix); }) : null;
|
4165 | },
|
4166 | selectorLegend: function (id) {
|
4167 | return "." + (CLASS.legendItem + this.getTargetSelectorSuffix(id));
|
4168 | },
|
4169 | selectorLegends: function (ids) {
|
4170 | var _this = this;
|
4171 | return ids && ids.length ?
|
4172 | ids.map(function (id) { return _this.selectorLegend(id); }) : null;
|
4173 | }
|
4174 | };
|
4175 |
|
4176 |
|
4177 |
|
4178 |
|
4179 |
|
4180 | var category = {
|
4181 | |
4182 |
|
4183 |
|
4184 |
|
4185 |
|
4186 |
|
4187 | categoryName: function (i) {
|
4188 | var categories = this.config.axis_x_categories;
|
4189 | return categories && i < categories.length ? categories[i] : i;
|
4190 | }
|
4191 | };
|
4192 |
|
4193 |
|
4194 |
|
4195 |
|
4196 |
|
4197 |
|
4198 |
|
4199 |
|
4200 |
|
4201 |
|
4202 |
|
4203 |
|
4204 |
|
4205 |
|
4206 | var colorizePattern = function (pattern, color, id) {
|
4207 | var node = select(pattern.cloneNode(true));
|
4208 | node
|
4209 | .attr("id", id)
|
4210 | .insert("rect", ":first-child")
|
4211 | .attr("width", node.attr("width"))
|
4212 | .attr("height", node.attr("height"))
|
4213 | .style("fill", color);
|
4214 | return {
|
4215 | id: id,
|
4216 | node: node.node()
|
4217 | };
|
4218 | };
|
4219 |
|
4220 |
|
4221 | var schemeCategory10 = ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"];
|
4222 | var color = {
|
4223 | |
4224 |
|
4225 |
|
4226 |
|
4227 |
|
4228 |
|
4229 | getColorFromCss: function () {
|
4230 | var cacheKey = KEY.colorPattern;
|
4231 | var body = doc.body;
|
4232 | var pattern = body[cacheKey];
|
4233 | if (!pattern) {
|
4234 | var delimiter = ";";
|
4235 | var span = doc.createElement("span");
|
4236 | span.className = CLASS.colorPattern;
|
4237 | span.style.display = "none";
|
4238 | body.appendChild(span);
|
4239 | var content = win.getComputedStyle(span).backgroundImage;
|
4240 | span.parentNode.removeChild(span);
|
4241 | if (content.indexOf(delimiter) > -1) {
|
4242 | pattern = content
|
4243 | .replace(/url[^#]*|["'()]|(\s|%20)/g, "")
|
4244 | .split(delimiter)
|
4245 | .map(function (v) { return v.trim().replace(/[\"'\s]/g, ""); })
|
4246 | .filter(Boolean);
|
4247 | body[cacheKey] = pattern;
|
4248 | }
|
4249 | }
|
4250 | return pattern;
|
4251 | },
|
4252 | generateColor: function () {
|
4253 | var $$ = this;
|
4254 | var config = $$.config;
|
4255 | var colors = config.data_colors;
|
4256 | var callback = config.data_color;
|
4257 | var ids = [];
|
4258 | var pattern = notEmpty(config.color_pattern) ? config.color_pattern :
|
4259 | scaleOrdinal($$.getColorFromCss() || schemeCategory10).range();
|
4260 | var originalColorPattern = pattern;
|
4261 | if (isFunction(config.color_tiles)) {
|
4262 | var tiles_1 = config.color_tiles.bind($$.api)();
|
4263 |
|
4264 | var colorizedPatterns = pattern.map(function (p, index) {
|
4265 | var color = p.replace(/[#\(\)\s,]/g, "");
|
4266 | var id = $$.state.datetimeId + "-pattern-" + color + "-" + index;
|
4267 | return colorizePattern(tiles_1[index % tiles_1.length], p, id);
|
4268 | });
|
4269 | pattern = colorizedPatterns.map(function (p) { return "url(#" + p.id + ")"; });
|
4270 | $$.patterns = colorizedPatterns;
|
4271 | }
|
4272 | return function (d) {
|
4273 | var id = d.id || (d.data && d.data.id) || d;
|
4274 | var isLine = $$.isTypeOf(id, ["line", "spline", "step"]) || !config.data_types[id];
|
4275 | var color;
|
4276 |
|
4277 | if (isFunction(colors[id])) {
|
4278 | color = colors[id].bind($$.api)(d);
|
4279 |
|
4280 | }
|
4281 | else if (colors[id]) {
|
4282 | color = colors[id];
|
4283 |
|
4284 | }
|
4285 | else {
|
4286 | if (ids.indexOf(id) < 0) {
|
4287 | ids.push(id);
|
4288 | }
|
4289 | color = isLine ? originalColorPattern[ids.indexOf(id) % originalColorPattern.length] :
|
4290 | pattern[ids.indexOf(id) % pattern.length];
|
4291 | colors[id] = color;
|
4292 | }
|
4293 | return isFunction(callback) ?
|
4294 | callback.bind($$.api)(color, d) : color;
|
4295 | };
|
4296 | },
|
4297 | generateLevelColor: function () {
|
4298 | var $$ = this;
|
4299 | var config = $$.config;
|
4300 | var colors = config.color_pattern;
|
4301 | var threshold = config.color_threshold;
|
4302 | var asValue = threshold.unit === "value";
|
4303 | var max = threshold.max || 100;
|
4304 | var values = threshold.values &&
|
4305 | threshold.values.length ? threshold.values : [];
|
4306 | return notEmpty(threshold) ? function (value) {
|
4307 | var v = asValue ? value : (value * 100 / max);
|
4308 | var color = colors[colors.length - 1];
|
4309 | for (var i = 0, l = values.length; i < l; i++) {
|
4310 | if (v <= values[i]) {
|
4311 | color = colors[i];
|
4312 | break;
|
4313 | }
|
4314 | }
|
4315 | return color;
|
4316 | } : null;
|
4317 | },
|
4318 | |
4319 |
|
4320 |
|
4321 |
|
4322 |
|
4323 |
|
4324 |
|
4325 | setOverColor: function (isOver, d) {
|
4326 | var $$ = this;
|
4327 | var config = $$.config, main = $$.$el.main;
|
4328 | var onover = config.color_onover;
|
4329 | var color = isOver ? onover : $$.color;
|
4330 | if (isObject(color)) {
|
4331 | color = function (_a) {
|
4332 | var id = _a.id;
|
4333 | return (id in onover ? onover[id] : $$.color(id));
|
4334 | };
|
4335 | }
|
4336 | else if (isString(color)) {
|
4337 | color = function () { return onover; };
|
4338 | }
|
4339 | else if (isFunction(onover)) {
|
4340 | color = color.bind($$.api);
|
4341 | }
|
4342 | main.selectAll(isObject(d) ?
|
4343 |
|
4344 | "." + CLASS.arc + $$.getTargetSelectorSuffix(d.id) :
|
4345 | "." + CLASS.shape + "-" + d).style("fill", color);
|
4346 | }
|
4347 | };
|
4348 |
|
4349 |
|
4350 |
|
4351 |
|
4352 |
|
4353 |
|
4354 |
|
4355 |
|
4356 |
|
4357 | var TYPE = {
|
4358 | AREA: "area",
|
4359 | AREA_LINE_RANGE: "area-line-range",
|
4360 | AREA_SPLINE: "area-spline",
|
4361 | AREA_SPLINE_RANGE: "area-spline-range",
|
4362 | AREA_STEP: "area-step",
|
4363 | BAR: "bar",
|
4364 | BUBBLE: "bubble",
|
4365 | CANDLESTICK: "candlestick",
|
4366 | DONUT: "donut",
|
4367 | GAUGE: "gauge",
|
4368 | LINE: "line",
|
4369 | PIE: "pie",
|
4370 | RADAR: "radar",
|
4371 | SCATTER: "scatter",
|
4372 | SPLINE: "spline",
|
4373 | STEP: "step"
|
4374 | };
|
4375 |
|
4376 |
|
4377 |
|
4378 |
|
4379 | var TYPE_BY_CATEGORY = {
|
4380 | Area: [
|
4381 | TYPE.AREA,
|
4382 | TYPE.AREA_SPLINE,
|
4383 | TYPE.AREA_SPLINE_RANGE,
|
4384 | TYPE.AREA_LINE_RANGE,
|
4385 | TYPE.AREA_STEP
|
4386 | ],
|
4387 | AreaRange: [
|
4388 | TYPE.AREA_SPLINE_RANGE,
|
4389 | TYPE.AREA_LINE_RANGE
|
4390 | ],
|
4391 | Arc: [
|
4392 | TYPE.PIE,
|
4393 | TYPE.DONUT,
|
4394 | TYPE.GAUGE,
|
4395 | TYPE.RADAR
|
4396 | ],
|
4397 | Line: [
|
4398 | TYPE.LINE,
|
4399 | TYPE.SPLINE,
|
4400 | TYPE.AREA,
|
4401 | TYPE.AREA_SPLINE,
|
4402 | TYPE.AREA_SPLINE_RANGE,
|
4403 | TYPE.AREA_LINE_RANGE,
|
4404 | TYPE.STEP,
|
4405 | TYPE.AREA_STEP
|
4406 | ],
|
4407 | Step: [
|
4408 | TYPE.STEP,
|
4409 | TYPE.AREA_STEP
|
4410 | ],
|
4411 | Spline: [
|
4412 | TYPE.SPLINE,
|
4413 | TYPE.AREA_SPLINE,
|
4414 | TYPE.AREA_SPLINE_RANGE
|
4415 | ]
|
4416 | };
|
4417 |
|
4418 | var domain = {
|
4419 | getYDomainMinMax: function (targets, type) {
|
4420 | var $$ = this;
|
4421 | var axis = $$.axis, config = $$.config;
|
4422 | var isMin = type === "min";
|
4423 | var dataGroups = config.data_groups;
|
4424 | var ids = $$.mapToIds(targets);
|
4425 | var ys = $$.getValuesAsIdKeyed(targets);
|
4426 | if (dataGroups.length > 0) {
|
4427 | var hasValue_1 = $$["has" + (isMin ? "Negative" : "Positive") + "ValueInTargets"](targets);
|
4428 | var _loop_1 = function (j, idsInGroup) {
|
4429 |
|
4430 | idsInGroup = idsInGroup.filter(function (v) { return ids.indexOf(v) >= 0; });
|
4431 | if (idsInGroup.length === 0) {
|
4432 | return out_idsInGroup_1 = idsInGroup, "continue";
|
4433 | }
|
4434 | var baseId = idsInGroup[0];
|
4435 | var baseAxisId = axis.getId(baseId);
|
4436 |
|
4437 | if (hasValue_1 && ys[baseId]) {
|
4438 | ys[baseId] = ys[baseId].map(function (v) { return ((isMin ? v < 0 : v > 0) ? v : 0); });
|
4439 | }
|
4440 | var _loop_2 = function (k, id) {
|
4441 | if (!ys[id]) {
|
4442 | return "continue";
|
4443 | }
|
4444 | var axisId = axis.getId(id);
|
4445 | ys[id].forEach(function (v, i) {
|
4446 | var val = +v;
|
4447 | var meetCondition = isMin ? val > 0 : val < 0;
|
4448 | if (axisId === baseAxisId && !(hasValue_1 && meetCondition)) {
|
4449 | ys[baseId][i] += val;
|
4450 | }
|
4451 | });
|
4452 | };
|
4453 | for (var k = 1, id = void 0; (id = idsInGroup[k]); k++) {
|
4454 | _loop_2(k, id);
|
4455 | }
|
4456 | out_idsInGroup_1 = idsInGroup;
|
4457 | };
|
4458 | var out_idsInGroup_1;
|
4459 | for (var j = 0, idsInGroup = void 0; (idsInGroup = dataGroups[j]); j++) {
|
4460 | _loop_1(j, idsInGroup);
|
4461 | idsInGroup = out_idsInGroup_1;
|
4462 | }
|
4463 | }
|
4464 | return getMinMax$1(type, Object.keys(ys).map(function (key) { return getMinMax$1(type, ys[key]); }));
|
4465 | },
|
4466 | getYDomainMin: function (targets) {
|
4467 | return this.getYDomainMinMax(targets, "min");
|
4468 | },
|
4469 | getYDomainMax: function (targets) {
|
4470 | return this.getYDomainMinMax(targets, "max");
|
4471 | },
|
4472 | |
4473 |
|
4474 |
|
4475 |
|
4476 |
|
4477 |
|
4478 | isHiddenTargetWithYDomain: function (id) {
|
4479 | var $$ = this;
|
4480 | return $$.state.hiddenTargetIds
|
4481 | .some(function (v) { return $$.axis.getId(v) === id; });
|
4482 | },
|
4483 | getYDomain: function (targets, axisId, xDomain) {
|
4484 | var $$ = this;
|
4485 | var axis = $$.axis, config = $$.config, scale = $$.scale;
|
4486 | var pfx = "axis_" + axisId;
|
4487 | if ($$.isStackNormalized()) {
|
4488 | return [0, 100];
|
4489 | }
|
4490 | var isLog = scale && scale[axisId] && scale[axisId].type === "log";
|
4491 | var targetsByAxisId = targets.filter(function (t) { return axis.getId(t.id) === axisId; });
|
4492 | var yTargets = xDomain ? $$.filterByXDomain(targetsByAxisId, xDomain) : targetsByAxisId;
|
4493 | if (yTargets.length === 0) {
|
4494 | if ($$.isHiddenTargetWithYDomain(axisId)) {
|
4495 | return scale[axisId].domain();
|
4496 | }
|
4497 | else {
|
4498 | return axisId === "y2" ?
|
4499 | scale.y.domain() :
|
4500 |
|
4501 |
|
4502 | $$.getYDomain(targets, "y2", xDomain);
|
4503 | }
|
4504 | }
|
4505 | var yMin = config[pfx + "_min"];
|
4506 | var yMax = config[pfx + "_max"];
|
4507 | var yDomainMin = $$.getYDomainMin(yTargets);
|
4508 | var yDomainMax = $$.getYDomainMax(yTargets);
|
4509 | var center = config[pfx + "_center"];
|
4510 | var isZeroBased = __spreadArray([TYPE.BAR, TYPE.BUBBLE, TYPE.SCATTER], TYPE_BY_CATEGORY.Line).some(function (v) {
|
4511 | var type = v.indexOf("area") > -1 ? "area" : v;
|
4512 | return $$.hasType(v, yTargets) && config[type + "_zerobased"];
|
4513 | });
|
4514 | var isInverted = config[pfx + "_inverted"];
|
4515 | var showHorizontalDataLabel = $$.hasDataLabel() && config.axis_rotated;
|
4516 | var showVerticalDataLabel = $$.hasDataLabel() && !config.axis_rotated;
|
4517 |
|
4518 | yDomainMin = isValue(yMin) ? yMin :
|
4519 | (isValue(yMax) ? (yDomainMin < yMax ? yDomainMin : yMax - 10) : yDomainMin);
|
4520 | yDomainMax = isValue(yMax) ? yMax :
|
4521 | (isValue(yMin) ? (yMin < yDomainMax ? yDomainMax : yMin + 10) : yDomainMax);
|
4522 | if (isNaN(yDomainMin)) {
|
4523 | yDomainMin = 0;
|
4524 | }
|
4525 | if (isNaN(yDomainMax)) {
|
4526 | yDomainMax = yDomainMin;
|
4527 | }
|
4528 | if (yDomainMin === yDomainMax) {
|
4529 | yDomainMin < 0 ? yDomainMax = 0 : yDomainMin = 0;
|
4530 | }
|
4531 | var isAllPositive = yDomainMin >= 0 && yDomainMax >= 0;
|
4532 | var isAllNegative = yDomainMin <= 0 && yDomainMax <= 0;
|
4533 |
|
4534 | if ((isValue(yMin) && isAllPositive) || (isValue(yMax) && isAllNegative)) {
|
4535 | isZeroBased = false;
|
4536 | }
|
4537 |
|
4538 | if (isZeroBased) {
|
4539 | isAllPositive && (yDomainMin = 0);
|
4540 | isAllNegative && (yDomainMax = 0);
|
4541 | }
|
4542 | var domainLength = Math.abs(yDomainMax - yDomainMin);
|
4543 | var padding = { top: domainLength * 0.1, bottom: domainLength * 0.1 };
|
4544 | if (isDefined(center)) {
|
4545 | var yDomainAbs = Math.max(Math.abs(yDomainMin), Math.abs(yDomainMax));
|
4546 | yDomainMax = center + yDomainAbs;
|
4547 | yDomainMin = center - yDomainAbs;
|
4548 | }
|
4549 |
|
4550 | if (showHorizontalDataLabel) {
|
4551 | var diff_1 = diffDomain(scale.y.range());
|
4552 | var ratio_1 = $$.getDataLabelLength(yDomainMin, yDomainMax, "width")
|
4553 | .map(function (v) { return v / diff_1; });
|
4554 | ["bottom", "top"].forEach(function (v, i) {
|
4555 | padding[v] += domainLength * (ratio_1[i] / (1 - ratio_1[0] - ratio_1[1]));
|
4556 | });
|
4557 | }
|
4558 | else if (showVerticalDataLabel) {
|
4559 | var lengths_1 = $$.getDataLabelLength(yDomainMin, yDomainMax, "height");
|
4560 | ["bottom", "top"].forEach(function (v, i) {
|
4561 | padding[v] += axis.convertPixelsToAxisPadding(lengths_1[i], domainLength);
|
4562 | });
|
4563 | }
|
4564 |
|
4565 |
|
4566 | var p = config[pfx + "_padding"];
|
4567 | if (notEmpty(p)) {
|
4568 | ["bottom", "top"].forEach(function (v) {
|
4569 | padding[v] = axis.getPadding(p, v, padding[v], domainLength);
|
4570 | });
|
4571 | }
|
4572 |
|
4573 | if (isZeroBased) {
|
4574 | isAllPositive && (padding.bottom = yDomainMin);
|
4575 | isAllNegative && (padding.top = -yDomainMax);
|
4576 | }
|
4577 | var domain = isLog ? [yDomainMin, yDomainMax].map(function (v) { return (v < 0 ? 0 : v); }) :
|
4578 | [yDomainMin - padding.bottom, yDomainMax + padding.top];
|
4579 | return isInverted ? domain.reverse() : domain;
|
4580 | },
|
4581 | getXDomainMinMax: function (targets, type) {
|
4582 | var $$ = this;
|
4583 | var configValue = $$.config["axis_x_" + type];
|
4584 | var dataValue = getMinMax$1(type, targets.map(function (t) { return getMinMax$1(type, t.values.map(function (v) { return v.x; })); }));
|
4585 | var value = isObject(configValue) ? configValue.value : configValue;
|
4586 | value = isDefined(value) && $$.axis.isTimeSeries() ? parseDate.bind(this)(value) : value;
|
4587 | if (isObject(configValue) && configValue.fit && ((type === "min" && value < dataValue) || (type === "max" && value > dataValue))) {
|
4588 | value = undefined;
|
4589 | }
|
4590 | return isDefined(value) ? value : dataValue;
|
4591 | },
|
4592 | getXDomainMin: function (targets) {
|
4593 | return this.getXDomainMinMax(targets, "min");
|
4594 | },
|
4595 | getXDomainMax: function (targets) {
|
4596 | return this.getXDomainMinMax(targets, "max");
|
4597 | },
|
4598 | getXDomainPadding: function (domain) {
|
4599 | var $$ = this;
|
4600 | var axis = $$.axis, config = $$.config;
|
4601 | var diff = domain[1] - domain[0];
|
4602 | var xPadding = config.axis_x_padding;
|
4603 | var maxDataCount;
|
4604 | var padding;
|
4605 | if (axis.isCategorized()) {
|
4606 | padding = 0;
|
4607 | }
|
4608 | else if ($$.hasType("bar")) {
|
4609 | maxDataCount = $$.getMaxDataCount();
|
4610 | padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5;
|
4611 | }
|
4612 | else {
|
4613 | padding = diff * 0.01;
|
4614 | }
|
4615 | var left = padding;
|
4616 | var right = padding;
|
4617 | if (isObject(xPadding) && notEmpty(xPadding)) {
|
4618 | left = isValue(xPadding.left) ? xPadding.left : padding;
|
4619 | right = isValue(xPadding.right) ? xPadding.right : padding;
|
4620 | }
|
4621 | else if (isNumber(config.axis_x_padding)) {
|
4622 | left = xPadding;
|
4623 | right = xPadding;
|
4624 | }
|
4625 | return { left: left, right: right };
|
4626 | },
|
4627 | getXDomain: function (targets) {
|
4628 | var $$ = this;
|
4629 | var isLog = $$.scale.x.type === "log";
|
4630 | var xDomain = [$$.getXDomainMin(targets), $$.getXDomainMax(targets)];
|
4631 | var min = 0;
|
4632 | var max = 0;
|
4633 | if (isLog) {
|
4634 | min = xDomain[0];
|
4635 | max = xDomain[1];
|
4636 | }
|
4637 | else {
|
4638 | var isCategorized = $$.axis.isCategorized();
|
4639 | var isTimeSeries = $$.axis.isTimeSeries();
|
4640 | var padding = $$.getXDomainPadding(xDomain);
|
4641 | var firstX = xDomain[0], lastX = xDomain[1];
|
4642 |
|
4643 | if ((firstX - lastX) === 0 && !isCategorized) {
|
4644 | if (isTimeSeries) {
|
4645 | firstX = new Date(firstX.getTime() * 0.5);
|
4646 | lastX = new Date(lastX.getTime() * 1.5);
|
4647 | }
|
4648 | else {
|
4649 | firstX = firstX === 0 ? 1 : (firstX * 0.5);
|
4650 | lastX = lastX === 0 ? -1 : (lastX * 1.5);
|
4651 | }
|
4652 | }
|
4653 | if (firstX || firstX === 0) {
|
4654 | min = isTimeSeries ? new Date(firstX.getTime() - padding.left) : firstX - padding.left;
|
4655 | }
|
4656 | if (lastX || lastX === 0) {
|
4657 | max = isTimeSeries ? new Date(lastX.getTime() + padding.right) : lastX + padding.right;
|
4658 | }
|
4659 | }
|
4660 | return [min, max];
|
4661 | },
|
4662 | updateXDomain: function (targets, withUpdateXDomain, withUpdateOrgXDomain, withTrim, domain) {
|
4663 | var $$ = this;
|
4664 | var config = $$.config, org = $$.org, _a = $$.scale, x = _a.x, subX = _a.subX;
|
4665 | var zoomEnabled = config.zoom_enabled;
|
4666 | if (withUpdateOrgXDomain) {
|
4667 | x.domain(domain || sortValue($$.getXDomain(targets)));
|
4668 | org.xDomain = x.domain();
|
4669 | zoomEnabled && $$.zoom.updateScaleExtent();
|
4670 | subX.domain(x.domain());
|
4671 | $$.brush && $$.brush.scale(subX);
|
4672 | }
|
4673 | if (withUpdateXDomain) {
|
4674 | var domainValue = domain || (!$$.brush || brushEmpty($$)) ?
|
4675 | org.xDomain : getBrushSelection($$).map(subX.invert);
|
4676 | x.domain(domainValue);
|
4677 | zoomEnabled && $$.zoom.updateScaleExtent();
|
4678 | }
|
4679 |
|
4680 | withTrim && x.domain($$.trimXDomain(x.orgDomain()));
|
4681 | return x.domain();
|
4682 | },
|
4683 | trimXDomain: function (domain) {
|
4684 | var zoomDomain = this.getZoomDomain();
|
4685 | var min = zoomDomain[0], max = zoomDomain[1];
|
4686 | if (domain[0] <= min) {
|
4687 | domain[1] = +domain[1] + (min - domain[0]);
|
4688 | domain[0] = min;
|
4689 | }
|
4690 | if (max <= domain[1]) {
|
4691 | domain[0] = +domain[0] - (domain[1] - max);
|
4692 | domain[1] = max;
|
4693 | }
|
4694 | return domain;
|
4695 | },
|
4696 | |
4697 |
|
4698 |
|
4699 |
|
4700 |
|
4701 | getZoomDomain: function () {
|
4702 | var $$ = this;
|
4703 | var config = $$.config, org = $$.org;
|
4704 | var _a = org.xDomain, min = _a[0], max = _a[1];
|
4705 | if (isDefined(config.zoom_x_min)) {
|
4706 | min = getMinMax$1("min", [min, config.zoom_x_min]);
|
4707 | }
|
4708 | if (isDefined(config.zoom_x_max)) {
|
4709 | max = getMinMax$1("max", [max, config.zoom_x_max]);
|
4710 | }
|
4711 | return [min, max];
|
4712 | }
|
4713 | };
|
4714 |
|
4715 |
|
4716 |
|
4717 |
|
4718 |
|
4719 |
|
4720 |
|
4721 |
|
4722 |
|
4723 |
|
4724 |
|
4725 |
|
4726 |
|
4727 | function getFormat($$, typeValue, v) {
|
4728 | var config = $$.config;
|
4729 | var type = "axis_" + typeValue + "_tick_format";
|
4730 | var format = config[type] ?
|
4731 | config[type] : $$.defaultValueFormat;
|
4732 | return format(v);
|
4733 | }
|
4734 | var format = {
|
4735 | getYFormat: function (forArc) {
|
4736 | var $$ = this;
|
4737 | var yFormat = $$.yFormat, y2Format = $$.y2Format;
|
4738 | if (forArc && !$$.hasType("gauge")) {
|
4739 | yFormat = $$.defaultArcValueFormat;
|
4740 | y2Format = $$.defaultArcValueFormat;
|
4741 | }
|
4742 | return function (v, ratio, id) {
|
4743 | var format = $$.axis && $$.axis.getId(id) === "y2" ?
|
4744 | y2Format : yFormat;
|
4745 | return format.call($$, v, ratio);
|
4746 | };
|
4747 | },
|
4748 | yFormat: function (v) {
|
4749 | return getFormat(this, "y", v);
|
4750 | },
|
4751 | y2Format: function (v) {
|
4752 | return getFormat(this, "y2", v);
|
4753 | },
|
4754 | defaultValueFormat: function (v) {
|
4755 | return isValue(v) ? +v : "";
|
4756 | },
|
4757 | defaultArcValueFormat: function (v, ratio) {
|
4758 | return (ratio * 100).toFixed(1) + "%";
|
4759 | },
|
4760 | dataLabelFormat: function (targetId) {
|
4761 | var $$ = this;
|
4762 | var dataLabels = $$.config.data_labels;
|
4763 | var defaultFormat = function (v) { return (isValue(v) ? +v : ""); };
|
4764 | var format = defaultFormat;
|
4765 |
|
4766 | if (isFunction(dataLabels.format)) {
|
4767 | format = dataLabels.format;
|
4768 | }
|
4769 | else if (isObjectType(dataLabels.format)) {
|
4770 | if (dataLabels.format[targetId]) {
|
4771 | format = dataLabels.format[targetId] === true ?
|
4772 | defaultFormat : dataLabels.format[targetId];
|
4773 | }
|
4774 | else {
|
4775 | format = function () { return ""; };
|
4776 | }
|
4777 | }
|
4778 | return format.bind($$.api);
|
4779 | }
|
4780 | };
|
4781 |
|
4782 |
|
4783 |
|
4784 |
|
4785 |
|
4786 | var legend$1 = {
|
4787 | |
4788 |
|
4789 |
|
4790 |
|
4791 | initLegend: function () {
|
4792 | var $$ = this;
|
4793 | var config = $$.config, $el = $$.$el;
|
4794 | $$.legendItemTextBox = {};
|
4795 | $$.state.legendHasRendered = false;
|
4796 | if (config.legend_show) {
|
4797 | if (!config.legend_contents_bindto) {
|
4798 | $el.legend = $$.$el.svg.append("g")
|
4799 | .classed(CLASS.legend, true)
|
4800 | .attr("transform", $$.getTranslate("legend"));
|
4801 | }
|
4802 |
|
4803 |
|
4804 | $$.updateLegend();
|
4805 | }
|
4806 | else {
|
4807 | $$.state.hiddenLegendIds = $$.mapToIds($$.data.targets);
|
4808 | }
|
4809 | },
|
4810 | |
4811 |
|
4812 |
|
4813 |
|
4814 |
|
4815 |
|
4816 |
|
4817 | updateLegend: function (targetIds, options, transitions) {
|
4818 | var $$ = this;
|
4819 | var config = $$.config, state = $$.state, scale = $$.scale, $el = $$.$el;
|
4820 | var optionz = options || {
|
4821 | withTransform: false,
|
4822 | withTransitionForTransform: false,
|
4823 | withTransition: false
|
4824 | };
|
4825 | optionz.withTransition = getOption(optionz, "withTransition", true);
|
4826 | optionz.withTransitionForTransform = getOption(optionz, "withTransitionForTransform", true);
|
4827 | if (config.legend_contents_bindto && config.legend_contents_template) {
|
4828 | $$.updateLegendTemplate();
|
4829 | }
|
4830 | else {
|
4831 | $$.updateLegendElement(targetIds || $$.mapToIds($$.data.targets), optionz, transitions);
|
4832 | }
|
4833 |
|
4834 | $el.legend.selectAll("." + CLASS.legendItem)
|
4835 | .classed(CLASS.legendItemHidden, function (id) {
|
4836 | var hide = !$$.isTargetToShow(id);
|
4837 | if (hide) {
|
4838 | this.style.opacity = null;
|
4839 | }
|
4840 | return hide;
|
4841 | });
|
4842 |
|
4843 | $$.updateScales(false, !scale.zoom);
|
4844 | $$.updateSvgSize();
|
4845 |
|
4846 | $$.transformAll(optionz.withTransitionForTransform, transitions);
|
4847 | state.legendHasRendered = true;
|
4848 | },
|
4849 | |
4850 |
|
4851 |
|
4852 |
|
4853 | updateLegendTemplate: function () {
|
4854 | var $$ = this;
|
4855 | var config = $$.config, $el = $$.$el;
|
4856 | var wrapper = select(config.legend_contents_bindto);
|
4857 | var template = config.legend_contents_template;
|
4858 | if (!wrapper.empty()) {
|
4859 | var targets = $$.mapToIds($$.data.targets);
|
4860 | var ids_1 = [];
|
4861 | var html_1 = "";
|
4862 | targets.forEach(function (v) {
|
4863 | var content = isFunction(template) ?
|
4864 | template.bind($$.api)(v, $$.color(v), $$.api.data(v)[0].values) :
|
4865 | tplProcess(template, {
|
4866 | COLOR: $$.color(v),
|
4867 | TITLE: v
|
4868 | });
|
4869 | if (content) {
|
4870 | ids_1.push(v);
|
4871 | html_1 += content;
|
4872 | }
|
4873 | });
|
4874 | var legendItem = wrapper.html(html_1)
|
4875 | .selectAll(function () { return this.childNodes; })
|
4876 | .data(ids_1);
|
4877 | $$.setLegendItem(legendItem);
|
4878 | $el.legend = wrapper;
|
4879 | }
|
4880 | },
|
4881 | |
4882 |
|
4883 |
|
4884 |
|
4885 |
|
4886 | updateSizeForLegend: function (size) {
|
4887 | var $$ = this;
|
4888 | var config = $$.config, _a = $$.state, isLegendTop = _a.isLegendTop, isLegendLeft = _a.isLegendLeft, isLegendRight = _a.isLegendRight, isLegendInset = _a.isLegendInset, current = _a.current;
|
4889 | var width = size.width, height = size.height;
|
4890 | var insetLegendPosition = {
|
4891 | top: isLegendTop ?
|
4892 | $$.getCurrentPaddingTop() + config.legend_inset_y + 5.5 :
|
4893 | current.height - height - $$.getCurrentPaddingBottom() - config.legend_inset_y,
|
4894 | left: isLegendLeft ?
|
4895 | $$.getCurrentPaddingLeft() + config.legend_inset_x + 0.5 :
|
4896 | current.width - width - $$.getCurrentPaddingRight() - config.legend_inset_x + 0.5
|
4897 | };
|
4898 | $$.state.margin3 = {
|
4899 | top: isLegendRight ?
|
4900 | 0 : isLegendInset ? insetLegendPosition.top : current.height - height,
|
4901 | right: NaN,
|
4902 | bottom: 0,
|
4903 | left: isLegendRight ?
|
4904 | current.width - width : isLegendInset ? insetLegendPosition.left : 0
|
4905 | };
|
4906 | },
|
4907 | |
4908 |
|
4909 |
|
4910 |
|
4911 |
|
4912 | transformLegend: function (withTransition) {
|
4913 | var $$ = this;
|
4914 | var legend = $$.$el.legend;
|
4915 | (withTransition ? legend.transition() : legend)
|
4916 | .attr("transform", $$.getTranslate("legend"));
|
4917 | },
|
4918 | |
4919 |
|
4920 |
|
4921 |
|
4922 |
|
4923 | updateLegendStep: function (step) {
|
4924 | this.state.legendStep = step;
|
4925 | },
|
4926 | |
4927 |
|
4928 |
|
4929 |
|
4930 |
|
4931 | updateLegendItemWidth: function (width) {
|
4932 | this.state.legendItemWidth = width;
|
4933 | },
|
4934 | |
4935 |
|
4936 |
|
4937 |
|
4938 |
|
4939 | updateLegendItemHeight: function (height) {
|
4940 | this.state.legendItemHeight = height;
|
4941 | },
|
4942 | |
4943 |
|
4944 |
|
4945 |
|
4946 |
|
4947 |
|
4948 | updateLegendItemColor: function (id, color) {
|
4949 | var legend = this.$el.legend;
|
4950 | if (legend) {
|
4951 | legend.select("." + CLASS.legendItem + "-" + id + " line")
|
4952 | .style("stroke", color);
|
4953 | }
|
4954 | },
|
4955 | |
4956 |
|
4957 |
|
4958 |
|
4959 |
|
4960 | getLegendWidth: function () {
|
4961 | var $$ = this;
|
4962 | var _a = $$.state, width = _a.current.width, isLegendRight = _a.isLegendRight, isLegendInset = _a.isLegendInset, legendItemWidth = _a.legendItemWidth, legendStep = _a.legendStep;
|
4963 | return $$.config.legend_show ? (isLegendRight || isLegendInset ?
|
4964 | legendItemWidth * (legendStep + 1) : width) : 0;
|
4965 | },
|
4966 | |
4967 |
|
4968 |
|
4969 |
|
4970 |
|
4971 | getLegendHeight: function () {
|
4972 | var $$ = this;
|
4973 | var _a = $$.state, current = _a.current, isLegendRight = _a.isLegendRight, legendItemHeight = _a.legendItemHeight, legendStep = _a.legendStep;
|
4974 | return $$.config.legend_show ? (isLegendRight ?
|
4975 | current.height : Math.max(20, legendItemHeight) * (legendStep + 1)) : 0;
|
4976 | },
|
4977 | |
4978 |
|
4979 |
|
4980 |
|
4981 |
|
4982 |
|
4983 | opacityForLegend: function (legendItem) {
|
4984 | return legendItem.classed(CLASS.legendItemHidden) ? null : "1";
|
4985 | },
|
4986 | |
4987 |
|
4988 |
|
4989 |
|
4990 |
|
4991 |
|
4992 | opacityForUnfocusedLegend: function (legendItem) {
|
4993 | return legendItem.classed(CLASS.legendItemHidden) ? null : "0.3";
|
4994 | },
|
4995 | |
4996 |
|
4997 |
|
4998 |
|
4999 |
|
5000 |
|
5001 | toggleFocusLegend: function (targetIds, focus) {
|
5002 | var $$ = this;
|
5003 | var legend = $$.$el.legend;
|
5004 | var targetIdz = $$.mapToTargetIds(targetIds);
|
5005 | legend && legend.selectAll("." + CLASS.legendItem)
|
5006 | .filter(function (id) { return targetIdz.indexOf(id) >= 0; })
|
5007 | .classed(CLASS.legendItemFocused, focus)
|
5008 | .transition()
|
5009 | .duration(100)
|
5010 | .style("opacity", function () {
|
5011 | return (focus ? $$.opacityForLegend : $$.opacityForUnfocusedLegend)
|
5012 | .call($$, select(this));
|
5013 | });
|
5014 | },
|
5015 | |
5016 |
|
5017 |
|
5018 |
|
5019 | revertLegend: function () {
|
5020 | var $$ = this;
|
5021 | var legend = $$.$el.legend;
|
5022 | legend && legend.selectAll("." + CLASS.legendItem)
|
5023 | .classed(CLASS.legendItemFocused, false)
|
5024 | .transition()
|
5025 | .duration(100)
|
5026 | .style("opacity", function () {
|
5027 | return $$.opacityForLegend(select(this));
|
5028 | });
|
5029 | },
|
5030 | |
5031 |
|
5032 |
|
5033 |
|
5034 |
|
5035 | showLegend: function (targetIds) {
|
5036 | var $$ = this;
|
5037 | var config = $$.config, $el = $$.$el;
|
5038 | if (!config.legend_show) {
|
5039 | config.legend_show = true;
|
5040 | $el.legend ?
|
5041 | $el.legend.style("visibility", "visible") :
|
5042 | $$.initLegend();
|
5043 | !$$.state.legendHasRendered && $$.updateLegend();
|
5044 | }
|
5045 | $$.removeHiddenLegendIds(targetIds);
|
5046 | $el.legend.selectAll($$.selectorLegends(targetIds))
|
5047 | .style("visibility", "visible")
|
5048 | .transition()
|
5049 | .style("opacity", function () {
|
5050 | return $$.opacityForLegend(select(this));
|
5051 | });
|
5052 | },
|
5053 | |
5054 |
|
5055 |
|
5056 |
|
5057 |
|
5058 | hideLegend: function (targetIds) {
|
5059 | var $$ = this;
|
5060 | var config = $$.config, legend = $$.$el.legend;
|
5061 | if (config.legend_show && isEmpty(targetIds)) {
|
5062 | config.legend_show = false;
|
5063 | legend.style("visibility", "hidden");
|
5064 | }
|
5065 | $$.addHiddenLegendIds(targetIds);
|
5066 | legend.selectAll($$.selectorLegends(targetIds))
|
5067 | .style("opacity", "0")
|
5068 | .style("visibility", "hidden");
|
5069 | },
|
5070 | |
5071 |
|
5072 |
|
5073 |
|
5074 |
|
5075 |
|
5076 |
|
5077 | getLegendItemTextBox: function (id, textElement) {
|
5078 | var $$ = this;
|
5079 | var cache = $$.cache, state = $$.state;
|
5080 | var data;
|
5081 |
|
5082 | var cacheKey = KEY.legendItemTextBox;
|
5083 | if (id) {
|
5084 | data = (!state.redrawing && cache.get(cacheKey)) || {};
|
5085 | if (!data[id]) {
|
5086 | data[id] = $$.getTextRect(textElement, CLASS.legendItem);
|
5087 | cache.add(cacheKey, data);
|
5088 | }
|
5089 | data = data[id];
|
5090 | }
|
5091 | return data;
|
5092 | },
|
5093 | |
5094 |
|
5095 |
|
5096 |
|
5097 |
|
5098 | setLegendItem: function (item) {
|
5099 | var $$ = this;
|
5100 | var api = $$.api, config = $$.config, state = $$.state;
|
5101 | var isTouch = state.inputType === "touch";
|
5102 | var hasGauge = $$.hasType("gauge");
|
5103 | item
|
5104 | .attr("class", function (id) {
|
5105 | var node = select(this);
|
5106 | var itemClass = (!node.empty() && node.attr("class")) || "";
|
5107 | return itemClass + $$.generateClass(CLASS.legendItem, id);
|
5108 | })
|
5109 | .style("visibility", function (id) { return ($$.isLegendToShow(id) ? "visible" : "hidden"); });
|
5110 | if (config.interaction_enabled) {
|
5111 | item
|
5112 | .style("cursor", "pointer")
|
5113 | .on("click", function (event, id) {
|
5114 | if (!callFn(config.legend_item_onclick, api, id)) {
|
5115 | if (event.altKey) {
|
5116 | api.hide();
|
5117 | api.show(id);
|
5118 | }
|
5119 | else {
|
5120 | api.toggle(id);
|
5121 | select(this)
|
5122 | .classed(CLASS.legendItemFocused, false)
|
5123 | .style("opacity", null);
|
5124 | }
|
5125 | }
|
5126 | isTouch && $$.hideTooltip();
|
5127 | });
|
5128 | !isTouch && item
|
5129 | .on("mouseout", function (event, id) {
|
5130 | if (!callFn(config.legend_item_onout, api, id)) {
|
5131 | select(this).classed(CLASS.legendItemFocused, false);
|
5132 | if (hasGauge) {
|
5133 | $$.undoMarkOverlapped($$, "." + CLASS.gaugeValue);
|
5134 | }
|
5135 | $$.api.revert();
|
5136 | }
|
5137 | })
|
5138 | .on("mouseover", function (event, id) {
|
5139 | if (!callFn(config.legend_item_onover, api, id)) {
|
5140 | select(this).classed(CLASS.legendItemFocused, true);
|
5141 | if (hasGauge) {
|
5142 | $$.markOverlapped(id, $$, "." + CLASS.gaugeValue);
|
5143 | }
|
5144 | if (!state.transiting && $$.isTargetToShow(id)) {
|
5145 | api.focus(id);
|
5146 | }
|
5147 | }
|
5148 | });
|
5149 | }
|
5150 | },
|
5151 | |
5152 |
|
5153 |
|
5154 |
|
5155 |
|
5156 |
|
5157 | updateLegendElement: function (targetIds, options) {
|
5158 | var $$ = this;
|
5159 | var config = $$.config, state = $$.state, legend = $$.$el.legend;
|
5160 | var paddingTop = 4;
|
5161 | var paddingRight = 10;
|
5162 | var posMin = 10;
|
5163 | var tileWidth = config.legend_item_tile_width + 5;
|
5164 | var maxWidth = 0;
|
5165 | var maxHeight = 0;
|
5166 | var xForLegend;
|
5167 | var yForLegend;
|
5168 | var totalLength = 0;
|
5169 | var offsets = {};
|
5170 | var widths = {};
|
5171 | var heights = {};
|
5172 | var margins = [0];
|
5173 | var steps = {};
|
5174 | var step = 0;
|
5175 | var background;
|
5176 | var isLegendRightOrInset = state.isLegendRight || state.isLegendInset;
|
5177 |
|
5178 | var targetIdz = targetIds
|
5179 | .filter(function (id) { return !isDefined(config.data_names[id]) || config.data_names[id] !== null; });
|
5180 | var withTransition = options.withTransition;
|
5181 | var updatePositions = function (textElement, id, index) {
|
5182 | var reset = index === 0;
|
5183 | var isLast = index === targetIdz.length - 1;
|
5184 | var box = $$.getLegendItemTextBox(id, textElement);
|
5185 | var itemWidth = box.width + tileWidth +
|
5186 | (isLast && !isLegendRightOrInset ? 0 : paddingRight) + config.legend_padding;
|
5187 | var itemHeight = box.height + paddingTop;
|
5188 | var itemLength = isLegendRightOrInset ? itemHeight : itemWidth;
|
5189 | var areaLength = isLegendRightOrInset ? $$.getLegendHeight() : $$.getLegendWidth();
|
5190 | var margin;
|
5191 |
|
5192 | var updateValues = function (id2, withoutStep) {
|
5193 | if (!withoutStep) {
|
5194 | margin = (areaLength - totalLength - itemLength) / 2;
|
5195 | if (margin < posMin) {
|
5196 | margin = (areaLength - itemLength) / 2;
|
5197 | totalLength = 0;
|
5198 | step++;
|
5199 | }
|
5200 | }
|
5201 | steps[id2] = step;
|
5202 | margins[step] = state.isLegendInset ? 10 : margin;
|
5203 | offsets[id2] = totalLength;
|
5204 | totalLength += itemLength;
|
5205 | };
|
5206 | if (reset) {
|
5207 | totalLength = 0;
|
5208 | step = 0;
|
5209 | maxWidth = 0;
|
5210 | maxHeight = 0;
|
5211 | }
|
5212 | if (config.legend_show && !$$.isLegendToShow(id)) {
|
5213 | widths[id] = 0;
|
5214 | heights[id] = 0;
|
5215 | steps[id] = 0;
|
5216 | offsets[id] = 0;
|
5217 | return;
|
5218 | }
|
5219 | widths[id] = itemWidth;
|
5220 | heights[id] = itemHeight;
|
5221 | if (!maxWidth || itemWidth >= maxWidth) {
|
5222 | maxWidth = itemWidth;
|
5223 | }
|
5224 | if (!maxHeight || itemHeight >= maxHeight) {
|
5225 | maxHeight = itemHeight;
|
5226 | }
|
5227 | var maxLength = isLegendRightOrInset ? maxHeight : maxWidth;
|
5228 | if (config.legend_equally) {
|
5229 | Object.keys(widths).forEach(function (id2) { return (widths[id2] = maxWidth); });
|
5230 | Object.keys(heights).forEach(function (id2) { return (heights[id2] = maxHeight); });
|
5231 | margin = (areaLength - maxLength * targetIdz.length) / 2;
|
5232 | if (margin < posMin) {
|
5233 | totalLength = 0;
|
5234 | step = 0;
|
5235 | targetIdz.forEach(function (id2) { return updateValues(id2); });
|
5236 | }
|
5237 | else {
|
5238 | updateValues(id, true);
|
5239 | }
|
5240 | }
|
5241 | else {
|
5242 | updateValues(id);
|
5243 | }
|
5244 | };
|
5245 | if (state.isLegendInset) {
|
5246 | step = config.legend_inset_step ? config.legend_inset_step : targetIdz.length;
|
5247 | $$.updateLegendStep(step);
|
5248 | }
|
5249 | if (state.isLegendRight) {
|
5250 | xForLegend = function (id) { return maxWidth * steps[id]; };
|
5251 | yForLegend = function (id) { return margins[steps[id]] + offsets[id]; };
|
5252 | }
|
5253 | else if (state.isLegendInset) {
|
5254 | xForLegend = function (id) { return maxWidth * steps[id] + 10; };
|
5255 | yForLegend = function (id) { return margins[steps[id]] + offsets[id]; };
|
5256 | }
|
5257 | else {
|
5258 | xForLegend = function (id) { return margins[steps[id]] + offsets[id]; };
|
5259 | yForLegend = function (id) { return maxHeight * steps[id]; };
|
5260 | }
|
5261 | var xForLegendText = function (id, i) { return xForLegend(id, i) + 4 + config.legend_item_tile_width; };
|
5262 | var xForLegendRect = function (id, i) { return xForLegend(id, i); };
|
5263 | var x1ForLegendTile = function (id, i) { return xForLegend(id, i) - 2; };
|
5264 | var x2ForLegendTile = function (id, i) { return xForLegend(id, i) - 2 + config.legend_item_tile_width; };
|
5265 | var yForLegendText = function (id, i) { return yForLegend(id, i) + 9; };
|
5266 | var yForLegendRect = function (id, i) { return yForLegend(id, i) - 5; };
|
5267 | var yForLegendTile = function (id, i) { return yForLegend(id, i) + 4; };
|
5268 | var pos = -200;
|
5269 |
|
5270 | var l = legend.selectAll("." + CLASS.legendItem)
|
5271 | .data(targetIdz)
|
5272 | .enter()
|
5273 | .append("g");
|
5274 | $$.setLegendItem(l);
|
5275 | l.append("text")
|
5276 | .text(function (id) { return (isDefined(config.data_names[id]) ? config.data_names[id] : id); })
|
5277 | .each(function (id, i) {
|
5278 | updatePositions(this, id, i);
|
5279 | })
|
5280 | .style("pointer-events", "none")
|
5281 | .attr("x", isLegendRightOrInset ? xForLegendText : pos)
|
5282 | .attr("y", isLegendRightOrInset ? pos : yForLegendText);
|
5283 | l.append("rect")
|
5284 | .attr("class", CLASS.legendItemEvent)
|
5285 | .style("fill-opacity", "0")
|
5286 | .attr("x", isLegendRightOrInset ? xForLegendRect : pos)
|
5287 | .attr("y", isLegendRightOrInset ? pos : yForLegendRect);
|
5288 | var getColor = function (id) {
|
5289 | var data = $$.getDataById(id);
|
5290 | return $$.levelColor ?
|
5291 | $$.levelColor(data.values[0].value) :
|
5292 | $$.color(data);
|
5293 | };
|
5294 | var usePoint = config.legend_usePoint;
|
5295 | if (usePoint) {
|
5296 | var ids_2 = [];
|
5297 | l.append(function (d) {
|
5298 | var pattern = notEmpty(config.point_pattern) ?
|
5299 | config.point_pattern : [config.point_type];
|
5300 | ids_2.indexOf(d) === -1 && ids_2.push(d);
|
5301 | var point = pattern[ids_2.indexOf(d) % pattern.length];
|
5302 | if (point === "rectangle") {
|
5303 | point = "rect";
|
5304 | }
|
5305 | return doc.createElementNS(namespaces.svg, ("hasValidPointType" in $$) && $$.hasValidPointType(point) ? point : "use");
|
5306 | })
|
5307 | .attr("class", CLASS.legendItemPoint)
|
5308 | .style("fill", getColor)
|
5309 | .style("pointer-events", "none")
|
5310 | .attr("href", function (data, idx, selection) {
|
5311 | var node = selection[idx];
|
5312 | var nodeName = node.nodeName.toLowerCase();
|
5313 | return nodeName === "use" ? "#" + state.datetimeId + "-point-" + data : undefined;
|
5314 | });
|
5315 | }
|
5316 | else {
|
5317 | l.append("line")
|
5318 | .attr("class", CLASS.legendItemTile)
|
5319 | .style("stroke", getColor)
|
5320 | .style("pointer-events", "none")
|
5321 | .attr("x1", isLegendRightOrInset ? x1ForLegendTile : pos)
|
5322 | .attr("y1", isLegendRightOrInset ? pos : yForLegendTile)
|
5323 | .attr("x2", isLegendRightOrInset ? x2ForLegendTile : pos)
|
5324 | .attr("y2", isLegendRightOrInset ? pos : yForLegendTile)
|
5325 | .attr("stroke-width", config.legend_item_tile_height);
|
5326 | }
|
5327 |
|
5328 | background = legend.select("." + CLASS.legendBackground + " rect");
|
5329 | if (state.isLegendInset && maxWidth > 0 && background.size() === 0) {
|
5330 | background = legend.insert("g", "." + CLASS.legendItem)
|
5331 | .attr("class", CLASS.legendBackground)
|
5332 | .append("rect");
|
5333 | }
|
5334 | var texts = legend.selectAll("text")
|
5335 | .data(targetIdz)
|
5336 | .text(function (id) { return (isDefined(config.data_names[id]) ? config.data_names[id] : id); })
|
5337 | .each(function (id, i) {
|
5338 | updatePositions(this, id, i);
|
5339 | });
|
5340 | (withTransition ? texts.transition() : texts)
|
5341 | .attr("x", xForLegendText)
|
5342 | .attr("y", yForLegendText);
|
5343 | var rects = legend.selectAll("rect." + CLASS.legendItemEvent)
|
5344 | .data(targetIdz);
|
5345 | (withTransition ? rects.transition() : rects)
|
5346 | .attr("width", function (id) { return widths[id]; })
|
5347 | .attr("height", function (id) { return heights[id]; })
|
5348 | .attr("x", xForLegendRect)
|
5349 | .attr("y", yForLegendRect);
|
5350 | if (usePoint) {
|
5351 | var tiles = legend.selectAll("." + CLASS.legendItemPoint)
|
5352 | .data(targetIdz);
|
5353 | (withTransition ? tiles.transition() : tiles)
|
5354 | .each(function () {
|
5355 | var nodeName = this.nodeName.toLowerCase();
|
5356 | var pointR = config.point_r;
|
5357 | var x = "x";
|
5358 | var y = "y";
|
5359 | var xOffset = 2;
|
5360 | var yOffset = 2.5;
|
5361 | var radius;
|
5362 | var width;
|
5363 | var height;
|
5364 | if (nodeName === "circle") {
|
5365 | var size = pointR * 0.2;
|
5366 | x = "cx";
|
5367 | y = "cy";
|
5368 | radius = pointR + size;
|
5369 | xOffset = pointR * 2;
|
5370 | yOffset = -size;
|
5371 | }
|
5372 | else if (nodeName === "rect") {
|
5373 | var size = pointR * 2.5;
|
5374 | width = size;
|
5375 | height = size;
|
5376 | yOffset = 3;
|
5377 | }
|
5378 | select(this)
|
5379 | .attr(x, function (d) { return x1ForLegendTile(d) + xOffset; })
|
5380 | .attr(y, function (d) { return yForLegendTile(d) - yOffset; })
|
5381 | .attr("r", radius)
|
5382 | .attr("width", width)
|
5383 | .attr("height", height);
|
5384 | });
|
5385 | }
|
5386 | else {
|
5387 | var tiles = legend.selectAll("line." + CLASS.legendItemTile)
|
5388 | .data(targetIdz);
|
5389 | (withTransition ? tiles.transition() : tiles)
|
5390 | .style("stroke", getColor)
|
5391 | .attr("x1", x1ForLegendTile)
|
5392 | .attr("y1", yForLegendTile)
|
5393 | .attr("x2", x2ForLegendTile)
|
5394 | .attr("y2", yForLegendTile);
|
5395 | }
|
5396 | if (background) {
|
5397 | (withTransition ? background.transition() : background)
|
5398 | .attr("height", $$.getLegendHeight() - 12)
|
5399 | .attr("width", maxWidth * (step + 1) + 10);
|
5400 | }
|
5401 |
|
5402 | $$.updateLegendItemWidth(maxWidth);
|
5403 | $$.updateLegendItemHeight(maxHeight);
|
5404 | $$.updateLegendStep(step);
|
5405 | }
|
5406 | };
|
5407 |
|
5408 |
|
5409 |
|
5410 |
|
5411 |
|
5412 | var redraw = {
|
5413 | redraw: function (options) {
|
5414 | if (options === void 0) { options = {}; }
|
5415 | var $$ = this;
|
5416 | var config = $$.config, state = $$.state, $el = $$.$el;
|
5417 | var main = $el.main;
|
5418 | state.redrawing = true;
|
5419 | var targetsToShow = $$.filterTargetsToShow($$.data.targets);
|
5420 | var initializing = options.initializing;
|
5421 | var flow = options.flow;
|
5422 | var wth = $$.getWithOption(options);
|
5423 | var duration = wth.Transition ? config.transition_duration : 0;
|
5424 | var durationForExit = wth.TransitionForExit ? duration : 0;
|
5425 | var durationForAxis = wth.TransitionForAxis ? duration : 0;
|
5426 | var transitions = $$.axis && $$.axis.generateTransitions(durationForAxis);
|
5427 | $$.updateSizes(initializing);
|
5428 |
|
5429 | if (wth.Legend && config.legend_show) {
|
5430 | options.withTransition = !!duration;
|
5431 | $$.updateLegend($$.mapToIds($$.data.targets), options, transitions);
|
5432 | }
|
5433 | else if (wth.Dimension) {
|
5434 |
|
5435 |
|
5436 | $$.updateDimension(true);
|
5437 | }
|
5438 |
|
5439 | if (!$$.hasArcType() || state.hasRadar) {
|
5440 | $$.updateCircleY && ($$.circleY = $$.updateCircleY());
|
5441 | }
|
5442 |
|
5443 | if (state.hasAxis) {
|
5444 |
|
5445 | $$.axis.redrawAxis(targetsToShow, wth, transitions, flow, initializing);
|
5446 |
|
5447 | config.data_empty_label_text && main.select("text." + CLASS.text + "." + CLASS.empty)
|
5448 | .attr("x", state.width / 2)
|
5449 | .attr("y", state.height / 2)
|
5450 | .text(config.data_empty_label_text)
|
5451 | .style("display", targetsToShow.length ? "none" : null);
|
5452 |
|
5453 | $$.hasGrid() && $$.updateGrid(duration);
|
5454 |
|
5455 | config.regions.length && $$.updateRegion(duration);
|
5456 | ["bar", "candlestick", "line", "area"].forEach(function (v) {
|
5457 | var name = capitalize(v);
|
5458 | if ((/^(line|area)$/.test(v) && $$.hasTypeOf(name)) || $$.hasType(v)) {
|
5459 | $$["update" + name](durationForExit);
|
5460 | }
|
5461 | });
|
5462 |
|
5463 | $el.text && main.selectAll("." + CLASS.selectedCircles)
|
5464 | .filter($$.isBarType.bind($$))
|
5465 | .selectAll("circle")
|
5466 | .remove();
|
5467 |
|
5468 | if (config.interaction_enabled && !flow && wth.EventRect) {
|
5469 | $$.redrawEventRect();
|
5470 | $$.bindZoomEvent && $$.bindZoomEvent();
|
5471 | }
|
5472 | }
|
5473 | else {
|
5474 |
|
5475 | $el.arcs && $$.redrawArc(duration, durationForExit, wth.Transform);
|
5476 |
|
5477 | $el.radar && $$.redrawRadar(durationForExit);
|
5478 | }
|
5479 |
|
5480 | if (!state.resizing && ($$.hasPointType() || state.hasRadar)) {
|
5481 | $$.updateCircle();
|
5482 | }
|
5483 |
|
5484 | $$.hasDataLabel() && !$$.hasArcType(null, ["radar"]) && $$.updateText(durationForExit);
|
5485 |
|
5486 | $$.redrawTitle && $$.redrawTitle();
|
5487 | initializing && $$.updateTypesElements();
|
5488 | $$.generateRedrawList(targetsToShow, flow, duration, wth.Subchart);
|
5489 | $$.callPluginHook("$redraw", options, duration);
|
5490 | },
|
5491 | |
5492 |
|
5493 |
|
5494 |
|
5495 |
|
5496 |
|
5497 |
|
5498 |
|
5499 | generateRedrawList: function (targets, flow, duration, withSubchart) {
|
5500 | var $$ = this;
|
5501 | var config = $$.config, state = $$.state;
|
5502 | var shape = $$.getDrawShape();
|
5503 | if (state.hasAxis) {
|
5504 |
|
5505 | config.subchart_show && $$.redrawSubchart(withSubchart, duration, shape);
|
5506 | }
|
5507 |
|
5508 | var flowFn = flow && $$.generateFlow({
|
5509 | targets: targets,
|
5510 | flow: flow,
|
5511 | duration: flow.duration,
|
5512 | shape: shape,
|
5513 | xv: $$.xv.bind($$)
|
5514 | });
|
5515 | var isTransition = (duration || flowFn) && isTabVisible();
|
5516 |
|
5517 | var redrawList = $$.getRedrawList(shape, flow, flowFn, isTransition);
|
5518 |
|
5519 | var afterRedraw = flow || config.onrendered ? function () {
|
5520 | flowFn && flowFn();
|
5521 | state.redrawing = false;
|
5522 | callFn(config.onrendered, $$.api);
|
5523 | } : null;
|
5524 | if (afterRedraw) {
|
5525 |
|
5526 | if (isTransition && redrawList.length) {
|
5527 |
|
5528 | var waitForDraw_1 = generateWait();
|
5529 |
|
5530 | transition().duration(duration)
|
5531 | .each(function () {
|
5532 | redrawList
|
5533 | .reduce(function (acc, t1) { return acc.concat(t1); }, [])
|
5534 | .forEach(function (t) { return waitForDraw_1.add(t); });
|
5535 | })
|
5536 | .call(waitForDraw_1, afterRedraw);
|
5537 | }
|
5538 | else if (!state.transiting) {
|
5539 | afterRedraw();
|
5540 | }
|
5541 | }
|
5542 |
|
5543 | $$.mapToIds($$.data.targets).forEach(function (id) {
|
5544 | state.withoutFadeIn[id] = true;
|
5545 | });
|
5546 | },
|
5547 | getRedrawList: function (shape, flow, flowFn, isTransition) {
|
5548 | var $$ = this;
|
5549 | var config = $$.config, _a = $$.state, hasAxis = _a.hasAxis, hasRadar = _a.hasRadar, grid = $$.$el.grid;
|
5550 | var _b = shape.pos, cx = _b.cx, cy = _b.cy, xForText = _b.xForText, yForText = _b.yForText;
|
5551 | var list = [];
|
5552 | if (hasAxis) {
|
5553 | if (config.grid_x_lines.length || config.grid_y_lines.length) {
|
5554 | list.push($$.redrawGrid(isTransition));
|
5555 | }
|
5556 | if (config.regions.length) {
|
5557 | list.push($$.redrawRegion(isTransition));
|
5558 | }
|
5559 | Object.keys(shape.type).forEach(function (v) {
|
5560 | var name = capitalize(v);
|
5561 | var drawFn = shape.type[v];
|
5562 | if ((/^(area|line)$/.test(v) && $$.hasTypeOf(name)) || $$.hasType(v)) {
|
5563 | list.push($$["redraw" + name](drawFn, isTransition));
|
5564 | }
|
5565 | });
|
5566 | !flow && grid.main && list.push($$.updateGridFocus());
|
5567 | }
|
5568 | if (!$$.hasArcType() || hasRadar) {
|
5569 | notEmpty(config.data_labels) && config.data_labels !== false &&
|
5570 | list.push($$.redrawText(xForText, yForText, flow, isTransition));
|
5571 | }
|
5572 | if (($$.hasPointType() || hasRadar) && !config.point_focus_only) {
|
5573 | $$.redrawCircle && list.push($$.redrawCircle(cx, cy, isTransition, flowFn));
|
5574 | }
|
5575 | return list;
|
5576 | },
|
5577 | updateAndRedraw: function (options) {
|
5578 | if (options === void 0) { options = {}; }
|
5579 | var $$ = this;
|
5580 | var config = $$.config, state = $$.state;
|
5581 | var transitions;
|
5582 |
|
5583 | options.withTransition = getOption(options, "withTransition", true);
|
5584 | options.withTransform = getOption(options, "withTransform", false);
|
5585 | options.withLegend = getOption(options, "withLegend", false);
|
5586 |
|
5587 | options.withUpdateXDomain = true;
|
5588 | options.withUpdateOrgXDomain = true;
|
5589 | options.withTransitionForExit = false;
|
5590 | options.withTransitionForTransform = getOption(options, "withTransitionForTransform", options.withTransition);
|
5591 |
|
5592 | if (!(options.withLegend && config.legend_show)) {
|
5593 | if (state.hasAxis) {
|
5594 | transitions = $$.axis.generateTransitions(options.withTransitionForAxis ? config.transition_duration : 0);
|
5595 | }
|
5596 |
|
5597 | $$.updateScales();
|
5598 | $$.updateSvgSize();
|
5599 |
|
5600 | $$.transformAll(options.withTransitionForTransform, transitions);
|
5601 | }
|
5602 |
|
5603 | $$.redraw(options, transitions);
|
5604 | },
|
5605 | redrawWithoutRescale: function () {
|
5606 | this.redraw({
|
5607 | withY: false,
|
5608 | withSubchart: false,
|
5609 | withEventRect: false,
|
5610 | withTransitionForAxis: false
|
5611 | });
|
5612 | }
|
5613 | };
|
5614 |
|
5615 |
|
5616 |
|
5617 |
|
5618 |
|
5619 |
|
5620 |
|
5621 |
|
5622 |
|
5623 |
|
5624 |
|
5625 |
|
5626 |
|
5627 | function getScale(type, min, max) {
|
5628 | if (type === void 0) { type = "linear"; }
|
5629 | if (min === void 0) { min = 0; }
|
5630 | if (max === void 0) { max = 1; }
|
5631 | var scale = ({
|
5632 | linear: scaleLinear,
|
5633 | log: scaleSymlog,
|
5634 | _log: scaleLog,
|
5635 | time: scaleTime
|
5636 | })[type]();
|
5637 | scale.type = type;
|
5638 | /_?log/.test(type) && scale.clamp(true);
|
5639 | return scale.range([min, max]);
|
5640 | }
|
5641 | var scale = {
|
5642 | |
5643 |
|
5644 |
|
5645 |
|
5646 |
|
5647 |
|
5648 |
|
5649 |
|
5650 |
|
5651 | getXScale: function (min, max, domain, offset) {
|
5652 | var $$ = this;
|
5653 | var scale = $$.scale.zoom || getScale($$.axis.getAxisType("x"), min, max);
|
5654 | return $$.getCustomizedScale(domain ? scale.domain(domain) : scale, offset);
|
5655 | },
|
5656 | |
5657 |
|
5658 |
|
5659 |
|
5660 |
|
5661 |
|
5662 |
|
5663 |
|
5664 |
|
5665 | getYScale: function (id, min, max, domain) {
|
5666 | var $$ = this;
|
5667 | var scale = getScale($$.axis.getAxisType(id), min, max);
|
5668 | domain && scale.domain(domain);
|
5669 | return scale;
|
5670 | },
|
5671 | |
5672 |
|
5673 |
|
5674 |
|
5675 |
|
5676 |
|
5677 |
|
5678 | getYScaleById: function (id, isSub) {
|
5679 | if (isSub === void 0) { isSub = false; }
|
5680 | var isY2 = this.axis.getId(id) === "y2";
|
5681 | var key = isSub ? (isY2 ? "subY2" : "subY") : (isY2 ? "y2" : "y");
|
5682 | return this.scale[key];
|
5683 | },
|
5684 | |
5685 |
|
5686 |
|
5687 |
|
5688 |
|
5689 |
|
5690 |
|
5691 | getCustomizedScale: function (scaleValue, offsetValue) {
|
5692 | var $$ = this;
|
5693 | var offset = offsetValue || (function () { return $$.axis.x.tickOffset(); });
|
5694 | var scale = function (d, raw) {
|
5695 | var v = scaleValue(d) + offset();
|
5696 | return raw ? v : Math.ceil(v);
|
5697 | };
|
5698 |
|
5699 | for (var key in scaleValue) {
|
5700 | scale[key] = scaleValue[key];
|
5701 | }
|
5702 | scale.orgDomain = function () { return scaleValue.domain(); };
|
5703 | scale.orgScale = function () { return scaleValue; };
|
5704 |
|
5705 | if ($$.axis.isCategorized()) {
|
5706 | scale.domain = function (domainValue) {
|
5707 | var domain = domainValue;
|
5708 | if (!arguments.length) {
|
5709 | domain = this.orgDomain();
|
5710 | return [domain[0], domain[1] + 1];
|
5711 | }
|
5712 | scaleValue.domain(domain);
|
5713 | return scale;
|
5714 | };
|
5715 | }
|
5716 | return scale;
|
5717 | },
|
5718 | |
5719 |
|
5720 |
|
5721 |
|
5722 |
|
5723 |
|
5724 | updateScales: function (isInit, updateXDomain) {
|
5725 | if (updateXDomain === void 0) { updateXDomain = true; }
|
5726 | var $$ = this;
|
5727 | var axis = $$.axis, config = $$.config, format = $$.format, org = $$.org, scale = $$.scale, _a = $$.state, width = _a.width, height = _a.height, width2 = _a.width2, height2 = _a.height2, hasAxis = _a.hasAxis;
|
5728 | if (hasAxis) {
|
5729 | var isRotated = config.axis_rotated;
|
5730 |
|
5731 | var min = {
|
5732 | x: isRotated ? 1 : 0,
|
5733 | y: isRotated ? 0 : height,
|
5734 | subX: isRotated ? 1 : 0,
|
5735 | subY: isRotated ? 0 : height2
|
5736 | };
|
5737 | var max = {
|
5738 | x: isRotated ? height : width,
|
5739 | y: isRotated ? width : 1,
|
5740 | subX: isRotated ? height : width,
|
5741 | subY: isRotated ? width2 : 1
|
5742 | };
|
5743 |
|
5744 |
|
5745 | var xDomain = updateXDomain && scale.x && scale.x.orgDomain();
|
5746 | var xSubDomain = updateXDomain && org.xDomain;
|
5747 | scale.x = $$.getXScale(min.x, max.x, xDomain, function () { return axis.x.tickOffset(); });
|
5748 | scale.subX = $$.getXScale(min.x, max.x, xSubDomain, function (d) { return (d % 1 ? 0 : axis.subX.tickOffset()); });
|
5749 | format.xAxisTick = axis.getXAxisTickFormat();
|
5750 | axis.setAxis("x", scale.x, config.axis_x_tick_outer, isInit);
|
5751 | if (config.subchart_show) {
|
5752 | axis.setAxis("subX", scale.subX, config.axis_x_tick_outer, isInit);
|
5753 | }
|
5754 |
|
5755 | scale.y = $$.getYScale("y", min.y, max.y, scale.y ? scale.y.domain() : config.axis_y_default);
|
5756 | scale.subY = $$.getYScale("y", min.subY, max.subY, scale.subY ? scale.subY.domain() : config.axis_y_default);
|
5757 | axis.setAxis("y", scale.y, config.axis_y_tick_outer, isInit);
|
5758 |
|
5759 | if (config.axis_y2_show) {
|
5760 | scale.y2 = $$.getYScale("y2", min.y, max.y, scale.y2 ? scale.y2.domain() : config.axis_y2_default);
|
5761 | scale.subY2 = $$.getYScale("y2", min.subY, max.subY, scale.subY2 ? scale.subY2.domain() : config.axis_y2_default);
|
5762 | axis.setAxis("y2", scale.y2, config.axis_y2_tick_outer, isInit);
|
5763 | }
|
5764 | }
|
5765 | else {
|
5766 |
|
5767 | $$.updateArc && $$.updateArc();
|
5768 | }
|
5769 | },
|
5770 | |
5771 |
|
5772 |
|
5773 |
|
5774 |
|
5775 |
|
5776 | xx: function (d) {
|
5777 | var $$ = this;
|
5778 | var config = $$.config, _a = $$.scale, x = _a.x, zoom = _a.zoom;
|
5779 | var fn = config.zoom_enabled && zoom ?
|
5780 | zoom : x;
|
5781 | return d ? fn(isValue(d.x) ? d.x : d) : null;
|
5782 | },
|
5783 | xv: function (d) {
|
5784 | var $$ = this;
|
5785 | var axis = $$.axis, config = $$.config, x = $$.scale.x;
|
5786 | var value = $$.getBaseValue(d);
|
5787 | if (axis.isTimeSeries()) {
|
5788 | value = parseDate.call($$, value);
|
5789 | }
|
5790 | else if (axis.isCategorized() && isString(value)) {
|
5791 | value = config.axis_x_categories.indexOf(value);
|
5792 | }
|
5793 | return Math.ceil(x(value));
|
5794 | },
|
5795 | yv: function (d) {
|
5796 | var $$ = this;
|
5797 | var _a = $$.scale, y = _a.y, y2 = _a.y2;
|
5798 | var yScale = d.axis && d.axis === "y2" ? y2 : y;
|
5799 | return Math.ceil(yScale($$.getBaseValue(d)));
|
5800 | },
|
5801 | subxx: function (d) {
|
5802 | return d ? this.scale.subX(d.x) : null;
|
5803 | }
|
5804 | };
|
5805 |
|
5806 |
|
5807 |
|
5808 |
|
5809 |
|
5810 | var shape = {
|
5811 | |
5812 |
|
5813 |
|
5814 |
|
5815 |
|
5816 | getDrawShape: function () {
|
5817 | var $$ = this;
|
5818 | var isRotated = $$.config.axis_rotated;
|
5819 | var hasRadar = $$.state.hasRadar;
|
5820 | var shape = { type: {}, indices: {}, pos: {} };
|
5821 | ["bar", "candlestick", "line", "area"].forEach(function (v) {
|
5822 | var name = capitalize(/^(bubble|scatter)$/.test(v) ? "line" : v);
|
5823 | if ($$.hasType(v) || $$.hasTypeOf(name) || (v === "line" && ($$.hasType("bubble") || $$.hasType("scatter")))) {
|
5824 | var indices = $$.getShapeIndices($$["is" + name + "Type"]);
|
5825 | var drawFn = $$["generateDraw" + name];
|
5826 | shape.indices[v] = indices;
|
5827 | shape.type[v] = drawFn ? drawFn.bind($$)(indices, false) : undefined;
|
5828 | }
|
5829 | });
|
5830 | if (!$$.hasArcType() || hasRadar) {
|
5831 |
|
5832 | var cx = hasRadar ? $$.radarCircleX : (isRotated ? $$.circleY : $$.circleX);
|
5833 | var cy = hasRadar ? $$.radarCircleY : (isRotated ? $$.circleX : $$.circleY);
|
5834 | shape.pos = {
|
5835 | xForText: $$.generateXYForText(shape.indices, true),
|
5836 | yForText: $$.generateXYForText(shape.indices, false),
|
5837 | cx: (cx || function () { }).bind($$),
|
5838 | cy: (cy || function () { }).bind($$)
|
5839 | };
|
5840 | }
|
5841 | return shape;
|
5842 | },
|
5843 | getShapeIndices: function (typeFilter) {
|
5844 | var $$ = this;
|
5845 | var config = $$.config;
|
5846 | var xs = config.data_xs;
|
5847 | var hasXs = notEmpty(xs);
|
5848 | var indices = {};
|
5849 | var i = hasXs ? {} : 0;
|
5850 | if (hasXs) {
|
5851 | getUnique(Object.keys(xs).map(function (v) { return xs[v]; }))
|
5852 | .forEach(function (v) {
|
5853 | i[v] = 0;
|
5854 | indices[v] = {};
|
5855 | });
|
5856 | }
|
5857 | $$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$))
|
5858 | .forEach(function (d) {
|
5859 | var xKey = d.id in xs ? xs[d.id] : "";
|
5860 | var ind = xKey ? indices[xKey] : indices;
|
5861 | for (var j = 0, groups = void 0; (groups = config.data_groups[j]); j++) {
|
5862 | if (groups.indexOf(d.id) < 0) {
|
5863 | continue;
|
5864 | }
|
5865 | for (var k = 0, row = void 0; (row = groups[k]); k++) {
|
5866 | if (row in ind) {
|
5867 | ind[d.id] = ind[row];
|
5868 | break;
|
5869 | }
|
5870 | }
|
5871 | }
|
5872 | if (isUndefined(ind[d.id])) {
|
5873 | ind[d.id] = xKey ? i[xKey]++ : i++;
|
5874 | ind.__max__ = (xKey ? i[xKey] : i) - 1;
|
5875 | }
|
5876 | });
|
5877 | return indices;
|
5878 | },
|
5879 | |
5880 |
|
5881 |
|
5882 |
|
5883 |
|
5884 |
|
5885 |
|
5886 | getIndices: function (indices, id) {
|
5887 | var xs = this.config.data_xs;
|
5888 | return notEmpty(xs) ?
|
5889 | indices[xs[id]] : indices;
|
5890 | },
|
5891 | |
5892 |
|
5893 |
|
5894 |
|
5895 |
|
5896 |
|
5897 | getIndicesMax: function (indices) {
|
5898 | return notEmpty(this.config.data_xs) ?
|
5899 |
|
5900 | Object.keys(indices)
|
5901 | .map(function (v) { return indices[v].__max__ || 0; })
|
5902 | .reduce(function (acc, curr) { return acc + curr; }) : indices.__max__;
|
5903 | },
|
5904 | getShapeX: function (offset, indices, isSub) {
|
5905 | var $$ = this;
|
5906 | var config = $$.config, scale = $$.scale;
|
5907 | var currScale = isSub ? scale.subX : (scale.zoom || scale.x);
|
5908 | var barPadding = config.bar_padding;
|
5909 | var sum = function (p, c) { return p + c; };
|
5910 | var halfWidth = isObjectType(offset) && (offset._$total.length ? offset._$total.reduce(sum) / 2 : 0);
|
5911 | return function (d) {
|
5912 | var ind = $$.getIndices(indices, d.id);
|
5913 | var index = d.id in ind ? ind[d.id] : 0;
|
5914 | var targetsNum = (ind.__max__ || 0) + 1;
|
5915 | var x = 0;
|
5916 | if (notEmpty(d.x)) {
|
5917 | var xPos = currScale(d.x, true);
|
5918 | if (halfWidth) {
|
5919 | x = xPos - (offset[d.id] || offset._$width) +
|
5920 | offset._$total.slice(0, index + 1).reduce(sum) -
|
5921 | halfWidth;
|
5922 | }
|
5923 | else {
|
5924 | x = xPos - (isNumber(offset) ? offset : offset._$width) * (targetsNum / 2 - index);
|
5925 | }
|
5926 | }
|
5927 |
|
5928 | if (offset && x && targetsNum > 1 && barPadding) {
|
5929 | if (index) {
|
5930 | x += barPadding * index;
|
5931 | }
|
5932 | if (targetsNum > 2) {
|
5933 | x -= (targetsNum - 1) * barPadding / 2;
|
5934 | }
|
5935 | else if (targetsNum === 2) {
|
5936 | x -= barPadding / 2;
|
5937 | }
|
5938 | }
|
5939 | return x;
|
5940 | };
|
5941 | },
|
5942 | getShapeY: function (isSub) {
|
5943 | var $$ = this;
|
5944 | var isStackNormalized = $$.isStackNormalized();
|
5945 | return function (d) {
|
5946 | var value = d.value;
|
5947 | if (isNumber(d)) {
|
5948 | value = d;
|
5949 | }
|
5950 | else if (isStackNormalized) {
|
5951 | value = $$.getRatio("index", d, true);
|
5952 | }
|
5953 | else if ($$.isBubbleZType(d)) {
|
5954 | value = $$.getBubbleZData(d.value, "y");
|
5955 | }
|
5956 | return $$.getYScaleById(d.id, isSub)(value);
|
5957 | };
|
5958 | },
|
5959 | |
5960 |
|
5961 |
|
5962 |
|
5963 |
|
5964 |
|
5965 | getShapeYMin: function (id) {
|
5966 | var $$ = this;
|
5967 | var scale = $$.scale[$$.axis.getId(id)];
|
5968 | var yMin = scale.domain()[0];
|
5969 | return !$$.isGrouped(id) && yMin > 0 ? yMin : 0;
|
5970 | },
|
5971 | |
5972 |
|
5973 |
|
5974 |
|
5975 |
|
5976 |
|
5977 | getShapeOffsetData: function (typeFilter) {
|
5978 | var $$ = this;
|
5979 | var targets = $$.orderTargets($$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$)));
|
5980 | var isStackNormalized = $$.isStackNormalized();
|
5981 | var shapeOffsetTargets = targets.map(function (target) {
|
5982 | var rowValues = target.values;
|
5983 | var values = {};
|
5984 | if ($$.isStepType(target)) {
|
5985 | rowValues = $$.convertValuesToStep(rowValues);
|
5986 | }
|
5987 | var rowValueMapByXValue = rowValues.reduce(function (out, d) {
|
5988 | var key = Number(d.x);
|
5989 | out[key] = d;
|
5990 | values[key] = isStackNormalized ? $$.getRatio("index", d, true) : d.value;
|
5991 | return out;
|
5992 | }, {});
|
5993 | return {
|
5994 | id: target.id,
|
5995 | rowValues: rowValues,
|
5996 | rowValueMapByXValue: rowValueMapByXValue,
|
5997 | values: values
|
5998 | };
|
5999 | });
|
6000 | var indexMapByTargetId = targets.reduce(function (out, _a, index) {
|
6001 | var id = _a.id;
|
6002 | out[id] = index;
|
6003 | return out;
|
6004 | }, {});
|
6005 | return { indexMapByTargetId: indexMapByTargetId, shapeOffsetTargets: shapeOffsetTargets };
|
6006 | },
|
6007 | getShapeOffset: function (typeFilter, indices, isSub) {
|
6008 | var $$ = this;
|
6009 | var _a = $$.getShapeOffsetData(typeFilter), shapeOffsetTargets = _a.shapeOffsetTargets, indexMapByTargetId = _a.indexMapByTargetId;
|
6010 | return function (d, idx) {
|
6011 | var ind = $$.getIndices(indices, d.id);
|
6012 | var scale = $$.getYScaleById(d.id, isSub);
|
6013 | var y0 = scale($$.getShapeYMin(d.id));
|
6014 | var dataXAsNumber = Number(d.x);
|
6015 | var offset = y0;
|
6016 | shapeOffsetTargets
|
6017 | .filter(function (t) { return t.id !== d.id; })
|
6018 | .forEach(function (t) {
|
6019 | if (ind[t.id] === ind[d.id] && indexMapByTargetId[t.id] < indexMapByTargetId[d.id]) {
|
6020 | var row = t.rowValues[idx];
|
6021 |
|
6022 | if (!row || Number(row.x) !== dataXAsNumber) {
|
6023 | row = t.rowValueMapByXValue[dataXAsNumber];
|
6024 | }
|
6025 | if (row && row.value * d.value >= 0) {
|
6026 | offset += scale(t.values[dataXAsNumber]) - y0;
|
6027 | }
|
6028 | }
|
6029 | });
|
6030 | return offset;
|
6031 | };
|
6032 | },
|
6033 | getBarW: function (type, axis, targetsNum) {
|
6034 | var $$ = this;
|
6035 | var config = $$.config, org = $$.org, scale = $$.scale;
|
6036 | var maxDataCount = $$.getMaxDataCount();
|
6037 | var isGrouped = type === "bar" && config.data_groups.length;
|
6038 | var configName = type + "_width";
|
6039 | var tickInterval = scale.zoom && !$$.axis.isCategorized() ?
|
6040 | (org.xDomain.map(function (v) { return scale.zoom(v); })
|
6041 | .reduce(function (a, c) { return Math.abs(a) + c; }) / maxDataCount) : axis.tickInterval(maxDataCount);
|
6042 | var getWidth = function (id) {
|
6043 | var width = id ? config[configName][id] : config[configName];
|
6044 | var ratio = id ? width.ratio : config[configName + "_ratio"];
|
6045 | var max = id ? width.max : config[configName + "_max"];
|
6046 | var w = isNumber(width) ?
|
6047 | width : targetsNum ? (tickInterval * ratio) / targetsNum : 0;
|
6048 | return max && w > max ? max : w;
|
6049 | };
|
6050 | var result = getWidth();
|
6051 | if (!isGrouped && isObjectType(config[configName])) {
|
6052 | result = { _$width: result, _$total: [] };
|
6053 | $$.filterTargetsToShow($$.data.targets).forEach(function (v) {
|
6054 | if (config[configName][v.id]) {
|
6055 | result[v.id] = getWidth(v.id);
|
6056 | result._$total.push(result[v.id] || result._$width);
|
6057 | }
|
6058 | });
|
6059 | }
|
6060 | return result;
|
6061 | },
|
6062 | isWithinShape: function (that, d) {
|
6063 | var $$ = this;
|
6064 | var shape = select(that);
|
6065 | var isWithin;
|
6066 | if (!$$.isTargetToShow(d.id)) {
|
6067 | isWithin = false;
|
6068 | }
|
6069 | else if (("hasValidPointType" in $$) && $$.hasValidPointType(that.nodeName)) {
|
6070 | isWithin = $$.isStepType(d) ?
|
6071 | $$.isWithinStep(that, $$.getYScaleById(d.id)(d.value)) :
|
6072 | $$.isWithinCircle(that, $$.isBubbleType(d) ? $$.pointSelectR(d) * 1.5 : 0);
|
6073 | }
|
6074 | else if (that.nodeName === "path") {
|
6075 | isWithin = shape.classed(CLASS.bar) ? $$.isWithinBar(that) : true;
|
6076 | }
|
6077 | return isWithin;
|
6078 | },
|
6079 | getInterpolate: function (d) {
|
6080 | var $$ = this;
|
6081 | var interpolation = $$.getInterpolateType(d);
|
6082 | return {
|
6083 | "basis": curveBasis,
|
6084 | "basis-closed": curveBasisClosed,
|
6085 | "basis-open": curveBasisOpen,
|
6086 | "bundle": curveBundle,
|
6087 | "cardinal": curveCardinal,
|
6088 | "cardinal-closed": curveCardinalClosed,
|
6089 | "cardinal-open": curveCardinalOpen,
|
6090 | "catmull-rom": curveCatmullRom,
|
6091 | "catmull-rom-closed": curveCatmullRomClosed,
|
6092 | "catmull-rom-open": curveCatmullRomOpen,
|
6093 | "monotone-x": curveMonotoneX,
|
6094 | "monotone-y": curveMonotoneY,
|
6095 | "natural": curveNatural,
|
6096 | "linear-closed": curveLinearClosed,
|
6097 | "linear": curveLinear,
|
6098 | "step": curveStep,
|
6099 | "step-after": curveStepAfter,
|
6100 | "step-before": curveStepBefore
|
6101 | }[interpolation];
|
6102 | },
|
6103 | getInterpolateType: function (d) {
|
6104 | var $$ = this;
|
6105 | var config = $$.config;
|
6106 | var type = config.spline_interpolation_type;
|
6107 | var interpolation = $$.isInterpolationType(type) ? type : "cardinal";
|
6108 | return $$.isSplineType(d) ?
|
6109 | interpolation : ($$.isStepType(d) ?
|
6110 | config.line_step_type : "linear");
|
6111 | }
|
6112 | };
|
6113 |
|
6114 |
|
6115 |
|
6116 |
|
6117 |
|
6118 | var size = {
|
6119 | |
6120 |
|
6121 |
|
6122 |
|
6123 | setContainerSize: function () {
|
6124 | var $$ = this;
|
6125 | var state = $$.state;
|
6126 | state.current.width = $$.getCurrentWidth();
|
6127 | state.current.height = $$.getCurrentHeight();
|
6128 | },
|
6129 | getCurrentWidth: function () {
|
6130 | var $$ = this;
|
6131 | return $$.config.size_width || $$.getParentWidth();
|
6132 | },
|
6133 | getCurrentHeight: function () {
|
6134 | var $$ = this;
|
6135 | var config = $$.config;
|
6136 | var h = config.size_height || $$.getParentHeight();
|
6137 | return h > 0 ? h : 320 / ($$.hasType("gauge") && !config.gauge_fullCircle ? 2 : 1);
|
6138 | },
|
6139 | getCurrentPaddingTop: function () {
|
6140 | var $$ = this;
|
6141 | var config = $$.config, hasAxis = $$.state.hasAxis, $el = $$.$el;
|
6142 | var axesLen = hasAxis ? config.axis_y2_axes.length : 0;
|
6143 | var padding = isValue(config.padding_top) ?
|
6144 | config.padding_top : 0;
|
6145 | if ($el.title && $el.title.node()) {
|
6146 | padding += $$.getTitlePadding();
|
6147 | }
|
6148 | if (axesLen && config.axis_rotated) {
|
6149 | padding += $$.getHorizontalAxisHeight("y2") * axesLen;
|
6150 | }
|
6151 | return padding;
|
6152 | },
|
6153 | getCurrentPaddingBottom: function () {
|
6154 | var $$ = this;
|
6155 | var config = $$.config, hasAxis = $$.state.hasAxis;
|
6156 | var axisId = config.axis_rotated ? "y" : "x";
|
6157 | var axesLen = hasAxis ? config["axis_" + axisId + "_axes"].length : 0;
|
6158 | var padding = isValue(config.padding_bottom) ?
|
6159 | config.padding_bottom : 0;
|
6160 | return padding + (axesLen ? $$.getHorizontalAxisHeight(axisId) * axesLen : 0);
|
6161 | },
|
6162 | getCurrentPaddingLeft: function (withoutRecompute) {
|
6163 | var $$ = this;
|
6164 | var config = $$.config, hasAxis = $$.state.hasAxis;
|
6165 | var isRotated = config.axis_rotated;
|
6166 | var axisId = isRotated ? "x" : "y";
|
6167 | var axesLen = hasAxis ? config["axis_" + axisId + "_axes"].length : 0;
|
6168 | var axisWidth = hasAxis ? $$.getAxisWidthByAxisId(axisId, withoutRecompute) : 0;
|
6169 | var padding;
|
6170 | if (isValue(config.padding_left)) {
|
6171 | padding = config.padding_left;
|
6172 | }
|
6173 | else if (hasAxis && isRotated) {
|
6174 | padding = !config.axis_x_show ?
|
6175 | 1 : Math.max(ceil10(axisWidth), 40);
|
6176 | }
|
6177 | else if (hasAxis && (!config.axis_y_show || config.axis_y_inner)) {
|
6178 | padding = $$.axis.getAxisLabelPosition("y").isOuter ? 30 : 1;
|
6179 | }
|
6180 | else {
|
6181 | padding = ceil10(axisWidth);
|
6182 | }
|
6183 | return padding + (axisWidth * axesLen);
|
6184 | },
|
6185 | getCurrentPaddingRight: function (withXAxisTickTextOverflow) {
|
6186 | if (withXAxisTickTextOverflow === void 0) { withXAxisTickTextOverflow = false; }
|
6187 | var $$ = this;
|
6188 | var config = $$.config, hasAxis = $$.state.hasAxis;
|
6189 | var defaultPadding = 10;
|
6190 | var legendWidthOnRight = $$.state.isLegendRight ? $$.getLegendWidth() + 20 : 0;
|
6191 | var axesLen = hasAxis ? config.axis_y2_axes.length : 0;
|
6192 | var axisWidth = hasAxis ? $$.getAxisWidthByAxisId("y2") : 0;
|
6193 | var xAxisTickTextOverflow = withXAxisTickTextOverflow ?
|
6194 | $$.axis.getXAxisTickTextY2Overflow(defaultPadding) : 0;
|
6195 | var padding;
|
6196 | if (isValue(config.padding_right)) {
|
6197 | padding = config.padding_right + 1;
|
6198 | }
|
6199 | else if ($$.axis && config.axis_rotated) {
|
6200 | padding = defaultPadding + legendWidthOnRight;
|
6201 | }
|
6202 | else if ($$.axis && (!config.axis_y2_show || config.axis_y2_inner)) {
|
6203 | padding = Math.max(2 + legendWidthOnRight + ($$.axis.getAxisLabelPosition("y2").isOuter ? 20 : 0), xAxisTickTextOverflow);
|
6204 | }
|
6205 | else {
|
6206 | padding = Math.max(ceil10(axisWidth) + legendWidthOnRight, xAxisTickTextOverflow);
|
6207 | }
|
6208 | return padding + (axisWidth * axesLen);
|
6209 | },
|
6210 | |
6211 |
|
6212 |
|
6213 |
|
6214 |
|
6215 |
|
6216 | getParentRectValue: function (key) {
|
6217 | var offsetName = "offset" + capitalize(key);
|
6218 | var parent = this.$el.chart.node();
|
6219 | var v;
|
6220 | while (!v && parent && parent.tagName !== "BODY") {
|
6221 | try {
|
6222 | v = parent.getBoundingClientRect()[key];
|
6223 | }
|
6224 | catch (e) {
|
6225 | if (offsetName in parent) {
|
6226 |
|
6227 |
|
6228 | v = parent[offsetName];
|
6229 | }
|
6230 | }
|
6231 | parent = parent.parentNode;
|
6232 | }
|
6233 | if (key === "width") {
|
6234 |
|
6235 |
|
6236 | var bodyWidth = doc.body.offsetWidth;
|
6237 | v > bodyWidth && (v = bodyWidth);
|
6238 | }
|
6239 | return v;
|
6240 | },
|
6241 | getParentWidth: function () {
|
6242 | return this.getParentRectValue("width");
|
6243 | },
|
6244 | getParentHeight: function () {
|
6245 | var h = this.$el.chart.style("height");
|
6246 | return h.indexOf("px") > 0 ? parseInt(h, 10) : 0;
|
6247 | },
|
6248 | getSvgLeft: function (withoutRecompute) {
|
6249 | var $$ = this;
|
6250 | var config = $$.config, $el = $$.$el;
|
6251 | var hasLeftAxisRect = config.axis_rotated || (!config.axis_rotated && !config.axis_y_inner);
|
6252 | var leftAxisClass = config.axis_rotated ? CLASS.axisX : CLASS.axisY;
|
6253 | var leftAxis = $el.main.select("." + leftAxisClass).node();
|
6254 | var svgRect = leftAxis && hasLeftAxisRect ? leftAxis.getBoundingClientRect() : { right: 0 };
|
6255 | var chartRect = $el.chart.node().getBoundingClientRect();
|
6256 | var hasArc = $$.hasArcType();
|
6257 | var svgLeft = svgRect.right - chartRect.left -
|
6258 | (hasArc ? 0 : $$.getCurrentPaddingLeft(withoutRecompute));
|
6259 | return svgLeft > 0 ? svgLeft : 0;
|
6260 | },
|
6261 | updateDimension: function (withoutAxis) {
|
6262 | var $$ = this;
|
6263 | var config = $$.config, hasAxis = $$.state.hasAxis, $el = $$.$el;
|
6264 | if (hasAxis && !withoutAxis && $$.axis.x && config.axis_rotated) {
|
6265 | $$.axis.subX && $$.axis.subX.create($el.axis.subX);
|
6266 | }
|
6267 |
|
6268 | $$.updateScales(withoutAxis);
|
6269 | $$.updateSvgSize();
|
6270 | $$.transformAll(false);
|
6271 | },
|
6272 | updateSvgSize: function () {
|
6273 | var $$ = this;
|
6274 | var _a = $$.state, clip = _a.clip, current = _a.current, hasAxis = _a.hasAxis, width = _a.width, height = _a.height, svg = $$.$el.svg;
|
6275 | svg
|
6276 | .attr("width", current.width)
|
6277 | .attr("height", current.height);
|
6278 | if (hasAxis) {
|
6279 | var brush = svg.select("." + CLASS.brush + " .overlay");
|
6280 | var brushSize = { width: 0, height: 0 };
|
6281 | if (brush.size()) {
|
6282 | brushSize.width = +brush.attr("width");
|
6283 | brushSize.height = +brush.attr("height");
|
6284 | }
|
6285 | svg.selectAll(["#" + clip.id, "#" + clip.idGrid])
|
6286 | .select("rect")
|
6287 | .attr("width", width)
|
6288 | .attr("height", height);
|
6289 | svg.select("#" + clip.idXAxis)
|
6290 | .select("rect")
|
6291 | .call($$.setXAxisClipPath.bind($$));
|
6292 | svg.select("#" + clip.idYAxis)
|
6293 | .select("rect")
|
6294 | .call($$.setYAxisClipPath.bind($$));
|
6295 | clip.idSubchart && svg.select("#" + clip.idSubchart)
|
6296 | .select("rect")
|
6297 | .attr("width", width)
|
6298 | .attr("height", brushSize.height);
|
6299 | }
|
6300 | },
|
6301 | |
6302 |
|
6303 |
|
6304 |
|
6305 |
|
6306 | updateSizes: function (isInit) {
|
6307 | var $$ = this;
|
6308 | var config = $$.config, state = $$.state, legend = $$.$el.legend;
|
6309 | var isRotated = config.axis_rotated;
|
6310 | var hasArc = $$.hasArcType();
|
6311 | !isInit && $$.setContainerSize();
|
6312 | var currLegend = {
|
6313 | width: legend ? $$.getLegendWidth() : 0,
|
6314 | height: legend ? $$.getLegendHeight() : 0
|
6315 | };
|
6316 | if (!hasArc && config.axis_x_show && config.axis_x_tick_autorotate) {
|
6317 | $$.updateXAxisTickClip();
|
6318 | }
|
6319 | var legendHeightForBottom = state.isLegendRight || state.isLegendInset ? 0 : currLegend.height;
|
6320 | var xAxisHeight = isRotated || hasArc ? 0 : $$.getHorizontalAxisHeight("x");
|
6321 | var subchartXAxisHeight = config.subchart_axis_x_show && config.subchart_axis_x_tick_text_show ?
|
6322 | xAxisHeight : 30;
|
6323 | var subchartHeight = config.subchart_show && !hasArc ?
|
6324 | (config.subchart_size_height + subchartXAxisHeight) : 0;
|
6325 |
|
6326 | state.margin = !hasArc && isRotated ? {
|
6327 | top: $$.getHorizontalAxisHeight("y2") + $$.getCurrentPaddingTop(),
|
6328 | right: hasArc ? 0 : $$.getCurrentPaddingRight(true),
|
6329 | bottom: $$.getHorizontalAxisHeight("y") + legendHeightForBottom + $$.getCurrentPaddingBottom(),
|
6330 | left: subchartHeight + (hasArc ? 0 : $$.getCurrentPaddingLeft())
|
6331 | } : {
|
6332 | top: 4 + $$.getCurrentPaddingTop(),
|
6333 | right: hasArc ? 0 : $$.getCurrentPaddingRight(true),
|
6334 | bottom: xAxisHeight + subchartHeight + legendHeightForBottom + $$.getCurrentPaddingBottom(),
|
6335 | left: hasArc ? 0 : $$.getCurrentPaddingLeft()
|
6336 | };
|
6337 |
|
6338 | state.margin2 = isRotated ? {
|
6339 | top: state.margin.top,
|
6340 | right: NaN,
|
6341 | bottom: 20 + legendHeightForBottom,
|
6342 | left: $$.state.rotatedPadding.left
|
6343 | } : {
|
6344 | top: state.current.height - subchartHeight - legendHeightForBottom,
|
6345 | right: NaN,
|
6346 | bottom: subchartXAxisHeight + legendHeightForBottom,
|
6347 | left: state.margin.left
|
6348 | };
|
6349 |
|
6350 | state.margin3 = {
|
6351 | top: 0,
|
6352 | right: NaN,
|
6353 | bottom: 0,
|
6354 | left: 0
|
6355 | };
|
6356 | $$.updateSizeForLegend && $$.updateSizeForLegend(currLegend);
|
6357 | state.width = state.current.width - state.margin.left - state.margin.right;
|
6358 | state.height = state.current.height - state.margin.top - state.margin.bottom;
|
6359 | if (state.width < 0) {
|
6360 | state.width = 0;
|
6361 | }
|
6362 | if (state.height < 0) {
|
6363 | state.height = 0;
|
6364 | }
|
6365 | state.width2 = isRotated ?
|
6366 | state.margin.left - state.rotatedPadding.left - state.rotatedPadding.right : state.width;
|
6367 | state.height2 = isRotated ?
|
6368 | state.height : state.current.height - state.margin2.top - state.margin2.bottom;
|
6369 | if (state.width2 < 0) {
|
6370 | state.width2 = 0;
|
6371 | }
|
6372 | if (state.height2 < 0) {
|
6373 | state.height2 = 0;
|
6374 | }
|
6375 |
|
6376 | var hasGauge = $$.hasType("gauge");
|
6377 | var isLegendRight = config.legend_show && state.isLegendRight;
|
6378 | state.arcWidth = state.width - (isLegendRight ? currLegend.width + 10 : 0);
|
6379 | state.arcHeight = state.height - (isLegendRight && !hasGauge ? 0 : 10);
|
6380 | if (hasGauge && !config.gauge_fullCircle) {
|
6381 | state.arcHeight += state.height - $$.getPaddingBottomForGauge();
|
6382 | }
|
6383 | $$.updateRadius && $$.updateRadius();
|
6384 | if (state.isLegendRight && hasArc) {
|
6385 | state.margin3.left = state.arcWidth / 2 + state.radiusExpanded * 1.1;
|
6386 | }
|
6387 | }
|
6388 | };
|
6389 |
|
6390 |
|
6391 |
|
6392 |
|
6393 |
|
6394 | var text = {
|
6395 | opacityForText: function (d) {
|
6396 | var $$ = this;
|
6397 | return $$.isBarType(d) && !$$.meetsLabelThreshold(Math.abs($$.getRatio("bar", d)), "bar") ? "0" : ($$.hasDataLabel ? "1" : "0");
|
6398 | },
|
6399 | |
6400 |
|
6401 |
|
6402 |
|
6403 | initText: function () {
|
6404 | var $el = this.$el;
|
6405 | $el.main.select("." + CLASS.chart).append("g")
|
6406 | .attr("class", CLASS.chartTexts);
|
6407 | },
|
6408 | |
6409 |
|
6410 |
|
6411 |
|
6412 |
|
6413 | updateTargetsForText: function (targets) {
|
6414 | var $$ = this;
|
6415 | var classChartText = $$.getChartClass("Text");
|
6416 | var classTexts = $$.getClass("texts", "id");
|
6417 | var classFocus = $$.classFocus.bind($$);
|
6418 | var mainTextUpdate = $$.$el.main.select("." + CLASS.chartTexts).selectAll("." + CLASS.chartText)
|
6419 | .data(targets)
|
6420 | .attr("class", function (d) { return classChartText(d) + classFocus(d); });
|
6421 | var mainTextEnter = mainTextUpdate.enter().append("g")
|
6422 | .style("opacity", "0")
|
6423 | .attr("class", classChartText)
|
6424 | .style("pointer-events", "none");
|
6425 | mainTextEnter.append("g")
|
6426 | .attr("class", classTexts);
|
6427 | },
|
6428 | |
6429 |
|
6430 |
|
6431 |
|
6432 |
|
6433 | updateText: function (durationForExit) {
|
6434 | var $$ = this;
|
6435 | var config = $$.config, $el = $$.$el;
|
6436 | var classText = $$.getClass("text", "index");
|
6437 | var text = $el.main.selectAll("." + CLASS.texts)
|
6438 | .selectAll("." + CLASS.text)
|
6439 | .data($$.labelishData.bind($$));
|
6440 | text.exit()
|
6441 | .transition()
|
6442 | .duration(durationForExit)
|
6443 | .style("fill-opacity", "0")
|
6444 | .remove();
|
6445 | $el.text = text.enter()
|
6446 | .append("text")
|
6447 | .merge(text)
|
6448 | .attr("class", classText)
|
6449 | .attr("text-anchor", function (d) {
|
6450 |
|
6451 | var isEndAnchor = d.value < 0;
|
6452 | if ($$.isCandlestickType(d)) {
|
6453 | var data = $$.getCandlestickData(d);
|
6454 | isEndAnchor = data && !data._isUp;
|
6455 | }
|
6456 | return (config.axis_rotated ? (isEndAnchor ? "end" : "start") : "middle");
|
6457 | })
|
6458 | .style("fill", $$.updateTextColor.bind($$))
|
6459 | .style("fill-opacity", "0")
|
6460 | .each(function (d, i, j) {
|
6461 | var node = select(this);
|
6462 | var value = d.value;
|
6463 | if ($$.isBubbleZType(d)) {
|
6464 | value = $$.getBubbleZData(value, "z");
|
6465 | }
|
6466 | else if ($$.isCandlestickType(d)) {
|
6467 | var data = $$.getCandlestickData(d);
|
6468 | if (data) {
|
6469 | value = data.close;
|
6470 | }
|
6471 | }
|
6472 | value = $$.dataLabelFormat(d.id)(value, d.id, i, j);
|
6473 | if (isNumber(value)) {
|
6474 | this.textContent = value;
|
6475 | }
|
6476 | else {
|
6477 | setTextValue(node, value);
|
6478 | }
|
6479 | });
|
6480 | },
|
6481 | updateTextColor: function (d) {
|
6482 | var $$ = this;
|
6483 | var config = $$.config;
|
6484 | var labelColors = config.data_labels_colors;
|
6485 | var defaultColor = $$.isArcType(d) && !$$.isRadarType(d) ? null : $$.color(d);
|
6486 | var color;
|
6487 | if (isString(labelColors)) {
|
6488 | color = labelColors;
|
6489 | }
|
6490 | else if (isObject(labelColors)) {
|
6491 | var id = (d.data || d).id;
|
6492 | color = labelColors[id];
|
6493 | }
|
6494 | else if (isFunction(labelColors)) {
|
6495 | color = labelColors.bind($$.api)(defaultColor, d);
|
6496 | }
|
6497 | if ($$.isCandlestickType(d) && !isFunction(labelColors)) {
|
6498 | var value = $$.getCandlestickData(d);
|
6499 | if (value && !value._isUp) {
|
6500 | var downColor = config.candlestick_color_down;
|
6501 | color = isObject(downColor) ? downColor[d.id] : downColor;
|
6502 | }
|
6503 | }
|
6504 | return color || defaultColor;
|
6505 | },
|
6506 | |
6507 |
|
6508 |
|
6509 |
|
6510 |
|
6511 |
|
6512 |
|
6513 |
|
6514 |
|
6515 | redrawText: function (x, y, forFlow, withTransition) {
|
6516 | var $$ = this;
|
6517 | var t = getRandom(true);
|
6518 | $$.$el.text
|
6519 | .style("fill", $$.updateTextColor.bind($$))
|
6520 | .style("fill-opacity", forFlow ? 0 : $$.opacityForText.bind($$))
|
6521 | .each(function (d, i) {
|
6522 |
|
6523 | var node = withTransition && this.getAttribute("x") ?
|
6524 | select(this).transition(t) : select(this);
|
6525 | var posX = x.bind(this)(d, i);
|
6526 | var posY = y.bind(this)(d, i);
|
6527 |
|
6528 | if (this.childElementCount) {
|
6529 | node.attr("transform", "translate(" + posX + " " + posY + ")");
|
6530 | }
|
6531 | else {
|
6532 | node.attr("x", posX).attr("y", posY);
|
6533 | }
|
6534 | });
|
6535 |
|
6536 |
|
6537 | return true;
|
6538 | },
|
6539 | |
6540 |
|
6541 |
|
6542 |
|
6543 |
|
6544 |
|
6545 |
|
6546 | getTextRect: function (element, className) {
|
6547 | var $$ = this;
|
6548 | var base = (element.node ? element.node() : element);
|
6549 | if (!/text/i.test(base.tagName)) {
|
6550 | base = base.querySelector("text");
|
6551 | }
|
6552 | var text = base.textContent;
|
6553 | var cacheKey = KEY.textRect + "-" + text.replace(/\W/g, "_");
|
6554 | var rect = $$.cache.get(cacheKey);
|
6555 | if (!rect) {
|
6556 | $$.$el.svg.append("text")
|
6557 | .style("visibility", "hidden")
|
6558 | .style("font", select(base).style("font"))
|
6559 | .classed(className, true)
|
6560 | .text(text)
|
6561 | .call(function (v) {
|
6562 | rect = getBoundingRect(v.node());
|
6563 | })
|
6564 | .remove();
|
6565 | $$.cache.add(cacheKey, rect);
|
6566 | }
|
6567 | return rect;
|
6568 | },
|
6569 | |
6570 |
|
6571 |
|
6572 |
|
6573 |
|
6574 |
|
6575 |
|
6576 | generateXYForText: function (indices, forX) {
|
6577 | var $$ = this;
|
6578 | var types = Object.keys(indices);
|
6579 | var points = {};
|
6580 | var getter = forX ? $$.getXForText : $$.getYForText;
|
6581 | $$.hasType("radar") && types.push("radar");
|
6582 | types.forEach(function (v) {
|
6583 | points[v] = $$["generateGet" + capitalize(v) + "Points"](indices[v], false);
|
6584 | });
|
6585 | return function (d, i) {
|
6586 | var type = ($$.isAreaType(d) && "area") ||
|
6587 | ($$.isBarType(d) && "bar") ||
|
6588 | ($$.isCandlestickType(d) && "candlestick") ||
|
6589 | ($$.isRadarType(d) && "radar") || "line";
|
6590 | return getter.call($$, points[type](d, i), d, this);
|
6591 | };
|
6592 | },
|
6593 | |
6594 |
|
6595 |
|
6596 |
|
6597 |
|
6598 |
|
6599 |
|
6600 |
|
6601 | getCenteredTextPos: function (d, points, textElement) {
|
6602 | var $$ = this;
|
6603 | var config = $$.config;
|
6604 | var isRotated = config.axis_rotated;
|
6605 | if (config.data_labels.centered && $$.isBarType(d)) {
|
6606 | var rect = getBoundingRect(textElement);
|
6607 | var isPositive = d.value >= 0;
|
6608 | if (isRotated) {
|
6609 | var w = (isPositive ?
|
6610 | points[1][1] - points[0][1] :
|
6611 | points[0][1] - points[1][1]) / 2 + (rect.width / 2);
|
6612 | return isPositive ? -w - 3 : w + 2;
|
6613 | }
|
6614 | else {
|
6615 | var h = (isPositive ?
|
6616 | points[0][1] - points[1][1] :
|
6617 | points[1][1] - points[0][1]) / 2 + (rect.height / 2);
|
6618 | return isPositive ? h : -h - 2;
|
6619 | }
|
6620 | }
|
6621 | return 0;
|
6622 | },
|
6623 | |
6624 |
|
6625 |
|
6626 |
|
6627 |
|
6628 |
|
6629 |
|
6630 | getTextPos: function (id, type) {
|
6631 | var pos = this.config.data_labels_position;
|
6632 | return (id in pos ? pos[id] : pos)[type] || 0;
|
6633 | },
|
6634 | |
6635 |
|
6636 |
|
6637 |
|
6638 |
|
6639 |
|
6640 |
|
6641 |
|
6642 | getXForText: function (points, d, textElement) {
|
6643 | var $$ = this;
|
6644 | var config = $$.config, state = $$.state;
|
6645 | var isRotated = config.axis_rotated;
|
6646 | var xPos = points[0][0];
|
6647 | if ($$.hasType("candlestick")) {
|
6648 | if (isRotated) {
|
6649 | xPos = $$.getCandlestickData(d)._isUp ?
|
6650 | points[2][2] + 4 : points[2][1] - 4;
|
6651 | }
|
6652 | else {
|
6653 | xPos += (points[1][0] - xPos) / 2;
|
6654 | }
|
6655 | }
|
6656 | else {
|
6657 | if (isRotated) {
|
6658 | var padding = $$.isBarType(d) ? 4 : 6;
|
6659 | xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1);
|
6660 | }
|
6661 | else {
|
6662 | xPos = $$.hasType("bar") ? (points[2][0] + points[0][0]) / 2 : xPos;
|
6663 | }
|
6664 | }
|
6665 |
|
6666 | if (d.value === null) {
|
6667 | if (xPos > state.width) {
|
6668 | var width = getBoundingRect(textElement).width;
|
6669 | xPos = state.width - width;
|
6670 | }
|
6671 | else if (xPos < 0) {
|
6672 | xPos = 4;
|
6673 | }
|
6674 | }
|
6675 | if (isRotated) {
|
6676 | xPos += $$.getCenteredTextPos(d, points, textElement);
|
6677 | }
|
6678 | return xPos + $$.getTextPos(d.id, "x");
|
6679 | },
|
6680 | |
6681 |
|
6682 |
|
6683 |
|
6684 |
|
6685 |
|
6686 |
|
6687 |
|
6688 | getYForText: function (points, d, textElement) {
|
6689 | var $$ = this;
|
6690 | var config = $$.config, state = $$.state;
|
6691 | var isRotated = config.axis_rotated;
|
6692 | var r = config.point_r;
|
6693 | var rect = getBoundingRect(textElement);
|
6694 | var value = d.value;
|
6695 | var baseY = 3;
|
6696 | var yPos;
|
6697 | if ($$.isCandlestickType(d)) {
|
6698 | value = $$.getCandlestickData(d);
|
6699 | if (isRotated) {
|
6700 | yPos = points[0][0];
|
6701 | yPos += ((points[1][0] - yPos) / 2) + baseY;
|
6702 | }
|
6703 | else {
|
6704 | yPos = value && value._isUp ?
|
6705 | points[2][2] - baseY :
|
6706 | points[2][1] + (baseY * 4);
|
6707 | }
|
6708 | }
|
6709 | else {
|
6710 | if (isRotated) {
|
6711 | yPos = (points[0][0] + points[2][0] + rect.height * 0.6) / 2;
|
6712 | }
|
6713 | else {
|
6714 | yPos = points[2][1];
|
6715 | if (isNumber(r) && r > 5 && ($$.isLineType(d) || $$.isScatterType(d))) {
|
6716 | baseY += config.point_r / 2.3;
|
6717 | }
|
6718 | if (value < 0 || (value === 0 && !state.hasPositiveValue && state.hasNegativeValue)) {
|
6719 | yPos += rect.height + ($$.isBarType(d) ? -baseY : baseY);
|
6720 | }
|
6721 | else {
|
6722 | var diff = -baseY * 2;
|
6723 | if ($$.isBarType(d)) {
|
6724 | diff = -baseY;
|
6725 | }
|
6726 | else if ($$.isBubbleType(d)) {
|
6727 | diff = baseY;
|
6728 | }
|
6729 | yPos += diff;
|
6730 | }
|
6731 | }
|
6732 | }
|
6733 |
|
6734 | if (d.value === null && !isRotated) {
|
6735 | var boxHeight = rect.height;
|
6736 | if (yPos < boxHeight) {
|
6737 | yPos = boxHeight;
|
6738 | }
|
6739 | else if (yPos > state.height) {
|
6740 | yPos = state.height - 4;
|
6741 | }
|
6742 | }
|
6743 | if (!isRotated) {
|
6744 | yPos += $$.getCenteredTextPos(d, points, textElement);
|
6745 | }
|
6746 | return yPos + $$.getTextPos(d.id, "y");
|
6747 | },
|
6748 | |
6749 |
|
6750 |
|
6751 |
|
6752 |
|
6753 |
|
6754 |
|
6755 |
|
6756 | markOverlapped: function (id, $$, selector) {
|
6757 | var textNodes = $$.$el.arcs.selectAll(selector);
|
6758 | var filteredTextNodes = textNodes.filter(function (node) { return node.data.id !== id; });
|
6759 | var textNode = textNodes.filter(function (node) { return node.data.id === id; });
|
6760 | var translate = getTranslation(textNode.node());
|
6761 |
|
6762 | var calcHypo = function (x, y) { return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); };
|
6763 | textNode.node() && filteredTextNodes.each(function () {
|
6764 | var coordinate = getTranslation(this);
|
6765 | var filteredTextNode = select(this);
|
6766 | var nodeForWidth = calcHypo(translate.e, translate.f) > calcHypo(coordinate.e, coordinate.f) ?
|
6767 | textNode : filteredTextNode;
|
6768 | var overlapsX = Math.ceil(Math.abs(translate.e - coordinate.e)) <
|
6769 | Math.ceil(nodeForWidth.node().getComputedTextLength());
|
6770 | var overlapsY = Math.ceil(Math.abs(translate.f - coordinate.f)) <
|
6771 | parseInt(textNode.style("font-size"), 10);
|
6772 | filteredTextNode.classed(CLASS.TextOverlapping, overlapsX && overlapsY);
|
6773 | });
|
6774 | },
|
6775 | |
6776 |
|
6777 |
|
6778 |
|
6779 |
|
6780 |
|
6781 |
|
6782 | undoMarkOverlapped: function ($$, selector) {
|
6783 | $$.$el.arcs.selectAll(selector)
|
6784 | .each(function () {
|
6785 | selectAll([this, this.previousSibling])
|
6786 | .classed(CLASS.TextOverlapping, false);
|
6787 | });
|
6788 | },
|
6789 | |
6790 |
|
6791 |
|
6792 |
|
6793 |
|
6794 |
|
6795 |
|
6796 | meetsLabelThreshold: function (ratio, type) {
|
6797 | if (ratio === void 0) { ratio = 0; }
|
6798 | var $$ = this;
|
6799 | var config = $$.config;
|
6800 | var threshold = config[type + "_label_threshold"] || 0;
|
6801 | return ratio >= threshold;
|
6802 | }
|
6803 | };
|
6804 |
|
6805 |
|
6806 |
|
6807 |
|
6808 |
|
6809 |
|
6810 |
|
6811 |
|
6812 |
|
6813 |
|
6814 |
|
6815 |
|
6816 | function getTextPos(pos, width) {
|
6817 | if (pos === void 0) { pos = "left"; }
|
6818 | var isNum = isNumber(width);
|
6819 | var position;
|
6820 | if (pos.indexOf("center") > -1) {
|
6821 | position = isNum ? width / 2 : "middle";
|
6822 | }
|
6823 | else if (pos.indexOf("right") > -1) {
|
6824 | position = isNum ? width : "end";
|
6825 | }
|
6826 | else {
|
6827 | position = isNum ? 0 : "start";
|
6828 | }
|
6829 | return position;
|
6830 | }
|
6831 | var title = {
|
6832 | |
6833 |
|
6834 |
|
6835 |
|
6836 | initTitle: function () {
|
6837 | var $$ = this;
|
6838 | var config = $$.config, $el = $$.$el;
|
6839 | if (config.title_text) {
|
6840 | $el.title = $el.svg.append("g");
|
6841 | var text = $el.title
|
6842 | .append("text")
|
6843 | .style("text-anchor", getTextPos(config.title_position))
|
6844 | .attr("class", CLASS.title);
|
6845 | setTextValue(text, config.title_text, [0.3, 1.5]);
|
6846 | }
|
6847 | },
|
6848 | |
6849 |
|
6850 |
|
6851 |
|
6852 | redrawTitle: function () {
|
6853 | var $$ = this;
|
6854 | var config = $$.config, current = $$.state.current, title = $$.$el.title;
|
6855 | if (title) {
|
6856 | var y = $$.yForTitle.call($$);
|
6857 | if (/g/i.test(title.node().tagName)) {
|
6858 | title.attr("transform", "translate(" + getTextPos(config.title_position, current.width) + ", " + y + ")");
|
6859 | }
|
6860 | else {
|
6861 | title.attr("x", $$.xForTitle.call($$)).attr("y", y);
|
6862 | }
|
6863 | }
|
6864 | },
|
6865 | |
6866 |
|
6867 |
|
6868 |
|
6869 |
|
6870 | xForTitle: function () {
|
6871 | var $$ = this;
|
6872 | var config = $$.config, current = $$.state.current;
|
6873 | var position = config.title_position || "left";
|
6874 | var textRectWidth = $$.getTextRect($$.$el.title, CLASS.title).width;
|
6875 | var x;
|
6876 | if (/(right|center)/.test(position)) {
|
6877 | x = current.width - textRectWidth;
|
6878 | if (position.indexOf("right") >= 0) {
|
6879 | x = current.width - textRectWidth - config.title_padding.right;
|
6880 | }
|
6881 | else if (position.indexOf("center") >= 0) {
|
6882 | x = (current.width - textRectWidth) / 2;
|
6883 | }
|
6884 | }
|
6885 | else {
|
6886 | x = (config.title_padding.left || 0);
|
6887 | }
|
6888 | return x;
|
6889 | },
|
6890 | |
6891 |
|
6892 |
|
6893 |
|
6894 |
|
6895 | yForTitle: function () {
|
6896 | var $$ = this;
|
6897 | return ($$.config.title_padding.top || 0) +
|
6898 | $$.getTextRect($$.$el.title, CLASS.title).height;
|
6899 | },
|
6900 | |
6901 |
|
6902 |
|
6903 |
|
6904 |
|
6905 | getTitlePadding: function () {
|
6906 | var $$ = this;
|
6907 | return $$.yForTitle() + ($$.config.title_padding.bottom || 0);
|
6908 | }
|
6909 | };
|
6910 |
|
6911 | var tooltip$1 = {
|
6912 | |
6913 |
|
6914 |
|
6915 |
|
6916 | initTooltip: function () {
|
6917 | var $$ = this;
|
6918 | var config = $$.config, $el = $$.$el;
|
6919 | $el.tooltip = select(config.tooltip_contents.bindto);
|
6920 | if ($el.tooltip.empty()) {
|
6921 | $el.tooltip = $el.chart
|
6922 | .style("position", "relative")
|
6923 | .append("div")
|
6924 | .attr("class", CLASS.tooltipContainer)
|
6925 | .style("position", "absolute")
|
6926 | .style("pointer-events", "none")
|
6927 | .style("display", "none");
|
6928 | }
|
6929 | $$.bindTooltipResizePos();
|
6930 | },
|
6931 | initShowTooltip: function () {
|
6932 | var $$ = this;
|
6933 | var config = $$.config, $el = $$.$el, _a = $$.state, hasAxis = _a.hasAxis, hasRadar = _a.hasRadar;
|
6934 |
|
6935 | if (config.tooltip_init_show) {
|
6936 | var isArc_1 = !(hasAxis && hasRadar);
|
6937 | if ($$.axis && $$.axis.isTimeSeries() && isString(config.tooltip_init_x)) {
|
6938 | var targets = $$.data.targets[0];
|
6939 | var i = void 0;
|
6940 | var val = void 0;
|
6941 | config.tooltip_init_x = parseDate.call($$, config.tooltip_init_x);
|
6942 | for (i = 0; (val = targets.values[i]); i++) {
|
6943 | if ((val.x - config.tooltip_init_x) === 0) {
|
6944 | break;
|
6945 | }
|
6946 | }
|
6947 | config.tooltip_init_x = i;
|
6948 | }
|
6949 | var data = $$.data.targets.map(function (d) {
|
6950 | var x = isArc_1 ? 0 : config.tooltip_init_x;
|
6951 | return $$.addName(d.values[x]);
|
6952 | });
|
6953 | if (isArc_1) {
|
6954 | data = [data[config.tooltip_init_x]];
|
6955 | }
|
6956 | $el.tooltip.html($$.getTooltipHTML(data, $$.axis && $$.axis.getXAxisTickFormat(), $$.getYFormat($$.hasArcType(null, ["radar"])), $$.color));
|
6957 | if (!config.tooltip_contents.bindto) {
|
6958 | $el.tooltip.style("top", config.tooltip_init_position.top)
|
6959 | .style("left", config.tooltip_init_position.left)
|
6960 | .style("display", "block");
|
6961 | }
|
6962 | }
|
6963 | },
|
6964 | |
6965 |
|
6966 |
|
6967 |
|
6968 |
|
6969 |
|
6970 | getTooltipHTML: function () {
|
6971 | var args = [];
|
6972 | for (var _i = 0; _i < arguments.length; _i++) {
|
6973 | args[_i] = arguments[_i];
|
6974 | }
|
6975 | var $$ = this;
|
6976 | var api = $$.api, config = $$.config;
|
6977 | return isFunction(config.tooltip_contents) ? config.tooltip_contents.bind(api).apply(void 0, args) : $$.getTooltipContent.apply($$, args);
|
6978 | },
|
6979 | |
6980 |
|
6981 |
|
6982 |
|
6983 |
|
6984 |
|
6985 |
|
6986 |
|
6987 |
|
6988 | getTooltipContent: function (d, defaultTitleFormat, defaultValueFormat, color) {
|
6989 | var $$ = this;
|
6990 | var api = $$.api, config = $$.config, state = $$.state;
|
6991 | var _a = ["title", "name", "value"].map(function (v) {
|
6992 | var fn = config["tooltip_format_" + v];
|
6993 | return isFunction(fn) ? fn.bind(api) : fn;
|
6994 | }), titleFormat = _a[0], nameFormat = _a[1], valueFormat = _a[2];
|
6995 | titleFormat = titleFormat || defaultTitleFormat;
|
6996 | nameFormat = nameFormat || (function (name) { return name; });
|
6997 | valueFormat = valueFormat || ($$.isStackNormalized() ? function (v, ratio) { return (ratio * 100).toFixed(2) + "%"; } : defaultValueFormat);
|
6998 | var order = config.tooltip_order;
|
6999 | var getRowValue = function (row) { return ($$.axis && $$.isBubbleZType(row) ? $$.getBubbleZData(row.value, "z") : $$.getBaseValue(row)); };
|
7000 | var getBgColor = $$.levelColor ? function (row) { return $$.levelColor(row.value); } : function (row) { return color(row); };
|
7001 | var contents = config.tooltip_contents;
|
7002 | var tplStr = contents.template;
|
7003 | var targetIds = $$.mapToTargetIds();
|
7004 | if (order === null && config.data_groups.length) {
|
7005 |
|
7006 | var ids_1 = $$.orderTargets($$.data.targets)
|
7007 | .map(function (i2) { return i2.id; })
|
7008 | .reverse();
|
7009 | d.sort(function (a, b) {
|
7010 | var v1 = a ? a.value : null;
|
7011 | var v2 = b ? b.value : null;
|
7012 | if (v1 > 0 && v2 > 0) {
|
7013 | v1 = a.id ? ids_1.indexOf(a.id) : null;
|
7014 | v2 = b.id ? ids_1.indexOf(b.id) : null;
|
7015 | }
|
7016 | return v1 - v2;
|
7017 | });
|
7018 | }
|
7019 | else if (/^(asc|desc)$/.test(order)) {
|
7020 | var isAscending_1 = order === "asc";
|
7021 | d.sort(function (a, b) {
|
7022 | var v1 = a ? getRowValue(a) : null;
|
7023 | var v2 = b ? getRowValue(b) : null;
|
7024 | return isAscending_1 ? v1 - v2 : v2 - v1;
|
7025 | });
|
7026 | }
|
7027 | else if (isFunction(order)) {
|
7028 | d.sort(order.bind(api));
|
7029 | }
|
7030 | var tpl = $$.getTooltipContentTemplate(tplStr);
|
7031 | var len = d.length;
|
7032 | var text;
|
7033 | var row;
|
7034 | var param;
|
7035 | var value;
|
7036 | var i;
|
7037 | var _loop_1 = function () {
|
7038 | row = d[i];
|
7039 | if (!row || !(getRowValue(row) || getRowValue(row) === 0)) {
|
7040 | return "continue";
|
7041 | }
|
7042 | if (isUndefined(text)) {
|
7043 | var title = (state.hasAxis || state.hasRadar) &&
|
7044 | sanitise(titleFormat ? titleFormat(row.x) : row.x);
|
7045 | text = tplProcess(tpl[0], {
|
7046 | CLASS_TOOLTIP: CLASS.tooltip,
|
7047 | TITLE: isValue(title) ? (tplStr ? title : "<tr><th colspan=\"2\">" + title + "</th></tr>") : ""
|
7048 | });
|
7049 | }
|
7050 | if (!row.ratio && $$.$el.arcs) {
|
7051 | row.ratio = $$.getRatio("arc", $$.$el.arcs.select("path." + CLASS.arc + "-" + row.id).data()[0]);
|
7052 | }
|
7053 | param = [row.ratio, row.id, row.index, d];
|
7054 | value = sanitise(valueFormat.apply(void 0, __spreadArray([getRowValue(row)], param)));
|
7055 | if ($$.isAreaRangeType(row)) {
|
7056 | var _b = ["high", "low"].map(function (v) { return sanitise(valueFormat.apply(void 0, __spreadArray([$$.getRangedData(row, v)], param))); }), high = _b[0], low = _b[1];
|
7057 | value = "<b>Mid:</b> " + value + " <b>High:</b> " + high + " <b>Low:</b> " + low;
|
7058 | }
|
7059 | else if ($$.isCandlestickType(row)) {
|
7060 | var _c = ["open", "high", "low", "close", "volume"].map(function (v) { return sanitise(valueFormat.apply(void 0, __spreadArray([$$.getRangedData(row, v, "candlestick")], param))); }), open_1 = _c[0], high = _c[1], low = _c[2], close_1 = _c[3], volume = _c[4];
|
7061 | value = "<b>Open:</b> " + open_1 + " <b>High:</b> " + high + " <b>Low:</b> " + low + " <b>Close:</b> " + close_1 + (volume ? " <b>Volume:</b> " + volume : "");
|
7062 | }
|
7063 | if (value !== undefined) {
|
7064 |
|
7065 | if (row.name === null) {
|
7066 | return "continue";
|
7067 | }
|
7068 | var name_1 = sanitise(nameFormat.apply(void 0, __spreadArray([row.name], param)));
|
7069 | var color_1 = getBgColor(row);
|
7070 | var contentValue_1 = {
|
7071 | CLASS_TOOLTIP_NAME: CLASS.tooltipName + $$.getTargetSelectorSuffix(row.id),
|
7072 | COLOR: (tplStr || !$$.patterns) ? color_1 : "<svg><rect style=\"fill:" + color_1 + "\" width=\"10\" height=\"10\"></rect></svg>",
|
7073 | NAME: name_1,
|
7074 | VALUE: value
|
7075 | };
|
7076 | if (tplStr && isObject(contents.text)) {
|
7077 | var index_1 = targetIds.indexOf(row.id);
|
7078 | Object.keys(contents.text).forEach(function (key) {
|
7079 | contentValue_1[key] = contents.text[key][index_1];
|
7080 | });
|
7081 | }
|
7082 | text += tplProcess(tpl[1], contentValue_1);
|
7083 | }
|
7084 | };
|
7085 | for (i = 0; i < len; i++) {
|
7086 | _loop_1();
|
7087 | }
|
7088 | return text + "</table>";
|
7089 | },
|
7090 | |
7091 |
|
7092 |
|
7093 |
|
7094 |
|
7095 |
|
7096 | getTooltipContentTemplate: function (tplStr) {
|
7097 | return (tplStr || "<table class=\"{=CLASS_TOOLTIP}\"><tbody>\n\t\t\t\t{=TITLE}\n\t\t\t\t{{<tr class=\"{=CLASS_TOOLTIP_NAME}\">\n\t\t\t\t\t<td class=\"name\">" + (this.patterns ? "{=COLOR}" : "<span style=\"background-color:{=COLOR}\"></span>") + "{=NAME}</td>\n\t\t\t\t\t<td class=\"value\">{=VALUE}</td>\n\t\t\t\t</tr>}}\n\t\t\t</tbody></table>")
|
7098 | .replace(/(\r?\n|\t)/g, "")
|
7099 | .split(/{{(.*)}}/);
|
7100 | },
|
7101 | |
7102 |
|
7103 |
|
7104 |
|
7105 |
|
7106 |
|
7107 |
|
7108 |
|
7109 |
|
7110 | tooltipPosition: function (dataToShow, tWidth, tHeight, element) {
|
7111 | var $$ = this;
|
7112 | var config = $$.config, scale = $$.scale, state = $$.state;
|
7113 | var width = state.width, height = state.height, current = state.current, isLegendRight = state.isLegendRight, inputType = state.inputType, event = state.event;
|
7114 | var hasGauge = $$.hasType("gauge") && !config.gauge_fullCircle;
|
7115 | var svgLeft = $$.getSvgLeft(true);
|
7116 | var chartRight = svgLeft + current.width - $$.getCurrentPaddingRight();
|
7117 | var chartLeft = $$.getCurrentPaddingLeft(true);
|
7118 | var size = 20;
|
7119 | var _a = getPointer(event, element), x = _a[0], y = _a[1];
|
7120 |
|
7121 | if ($$.hasArcType()) {
|
7122 | var raw = inputType === "touch" || $$.hasType("radar");
|
7123 | if (!raw) {
|
7124 | y += hasGauge ? height : height / 2;
|
7125 | x += (width - (isLegendRight ? $$.getLegendWidth() : 0)) / 2;
|
7126 | }
|
7127 | }
|
7128 | else {
|
7129 | var dataScale = scale.x(dataToShow[0].x);
|
7130 | if (config.axis_rotated) {
|
7131 | y = dataScale + size;
|
7132 | x += svgLeft + 100;
|
7133 | chartRight -= svgLeft;
|
7134 | }
|
7135 | else {
|
7136 | y -= 5;
|
7137 | x = svgLeft + chartLeft + size + ($$.zoomScale ? x : dataScale);
|
7138 | }
|
7139 | }
|
7140 |
|
7141 | if ((x + tWidth + 15) > chartRight) {
|
7142 | x -= tWidth + chartLeft;
|
7143 | }
|
7144 | if (y + tHeight > current.height) {
|
7145 | y -= hasGauge ? tHeight * 3 : tHeight + 30;
|
7146 | }
|
7147 | var pos = { top: y, left: x };
|
7148 |
|
7149 | Object.keys(pos).forEach(function (v) {
|
7150 | if (pos[v] < 0) {
|
7151 | pos[v] = 0;
|
7152 | }
|
7153 | });
|
7154 | return pos;
|
7155 | },
|
7156 | |
7157 |
|
7158 |
|
7159 |
|
7160 |
|
7161 |
|
7162 | showTooltip: function (selectedData, element) {
|
7163 | var $$ = this;
|
7164 | var config = $$.config, state = $$.state, tooltip = $$.$el.tooltip;
|
7165 | var bindto = config.tooltip_contents.bindto;
|
7166 | var forArc = $$.hasArcType(null, ["radar"]);
|
7167 | var dataToShow = selectedData.filter(function (d) { return d && isValue($$.getBaseValue(d)); });
|
7168 | if (!tooltip || dataToShow.length === 0 || !config.tooltip_show) {
|
7169 | return;
|
7170 | }
|
7171 | var datum = tooltip.datum();
|
7172 | var _a = datum || {}, _b = _a.width, width = _b === void 0 ? 0 : _b, _c = _a.height, height = _c === void 0 ? 0 : _c;
|
7173 | var dataStr = JSON.stringify(selectedData);
|
7174 | if (!datum || datum.current !== dataStr) {
|
7175 | var index = selectedData.concat().sort()[0].index;
|
7176 | callFn(config.tooltip_onshow, $$.api, selectedData);
|
7177 |
|
7178 | tooltip
|
7179 | .html($$.getTooltipHTML(selectedData,
|
7180 | $$.axis ? $$.axis.getXAxisTickFormat() : $$.categoryName.bind($$),
|
7181 | $$.getYFormat(forArc),
|
7182 | $$.color
|
7183 | ))
|
7184 | .style("display", null)
|
7185 | .style("visibility", null)
|
7186 | .datum(datum = {
|
7187 | index: index,
|
7188 | current: dataStr,
|
7189 | width: width = tooltip.property("offsetWidth"),
|
7190 | height: height = tooltip.property("offsetHeight")
|
7191 | });
|
7192 | callFn(config.tooltip_onshown, $$.api, selectedData);
|
7193 | $$._handleLinkedCharts(true, index);
|
7194 | }
|
7195 | if (!bindto) {
|
7196 | var fnPos = config.tooltip_position || $$.tooltipPosition;
|
7197 |
|
7198 | var pos_1 = fnPos.call(this, dataToShow, width, height, element);
|
7199 | ["top", "left"].forEach(function (v) {
|
7200 | var value = pos_1[v];
|
7201 | tooltip.style(v, value + "px");
|
7202 |
|
7203 | if (v === "left" && !datum.xPosInPercent) {
|
7204 | datum.xPosInPercent = value / state.current.width * 100;
|
7205 | }
|
7206 | });
|
7207 | }
|
7208 | },
|
7209 | |
7210 |
|
7211 |
|
7212 |
|
7213 | bindTooltipResizePos: function () {
|
7214 | var $$ = this;
|
7215 | var resizeFunction = $$.resizeFunction, state = $$.state, tooltip = $$.$el.tooltip;
|
7216 | resizeFunction.add(function () {
|
7217 | if (tooltip.style("display") === "block") {
|
7218 | var current = state.current;
|
7219 | var _a = tooltip.datum(), width = _a.width, xPosInPercent = _a.xPosInPercent;
|
7220 | var value = current.width / 100 * xPosInPercent;
|
7221 | var diff = current.width - (value + width);
|
7222 |
|
7223 | if (diff < 0) {
|
7224 | value += diff;
|
7225 | }
|
7226 | tooltip.style("left", value + "px");
|
7227 | }
|
7228 | });
|
7229 | },
|
7230 | |
7231 |
|
7232 |
|
7233 |
|
7234 |
|
7235 | hideTooltip: function (force) {
|
7236 | var $$ = this;
|
7237 | var api = $$.api, config = $$.config, tooltip = $$.$el.tooltip;
|
7238 | if (tooltip && tooltip.style("display") !== "none" && (!config.tooltip_doNotHide || force)) {
|
7239 | var selectedData = JSON.parse(tooltip.datum().current);
|
7240 | callFn(config.tooltip_onhide, api, selectedData);
|
7241 |
|
7242 | tooltip
|
7243 | .style("display", "none")
|
7244 | .style("visibility", "hidden")
|
7245 | .datum(null);
|
7246 | callFn(config.tooltip_onhidden, api, selectedData);
|
7247 | }
|
7248 | },
|
7249 | |
7250 |
|
7251 |
|
7252 |
|
7253 |
|
7254 |
|
7255 | _handleLinkedCharts: function (show, index) {
|
7256 | var $$ = this;
|
7257 | var charts = $$.charts, config = $$.config, event = $$.state.event;
|
7258 |
|
7259 |
|
7260 | if (event && event.isTrusted && config.tooltip_linked && charts.length > 1) {
|
7261 | var linkedName_1 = config.tooltip_linked_name;
|
7262 | charts
|
7263 | .filter(function (c) { return c !== $$.api; })
|
7264 | .forEach(function (c) {
|
7265 | var _a = c.internal, config = _a.config, $el = _a.$el;
|
7266 | var isLinked = config.tooltip_linked;
|
7267 | var name = config.tooltip_linked_name;
|
7268 | var isInDom = doc.body.contains($el.chart.node());
|
7269 | if (isLinked && linkedName_1 === name && isInDom) {
|
7270 | var data = $el.tooltip.data()[0];
|
7271 | var isNotSameIndex = index !== (data && data.index);
|
7272 | try {
|
7273 | c.tooltip[show && isNotSameIndex ? "show" : "hide"]({ index: index });
|
7274 | }
|
7275 | catch (e) { }
|
7276 | }
|
7277 | });
|
7278 | }
|
7279 | }
|
7280 | };
|
7281 |
|
7282 |
|
7283 |
|
7284 |
|
7285 |
|
7286 | var transform = {
|
7287 | getTranslate: function (target, index) {
|
7288 | if (index === void 0) { index = 0; }
|
7289 | var $$ = this;
|
7290 | var config = $$.config, state = $$.state;
|
7291 | var isRotated = config.axis_rotated;
|
7292 | var padding = 0;
|
7293 | var x;
|
7294 | var y;
|
7295 | if (index && /^(x|y2?)$/.test(target)) {
|
7296 | padding = $$.getAxisSize(target) * index;
|
7297 | }
|
7298 | if (target === "main") {
|
7299 | x = asHalfPixel(state.margin.left);
|
7300 | y = asHalfPixel(state.margin.top);
|
7301 | }
|
7302 | else if (target === "context") {
|
7303 | x = asHalfPixel(state.margin2.left);
|
7304 | y = asHalfPixel(state.margin2.top);
|
7305 | }
|
7306 | else if (target === "legend") {
|
7307 | x = state.margin3.left;
|
7308 | y = state.margin3.top;
|
7309 | }
|
7310 | else if (target === "x") {
|
7311 | x = isRotated ? -padding : 0;
|
7312 | y = isRotated ? 0 : state.height + padding;
|
7313 | }
|
7314 | else if (target === "y") {
|
7315 | x = isRotated ? 0 : -padding;
|
7316 | y = isRotated ? state.height + padding : 0;
|
7317 | }
|
7318 | else if (target === "y2") {
|
7319 | x = isRotated ? 0 : state.width + padding;
|
7320 | y = isRotated ? 1 - padding : 0;
|
7321 | }
|
7322 | else if (target === "subX") {
|
7323 | x = 0;
|
7324 | y = isRotated ? 0 : state.height2;
|
7325 | }
|
7326 | else if (target === "arc") {
|
7327 | x = state.arcWidth / 2;
|
7328 | y = state.arcHeight / 2;
|
7329 | }
|
7330 | else if (target === "radar") {
|
7331 | var width = $$.getRadarSize()[0];
|
7332 | x = state.width / 2 - width;
|
7333 | y = asHalfPixel(state.margin.top);
|
7334 | }
|
7335 | return "translate(" + x + ", " + y + ")";
|
7336 | },
|
7337 | transformMain: function (withTransition, transitions) {
|
7338 | var $$ = this;
|
7339 | var main = $$.$el.main;
|
7340 | var xAxis;
|
7341 | var yAxis;
|
7342 | var y2Axis;
|
7343 | if (transitions && transitions.axisX) {
|
7344 | xAxis = transitions.axisX;
|
7345 | }
|
7346 | else {
|
7347 | xAxis = main.select("." + CLASS.axisX);
|
7348 | if (withTransition) {
|
7349 | xAxis = xAxis.transition();
|
7350 | }
|
7351 | }
|
7352 | if (transitions && transitions.axisY) {
|
7353 | yAxis = transitions.axisY;
|
7354 | }
|
7355 | else {
|
7356 | yAxis = main.select("." + CLASS.axisY);
|
7357 | if (withTransition) {
|
7358 | yAxis = yAxis.transition();
|
7359 | }
|
7360 | }
|
7361 | if (transitions && transitions.axisY2) {
|
7362 | y2Axis = transitions.axisY2;
|
7363 | }
|
7364 | else {
|
7365 | y2Axis = main.select("." + CLASS.axisY2);
|
7366 | if (withTransition) {
|
7367 | y2Axis = y2Axis.transition();
|
7368 | }
|
7369 | }
|
7370 | (withTransition ? main.transition() : main)
|
7371 | .attr("transform", $$.getTranslate("main"));
|
7372 | xAxis.attr("transform", $$.getTranslate("x"));
|
7373 | yAxis.attr("transform", $$.getTranslate("y"));
|
7374 | y2Axis.attr("transform", $$.getTranslate("y2"));
|
7375 | main.select("." + CLASS.chartArcs)
|
7376 | .attr("transform", $$.getTranslate("arc"));
|
7377 | },
|
7378 | transformAll: function (withTransition, transitions) {
|
7379 | var $$ = this;
|
7380 | var config = $$.config, hasAxis = $$.state.hasAxis, $el = $$.$el;
|
7381 | $$.transformMain(withTransition, transitions);
|
7382 | hasAxis && config.subchart_show &&
|
7383 | $$.transformContext(withTransition, transitions);
|
7384 | $el.legend && $$.transformLegend(withTransition);
|
7385 | }
|
7386 | };
|
7387 |
|
7388 |
|
7389 |
|
7390 |
|
7391 |
|
7392 | var type = {
|
7393 | setTargetType: function (targetIds, type) {
|
7394 | var $$ = this;
|
7395 | var config = $$.config, withoutFadeIn = $$.state.withoutFadeIn;
|
7396 | $$.mapToTargetIds(targetIds).forEach(function (id) {
|
7397 | withoutFadeIn[id] = (type === config.data_types[id]);
|
7398 | config.data_types[id] = type;
|
7399 | });
|
7400 | if (!targetIds) {
|
7401 | config.data_type = type;
|
7402 | }
|
7403 | },
|
7404 | |
7405 |
|
7406 |
|
7407 |
|
7408 | updateTypesElements: function () {
|
7409 | var $$ = this;
|
7410 | var current = $$.state.current;
|
7411 | Object.keys(TYPE).forEach(function (v) {
|
7412 | var t = TYPE[v];
|
7413 | var has = $$.hasType(t, null, true);
|
7414 | var idx = current.types.indexOf(t);
|
7415 | if (idx === -1 && has) {
|
7416 | current.types.push(t);
|
7417 | }
|
7418 | else if (idx > -1 && !has) {
|
7419 | current.types.splice(idx, 1);
|
7420 | }
|
7421 | });
|
7422 |
|
7423 | $$.setChartElements();
|
7424 | },
|
7425 | |
7426 |
|
7427 |
|
7428 |
|
7429 |
|
7430 |
|
7431 |
|
7432 |
|
7433 | hasType: function (type, targetsValue, checkFromData) {
|
7434 | if (checkFromData === void 0) { checkFromData = false; }
|
7435 | var $$ = this;
|
7436 | var config = $$.config, current = $$.state.current;
|
7437 | var types = config.data_types;
|
7438 | var targets = targetsValue || $$.data.targets;
|
7439 | var has = false;
|
7440 | if (!checkFromData && current.types.length && current.types.indexOf(type) > -1) {
|
7441 | has = true;
|
7442 | }
|
7443 | else if (targets && targets.length) {
|
7444 | targets.forEach(function (target) {
|
7445 | var t = types[target.id];
|
7446 | if (t === type || (!t && type === "line")) {
|
7447 | has = true;
|
7448 | }
|
7449 | });
|
7450 | }
|
7451 | else if (Object.keys(types).length) {
|
7452 | Object.keys(types).forEach(function (id) {
|
7453 | if (types[id] === type) {
|
7454 | has = true;
|
7455 | }
|
7456 | });
|
7457 | }
|
7458 | else {
|
7459 | has = config.data_type === type;
|
7460 | }
|
7461 | return has;
|
7462 | },
|
7463 | |
7464 |
|
7465 |
|
7466 |
|
7467 |
|
7468 |
|
7469 |
|
7470 |
|
7471 | hasTypeOf: function (type, targets, exclude) {
|
7472 | var _this = this;
|
7473 | if (exclude === void 0) { exclude = []; }
|
7474 | if (type in TYPE_BY_CATEGORY) {
|
7475 | return !TYPE_BY_CATEGORY[type]
|
7476 | .filter(function (v) { return exclude.indexOf(v) === -1; })
|
7477 | .every(function (v) { return !_this.hasType(v, targets); });
|
7478 | }
|
7479 | return false;
|
7480 | },
|
7481 | |
7482 |
|
7483 |
|
7484 |
|
7485 |
|
7486 |
|
7487 |
|
7488 | isTypeOf: function (d, type) {
|
7489 | var id = isString(d) ? d : d.id;
|
7490 | var dataType = this.config.data_types[id] || this.config.data_type;
|
7491 | return isArray(type) ?
|
7492 | type.indexOf(dataType) >= 0 : dataType === type;
|
7493 | },
|
7494 | hasPointType: function () {
|
7495 | var $$ = this;
|
7496 | return $$.hasTypeOf("Line") || $$.hasType("bubble") || $$.hasType("scatter");
|
7497 | },
|
7498 | |
7499 |
|
7500 |
|
7501 |
|
7502 |
|
7503 |
|
7504 |
|
7505 | hasArcType: function (targets, exclude) {
|
7506 | return this.hasTypeOf("Arc", targets, exclude);
|
7507 | },
|
7508 | hasMultiArcGauge: function () {
|
7509 | return this.hasType("gauge") && this.config.gauge_type === "multi";
|
7510 | },
|
7511 | isLineType: function (d) {
|
7512 | var id = isString(d) ? d : d.id;
|
7513 | return !this.config.data_types[id] ||
|
7514 | this.isTypeOf(id, TYPE_BY_CATEGORY.Line);
|
7515 | },
|
7516 | isStepType: function (d) {
|
7517 | return this.isTypeOf(d, TYPE_BY_CATEGORY.Step);
|
7518 | },
|
7519 | isSplineType: function (d) {
|
7520 | return this.isTypeOf(d, TYPE_BY_CATEGORY.Spline);
|
7521 | },
|
7522 | isAreaType: function (d) {
|
7523 | return this.isTypeOf(d, TYPE_BY_CATEGORY.Area);
|
7524 | },
|
7525 | isAreaRangeType: function (d) {
|
7526 | return this.isTypeOf(d, TYPE_BY_CATEGORY.AreaRange);
|
7527 | },
|
7528 | isBarType: function (d) {
|
7529 | return this.isTypeOf(d, "bar");
|
7530 | },
|
7531 | isBubbleType: function (d) {
|
7532 | return this.isTypeOf(d, "bubble");
|
7533 | },
|
7534 | isCandlestickType: function (d) {
|
7535 | return this.isTypeOf(d, "candlestick");
|
7536 | },
|
7537 | isScatterType: function (d) {
|
7538 | return this.isTypeOf(d, "scatter");
|
7539 | },
|
7540 | isPieType: function (d) {
|
7541 | return this.isTypeOf(d, "pie");
|
7542 | },
|
7543 | isGaugeType: function (d) {
|
7544 | return this.isTypeOf(d, "gauge");
|
7545 | },
|
7546 | isDonutType: function (d) {
|
7547 | return this.isTypeOf(d, "donut");
|
7548 | },
|
7549 | isRadarType: function (d) {
|
7550 | return this.isTypeOf(d, "radar");
|
7551 | },
|
7552 | isArcType: function (d) {
|
7553 | return this.isPieType(d) ||
|
7554 | this.isDonutType(d) ||
|
7555 | this.isGaugeType(d) ||
|
7556 | this.isRadarType(d);
|
7557 | },
|
7558 |
|
7559 | isCirclePoint: function (node) {
|
7560 | var config = this.config;
|
7561 | var pattern = config.point_pattern;
|
7562 | var isCircle = false;
|
7563 | if (node && node.tagName === "circle") {
|
7564 | isCircle = true;
|
7565 | }
|
7566 | else {
|
7567 | isCircle = config.point_type === "circle" &&
|
7568 | (!pattern || (isArray(pattern) && pattern.length === 0));
|
7569 | }
|
7570 | return isCircle;
|
7571 | },
|
7572 | lineData: function (d) {
|
7573 | return this.isLineType(d) ? [d] : [];
|
7574 | },
|
7575 | arcData: function (d) {
|
7576 | return this.isArcType(d.data) ? [d] : [];
|
7577 | },
|
7578 | |
7579 |
|
7580 |
|
7581 |
|
7582 |
|
7583 |
|
7584 | labelishData: function (d) {
|
7585 | return this.isBarType(d) ||
|
7586 | this.isLineType(d) ||
|
7587 | this.isScatterType(d) ||
|
7588 | this.isBubbleType(d) ||
|
7589 | this.isCandlestickType(d) ||
|
7590 | this.isRadarType(d) ? d.values.filter(function (v) { return isNumber(v.value) || Boolean(v.value); }) : [];
|
7591 | },
|
7592 | barLineBubbleData: function (d) {
|
7593 | return this.isBarType(d) || this.isLineType(d) || this.isBubbleType(d) ?
|
7594 | d.values : [];
|
7595 | },
|
7596 |
|
7597 | isInterpolationType: function (type) {
|
7598 | return [
|
7599 | "basis",
|
7600 | "basis-closed",
|
7601 | "basis-open",
|
7602 | "bundle",
|
7603 | "cardinal",
|
7604 | "cardinal-closed",
|
7605 | "cardinal-open",
|
7606 | "catmull-rom",
|
7607 | "catmull-rom-closed",
|
7608 | "catmull-rom-open",
|
7609 | "linear",
|
7610 | "linear-closed",
|
7611 | "monotone-x",
|
7612 | "monotone-y",
|
7613 | "natural"
|
7614 | ].indexOf(type) >= 0;
|
7615 | }
|
7616 | };
|
7617 |
|
7618 |
|
7619 |
|
7620 |
|
7621 |
|
7622 |
|
7623 |
|
7624 |
|
7625 |
|
7626 |
|
7627 |
|
7628 |
|
7629 |
|
7630 | var ChartInternal = (function () {
|
7631 | function ChartInternal(api) {
|
7632 |
|
7633 | this.data = {
|
7634 | xs: {},
|
7635 | targets: []
|
7636 | };
|
7637 |
|
7638 | this.scale = {
|
7639 | x: null,
|
7640 | y: null,
|
7641 | y2: null,
|
7642 | subX: null,
|
7643 | subY: null,
|
7644 | subY2: null,
|
7645 | zoom: null
|
7646 | };
|
7647 |
|
7648 | this.org = {
|
7649 | xScale: null,
|
7650 | xDomain: null
|
7651 | };
|
7652 |
|
7653 | this.format = {
|
7654 | extraLineClasses: null,
|
7655 | xAxisTick: null,
|
7656 | dataTime: null,
|
7657 | defaultAxisTime: null,
|
7658 | axisTime: null
|
7659 | };
|
7660 | var $$ = this;
|
7661 | $$.api = api;
|
7662 | $$.config = new Options();
|
7663 | $$.cache = new Cache();
|
7664 | var store = new Store();
|
7665 | $$.$el = store.getStore("element");
|
7666 | $$.state = store.getStore("state");
|
7667 | }
|
7668 | ChartInternal.prototype.beforeInit = function () {
|
7669 | var $$ = this;
|
7670 | $$.callPluginHook("$beforeInit");
|
7671 |
|
7672 | callFn($$.config.onbeforeinit, $$.api);
|
7673 | };
|
7674 | ChartInternal.prototype.afterInit = function () {
|
7675 | var $$ = this;
|
7676 | $$.callPluginHook("$afterInit");
|
7677 |
|
7678 | callFn($$.config.onafterinit, $$.api);
|
7679 | };
|
7680 | ChartInternal.prototype.init = function () {
|
7681 | var $$ = this;
|
7682 | var config = $$.config, state = $$.state, $el = $$.$el;
|
7683 | state.hasAxis = !$$.hasArcType();
|
7684 | state.hasRadar = !state.hasAxis && $$.hasType("radar");
|
7685 | $$.initParams();
|
7686 | var bindto = {
|
7687 | element: config.bindto,
|
7688 | classname: "bb"
|
7689 | };
|
7690 | if (isObject(config.bindto)) {
|
7691 | bindto.element = config.bindto.element || "#chart";
|
7692 | bindto.classname = config.bindto.classname || bindto.classname;
|
7693 | }
|
7694 |
|
7695 | $el.chart = isFunction(bindto.element.node) ?
|
7696 | config.bindto.element : select(bindto.element || []);
|
7697 | if ($el.chart.empty()) {
|
7698 | $el.chart = select(doc.body.appendChild(doc.createElement("div")));
|
7699 | }
|
7700 | $el.chart.html("").classed(bindto.classname, true);
|
7701 | $$.initToRender();
|
7702 | };
|
7703 | |
7704 |
|
7705 |
|
7706 |
|
7707 |
|
7708 | ChartInternal.prototype.initToRender = function (forced) {
|
7709 | var $$ = this;
|
7710 | var config = $$.config, state = $$.state, chart = $$.$el.chart;
|
7711 | var isHidden = function () { return chart.style("display") === "none" || chart.style("visibility") === "hidden"; };
|
7712 | var isLazy = config.render.lazy || isHidden();
|
7713 | var MutationObserver = win.MutationObserver;
|
7714 | if (isLazy && MutationObserver && config.render.observe !== false && !forced) {
|
7715 | new MutationObserver(function (mutation, observer) {
|
7716 | if (!isHidden()) {
|
7717 | observer.disconnect();
|
7718 | !state.rendered && $$.initToRender(true);
|
7719 | }
|
7720 | }).observe(chart.node(), {
|
7721 | attributes: true,
|
7722 | attributeFilter: ["class", "style"]
|
7723 | });
|
7724 | }
|
7725 | if (!isLazy || forced) {
|
7726 | var convertedData = $$.convertData(config, $$.initWithData);
|
7727 | convertedData && $$.initWithData(convertedData);
|
7728 | $$.afterInit();
|
7729 | }
|
7730 | };
|
7731 | ChartInternal.prototype.initParams = function () {
|
7732 | var $$ = this;
|
7733 | var _a = $$, config = _a.config, format = _a.format, state = _a.state;
|
7734 | var isRotated = config.axis_rotated;
|
7735 |
|
7736 | state.datetimeId = "bb-" + +new Date();
|
7737 | $$.color = $$.generateColor();
|
7738 | $$.levelColor = $$.generateLevelColor();
|
7739 | if ($$.hasPointType()) {
|
7740 | $$.point = $$.generatePoint();
|
7741 | }
|
7742 | if (state.hasAxis) {
|
7743 | $$.initClip();
|
7744 | format.extraLineClasses = $$.generateExtraLineClass();
|
7745 | format.dataTime = config.data_xLocaltime ? timeParse : utcParse;
|
7746 | format.axisTime = config.axis_x_localtime ? timeFormat : utcFormat;
|
7747 | var isDragZoom_1 = $$.config.zoom_enabled && $$.config.zoom_type === "drag";
|
7748 | format.defaultAxisTime = function (d) {
|
7749 | var _a = $$.scale, x = _a.x, zoom = _a.zoom;
|
7750 | var isZoomed = isDragZoom_1 ? zoom :
|
7751 | zoom && x.orgDomain().toString() !== zoom.domain().toString();
|
7752 | var specifier = (d.getMilliseconds() && ".%L") ||
|
7753 | (d.getSeconds() && ".:%S") ||
|
7754 | (d.getMinutes() && "%I:%M") ||
|
7755 | (d.getHours() && "%I %p") ||
|
7756 | (d.getDate() !== 1 && "%b %d") ||
|
7757 | (isZoomed && d.getDate() === 1 && "%b\'%y") ||
|
7758 | (d.getMonth() && "%-m/%-d") || "%Y";
|
7759 | return format.axisTime(specifier)(d);
|
7760 | };
|
7761 | }
|
7762 | state.isLegendRight = config.legend_position === "right";
|
7763 | state.isLegendInset = config.legend_position === "inset";
|
7764 | state.isLegendTop = config.legend_inset_anchor === "top-left" ||
|
7765 | config.legend_inset_anchor === "top-right";
|
7766 | state.isLegendLeft = config.legend_inset_anchor === "top-left" ||
|
7767 | config.legend_inset_anchor === "bottom-left";
|
7768 | state.rotatedPaddingRight = isRotated && !config.axis_x_show ? 0 : 30;
|
7769 | state.inputType = convertInputType(config.interaction_inputType_mouse, config.interaction_inputType_touch);
|
7770 | };
|
7771 | ChartInternal.prototype.initWithData = function (data) {
|
7772 | var $$ = this;
|
7773 | var config = $$.config, scale = $$.scale, state = $$.state, $el = $$.$el, org = $$.org;
|
7774 | var hasAxis = state.hasAxis;
|
7775 | var hasInteraction = config.interaction_enabled;
|
7776 |
|
7777 |
|
7778 | if (hasAxis) {
|
7779 | $$.axis = $$.getAxisInstance();
|
7780 | config.zoom_enabled && $$.initZoom();
|
7781 | }
|
7782 |
|
7783 | $$.data.xs = {};
|
7784 | $$.data.targets = $$.convertDataToTargets(data);
|
7785 | if (config.data_filter) {
|
7786 | $$.data.targets = $$.data.targets.filter(config.data_filter.bind($$.api));
|
7787 | }
|
7788 |
|
7789 | if (config.data_hide) {
|
7790 | $$.addHiddenTargetIds(config.data_hide === true ?
|
7791 | $$.mapToIds($$.data.targets) : config.data_hide);
|
7792 | }
|
7793 | if (config.legend_hide) {
|
7794 | $$.addHiddenLegendIds(config.legend_hide === true ?
|
7795 | $$.mapToIds($$.data.targets) : config.legend_hide);
|
7796 | }
|
7797 |
|
7798 | $$.updateSizes();
|
7799 | $$.updateScales(true);
|
7800 |
|
7801 | var x = scale.x, y = scale.y, y2 = scale.y2, subX = scale.subX, subY = scale.subY, subY2 = scale.subY2;
|
7802 |
|
7803 | if (x) {
|
7804 | x.domain(sortValue($$.getXDomain($$.data.targets)));
|
7805 | subX.domain(x.domain());
|
7806 |
|
7807 | org.xDomain = x.domain();
|
7808 | }
|
7809 | if (y) {
|
7810 | y.domain($$.getYDomain($$.data.targets, "y"));
|
7811 | subY.domain(y.domain());
|
7812 | }
|
7813 | if (y2) {
|
7814 | y2.domain($$.getYDomain($$.data.targets, "y2"));
|
7815 | subY2 && subY2.domain(y2.domain());
|
7816 | }
|
7817 |
|
7818 | $el.svg = $el.chart.append("svg")
|
7819 | .style("overflow", "hidden")
|
7820 | .style("display", "block");
|
7821 | if (hasInteraction && state.inputType) {
|
7822 | var isTouch = state.inputType === "touch";
|
7823 | $el.svg.on(isTouch ? "touchstart" : "mouseenter", function () { return callFn(config.onover, $$.api); })
|
7824 | .on(isTouch ? "touchend" : "mouseleave", function () { return callFn(config.onout, $$.api); });
|
7825 | }
|
7826 | config.svg_classname && $el.svg.attr("class", config.svg_classname);
|
7827 |
|
7828 | var hasColorPatterns = (isFunction(config.color_tiles) && $$.patterns);
|
7829 | if (hasAxis || hasColorPatterns) {
|
7830 | $el.defs = $el.svg.append("defs");
|
7831 | if (hasAxis) {
|
7832 | ["id", "idXAxis", "idYAxis", "idGrid"].forEach(function (v) {
|
7833 | $$.appendClip($el.defs, state.clip[v]);
|
7834 | });
|
7835 | }
|
7836 |
|
7837 | if (hasColorPatterns) {
|
7838 | $$.patterns.forEach(function (p) { return $el.defs.append(function () { return p.node; }); });
|
7839 | }
|
7840 | }
|
7841 | $$.updateSvgSize();
|
7842 |
|
7843 | $$.bindResize();
|
7844 |
|
7845 | var main = $el.svg.append("g")
|
7846 | .classed(CLASS.main, true)
|
7847 | .attr("transform", $$.getTranslate("main"));
|
7848 | $el.main = main;
|
7849 |
|
7850 | config.subchart_show && $$.initSubchart();
|
7851 | config.tooltip_show && $$.initTooltip();
|
7852 | config.title_text && $$.initTitle();
|
7853 | config.legend_show && $$.initLegend();
|
7854 |
|
7855 |
|
7856 | if (config.data_empty_label_text) {
|
7857 | main.append("text")
|
7858 | .attr("class", CLASS.text + " " + CLASS.empty)
|
7859 | .attr("text-anchor", "middle")
|
7860 | .attr("dominant-baseline", "middle");
|
7861 | }
|
7862 | if (hasAxis) {
|
7863 |
|
7864 | config.regions.length && $$.initRegion();
|
7865 |
|
7866 | !config.clipPath && $$.axis.init();
|
7867 | }
|
7868 |
|
7869 | main.append("g").attr("class", CLASS.chart)
|
7870 | .attr("clip-path", state.clip.path);
|
7871 | $$.callPluginHook("$init");
|
7872 | if (hasAxis) {
|
7873 |
|
7874 | hasInteraction && $$.initEventRect && $$.initEventRect();
|
7875 |
|
7876 | $$.initGrid();
|
7877 |
|
7878 | config.clipPath && $$.axis && $$.axis.init();
|
7879 | }
|
7880 | $$.initChartElements();
|
7881 |
|
7882 | $$.updateTargets($$.data.targets);
|
7883 |
|
7884 | $$.updateDimension();
|
7885 |
|
7886 | callFn(config.oninit, $$.api);
|
7887 |
|
7888 | $$.setBackground();
|
7889 | $$.redraw({
|
7890 | withTransition: false,
|
7891 | withTransform: true,
|
7892 | withUpdateXDomain: true,
|
7893 | withUpdateOrgXDomain: true,
|
7894 | withTransitionForAxis: false,
|
7895 | initializing: true
|
7896 | });
|
7897 |
|
7898 | if (config.data_onmin || config.data_onmax) {
|
7899 | var minMax = $$.getMinMaxData();
|
7900 | callFn(config.data_onmin, $$.api, minMax.min);
|
7901 | callFn(config.data_onmax, $$.api, minMax.max);
|
7902 | }
|
7903 | config.tooltip_show && $$.initShowTooltip();
|
7904 | state.rendered = true;
|
7905 | };
|
7906 | ChartInternal.prototype.initChartElements = function () {
|
7907 | var $$ = this;
|
7908 | var _a = $$.state, hasAxis = _a.hasAxis, hasRadar = _a.hasRadar;
|
7909 | var types = [];
|
7910 | if (hasAxis) {
|
7911 | ["bar", "bubble", "candlestick", "line"].forEach(function (v) {
|
7912 | var name = capitalize(v);
|
7913 | if ((v === "line" && $$.hasTypeOf(name)) || $$.hasType(v)) {
|
7914 | types.push(name);
|
7915 | }
|
7916 | });
|
7917 | }
|
7918 | else {
|
7919 | if (!hasRadar) {
|
7920 | types.push("Arc", "Pie");
|
7921 | }
|
7922 | if ($$.hasType("gauge")) {
|
7923 | types.push("Gauge");
|
7924 | }
|
7925 | else if (hasRadar) {
|
7926 | types.push("Radar");
|
7927 | }
|
7928 | }
|
7929 | types.forEach(function (v) {
|
7930 | $$["init" + v]();
|
7931 | });
|
7932 | notEmpty($$.config.data_labels) && !$$.hasArcType(null, ["radar"]) && $$.initText();
|
7933 | };
|
7934 | ChartInternal.prototype.setChartElements = function () {
|
7935 | var $$ = this;
|
7936 | var _a = $$.$el, chart = _a.chart, svg = _a.svg, defs = _a.defs, main = _a.main, tooltip = _a.tooltip, legend = _a.legend, title = _a.title, grid = _a.grid, arc = _a.arcs, circles = _a.circle, bars = _a.bar, candlestick = _a.candlestick, lines = _a.line, areas = _a.area, texts = _a.text;
|
7937 | $$.api.$ = {
|
7938 | chart: chart,
|
7939 | svg: svg,
|
7940 | defs: defs,
|
7941 | main: main,
|
7942 | tooltip: tooltip,
|
7943 | legend: legend,
|
7944 | title: title,
|
7945 | grid: grid,
|
7946 | arc: arc,
|
7947 | circles: circles,
|
7948 | bar: { bars: bars },
|
7949 | candlestick: candlestick,
|
7950 | line: { lines: lines, areas: areas },
|
7951 | text: { texts: texts }
|
7952 | };
|
7953 | };
|
7954 | |
7955 |
|
7956 |
|
7957 |
|
7958 | ChartInternal.prototype.setBackground = function () {
|
7959 | var $$ = this;
|
7960 | var bg = $$.config.background, state = $$.state, svg = $$.$el.svg;
|
7961 | if (notEmpty(bg)) {
|
7962 | var element = svg.select("g")
|
7963 | .insert(bg.imgUrl ? "image" : "rect", ":first-child");
|
7964 | if (bg.imgUrl) {
|
7965 | element.attr("href", bg.imgUrl);
|
7966 | }
|
7967 | else if (bg.color) {
|
7968 | element
|
7969 | .style("fill", bg.color)
|
7970 | .attr("clip-path", state.clip.path);
|
7971 | }
|
7972 | element
|
7973 | .attr("class", bg["class"] || null)
|
7974 | .attr("width", "100%")
|
7975 | .attr("height", "100%");
|
7976 | }
|
7977 | };
|
7978 | |
7979 |
|
7980 |
|
7981 |
|
7982 |
|
7983 | ChartInternal.prototype.updateTargets = function (targets) {
|
7984 | var $$ = this;
|
7985 | var _a = $$.state, hasAxis = _a.hasAxis, hasRadar = _a.hasRadar;
|
7986 |
|
7987 | $$.updateTargetsForText(targets);
|
7988 | if (hasAxis) {
|
7989 | ["bar", "candlestick", "line"].forEach(function (v) {
|
7990 | var name = capitalize(v);
|
7991 | if ((v === "line" && $$.hasTypeOf(name)) || $$.hasType(v)) {
|
7992 | $$["updateTargetsFor" + name](targets.filter($$["is" + name + "Type"].bind($$)));
|
7993 | }
|
7994 | });
|
7995 |
|
7996 | $$.updateTargetsForSubchart &&
|
7997 | $$.updateTargetsForSubchart(targets);
|
7998 | }
|
7999 | else {
|
8000 |
|
8001 | $$.hasArcType(targets) && (hasRadar ?
|
8002 | $$.updateTargetsForRadar(targets.filter($$.isRadarType.bind($$))) :
|
8003 | $$.updateTargetsForArc(targets.filter($$.isArcType.bind($$))));
|
8004 | }
|
8005 |
|
8006 | if ($$.hasType("bubble") || $$.hasType("scatter")) {
|
8007 | $$.updateTargetForCircle && $$.updateTargetForCircle();
|
8008 | }
|
8009 |
|
8010 | $$.showTargets();
|
8011 | };
|
8012 | |
8013 |
|
8014 |
|
8015 |
|
8016 | ChartInternal.prototype.showTargets = function () {
|
8017 | var $$ = this;
|
8018 | var config = $$.config, svg = $$.$el.svg;
|
8019 | svg.selectAll("." + CLASS.target)
|
8020 | .filter(function (d) { return $$.isTargetToShow(d.id); })
|
8021 | .transition()
|
8022 | .duration(config.transition_duration)
|
8023 | .style("opacity", "1");
|
8024 | };
|
8025 | ChartInternal.prototype.getWithOption = function (options) {
|
8026 | var withOptions = {
|
8027 | Y: true,
|
8028 | Subchart: true,
|
8029 | Transition: true,
|
8030 | EventRect: true,
|
8031 | Dimension: true,
|
8032 | TrimXDomain: true,
|
8033 | Transform: false,
|
8034 | UpdateXDomain: false,
|
8035 | UpdateOrgXDomain: false,
|
8036 | Legend: false,
|
8037 | UpdateXAxis: "UpdateXDomain",
|
8038 | TransitionForExit: "Transition",
|
8039 | TransitionForAxis: "Transition"
|
8040 | };
|
8041 | Object.keys(withOptions).forEach(function (key) {
|
8042 | var defVal = withOptions[key];
|
8043 | if (isString(defVal)) {
|
8044 | defVal = withOptions[defVal];
|
8045 | }
|
8046 | withOptions[key] = getOption(options, "with" + key, defVal);
|
8047 | });
|
8048 | return withOptions;
|
8049 | };
|
8050 | ChartInternal.prototype.initialOpacity = function (d) {
|
8051 | var $$ = this;
|
8052 | var withoutFadeIn = $$.state.withoutFadeIn;
|
8053 | return $$.getBaseValue(d) !== null &&
|
8054 | withoutFadeIn[d.id] ? "1" : "0";
|
8055 | };
|
8056 | ChartInternal.prototype.bindResize = function () {
|
8057 | var $$ = this;
|
8058 | var config = $$.config, state = $$.state;
|
8059 | var resizeFunction = generateResize();
|
8060 | var list = [];
|
8061 | list.push(function () { return callFn(config.onresize, $$, $$.api); });
|
8062 | if (config.resize_auto) {
|
8063 | list.push(function () {
|
8064 | state.resizing = true;
|
8065 | $$.api.flush(false);
|
8066 | });
|
8067 | }
|
8068 | list.push(function () {
|
8069 | callFn(config.onresized, $$, $$.api);
|
8070 | state.resizing = false;
|
8071 | });
|
8072 |
|
8073 | list.forEach(function (v) { return resizeFunction.add(v); });
|
8074 | $$.resizeFunction = resizeFunction;
|
8075 |
|
8076 | win.addEventListener("resize", $$.resizeFunction = resizeFunction);
|
8077 | };
|
8078 | |
8079 |
|
8080 |
|
8081 |
|
8082 |
|
8083 |
|
8084 | ChartInternal.prototype.callPluginHook = function (phase) {
|
8085 | var _this = this;
|
8086 | var args = [];
|
8087 | for (var _i = 1; _i < arguments.length; _i++) {
|
8088 | args[_i - 1] = arguments[_i];
|
8089 | }
|
8090 | this.config.plugins.forEach(function (v) {
|
8091 | if (phase === "$beforeInit") {
|
8092 | v.$$ = _this;
|
8093 | _this.api.plugins.push(v);
|
8094 | }
|
8095 | v[phase].apply(v, args);
|
8096 | });
|
8097 | };
|
8098 | return ChartInternal;
|
8099 | }());
|
8100 | extend(ChartInternal.prototype, [
|
8101 |
|
8102 | dataConvert,
|
8103 | data$1,
|
8104 | dataLoad,
|
8105 | category,
|
8106 | classModule,
|
8107 | color,
|
8108 | domain,
|
8109 | interaction,
|
8110 | format,
|
8111 | legend$1,
|
8112 | redraw,
|
8113 | scale,
|
8114 | shape,
|
8115 | size,
|
8116 | text,
|
8117 | title,
|
8118 | tooltip$1,
|
8119 | transform,
|
8120 | type
|
8121 | ]);
|
8122 |
|
8123 |
|
8124 |
|
8125 |
|
8126 |
|
8127 |
|
8128 |
|
8129 |
|
8130 |
|
8131 |
|
8132 | function loadConfig(config) {
|
8133 | var thisConfig = this.config;
|
8134 | var target;
|
8135 | var keys;
|
8136 | var read;
|
8137 | var find = function () {
|
8138 | var key = keys.shift();
|
8139 | if (key && target && isObjectType(target) && key in target) {
|
8140 | target = target[key];
|
8141 | return find();
|
8142 | }
|
8143 | else if (!key) {
|
8144 | return target;
|
8145 | }
|
8146 | return undefined;
|
8147 | };
|
8148 | Object.keys(thisConfig).forEach(function (key) {
|
8149 | target = config;
|
8150 | keys = key.split("_");
|
8151 | read = find();
|
8152 | if (isDefined(read)) {
|
8153 | thisConfig[key] = read;
|
8154 | }
|
8155 | });
|
8156 | }
|
8157 |
|
8158 |
|
8159 |
|
8160 |
|
8161 |
|
8162 | var apiChart = {
|
8163 | |
8164 |
|
8165 |
|
8166 |
|
8167 |
|
8168 |
|
8169 |
|
8170 |
|
8171 |
|
8172 |
|
8173 |
|
8174 |
|
8175 |
|
8176 |
|
8177 |
|
8178 | resize: function (size) {
|
8179 | var $$ = this.internal;
|
8180 | var config = $$.config, state = $$.state;
|
8181 | if (state.rendered) {
|
8182 | config.size_width = size ? size.width : null;
|
8183 | config.size_height = size ? size.height : null;
|
8184 | state.resizing = true;
|
8185 | this.flush(false, true);
|
8186 | $$.resizeFunction();
|
8187 | }
|
8188 | },
|
8189 | |
8190 |
|
8191 |
|
8192 |
|
8193 |
|
8194 |
|
8195 |
|
8196 |
|
8197 |
|
8198 |
|
8199 |
|
8200 |
|
8201 |
|
8202 | flush: function (soft) {
|
8203 | var $$ = this.internal;
|
8204 | var state = $$.state;
|
8205 | if (state.rendered) {
|
8206 |
|
8207 |
|
8208 | if (state.resizing) {
|
8209 | $$.brush && $$.brush.updateResize();
|
8210 | }
|
8211 | else {
|
8212 |
|
8213 | $$.axis && $$.axis.setOrient();
|
8214 | }
|
8215 | $$.scale.zoom = null;
|
8216 | soft ? $$.redraw({
|
8217 | withTransform: true,
|
8218 | withUpdateXDomain: true,
|
8219 | withUpdateOrgXDomain: true,
|
8220 | withLegend: true
|
8221 | }) : $$.updateAndRedraw({
|
8222 | withLegend: true,
|
8223 | withTransition: false,
|
8224 | withTransitionForTransform: false
|
8225 | });
|
8226 |
|
8227 | if (!state.resizing && $$.brush) {
|
8228 | $$.brush.getSelection().call($$.brush.move);
|
8229 | $$.unselectRect();
|
8230 | }
|
8231 | }
|
8232 | else {
|
8233 | $$.initToRender(true);
|
8234 | }
|
8235 | },
|
8236 | |
8237 |
|
8238 |
|
8239 |
|
8240 |
|
8241 |
|
8242 |
|
8243 |
|
8244 |
|
8245 | destroy: function () {
|
8246 | var _this = this;
|
8247 | var $$ = this.internal;
|
8248 | var _a = $$.$el, chart = _a.chart, svg = _a.svg;
|
8249 | if (notEmpty($$)) {
|
8250 | $$.callPluginHook("$willDestroy");
|
8251 | $$.charts.splice($$.charts.indexOf(this), 1);
|
8252 |
|
8253 | svg.select("*").interrupt();
|
8254 | $$.resizeFunction.clear();
|
8255 | win.removeEventListener("resize", $$.resizeFunction);
|
8256 | chart.classed("bb", false).html("");
|
8257 |
|
8258 | Object.keys(this).forEach(function (key) {
|
8259 | key === "internal" && Object.keys($$).forEach(function (k) {
|
8260 | $$[k] = null;
|
8261 | });
|
8262 | _this[key] = null;
|
8263 | delete _this[key];
|
8264 | });
|
8265 |
|
8266 | for (var key in this) {
|
8267 | this[key] = function () { };
|
8268 | }
|
8269 | }
|
8270 | return null;
|
8271 | },
|
8272 | |
8273 |
|
8274 |
|
8275 |
|
8276 |
|
8277 |
|
8278 |
|
8279 |
|
8280 |
|
8281 |
|
8282 |
|
8283 |
|
8284 |
|
8285 |
|
8286 |
|
8287 |
|
8288 |
|
8289 |
|
8290 |
|
8291 |
|
8292 | config: function (name, value, redraw) {
|
8293 | var $$ = this.internal;
|
8294 | var config = $$.config;
|
8295 | var key = name && name.replace(/\./g, "_");
|
8296 | var res;
|
8297 | if (key in config) {
|
8298 | if (isDefined(value)) {
|
8299 | config[key] = value;
|
8300 | res = value;
|
8301 | redraw && this.flush();
|
8302 | }
|
8303 | else {
|
8304 | res = config[key];
|
8305 | }
|
8306 | }
|
8307 | return res;
|
8308 | }
|
8309 | };
|
8310 |
|
8311 |
|
8312 |
|
8313 |
|
8314 |
|
8315 | var apiColor = {
|
8316 | |
8317 |
|
8318 |
|
8319 |
|
8320 |
|
8321 |
|
8322 |
|
8323 |
|
8324 |
|
8325 |
|
8326 | color: function (id) {
|
8327 | return this.internal.color(id);
|
8328 | }
|
8329 | };
|
8330 |
|
8331 |
|
8332 |
|
8333 |
|
8334 |
|
8335 |
|
8336 |
|
8337 |
|
8338 |
|
8339 |
|
8340 |
|
8341 |
|
8342 |
|
8343 |
|
8344 |
|
8345 |
|
8346 |
|
8347 |
|
8348 |
|
8349 | function data(targetIds) {
|
8350 | var targets = this.internal.data.targets;
|
8351 | if (!isUndefined(targetIds)) {
|
8352 | var ids_1 = isArray(targetIds) ? targetIds : [targetIds];
|
8353 | return targets.filter(function (t) { return ids_1.some(function (v) { return v === t.id; }); });
|
8354 | }
|
8355 | return targets;
|
8356 | }
|
8357 | extend(data, {
|
8358 | |
8359 |
|
8360 |
|
8361 |
|
8362 |
|
8363 |
|
8364 |
|
8365 |
|
8366 |
|
8367 |
|
8368 |
|
8369 |
|
8370 |
|
8371 |
|
8372 |
|
8373 |
|
8374 |
|
8375 |
|
8376 | shown: function (targetIds) {
|
8377 | return this.internal.filterTargetsToShow(this.data(targetIds));
|
8378 | },
|
8379 | |
8380 |
|
8381 |
|
8382 |
|
8383 |
|
8384 |
|
8385 |
|
8386 |
|
8387 |
|
8388 |
|
8389 |
|
8390 |
|
8391 |
|
8392 | values: function (targetIds, flat) {
|
8393 | if (flat === void 0) { flat = true; }
|
8394 | var values = null;
|
8395 | if (targetIds) {
|
8396 | var targets = this.data(targetIds);
|
8397 | if (targets && isArray(targets)) {
|
8398 | values = [];
|
8399 | targets.forEach(function (v) {
|
8400 | var dataValue = v.values.map(function (d) { return d.value; });
|
8401 | flat ? (values = values.concat(dataValue)) : values.push(dataValue);
|
8402 | });
|
8403 | }
|
8404 | }
|
8405 | return values;
|
8406 | },
|
8407 | |
8408 |
|
8409 |
|
8410 |
|
8411 |
|
8412 |
|
8413 |
|
8414 |
|
8415 |
|
8416 |
|
8417 |
|
8418 |
|
8419 |
|
8420 |
|
8421 |
|
8422 |
|
8423 |
|
8424 |
|
8425 | names: function (names) {
|
8426 | var $$ = this.internal;
|
8427 | return $$.updateDataAttributes("names", names);
|
8428 | },
|
8429 | |
8430 |
|
8431 |
|
8432 |
|
8433 |
|
8434 |
|
8435 |
|
8436 |
|
8437 |
|
8438 |
|
8439 |
|
8440 |
|
8441 |
|
8442 |
|
8443 |
|
8444 |
|
8445 |
|
8446 |
|
8447 | colors: function (colors) {
|
8448 | return this.internal.updateDataAttributes("colors", colors);
|
8449 | },
|
8450 | |
8451 |
|
8452 |
|
8453 |
|
8454 |
|
8455 |
|
8456 |
|
8457 |
|
8458 |
|
8459 |
|
8460 |
|
8461 |
|
8462 |
|
8463 |
|
8464 |
|
8465 |
|
8466 |
|
8467 |
|
8468 |
|
8469 | axes: function (axes) {
|
8470 | return this.internal.updateDataAttributes("axes", axes);
|
8471 | },
|
8472 | |
8473 |
|
8474 |
|
8475 |
|
8476 |
|
8477 |
|
8478 |
|
8479 |
|
8480 |
|
8481 |
|
8482 |
|
8483 | min: function () {
|
8484 | return this.internal.getMinMaxData().min;
|
8485 | },
|
8486 | |
8487 |
|
8488 |
|
8489 |
|
8490 |
|
8491 |
|
8492 |
|
8493 |
|
8494 |
|
8495 |
|
8496 |
|
8497 | max: function () {
|
8498 | return this.internal.getMinMaxData().max;
|
8499 | }
|
8500 | });
|
8501 | var apiData = { data: data };
|
8502 |
|
8503 |
|
8504 |
|
8505 |
|
8506 |
|
8507 |
|
8508 |
|
8509 |
|
8510 |
|
8511 |
|
8512 |
|
8513 |
|
8514 | var b64EncodeUnicode = function (str) { return btoa(encodeURIComponent(str)
|
8515 | .replace(/%([0-9A-F]{2})/g, function (match, p) { return String.fromCharCode(Number("0x" + p)); })); };
|
8516 |
|
8517 |
|
8518 |
|
8519 |
|
8520 |
|
8521 |
|
8522 |
|
8523 |
|
8524 | function nodeToSvgDataUrl(node, option, orgSize) {
|
8525 | var _a = option || orgSize, width = _a.width, height = _a.height;
|
8526 | var serializer = new XMLSerializer();
|
8527 | var clone = node.cloneNode(true);
|
8528 | var cssText = getCssRules(toArray(doc.styleSheets))
|
8529 | .filter(function (r) { return r.cssText; })
|
8530 | .map(function (r) { return r.cssText; });
|
8531 | clone.setAttribute("xmlns", namespaces.xhtml);
|
8532 | var nodeXml = serializer.serializeToString(clone);
|
8533 |
|
8534 | var style = doc.createElement("style");
|
8535 | style.appendChild(doc.createTextNode(cssText.join("\n")));
|
8536 | var styleXml = serializer.serializeToString(style);
|
8537 |
|
8538 |
|
8539 | var dataStr = ("<svg xmlns=\"" + namespaces.svg + "\" width=\"" + width + "\" height=\"" + height + "\" \n\t\tviewBox=\"0 0 " + orgSize.width + " " + orgSize.height + "\" \n\t\tpreserveAspectRatio=\"" + (option && option.preserveAspectRatio === false ? "none" : "xMinYMid meet") + "\">\n\t\t\t<foreignObject width=\"100%\" height=\"100%\">\n\t\t\t\t" + styleXml + "\n\t\t\t\t" + nodeXml.replace(/(url\()[^#]+/g, "$1") + "\n\t\t\t</foreignObject></svg>")
|
8540 | .replace("/\n/g", "%0A");
|
8541 | return "data:image/svg+xml;base64," + b64EncodeUnicode(dataStr);
|
8542 | }
|
8543 | var apiExport = {
|
8544 | |
8545 |
|
8546 |
|
8547 |
|
8548 |
|
8549 |
|
8550 |
|
8551 |
|
8552 |
|
8553 |
|
8554 |
|
8555 |
|
8556 |
|
8557 |
|
8558 |
|
8559 |
|
8560 |
|
8561 |
|
8562 |
|
8563 |
|
8564 |
|
8565 |
|
8566 |
|
8567 |
|
8568 |
|
8569 |
|
8570 |
|
8571 |
|
8572 |
|
8573 |
|
8574 |
|
8575 |
|
8576 |
|
8577 |
|
8578 |
|
8579 |
|
8580 |
|
8581 |
|
8582 |
|
8583 |
|
8584 |
|
8585 | "export": function (option, callback) {
|
8586 | var _this = this;
|
8587 | var $$ = this.internal;
|
8588 | var state = $$.state, chart = $$.$el.chart;
|
8589 | var _a = state.current, width = _a.width, height = _a.height;
|
8590 | var opt = mergeObj({
|
8591 | width: width,
|
8592 | height: height,
|
8593 | preserveAspectRatio: true,
|
8594 | mimeType: "image/png"
|
8595 | }, option);
|
8596 | var svgDataUrl = nodeToSvgDataUrl(chart.node(), opt, { width: width, height: height });
|
8597 | if (callback && isFunction(callback)) {
|
8598 | var img_1 = new Image();
|
8599 | img_1.crossOrigin = "Anonymous";
|
8600 | img_1.onload = function () {
|
8601 | var canvas = doc.createElement("canvas");
|
8602 | var ctx = canvas.getContext("2d");
|
8603 | canvas.width = opt.width || width;
|
8604 | canvas.height = opt.height || height;
|
8605 | ctx.drawImage(img_1, 0, 0);
|
8606 | callback.bind(_this)(canvas.toDataURL(opt.mimeType));
|
8607 | };
|
8608 | img_1.src = svgDataUrl;
|
8609 | }
|
8610 | return svgDataUrl;
|
8611 | }
|
8612 | };
|
8613 |
|
8614 |
|
8615 |
|
8616 |
|
8617 |
|
8618 | var apiFocus = {
|
8619 | |
8620 |
|
8621 |
|
8622 |
|
8623 |
|
8624 |
|
8625 |
|
8626 |
|
8627 |
|
8628 |
|
8629 |
|
8630 |
|
8631 |
|
8632 |
|
8633 |
|
8634 |
|
8635 |
|
8636 | focus: function (targetIdsValue) {
|
8637 | var $$ = this.internal;
|
8638 | var state = $$.state;
|
8639 | var targetIds = $$.mapToTargetIds(targetIdsValue);
|
8640 | var candidates = $$.$el.svg.selectAll($$.selectorTargets(targetIds.filter($$.isTargetToShow, $$)));
|
8641 | this.revert();
|
8642 | this.defocus();
|
8643 | candidates.classed(CLASS.focused, true).classed(CLASS.defocused, false);
|
8644 | if ($$.hasArcType() && !state.hasRadar) {
|
8645 | $$.expandArc(targetIds);
|
8646 | $$.hasType("gauge") &&
|
8647 | $$.markOverlapped(targetIdsValue, $$, "." + CLASS.gaugeValue);
|
8648 | }
|
8649 | $$.toggleFocusLegend(targetIds, true);
|
8650 | state.focusedTargetIds = targetIds;
|
8651 | state.defocusedTargetIds = state.defocusedTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; });
|
8652 | },
|
8653 | |
8654 |
|
8655 |
|
8656 |
|
8657 |
|
8658 |
|
8659 |
|
8660 |
|
8661 |
|
8662 |
|
8663 |
|
8664 |
|
8665 |
|
8666 |
|
8667 |
|
8668 |
|
8669 |
|
8670 | defocus: function (targetIdsValue) {
|
8671 | var $$ = this.internal;
|
8672 | var state = $$.state;
|
8673 | var targetIds = $$.mapToTargetIds(targetIdsValue);
|
8674 | var candidates = $$.$el.svg.selectAll($$.selectorTargets(targetIds.filter($$.isTargetToShow, $$)));
|
8675 | candidates.classed(CLASS.focused, false).classed(CLASS.defocused, true);
|
8676 | if ($$.hasArcType()) {
|
8677 | $$.unexpandArc(targetIds);
|
8678 | $$.hasType("gauge") &&
|
8679 | $$.undoMarkOverlapped($$, "." + CLASS.gaugeValue);
|
8680 | }
|
8681 | $$.toggleFocusLegend(targetIds, false);
|
8682 | state.focusedTargetIds = state.focusedTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; });
|
8683 | state.defocusedTargetIds = targetIds;
|
8684 | },
|
8685 | |
8686 |
|
8687 |
|
8688 |
|
8689 |
|
8690 |
|
8691 |
|
8692 |
|
8693 |
|
8694 |
|
8695 |
|
8696 |
|
8697 |
|
8698 |
|
8699 |
|
8700 |
|
8701 |
|
8702 | revert: function (targetIdsValue) {
|
8703 | var $$ = this.internal;
|
8704 | var config = $$.config, state = $$.state, $el = $$.$el;
|
8705 | var targetIds = $$.mapToTargetIds(targetIdsValue);
|
8706 | var candidates = $el.svg.selectAll($$.selectorTargets(targetIds));
|
8707 | candidates.classed(CLASS.focused, false).classed(CLASS.defocused, false);
|
8708 | $$.hasArcType() && $$.unexpandArc(targetIds);
|
8709 | if (config.legend_show) {
|
8710 | $$.showLegend(targetIds.filter($$.isLegendToShow.bind($$)));
|
8711 | $el.legend.selectAll($$.selectorLegends(targetIds))
|
8712 | .filter(function () {
|
8713 | return select(this).classed(CLASS.legendItemFocused);
|
8714 | })
|
8715 | .classed(CLASS.legendItemFocused, false);
|
8716 | }
|
8717 | state.focusedTargetIds = [];
|
8718 | state.defocusedTargetIds = [];
|
8719 | }
|
8720 | };
|
8721 |
|
8722 |
|
8723 |
|
8724 |
|
8725 |
|
8726 |
|
8727 |
|
8728 |
|
8729 |
|
8730 | var legend = {
|
8731 | |
8732 |
|
8733 |
|
8734 |
|
8735 |
|
8736 |
|
8737 |
|
8738 |
|
8739 |
|
8740 |
|
8741 |
|
8742 |
|
8743 |
|
8744 |
|
8745 |
|
8746 |
|
8747 |
|
8748 |
|
8749 |
|
8750 | show: function (targetIds) {
|
8751 | var $$ = this.internal;
|
8752 | $$.showLegend($$.mapToTargetIds(targetIds));
|
8753 | $$.updateAndRedraw({ withLegend: true });
|
8754 | },
|
8755 | |
8756 |
|
8757 |
|
8758 |
|
8759 |
|
8760 |
|
8761 |
|
8762 |
|
8763 |
|
8764 |
|
8765 |
|
8766 |
|
8767 |
|
8768 |
|
8769 |
|
8770 |
|
8771 |
|
8772 |
|
8773 |
|
8774 | hide: function (targetIds) {
|
8775 | var $$ = this.internal;
|
8776 | $$.hideLegend($$.mapToTargetIds(targetIds));
|
8777 | $$.updateAndRedraw({ withLegend: true });
|
8778 | }
|
8779 | };
|
8780 | var apiLegend = { legend: legend };
|
8781 |
|
8782 |
|
8783 |
|
8784 |
|
8785 |
|
8786 | var apiLoad = {
|
8787 | |
8788 |
|
8789 |
|
8790 |
|
8791 |
|
8792 |
|
8793 |
|
8794 |
|
8795 |
|
8796 |
|
8797 |
|
8798 |
|
8799 |
|
8800 |
|
8801 |
|
8802 |
|
8803 |
|
8804 |
|
8805 |
|
8806 |
|
8807 |
|
8808 |
|
8809 |
|
8810 |
|
8811 |
|
8812 |
|
8813 |
|
8814 |
|
8815 |
|
8816 |
|
8817 |
|
8818 |
|
8819 |
|
8820 |
|
8821 |
|
8822 |
|
8823 |
|
8824 |
|
8825 |
|
8826 |
|
8827 |
|
8828 |
|
8829 |
|
8830 |
|
8831 |
|
8832 |
|
8833 |
|
8834 |
|
8835 |
|
8836 |
|
8837 |
|
8838 |
|
8839 |
|
8840 |
|
8841 |
|
8842 |
|
8843 |
|
8844 |
|
8845 |
|
8846 |
|
8847 |
|
8848 |
|
8849 |
|
8850 |
|
8851 |
|
8852 |
|
8853 |
|
8854 |
|
8855 |
|
8856 |
|
8857 |
|
8858 |
|
8859 |
|
8860 |
|
8861 |
|
8862 |
|
8863 |
|
8864 |
|
8865 |
|
8866 | load: function (args) {
|
8867 | var $$ = this.internal;
|
8868 | var config = $$.config;
|
8869 |
|
8870 | args.xs && $$.addXs(args.xs);
|
8871 |
|
8872 | "names" in args && this.data.names(args.names);
|
8873 |
|
8874 | "classes" in args && Object.keys(args.classes).forEach(function (id) {
|
8875 | config.data_classes[id] = args.classes[id];
|
8876 | });
|
8877 |
|
8878 | if ("categories" in args && $$.axis.isCategorized()) {
|
8879 | config.axis_x_categories = args.categories;
|
8880 | }
|
8881 |
|
8882 | "axes" in args && Object.keys(args.axes).forEach(function (id) {
|
8883 | config.data_axes[id] = args.axes[id];
|
8884 | });
|
8885 |
|
8886 | "colors" in args && Object.keys(args.colors).forEach(function (id) {
|
8887 | config.data_colors[id] = args.colors[id];
|
8888 | });
|
8889 |
|
8890 | if ("unload" in args && args.unload !== false) {
|
8891 |
|
8892 | $$.unload($$.mapToTargetIds(args.unload === true ? null : args.unload), function () {
|
8893 | return $$.loadFromArgs(args);
|
8894 | });
|
8895 | }
|
8896 | else {
|
8897 | $$.loadFromArgs(args);
|
8898 | }
|
8899 | },
|
8900 | |
8901 |
|
8902 |
|
8903 |
|
8904 |
|
8905 |
|
8906 |
|
8907 |
|
8908 |
|
8909 |
|
8910 |
|
8911 |
|
8912 |
|
8913 |
|
8914 |
|
8915 |
|
8916 |
|
8917 |
|
8918 |
|
8919 |
|
8920 |
|
8921 |
|
8922 |
|
8923 | unload: function (argsValue) {
|
8924 | var _this = this;
|
8925 | var $$ = this.internal;
|
8926 | var args = argsValue || {};
|
8927 | if (isArray(args)) {
|
8928 | args = { ids: args };
|
8929 | }
|
8930 | else if (isString(args)) {
|
8931 | args = { ids: [args] };
|
8932 | }
|
8933 | var ids = $$.mapToTargetIds(args.ids);
|
8934 | $$.unload(ids, function () {
|
8935 | $$.redraw({
|
8936 | withUpdateOrgXDomain: true,
|
8937 | withUpdateXDomain: true,
|
8938 | withLegend: true
|
8939 | });
|
8940 | $$.cache.remove(ids);
|
8941 | args.done && args.done.call(_this);
|
8942 | });
|
8943 | }
|
8944 | };
|
8945 |
|
8946 |
|
8947 |
|
8948 |
|
8949 |
|
8950 |
|
8951 |
|
8952 |
|
8953 |
|
8954 |
|
8955 |
|
8956 |
|
8957 | function showHide(show, targetIdsValue, options) {
|
8958 | var $$ = this.internal;
|
8959 | var targetIds = $$.mapToTargetIds(targetIdsValue);
|
8960 | $$.state.toggling = true;
|
8961 | $$[(show ? "remove" : "add") + "HiddenTargetIds"](targetIds);
|
8962 | var targets = $$.$el.svg.selectAll($$.selectorTargets(targetIds));
|
8963 | var opacity = show ? "1" : "0";
|
8964 | show && targets.style("display", null);
|
8965 | targets.transition()
|
8966 | .style("opacity", opacity, "important")
|
8967 | .call(endall, function () {
|
8968 |
|
8969 | !show && targets.style("display", "none");
|
8970 | targets.style("opacity", opacity);
|
8971 | });
|
8972 | options.withLegend && $$[(show ? "show" : "hide") + "Legend"](targetIds);
|
8973 | $$.redraw({
|
8974 | withUpdateOrgXDomain: true,
|
8975 | withUpdateXDomain: true,
|
8976 | withLegend: true
|
8977 | });
|
8978 | $$.state.toggling = false;
|
8979 | }
|
8980 | var apiShow = {
|
8981 | |
8982 |
|
8983 |
|
8984 |
|
8985 |
|
8986 |
|
8987 |
|
8988 |
|
8989 |
|
8990 |
|
8991 |
|
8992 |
|
8993 |
|
8994 |
|
8995 |
|
8996 |
|
8997 |
|
8998 |
|
8999 |
|
9000 | show: function (targetIdsValue, options) {
|
9001 | if (options === void 0) { options = {}; }
|
9002 | showHide.call(this, true, targetIdsValue, options);
|
9003 | },
|
9004 | |
9005 |
|
9006 |
|
9007 |
|
9008 |
|
9009 |
|
9010 |
|
9011 |
|
9012 |
|
9013 |
|
9014 |
|
9015 |
|
9016 |
|
9017 |
|
9018 |
|
9019 |
|
9020 |
|
9021 |
|
9022 |
|
9023 | hide: function (targetIdsValue, options) {
|
9024 | if (options === void 0) { options = {}; }
|
9025 | showHide.call(this, false, targetIdsValue, options);
|
9026 | },
|
9027 | |
9028 |
|
9029 |
|
9030 |
|
9031 |
|
9032 |
|
9033 |
|
9034 |
|
9035 |
|
9036 |
|
9037 |
|
9038 |
|
9039 |
|
9040 |
|
9041 |
|
9042 |
|
9043 |
|
9044 |
|
9045 |
|
9046 | toggle: function (targetIds, options) {
|
9047 | var _this = this;
|
9048 | if (options === void 0) { options = {}; }
|
9049 | var $$ = this.internal;
|
9050 | var targets = { show: [], hide: [] };
|
9051 |
|
9052 | $$.mapToTargetIds(targetIds)
|
9053 | .forEach(function (id) { return targets[$$.isTargetToShow(id) ? "hide" : "show"].push(id); });
|
9054 |
|
9055 |
|
9056 | targets.show.length && this.show(targets.show, options);
|
9057 | targets.hide.length && setTimeout(function () { return _this.hide(targets.hide, options); }, 0);
|
9058 | }
|
9059 | };
|
9060 |
|
9061 |
|
9062 |
|
9063 |
|
9064 |
|
9065 |
|
9066 |
|
9067 |
|
9068 |
|
9069 | var tooltip = {
|
9070 | |
9071 |
|
9072 |
|
9073 |
|
9074 |
|
9075 |
|
9076 |
|
9077 |
|
9078 |
|
9079 |
|
9080 |
|
9081 |
|
9082 |
|
9083 |
|
9084 |
|
9085 |
|
9086 |
|
9087 |
|
9088 |
|
9089 |
|
9090 |
|
9091 |
|
9092 |
|
9093 |
|
9094 |
|
9095 |
|
9096 |
|
9097 |
|
9098 |
|
9099 |
|
9100 |
|
9101 |
|
9102 |
|
9103 |
|
9104 |
|
9105 |
|
9106 |
|
9107 |
|
9108 |
|
9109 |
|
9110 |
|
9111 |
|
9112 |
|
9113 |
|
9114 |
|
9115 |
|
9116 |
|
9117 |
|
9118 |
|
9119 |
|
9120 | show: function (args) {
|
9121 | var $$ = this.internal;
|
9122 | var config = $$.config, inputType = $$.state.inputType;
|
9123 | var index;
|
9124 | var mouse;
|
9125 |
|
9126 | if (args.mouse) {
|
9127 | mouse = args.mouse;
|
9128 | }
|
9129 |
|
9130 | if (args.data) {
|
9131 | var data = args.data;
|
9132 | var y = $$.getYScaleById(data.id)(data.value);
|
9133 | if ($$.isMultipleX()) {
|
9134 |
|
9135 | mouse = [$$.scale.x(data.x), y];
|
9136 | }
|
9137 | else {
|
9138 | if (!config.tooltip_grouped) {
|
9139 | mouse = [0, y];
|
9140 | }
|
9141 | index = isValue(data.index) ? data.index : $$.getIndexByX(data.x);
|
9142 | }
|
9143 | }
|
9144 | else if (isDefined(args.x)) {
|
9145 | index = $$.getIndexByX(args.x);
|
9146 | }
|
9147 | else if (isDefined(args.index)) {
|
9148 | index = args.index;
|
9149 | }
|
9150 | (inputType === "mouse" ?
|
9151 | ["mouseover", "mousemove"] : ["touchstart"]).forEach(function (eventName) {
|
9152 | $$.dispatchEvent(eventName, index, mouse);
|
9153 | });
|
9154 | },
|
9155 | |
9156 |
|
9157 |
|
9158 |
|
9159 |
|
9160 |
|
9161 | hide: function () {
|
9162 | var $$ = this.internal;
|
9163 | var inputType = $$.state.inputType, tooltip = $$.$el.tooltip;
|
9164 | var data = tooltip && tooltip.datum();
|
9165 | if (data) {
|
9166 | var index_1 = JSON.parse(data.current)[0].index;
|
9167 |
|
9168 | (inputType === "mouse" ?
|
9169 | ["mouseout"] : ["touchend"]).forEach(function (eventName) {
|
9170 | $$.dispatchEvent(eventName, index_1);
|
9171 | });
|
9172 | }
|
9173 |
|
9174 | inputType === "touch" && $$.callOverOutForTouch();
|
9175 | $$.hideTooltip(true);
|
9176 | $$.hideGridFocus();
|
9177 | $$.unexpandCircles && $$.unexpandCircles();
|
9178 | $$.unexpandBars && $$.unexpandBars();
|
9179 | }
|
9180 | };
|
9181 | var apiTooltip = { tooltip: tooltip };
|
9182 |
|
9183 |
|
9184 |
|
9185 |
|
9186 |
|
9187 |
|
9188 |
|
9189 |
|
9190 |
|
9191 |
|
9192 |
|
9193 |
|
9194 |
|
9195 |
|
9196 |
|
9197 |
|
9198 |
|
9199 |
|
9200 |
|
9201 |
|
9202 |
|
9203 |
|
9204 |
|
9205 |
|
9206 |
|
9207 |
|
9208 |
|
9209 |
|
9210 |
|
9211 |
|
9212 |
|
9213 |
|
9214 |
|
9215 |
|
9216 |
|
9217 |
|
9218 |
|
9219 |
|
9220 |
|
9221 |
|
9222 |
|
9223 |
|
9224 |
|
9225 |
|
9226 |
|
9227 |
|
9228 |
|
9229 |
|
9230 |
|
9231 |
|
9232 |
|
9233 |
|
9234 |
|
9235 |
|
9236 |
|
9237 |
|
9238 |
|
9239 |
|
9240 |
|
9241 |
|
9242 |
|
9243 |
|
9244 |
|
9245 |
|
9246 | var Chart = (function () {
|
9247 | function Chart(options) {
|
9248 | this.plugins = [];
|
9249 | var $$ = new ChartInternal(this);
|
9250 | this.internal = $$;
|
9251 |
|
9252 | (function bindThis(fn, target, argThis) {
|
9253 | Object.keys(fn).forEach(function (key) {
|
9254 | var isFunc = isFunction(fn[key]);
|
9255 | var isChild = target !== argThis;
|
9256 | var hasChild = Object.keys(fn[key]).length > 0;
|
9257 | if (isFunc && ((!isChild && hasChild) || isChild)) {
|
9258 | target[key] = fn[key].bind(argThis);
|
9259 | }
|
9260 | else if (!isFunc) {
|
9261 | target[key] = {};
|
9262 | }
|
9263 | hasChild && bindThis(fn[key], target[key], argThis);
|
9264 | });
|
9265 | })(Chart.prototype, this, this);
|
9266 | loadConfig.call($$, options);
|
9267 | $$.beforeInit();
|
9268 | $$.init();
|
9269 | }
|
9270 | return Chart;
|
9271 | }());
|
9272 |
|
9273 | extend(Chart.prototype, [
|
9274 | apiChart,
|
9275 | apiColor,
|
9276 | apiData,
|
9277 | apiExport,
|
9278 | apiFocus,
|
9279 | apiLegend,
|
9280 | apiLoad,
|
9281 | apiShow,
|
9282 | apiTooltip
|
9283 | ]);
|
9284 |
|
9285 |
|
9286 |
|
9287 |
|
9288 |
|
9289 |
|
9290 |
|
9291 |
|
9292 |
|
9293 |
|
9294 |
|
9295 |
|
9296 | function setMinMax($$, type, value) {
|
9297 | var config = $$.config;
|
9298 | var axisX = "axis_x_" + type;
|
9299 | var axisY = "axis_y_" + type;
|
9300 | var axisY2 = "axis_y2_" + type;
|
9301 | if (isDefined(value)) {
|
9302 | if (isObjectType(value)) {
|
9303 | isValue(value.x) && (config[axisX] = value.x);
|
9304 | isValue(value.y) && (config[axisY] = value.y);
|
9305 | isValue(value.y2) && (config[axisY2] = value.y2);
|
9306 | }
|
9307 | else {
|
9308 | config[axisY] = value;
|
9309 | config[axisY2] = value;
|
9310 | }
|
9311 | $$.redraw({
|
9312 | withUpdateOrgXDomain: true,
|
9313 | withUpdateXDomain: true
|
9314 | });
|
9315 | }
|
9316 | }
|
9317 |
|
9318 |
|
9319 |
|
9320 |
|
9321 |
|
9322 |
|
9323 |
|
9324 | function getMinMax($$, type) {
|
9325 | var config = $$.config;
|
9326 | return {
|
9327 | x: config["axis_x_" + type],
|
9328 | y: config["axis_y_" + type],
|
9329 | y2: config["axis_y2_" + type]
|
9330 | };
|
9331 | }
|
9332 |
|
9333 |
|
9334 |
|
9335 |
|
9336 | var axis$1 = {
|
9337 | |
9338 |
|
9339 |
|
9340 |
|
9341 |
|
9342 |
|
9343 |
|
9344 |
|
9345 |
|
9346 |
|
9347 |
|
9348 |
|
9349 |
|
9350 |
|
9351 |
|
9352 |
|
9353 |
|
9354 |
|
9355 |
|
9356 |
|
9357 |
|
9358 |
|
9359 |
|
9360 |
|
9361 |
|
9362 | labels: function (labels) {
|
9363 | var $$ = this.internal;
|
9364 | var labelText;
|
9365 | if (labels) {
|
9366 | Object.keys(labels).forEach(function (axisId) {
|
9367 | $$.axis.setLabelText(axisId, labels[axisId]);
|
9368 | });
|
9369 | $$.axis.updateLabels();
|
9370 | }
|
9371 | ["x", "y", "y2"].forEach(function (v) {
|
9372 | var text = $$.axis.getLabelText(v);
|
9373 | if (text) {
|
9374 | !labelText && (labelText = {});
|
9375 | labelText[v] = text;
|
9376 | }
|
9377 | });
|
9378 | return labelText;
|
9379 | },
|
9380 | |
9381 |
|
9382 |
|
9383 |
|
9384 |
|
9385 |
|
9386 |
|
9387 |
|
9388 |
|
9389 |
|
9390 |
|
9391 |
|
9392 |
|
9393 |
|
9394 |
|
9395 |
|
9396 |
|
9397 | min: function (min) {
|
9398 | var $$ = this.internal;
|
9399 | return isValue(min) ?
|
9400 | setMinMax($$, "min", min) :
|
9401 | getMinMax($$, "min");
|
9402 | },
|
9403 | |
9404 |
|
9405 |
|
9406 |
|
9407 |
|
9408 |
|
9409 |
|
9410 |
|
9411 |
|
9412 |
|
9413 |
|
9414 |
|
9415 |
|
9416 |
|
9417 |
|
9418 |
|
9419 |
|
9420 | max: function (max) {
|
9421 | var $$ = this.internal;
|
9422 | return arguments.length ?
|
9423 | setMinMax($$, "max", max) :
|
9424 | getMinMax($$, "max");
|
9425 | },
|
9426 | |
9427 |
|
9428 |
|
9429 |
|
9430 |
|
9431 |
|
9432 |
|
9433 |
|
9434 |
|
9435 |
|
9436 |
|
9437 |
|
9438 |
|
9439 |
|
9440 |
|
9441 |
|
9442 |
|
9443 |
|
9444 |
|
9445 |
|
9446 |
|
9447 |
|
9448 | range: function (range) {
|
9449 | var axis = this.axis;
|
9450 | if (arguments.length) {
|
9451 | isDefined(range.max) && axis.max(range.max);
|
9452 | isDefined(range.min) && axis.min(range.min);
|
9453 | }
|
9454 | else {
|
9455 | return {
|
9456 | max: axis.max(),
|
9457 | min: axis.min()
|
9458 | };
|
9459 | }
|
9460 | return undefined;
|
9461 | }
|
9462 | };
|
9463 | var apiAxis = { axis: axis$1 };
|
9464 |
|
9465 |
|
9466 |
|
9467 |
|
9468 |
|
9469 | var apiCategory = {
|
9470 | |
9471 |
|
9472 |
|
9473 |
|
9474 |
|
9475 |
|
9476 |
|
9477 |
|
9478 |
|
9479 |
|
9480 |
|
9481 | category: function (i, category) {
|
9482 | var $$ = this.internal;
|
9483 | var config = $$.config;
|
9484 | if (arguments.length > 1) {
|
9485 | config.axis_x_categories[i] = category;
|
9486 | $$.redraw();
|
9487 | }
|
9488 | return config.axis_x_categories[i];
|
9489 | },
|
9490 | |
9491 |
|
9492 |
|
9493 |
|
9494 |
|
9495 |
|
9496 |
|
9497 |
|
9498 |
|
9499 |
|
9500 |
|
9501 |
|
9502 | categories: function (categories) {
|
9503 | var $$ = this.internal;
|
9504 | var config = $$.config;
|
9505 | if (!arguments.length) {
|
9506 | return config.axis_x_categories;
|
9507 | }
|
9508 | config.axis_x_categories = categories;
|
9509 | $$.redraw();
|
9510 | return config.axis_x_categories;
|
9511 | }
|
9512 | };
|
9513 |
|
9514 |
|
9515 |
|
9516 |
|
9517 |
|
9518 |
|
9519 |
|
9520 |
|
9521 |
|
9522 |
|
9523 |
|
9524 |
|
9525 |
|
9526 |
|
9527 |
|
9528 |
|
9529 |
|
9530 |
|
9531 |
|
9532 |
|
9533 | function xgrids(grids) {
|
9534 | var $$ = this.internal;
|
9535 | var config = $$.config;
|
9536 | if (!grids) {
|
9537 | return config.grid_x_lines;
|
9538 | }
|
9539 | config.grid_x_lines = grids;
|
9540 | $$.redrawWithoutRescale();
|
9541 | return config.grid_x_lines;
|
9542 | }
|
9543 | extend(xgrids, {
|
9544 | |
9545 |
|
9546 |
|
9547 |
|
9548 |
|
9549 |
|
9550 |
|
9551 |
|
9552 |
|
9553 |
|
9554 |
|
9555 |
|
9556 |
|
9557 |
|
9558 |
|
9559 |
|
9560 |
|
9561 |
|
9562 |
|
9563 |
|
9564 | add: function (grids) {
|
9565 | return this.xgrids(this.internal.config.grid_x_lines
|
9566 | .concat(grids || []));
|
9567 | },
|
9568 | |
9569 |
|
9570 |
|
9571 |
|
9572 |
|
9573 |
|
9574 |
|
9575 |
|
9576 |
|
9577 |
|
9578 |
|
9579 |
|
9580 |
|
9581 |
|
9582 |
|
9583 |
|
9584 |
|
9585 |
|
9586 |
|
9587 | remove: function (params) {
|
9588 | this.internal.removeGridLines(params, true);
|
9589 | }
|
9590 | });
|
9591 | var apiXGrid = { xgrids: xgrids };
|
9592 |
|
9593 |
|
9594 |
|
9595 |
|
9596 |
|
9597 |
|
9598 |
|
9599 |
|
9600 |
|
9601 |
|
9602 |
|
9603 |
|
9604 |
|
9605 |
|
9606 |
|
9607 |
|
9608 |
|
9609 |
|
9610 |
|
9611 |
|
9612 | function ygrids(grids) {
|
9613 | var $$ = this.internal;
|
9614 | var config = $$.config;
|
9615 | if (!grids) {
|
9616 | return config.grid_y_lines;
|
9617 | }
|
9618 | config.grid_y_lines = grids;
|
9619 | $$.redrawWithoutRescale();
|
9620 | return config.grid_y_lines;
|
9621 | }
|
9622 | extend(ygrids, {
|
9623 | |
9624 |
|
9625 |
|
9626 |
|
9627 |
|
9628 |
|
9629 |
|
9630 |
|
9631 |
|
9632 |
|
9633 |
|
9634 |
|
9635 |
|
9636 |
|
9637 |
|
9638 |
|
9639 |
|
9640 |
|
9641 |
|
9642 |
|
9643 | add: function (grids) {
|
9644 | return this.ygrids(this.internal.config.grid_y_lines
|
9645 | .concat(grids || []));
|
9646 | },
|
9647 | |
9648 |
|
9649 |
|
9650 |
|
9651 |
|
9652 |
|
9653 |
|
9654 |
|
9655 |
|
9656 |
|
9657 |
|
9658 |
|
9659 |
|
9660 |
|
9661 |
|
9662 |
|
9663 |
|
9664 |
|
9665 |
|
9666 |
|
9667 |
|
9668 | remove: function (params) {
|
9669 | this.internal.removeGridLines(params, false);
|
9670 | }
|
9671 | });
|
9672 | var apiYGrid = { ygrids: ygrids };
|
9673 |
|
9674 |
|
9675 |
|
9676 |
|
9677 |
|
9678 | var apiGroup = {
|
9679 | |
9680 |
|
9681 |
|
9682 |
|
9683 |
|
9684 |
|
9685 |
|
9686 |
|
9687 |
|
9688 |
|
9689 |
|
9690 |
|
9691 |
|
9692 | groups: function (groups) {
|
9693 | var $$ = this.internal;
|
9694 | var config = $$.config;
|
9695 | if (isUndefined(groups)) {
|
9696 | return config.data_groups;
|
9697 | }
|
9698 | config.data_groups = groups;
|
9699 | $$.redraw();
|
9700 | return config.data_groups;
|
9701 | }
|
9702 | };
|
9703 |
|
9704 |
|
9705 |
|
9706 |
|
9707 |
|
9708 |
|
9709 |
|
9710 |
|
9711 |
|
9712 |
|
9713 |
|
9714 |
|
9715 |
|
9716 |
|
9717 |
|
9718 |
|
9719 |
|
9720 |
|
9721 |
|
9722 | function regions(regions) {
|
9723 | var $$ = this.internal;
|
9724 | var config = $$.config;
|
9725 | if (!regions) {
|
9726 | return config.regions;
|
9727 | }
|
9728 | config.regions = regions;
|
9729 | $$.redrawWithoutRescale();
|
9730 | return regions;
|
9731 | }
|
9732 | extend(regions, {
|
9733 | |
9734 |
|
9735 |
|
9736 |
|
9737 |
|
9738 |
|
9739 |
|
9740 |
|
9741 |
|
9742 |
|
9743 |
|
9744 |
|
9745 |
|
9746 |
|
9747 |
|
9748 |
|
9749 |
|
9750 |
|
9751 |
|
9752 |
|
9753 | add: function (regions) {
|
9754 | var $$ = this.internal;
|
9755 | var config = $$.config;
|
9756 | if (!regions) {
|
9757 | return config.regions;
|
9758 | }
|
9759 | config.regions = config.regions.concat(regions);
|
9760 | $$.redrawWithoutRescale();
|
9761 | return config.regions;
|
9762 | },
|
9763 | |
9764 |
|
9765 |
|
9766 |
|
9767 |
|
9768 |
|
9769 |
|
9770 |
|
9771 |
|
9772 |
|
9773 |
|
9774 |
|
9775 |
|
9776 |
|
9777 |
|
9778 |
|
9779 |
|
9780 |
|
9781 |
|
9782 | remove: function (optionsValue) {
|
9783 | var $$ = this.internal;
|
9784 | var config = $$.config;
|
9785 | var options = optionsValue || {};
|
9786 | var duration = getOption(options, "duration", config.transition_duration);
|
9787 | var classes = getOption(options, "classes", [CLASS.region]);
|
9788 | var regions = $$.$el.main.select("." + CLASS.regions)
|
9789 | .selectAll(classes.map(function (c) { return "." + c; }));
|
9790 | (duration ? regions.transition().duration(duration) : regions)
|
9791 | .style("opacity", "0")
|
9792 | .remove();
|
9793 | regions = config.regions;
|
9794 | if (Object.keys(options).length) {
|
9795 | regions = regions.filter(function (region) {
|
9796 | var found = false;
|
9797 | if (!region["class"]) {
|
9798 | return true;
|
9799 | }
|
9800 | region["class"].split(" ").forEach(function (c) {
|
9801 | if (classes.indexOf(c) >= 0) {
|
9802 | found = true;
|
9803 | }
|
9804 | });
|
9805 | return !found;
|
9806 | });
|
9807 | config.regions = regions;
|
9808 | }
|
9809 | else {
|
9810 | config.regions = [];
|
9811 | }
|
9812 | return regions;
|
9813 | }
|
9814 | });
|
9815 | var apiRegion = { regions: regions };
|
9816 |
|
9817 |
|
9818 |
|
9819 |
|
9820 |
|
9821 | var apiX = {
|
9822 | |
9823 |
|
9824 |
|
9825 |
|
9826 |
|
9827 |
|
9828 |
|
9829 |
|
9830 |
|
9831 |
|
9832 |
|
9833 |
|
9834 |
|
9835 |
|
9836 | x: function (x) {
|
9837 | var $$ = this.internal;
|
9838 | var axis = $$.axis, data = $$.data;
|
9839 | var isCategorized = axis.isCustomX() && axis.isCategorized();
|
9840 | if (isArray(x)) {
|
9841 | if (isCategorized) {
|
9842 | this.categories(x);
|
9843 | }
|
9844 | else {
|
9845 | $$.updateTargetX(data.targets, x);
|
9846 | $$.redraw({
|
9847 | withUpdateOrgXDomain: true,
|
9848 | withUpdateXDomain: true
|
9849 | });
|
9850 | }
|
9851 | }
|
9852 | return isCategorized ? this.categories() : data.xs;
|
9853 | },
|
9854 | |
9855 |
|
9856 |
|
9857 |
|
9858 |
|
9859 |
|
9860 |
|
9861 |
|
9862 |
|
9863 |
|
9864 |
|
9865 |
|
9866 |
|
9867 |
|
9868 |
|
9869 |
|
9870 |
|
9871 | xs: function (xs) {
|
9872 | var $$ = this.internal;
|
9873 | if (isObject(xs)) {
|
9874 | $$.updateTargetXs($$.data.targets, xs);
|
9875 | $$.redraw({
|
9876 | withUpdateOrgXDomain: true,
|
9877 | withUpdateXDomain: true
|
9878 | });
|
9879 | }
|
9880 | return $$.data.xs;
|
9881 | }
|
9882 | };
|
9883 |
|
9884 |
|
9885 |
|
9886 |
|
9887 |
|
9888 | var apiFlow = {
|
9889 | |
9890 |
|
9891 |
|
9892 |
|
9893 |
|
9894 |
|
9895 |
|
9896 |
|
9897 |
|
9898 |
|
9899 |
|
9900 |
|
9901 |
|
9902 |
|
9903 |
|
9904 |
|
9905 |
|
9906 |
|
9907 |
|
9908 |
|
9909 |
|
9910 |
|
9911 |
|
9912 |
|
9913 |
|
9914 |
|
9915 |
|
9916 |
|
9917 |
|
9918 |
|
9919 |
|
9920 |
|
9921 |
|
9922 |
|
9923 |
|
9924 |
|
9925 |
|
9926 |
|
9927 |
|
9928 |
|
9929 |
|
9930 |
|
9931 |
|
9932 |
|
9933 |
|
9934 |
|
9935 |
|
9936 |
|
9937 |
|
9938 | flow: function (args) {
|
9939 | var $$ = this.internal;
|
9940 | var data;
|
9941 | var domain;
|
9942 | var length = 0;
|
9943 | var tail = 0;
|
9944 | var diff;
|
9945 | var to;
|
9946 | if (args.json || args.rows || args.columns) {
|
9947 | data = $$.convertData(args);
|
9948 | }
|
9949 | if (!data || !isTabVisible()) {
|
9950 | return;
|
9951 | }
|
9952 | var notfoundIds = [];
|
9953 | var orgDataCount = $$.getMaxDataCount();
|
9954 | var targets = $$.convertDataToTargets(data, true);
|
9955 | var isTimeSeries = $$.axis.isTimeSeries();
|
9956 |
|
9957 | $$.data.targets.forEach(function (t) {
|
9958 | var found = false;
|
9959 | for (var i = 0; i < targets.length; i++) {
|
9960 | if (t.id === targets[i].id) {
|
9961 | found = true;
|
9962 | if (t.values[t.values.length - 1]) {
|
9963 | tail = t.values[t.values.length - 1].index + 1;
|
9964 | }
|
9965 | length = targets[i].values.length;
|
9966 | for (var j = 0; j < length; j++) {
|
9967 | targets[i].values[j].index = tail + j;
|
9968 | if (!isTimeSeries) {
|
9969 | targets[i].values[j].x = tail + j;
|
9970 | }
|
9971 | }
|
9972 | t.values = t.values.concat(targets[i].values);
|
9973 | targets.splice(i, 1);
|
9974 | break;
|
9975 | }
|
9976 | }
|
9977 | !found && notfoundIds.push(t.id);
|
9978 | });
|
9979 |
|
9980 | $$.data.targets.forEach(function (t) {
|
9981 | for (var i = 0; i < notfoundIds.length; i++) {
|
9982 | if (t.id === notfoundIds[i]) {
|
9983 | tail = t.values[t.values.length - 1].index + 1;
|
9984 | for (var j = 0; j < length; j++) {
|
9985 | t.values.push({
|
9986 | id: t.id,
|
9987 | index: tail + j,
|
9988 | x: isTimeSeries ? $$.getOtherTargetX(tail + j) : tail + j,
|
9989 | value: null
|
9990 | });
|
9991 | }
|
9992 | }
|
9993 | }
|
9994 | });
|
9995 |
|
9996 | if ($$.data.targets.length) {
|
9997 | targets.forEach(function (t) {
|
9998 | var missing = [];
|
9999 | for (var i = $$.data.targets[0].values[0].index; i < tail; i++) {
|
10000 | missing.push({
|
10001 | id: t.id,
|
10002 | index: i,
|
10003 | x: isTimeSeries ? $$.getOtherTargetX(i) : i,
|
10004 | value: null
|
10005 | });
|
10006 | }
|
10007 | t.values.forEach(function (v) {
|
10008 | v.index += tail;
|
10009 | if (!isTimeSeries) {
|
10010 | v.x += tail;
|
10011 | }
|
10012 | });
|
10013 | t.values = missing.concat(t.values);
|
10014 | });
|
10015 | }
|
10016 | $$.data.targets = $$.data.targets.concat(targets);
|
10017 |
|
10018 |
|
10019 | var baseTarget = $$.data.targets[0];
|
10020 | var baseValue = baseTarget.values[0];
|
10021 |
|
10022 | if (isDefined(args.to)) {
|
10023 | length = 0;
|
10024 | to = isTimeSeries ? parseDate.call($$, args.to) : args.to;
|
10025 | baseTarget.values.forEach(function (v) {
|
10026 | v.x < to && length++;
|
10027 | });
|
10028 | }
|
10029 | else if (isDefined(args.length)) {
|
10030 | length = args.length;
|
10031 | }
|
10032 |
|
10033 | if (!orgDataCount) {
|
10034 | if (isTimeSeries) {
|
10035 | diff = baseTarget.values.length > 1 ?
|
10036 | baseTarget.values[baseTarget.values.length - 1].x - baseValue.x :
|
10037 | baseValue.x - $$.getXDomain($$.data.targets)[0];
|
10038 | }
|
10039 | else {
|
10040 | diff = 1;
|
10041 | }
|
10042 | domain = [baseValue.x - diff, baseValue.x];
|
10043 | }
|
10044 | else if (orgDataCount === 1 && isTimeSeries) {
|
10045 | diff = (baseTarget.values[baseTarget.values.length - 1].x - baseValue.x) / 2;
|
10046 | domain = [new Date(+baseValue.x - diff), new Date(+baseValue.x + diff)];
|
10047 | }
|
10048 | domain && $$.updateXDomain(null, true, true, false, domain);
|
10049 |
|
10050 | $$.updateTargets($$.data.targets);
|
10051 |
|
10052 | $$.redraw({
|
10053 | flow: {
|
10054 | index: baseValue.index,
|
10055 | length: length,
|
10056 | duration: isValue(args.duration) ? args.duration : $$.config.transition_duration,
|
10057 | done: args.done,
|
10058 | orgDataCount: orgDataCount
|
10059 | },
|
10060 | withLegend: true,
|
10061 | withTransition: orgDataCount > 1,
|
10062 | withTrimXDomain: false,
|
10063 | withUpdateXAxis: true
|
10064 | });
|
10065 | }
|
10066 | };
|
10067 |
|
10068 |
|
10069 |
|
10070 |
|
10071 |
|
10072 |
|
10073 | var AxisRendererHelper = (function () {
|
10074 | function AxisRendererHelper(owner) {
|
10075 | var scale = getScale();
|
10076 | var config = owner.config, params = owner.params;
|
10077 | this.owner = owner;
|
10078 | this.config = config;
|
10079 | this.scale = scale;
|
10080 | if (config.noTransition || !params.config.transition_duration) {
|
10081 | config.withoutTransition = true;
|
10082 | }
|
10083 |
|
10084 | config.range = this.scaleExtent((params.orgXScale || scale).range());
|
10085 | }
|
10086 | |
10087 |
|
10088 |
|
10089 |
|
10090 |
|
10091 |
|
10092 | AxisRendererHelper.getSizeFor1Char = function (node) {
|
10093 |
|
10094 | var size = {
|
10095 | w: 5.5,
|
10096 | h: 11.5
|
10097 | };
|
10098 | !node.empty() && node.select("text")
|
10099 | .text("0")
|
10100 | .call(function (el) {
|
10101 | try {
|
10102 | var _a = el.node().getBBox(), width = _a.width, height = _a.height;
|
10103 | if (width && height) {
|
10104 | size.w = width;
|
10105 | size.h = height;
|
10106 | }
|
10107 | }
|
10108 | catch (e) {
|
10109 | }
|
10110 | finally {
|
10111 | el.text("");
|
10112 | }
|
10113 | });
|
10114 | this.getSizeFor1Char = function () { return size; };
|
10115 | return size;
|
10116 | };
|
10117 | |
10118 |
|
10119 |
|
10120 |
|
10121 |
|
10122 |
|
10123 | AxisRendererHelper.prototype.getTickTransformSetter = function (id) {
|
10124 | var config = this.config;
|
10125 | var fn = id === "x" ?
|
10126 | function (value) { return "translate(" + (value + config.tickOffset) + ",0)"; } :
|
10127 | function (value) { return "translate(0," + value + ")"; };
|
10128 | return function (selection, scale) {
|
10129 | selection.attr("transform", function (d) { return fn(Math.ceil(scale(d))); });
|
10130 | };
|
10131 | };
|
10132 | AxisRendererHelper.prototype.scaleExtent = function (domain) {
|
10133 | var start = domain[0];
|
10134 | var stop = domain[domain.length - 1];
|
10135 | return start < stop ? [start, stop] : [stop, start];
|
10136 | };
|
10137 | AxisRendererHelper.prototype.generateTicks = function (scale, isYAxes) {
|
10138 | var tickStepSize = this.owner.params.tickStepSize;
|
10139 | var _a = scale.domain(), start = _a[0], end = _a[1];
|
10140 | var ticks = [];
|
10141 |
|
10142 | if (isYAxes && tickStepSize) {
|
10143 | var interval = start;
|
10144 | while (interval <= end) {
|
10145 | ticks.push(interval);
|
10146 | interval += tickStepSize;
|
10147 | }
|
10148 | }
|
10149 | else if (scale.ticks) {
|
10150 | var tickArguments = this.config.tickArguments;
|
10151 |
|
10152 | if (scale.type === "log" && !tickArguments) {
|
10153 |
|
10154 |
|
10155 | var s = getScale("_log")
|
10156 | .domain([start > 0 ? start : 1, end])
|
10157 | .range(scale.range());
|
10158 | ticks = s.ticks();
|
10159 | for (var cnt = end.toFixed().length; ticks.length > 15; cnt--) {
|
10160 | ticks = s.ticks(cnt);
|
10161 | }
|
10162 | ticks.splice(0, 1, start);
|
10163 | ticks.splice(ticks.length - 1, 1, end);
|
10164 | }
|
10165 | else {
|
10166 | ticks = scale
|
10167 | .ticks.apply(scale, (this.config.tickArguments || []));
|
10168 | }
|
10169 | ticks = ticks
|
10170 | .map(function (v) {
|
10171 |
|
10172 | var r = (isString(v) && isNumber(v) && !isNaN(v) &&
|
10173 | Math.round(v * 10) / 10) || v;
|
10174 | return r;
|
10175 | });
|
10176 | }
|
10177 | else {
|
10178 | for (var i = Math.ceil(start); i < end; i++) {
|
10179 | ticks.push(i);
|
10180 | }
|
10181 | if (ticks.length > 0 && ticks[0] > 0) {
|
10182 | ticks.unshift(ticks[0] - (ticks[1] - ticks[0]));
|
10183 | }
|
10184 | }
|
10185 | return ticks;
|
10186 | };
|
10187 | AxisRendererHelper.prototype.copyScale = function () {
|
10188 | var newScale = this.scale.copy();
|
10189 | if (!newScale.domain().length) {
|
10190 | newScale.domain(this.scale.domain());
|
10191 | }
|
10192 | newScale.type = this.scale.type;
|
10193 | return newScale;
|
10194 | };
|
10195 | AxisRendererHelper.prototype.textFormatted = function (v) {
|
10196 | var tickFormat = this.config.tickFormat;
|
10197 |
|
10198 |
|
10199 |
|
10200 | var value = /\d+\.\d+0{5,}\d$/.test(v) ? +String(v).replace(/0+\d$/, "") : v;
|
10201 | var formatted = tickFormat ? tickFormat(value) : value;
|
10202 | return isDefined(formatted) ? formatted : "";
|
10203 | };
|
10204 | AxisRendererHelper.prototype.transitionise = function (selection) {
|
10205 | var config = this.config;
|
10206 | return config.withoutTransition ?
|
10207 | selection.interrupt() : selection.transition(config.transition);
|
10208 | };
|
10209 | return AxisRendererHelper;
|
10210 | }());
|
10211 |
|
10212 | var AxisRenderer = (function () {
|
10213 | function AxisRenderer(params) {
|
10214 | if (params === void 0) { params = {}; }
|
10215 | var config = {
|
10216 | innerTickSize: 6,
|
10217 | outerTickSize: params.outerTick ? 6 : 0,
|
10218 | orient: "bottom",
|
10219 | range: [],
|
10220 | tickArguments: null,
|
10221 | tickCentered: null,
|
10222 | tickCulling: true,
|
10223 | tickFormat: null,
|
10224 | tickLength: 9,
|
10225 | tickOffset: 0,
|
10226 | tickPadding: 3,
|
10227 | tickValues: null,
|
10228 | transition: null,
|
10229 | noTransition: params.noTransition
|
10230 | };
|
10231 | config.tickLength = Math.max(config.innerTickSize, 0) + config.tickPadding;
|
10232 | this.config = config;
|
10233 | this.params = params;
|
10234 | this.helper = new AxisRendererHelper(this);
|
10235 | }
|
10236 | |
10237 |
|
10238 |
|
10239 |
|
10240 |
|
10241 | AxisRenderer.prototype.create = function (g) {
|
10242 | var ctx = this;
|
10243 | var _a = this, config = _a.config, helper = _a.helper, params = _a.params;
|
10244 | var scale = helper.scale;
|
10245 | var orient = config.orient;
|
10246 | var splitTickText = this.splitTickText.bind(this);
|
10247 | var isLeftRight = /^(left|right)$/.test(orient);
|
10248 | var isTopBottom = /^(top|bottom)$/.test(orient);
|
10249 |
|
10250 | var tickTransform = helper.getTickTransformSetter(isTopBottom ? "x" : "y");
|
10251 | var axisPx = tickTransform === helper.axisX ? "y" : "x";
|
10252 | var sign = /^(top|left)$/.test(orient) ? -1 : 1;
|
10253 |
|
10254 | var rotate = params.tickTextRotate;
|
10255 | this.config.range = scale.rangeExtent ?
|
10256 | scale.rangeExtent() :
|
10257 | helper.scaleExtent((params.orgXScale || scale).range());
|
10258 | var innerTickSize = config.innerTickSize, tickLength = config.tickLength, range = config.range;
|
10259 |
|
10260 | var id = params.id;
|
10261 | var tickTextPos = id && /^(x|y|y2)$/.test(id) ?
|
10262 | params.config["axis_" + id + "_tick_text_position"] : { x: 0, y: 0 };
|
10263 |
|
10264 | var prefix = id === "subX" ? "subchart_axis_x" : "axis_" + id;
|
10265 | var axisShow = params.config[prefix + "_show"];
|
10266 | var tickShow = {
|
10267 | tick: axisShow ? params.config[prefix + "_tick_show"] : false,
|
10268 | text: axisShow ? params.config[prefix + "_tick_text_show"] : false
|
10269 | };
|
10270 | var $g;
|
10271 | g.each(function () {
|
10272 | var g = select(this);
|
10273 | var scale0 = this.__chart__ || scale;
|
10274 | var scale1 = helper.copyScale();
|
10275 | $g = g;
|
10276 | this.__chart__ = scale1;
|
10277 | config.tickOffset = params.isCategory ?
|
10278 | Math.ceil((scale1(1) - scale1(0)) / 2) : 0;
|
10279 |
|
10280 | var path = g.selectAll(".domain").data([0]);
|
10281 |
|
10282 | path.enter().append("path")
|
10283 | .attr("class", "domain")
|
10284 |
|
10285 | .merge(helper.transitionise(path).selection())
|
10286 | .attr("d", function () {
|
10287 | var outerTickSized = config.outerTickSize * sign;
|
10288 | return isTopBottom ?
|
10289 | "M" + range[0] + "," + outerTickSized + "V0H" + range[1] + "V" + outerTickSized :
|
10290 | "M" + outerTickSized + "," + range[0] + "H0V" + range[1] + "H" + outerTickSized;
|
10291 | });
|
10292 | if (tickShow.tick || tickShow.text) {
|
10293 |
|
10294 | var ticks_1 = config.tickValues || helper.generateTicks(scale1, isLeftRight);
|
10295 |
|
10296 | var tick = g.selectAll(".tick")
|
10297 | .data(ticks_1, scale1);
|
10298 |
|
10299 | var tickEnter = tick
|
10300 | .enter()
|
10301 | .insert("g", ".domain")
|
10302 | .attr("class", "tick")
|
10303 | .style("opacity", "1");
|
10304 |
|
10305 | var tickExit = tick.exit().remove();
|
10306 |
|
10307 | tick = tickEnter.merge(tick);
|
10308 | tickShow.tick && tickEnter.append("line");
|
10309 | tickShow.text && tickEnter.append("text");
|
10310 | var sizeFor1Char_1 = AxisRendererHelper.getSizeFor1Char(tick);
|
10311 | var counts_1 = [];
|
10312 | var tspan = tick.select("text")
|
10313 | .selectAll("tspan")
|
10314 | .data(function (d, index) {
|
10315 | var split = params.tickMultiline ?
|
10316 | splitTickText(d, scale1, ticks_1, isLeftRight, sizeFor1Char_1.w) : (isArray(helper.textFormatted(d)) ?
|
10317 | helper.textFormatted(d).concat() : [helper.textFormatted(d)]);
|
10318 | counts_1[index] = split.length;
|
10319 | return split.map(function (splitted) { return ({ index: index, splitted: splitted }); });
|
10320 | });
|
10321 | tspan.exit().remove();
|
10322 | tspan = tspan
|
10323 | .enter()
|
10324 | .append("tspan")
|
10325 | .merge(tspan)
|
10326 | .text(function (d) { return d.splitted; });
|
10327 |
|
10328 | tspan
|
10329 | .attr("x", isTopBottom ? 0 : tickLength * sign)
|
10330 | .attr("dx", (function () {
|
10331 | var dx = 0;
|
10332 | if (/(top|bottom)/.test(orient) && rotate) {
|
10333 | dx = 8 * Math.sin(Math.PI * (rotate / 180)) * (orient === "top" ? -1 : 1);
|
10334 | }
|
10335 | return dx + (tickTextPos.x || 0);
|
10336 | })())
|
10337 | .attr("dy", function (d, i) {
|
10338 | var defValue = ".71em";
|
10339 | var dy = 0;
|
10340 | if (orient !== "top") {
|
10341 | dy = sizeFor1Char_1.h;
|
10342 | if (i === 0) {
|
10343 | dy = isLeftRight ? -((counts_1[d.index] - 1) * (sizeFor1Char_1.h / 2) - 3) :
|
10344 | (tickTextPos.y === 0 ? defValue : 0);
|
10345 | }
|
10346 | }
|
10347 | return isNumber(dy) && tickTextPos.y ?
|
10348 | dy + tickTextPos.y : dy || defValue;
|
10349 | });
|
10350 | var lineUpdate = tick.select("line");
|
10351 | var textUpdate = tick.select("text");
|
10352 | tickEnter.select("line").attr(axisPx + "2", innerTickSize * sign);
|
10353 | tickEnter.select("text").attr(axisPx, tickLength * sign);
|
10354 | ctx.setTickLineTextPosition(lineUpdate, textUpdate);
|
10355 |
|
10356 | if (params.tickTitle) {
|
10357 | var title = textUpdate.select("title");
|
10358 | (title.empty() ? textUpdate.append("title") : title)
|
10359 | .text(function (index) { return params.tickTitle[index]; });
|
10360 | }
|
10361 | if (scale1.bandwidth) {
|
10362 | var x_1 = scale1;
|
10363 | var dx_1 = x_1.bandwidth() / 2;
|
10364 | scale0 = function (d) { return x_1(d) + dx_1; };
|
10365 | scale1 = scale0;
|
10366 | }
|
10367 | else if (scale0.bandwidth) {
|
10368 | scale0 = scale1;
|
10369 | }
|
10370 | else {
|
10371 | tickTransform(tickExit, scale1);
|
10372 | }
|
10373 | tickTransform(tickEnter, scale0);
|
10374 | tickTransform(helper.transitionise(tick).style("opacity", "1"), scale1);
|
10375 | }
|
10376 | });
|
10377 | this.g = $g;
|
10378 | };
|
10379 | |
10380 |
|
10381 |
|
10382 |
|
10383 |
|
10384 | AxisRenderer.prototype.getTickXY = function () {
|
10385 | var config = this.config;
|
10386 | var pos = { x: 0, y: 0 };
|
10387 | if (this.params.isCategory) {
|
10388 | pos.x = config.tickCentered ? 0 : config.tickOffset;
|
10389 | pos.y = config.tickCentered ? config.tickOffset : 0;
|
10390 | }
|
10391 | return pos;
|
10392 | };
|
10393 | |
10394 |
|
10395 |
|
10396 |
|
10397 |
|
10398 |
|
10399 | AxisRenderer.prototype.getTickSize = function (d) {
|
10400 | var scale = this.helper.scale;
|
10401 | var config = this.config;
|
10402 | var innerTickSize = config.innerTickSize, range = config.range;
|
10403 | var tickPosition = scale(d) +
|
10404 | (config.tickCentered ? 0 : config.tickOffset);
|
10405 | return range[0] < tickPosition && tickPosition < range[1] ? innerTickSize : 0;
|
10406 | };
|
10407 | |
10408 |
|
10409 |
|
10410 |
|
10411 |
|
10412 |
|
10413 | AxisRenderer.prototype.setTickLineTextPosition = function (lineUpdate, textUpdate) {
|
10414 | var tickPos = this.getTickXY();
|
10415 | var _a = this.config, innerTickSize = _a.innerTickSize, orient = _a.orient, tickLength = _a.tickLength, tickOffset = _a.tickOffset;
|
10416 | var rotate = this.params.tickTextRotate;
|
10417 | var textAnchorForText = function (r) {
|
10418 | var value = ["start", "end"];
|
10419 | orient === "top" && value.reverse();
|
10420 | return !r ? "middle" : (r > 0 ? value[0] : value[1]);
|
10421 | };
|
10422 | var textTransform = function (r) { return (r ? "rotate(" + r + ")" : null); };
|
10423 | var yForText = function (r) {
|
10424 | var r2 = r / (orient === "bottom" ? 15 : 23);
|
10425 | return r ? 11.5 - 2.5 * r2 * (r > 0 ? 1 : -1) : tickLength;
|
10426 | };
|
10427 | switch (orient) {
|
10428 | case "bottom":
|
10429 | lineUpdate
|
10430 | .attr("x1", tickPos.x)
|
10431 | .attr("x2", tickPos.x)
|
10432 | .attr("y2", this.getTickSize.bind(this));
|
10433 | textUpdate
|
10434 | .attr("x", 0)
|
10435 | .attr("y", yForText(rotate))
|
10436 | .style("text-anchor", textAnchorForText(rotate))
|
10437 | .attr("transform", textTransform(rotate));
|
10438 | break;
|
10439 | case "top":
|
10440 | lineUpdate
|
10441 | .attr("x2", 0)
|
10442 | .attr("y2", -innerTickSize);
|
10443 | textUpdate
|
10444 | .attr("x", 0)
|
10445 | .attr("y", -yForText(rotate) * 2)
|
10446 | .style("text-anchor", textAnchorForText(rotate))
|
10447 | .attr("transform", textTransform(rotate));
|
10448 | break;
|
10449 | case "left":
|
10450 | lineUpdate
|
10451 | .attr("x2", -innerTickSize)
|
10452 | .attr("y1", tickPos.y)
|
10453 | .attr("y2", tickPos.y);
|
10454 | textUpdate
|
10455 | .attr("x", -tickLength)
|
10456 | .attr("y", tickOffset)
|
10457 | .style("text-anchor", "end");
|
10458 | break;
|
10459 | case "right":
|
10460 | lineUpdate
|
10461 | .attr("x2", innerTickSize)
|
10462 | .attr("y2", 0);
|
10463 | textUpdate
|
10464 | .attr("x", tickLength)
|
10465 | .attr("y", 0)
|
10466 | .style("text-anchor", "start");
|
10467 | }
|
10468 | };
|
10469 |
|
10470 | AxisRenderer.prototype.splitTickText = function (d, scale, ticks, isLeftRight, charWidth) {
|
10471 | var params = this.params;
|
10472 | var tickText = this.helper.textFormatted(d);
|
10473 | var splitted = isString(tickText) && tickText.indexOf("\n") > -1 ?
|
10474 | tickText.split("\n") : [];
|
10475 | if (splitted.length) {
|
10476 | return splitted;
|
10477 | }
|
10478 | if (isArray(tickText)) {
|
10479 | return tickText;
|
10480 | }
|
10481 | var tickWidth = params.tickWidth;
|
10482 | if (!tickWidth || tickWidth <= 0) {
|
10483 | tickWidth = isLeftRight ? 95 : (params.isCategory ?
|
10484 | (Math.ceil(scale(ticks[1]) - scale(ticks[0])) - 12) : 110);
|
10485 | }
|
10486 |
|
10487 |
|
10488 | function split(splitted, text) {
|
10489 | var subtext;
|
10490 | var spaceIndex;
|
10491 | var textWidth;
|
10492 | for (var i = 1; i < text.length; i++) {
|
10493 | if (text.charAt(i) === " ") {
|
10494 | spaceIndex = i;
|
10495 | }
|
10496 | subtext = text.substr(0, i + 1);
|
10497 | textWidth = charWidth * subtext.length;
|
10498 |
|
10499 | if (tickWidth < textWidth) {
|
10500 | return split(splitted.concat(text.substr(0, spaceIndex || i)), text.slice(spaceIndex ? spaceIndex + 1 : i));
|
10501 | }
|
10502 | }
|
10503 | return splitted.concat(text);
|
10504 | }
|
10505 | return split(splitted, String(tickText));
|
10506 | };
|
10507 | AxisRenderer.prototype.scale = function (x) {
|
10508 | if (!arguments.length) {
|
10509 | return this.helper.scale;
|
10510 | }
|
10511 | this.helper.scale = x;
|
10512 | return this;
|
10513 | };
|
10514 | AxisRenderer.prototype.orient = function (x) {
|
10515 | if (!arguments.length) {
|
10516 | return this.config.orient;
|
10517 | }
|
10518 | this.config.orient = x in {
|
10519 | top: 1,
|
10520 | right: 1,
|
10521 | bottom: 1,
|
10522 | left: 1
|
10523 | } ? String(x) : "bottom";
|
10524 | return this;
|
10525 | };
|
10526 | AxisRenderer.prototype.tickFormat = function (format) {
|
10527 | var config = this.config;
|
10528 | if (!arguments.length) {
|
10529 | return config.tickFormat;
|
10530 | }
|
10531 | config.tickFormat = format;
|
10532 | return this;
|
10533 | };
|
10534 | AxisRenderer.prototype.tickCentered = function (isCentered) {
|
10535 | var config = this.config;
|
10536 | if (!arguments.length) {
|
10537 | return config.tickCentered;
|
10538 | }
|
10539 | config.tickCentered = isCentered;
|
10540 | return this;
|
10541 | };
|
10542 | |
10543 |
|
10544 |
|
10545 |
|
10546 |
|
10547 |
|
10548 | AxisRenderer.prototype.tickOffset = function () {
|
10549 | return this.config.tickOffset;
|
10550 | };
|
10551 | |
10552 |
|
10553 |
|
10554 |
|
10555 |
|
10556 |
|
10557 | AxisRenderer.prototype.tickInterval = function (size) {
|
10558 | var _this = this;
|
10559 | var interval;
|
10560 | if (this.params.isCategory) {
|
10561 | interval = this.config.tickOffset * 2;
|
10562 | }
|
10563 | else {
|
10564 | var length_1 = this.g.select("path.domain")
|
10565 | .node()
|
10566 | .getTotalLength() - this.config.outerTickSize * 2;
|
10567 | interval = length_1 / (size || this.g.selectAll("line").size());
|
10568 |
|
10569 | var intervalByValue = this.config.tickValues
|
10570 | .map(function (v, i, arr) {
|
10571 | var next = i + 1;
|
10572 | return next < arr.length ?
|
10573 | _this.helper.scale(arr[next]) - _this.helper.scale(v) : null;
|
10574 | }).filter(Boolean);
|
10575 | interval = Math.min.apply(Math, __spreadArray(__spreadArray([], intervalByValue), [interval]));
|
10576 | }
|
10577 | return interval === Infinity ? 0 : interval;
|
10578 | };
|
10579 | AxisRenderer.prototype.ticks = function () {
|
10580 | var args = [];
|
10581 | for (var _i = 0; _i < arguments.length; _i++) {
|
10582 | args[_i] = arguments[_i];
|
10583 | }
|
10584 | var config = this.config;
|
10585 | if (!args.length) {
|
10586 | return config.tickArguments;
|
10587 | }
|
10588 | config.tickArguments = toArray(args);
|
10589 | return this;
|
10590 | };
|
10591 | AxisRenderer.prototype.tickCulling = function (culling) {
|
10592 | var config = this.config;
|
10593 | if (!arguments.length) {
|
10594 | return config.tickCulling;
|
10595 | }
|
10596 | config.tickCulling = culling;
|
10597 | return this;
|
10598 | };
|
10599 | AxisRenderer.prototype.tickValues = function (x) {
|
10600 | var _this = this;
|
10601 | var config = this.config;
|
10602 | if (isFunction(x)) {
|
10603 | config.tickValues = function () { return x(_this.helper.scale.domain()); };
|
10604 | }
|
10605 | else {
|
10606 | if (!arguments.length) {
|
10607 | return config.tickValues;
|
10608 | }
|
10609 | config.tickValues = x;
|
10610 | }
|
10611 | return this;
|
10612 | };
|
10613 | AxisRenderer.prototype.setTransition = function (t) {
|
10614 | this.config.transition = t;
|
10615 | return this;
|
10616 | };
|
10617 | return AxisRenderer;
|
10618 | }());
|
10619 |
|
10620 |
|
10621 |
|
10622 |
|
10623 |
|
10624 | var axis = {
|
10625 | getAxisInstance: function () {
|
10626 | return this.axis || new Axis(this);
|
10627 | }
|
10628 | };
|
10629 | var Axis = (function () {
|
10630 | function Axis(owner) {
|
10631 | this.axesList = {};
|
10632 | this.tick = {
|
10633 | x: null, y: null, y2: null
|
10634 | };
|
10635 | this.xs = [];
|
10636 | this.orient = {
|
10637 | x: "bottom",
|
10638 | y: "left",
|
10639 | y2: "right",
|
10640 | subX: "bottom"
|
10641 | };
|
10642 | this.owner = owner;
|
10643 | this.setOrient();
|
10644 | }
|
10645 | Axis.prototype.getAxisClassName = function (id) {
|
10646 | return CLASS.axis + " " + CLASS["axis" + capitalize(id)];
|
10647 | };
|
10648 | Axis.prototype.isHorizontal = function ($$, forHorizontal) {
|
10649 | var isRotated = $$.config.axis_rotated;
|
10650 | return forHorizontal ? isRotated : !isRotated;
|
10651 | };
|
10652 | Axis.prototype.isCategorized = function () {
|
10653 | var _a = this.owner, config = _a.config, state = _a.state;
|
10654 | return config.axis_x_type.indexOf("category") >= 0 || state.hasRadar;
|
10655 | };
|
10656 | Axis.prototype.isCustomX = function () {
|
10657 | var config = this.owner.config;
|
10658 | return !this.isTimeSeries() && (config.data_x || notEmpty(config.data_xs));
|
10659 | };
|
10660 | Axis.prototype.isTimeSeries = function (id) {
|
10661 | if (id === void 0) { id = "x"; }
|
10662 | return this.owner.config["axis_" + id + "_type"] === "timeseries";
|
10663 | };
|
10664 | Axis.prototype.isLog = function (id) {
|
10665 | if (id === void 0) { id = "x"; }
|
10666 | return this.owner.config["axis_" + id + "_type"] === "log";
|
10667 | };
|
10668 | Axis.prototype.isTimeSeriesY = function () {
|
10669 | return this.isTimeSeries("y");
|
10670 | };
|
10671 | Axis.prototype.getAxisType = function (id) {
|
10672 | if (id === void 0) { id = "x"; }
|
10673 | var type = "linear";
|
10674 | if (this.isTimeSeries(id)) {
|
10675 | type = "time";
|
10676 | }
|
10677 | else if (this.isLog(id)) {
|
10678 | type = "log";
|
10679 | }
|
10680 | return type;
|
10681 | };
|
10682 | Axis.prototype.init = function () {
|
10683 | var _this = this;
|
10684 | var $$ = this.owner;
|
10685 | var config = $$.config, _a = $$.$el, main = _a.main, axis = _a.axis, clip = $$.state.clip;
|
10686 | var isRotated = config.axis_rotated;
|
10687 | var target = ["x", "y"];
|
10688 | config.axis_y2_show && target.push("y2");
|
10689 | target.forEach(function (v) {
|
10690 | var classAxis = _this.getAxisClassName(v);
|
10691 | var classLabel = CLASS["axis" + v.toUpperCase() + "Label"];
|
10692 | axis[v] = main.append("g")
|
10693 | .attr("class", classAxis)
|
10694 | .attr("clip-path", function () {
|
10695 | var res = null;
|
10696 | if (v === "x") {
|
10697 | res = clip.pathXAxis;
|
10698 | }
|
10699 | else if (v === "y") {
|
10700 | res = clip.pathYAxis;
|
10701 | }
|
10702 | return res;
|
10703 | })
|
10704 | .attr("transform", $$.getTranslate(v))
|
10705 | .style("visibility", config["axis_" + v + "_show"] ? "visible" : "hidden");
|
10706 | axis[v].append("text")
|
10707 | .attr("class", classLabel)
|
10708 | .attr("transform", ["rotate(-90)", null][v === "x" ? +!isRotated : +isRotated])
|
10709 | .style("text-anchor", function () { return _this.textAnchorForAxisLabel(v); });
|
10710 | _this.generateAxes(v);
|
10711 | });
|
10712 | };
|
10713 | |
10714 |
|
10715 |
|
10716 |
|
10717 | Axis.prototype.setOrient = function () {
|
10718 | var $$ = this.owner;
|
10719 | var _a = $$.config, isRotated = _a.axis_rotated, yInner = _a.axis_y_inner, y2Inner = _a.axis_y2_inner;
|
10720 | this.orient = {
|
10721 | x: isRotated ? "left" : "bottom",
|
10722 | y: isRotated ? (yInner ? "top" : "bottom") : (yInner ? "right" : "left"),
|
10723 | y2: isRotated ? (y2Inner ? "bottom" : "top") : (y2Inner ? "left" : "right"),
|
10724 | subX: isRotated ? "left" : "bottom"
|
10725 | };
|
10726 | };
|
10727 | |
10728 |
|
10729 |
|
10730 |
|
10731 |
|
10732 |
|
10733 | Axis.prototype.generateAxes = function (id) {
|
10734 | var $$ = this.owner;
|
10735 | var config = $$.config;
|
10736 | var axes = [];
|
10737 | var axesConfig = config["axis_" + id + "_axes"];
|
10738 | var isRotated = config.axis_rotated;
|
10739 | var d3Axis;
|
10740 | if (id === "x") {
|
10741 | d3Axis = isRotated ? axisLeft : axisBottom;
|
10742 | }
|
10743 | else if (id === "y") {
|
10744 | d3Axis = isRotated ? axisBottom : axisLeft;
|
10745 | }
|
10746 | else if (id === "y2") {
|
10747 | d3Axis = isRotated ? axisTop : axisRight;
|
10748 | }
|
10749 | if (axesConfig.length) {
|
10750 | axesConfig.forEach(function (v) {
|
10751 | var tick = v.tick || {};
|
10752 | var scale = $$.scale[id].copy();
|
10753 | v.domain && scale.domain(v.domain);
|
10754 | axes.push(d3Axis(scale)
|
10755 | .ticks(tick.count)
|
10756 | .tickFormat(isFunction(tick.format) ? tick.format.bind($$.api) : (function (x) { return x; }))
|
10757 | .tickValues(tick.values)
|
10758 | .tickSizeOuter(tick.outer === false ? 0 : 6));
|
10759 | });
|
10760 | }
|
10761 | this.axesList[id] = axes;
|
10762 | };
|
10763 | |
10764 |
|
10765 |
|
10766 |
|
10767 | Axis.prototype.updateAxes = function () {
|
10768 | var _this = this;
|
10769 | var $$ = this.owner;
|
10770 | var config = $$.config, main = $$.$el.main;
|
10771 | Object.keys(this.axesList).forEach(function (id) {
|
10772 | var axesConfig = config["axis_" + id + "_axes"];
|
10773 | var scale = $$.scale[id].copy();
|
10774 | var range = scale.range();
|
10775 | _this.axesList[id].forEach(function (v, i) {
|
10776 | var axisRange = v.scale().range();
|
10777 |
|
10778 |
|
10779 | if (!range.every(function (v, i) { return v === axisRange[i]; })) {
|
10780 | v.scale().range(range);
|
10781 | }
|
10782 | var className = _this.getAxisClassName(id) + "-" + (i + 1);
|
10783 | var g = main.select("." + className.replace(/\s/, "."));
|
10784 | if (g.empty()) {
|
10785 | g = main.append("g")
|
10786 | .attr("class", className)
|
10787 | .style("visibility", config["axis_" + id + "_show"] ? "visible" : "hidden")
|
10788 | .call(v);
|
10789 | }
|
10790 | else {
|
10791 | axesConfig[i].domain && scale.domain(axesConfig[i].domain);
|
10792 | _this.x.helper.transitionise(g)
|
10793 | .call(v.scale(scale));
|
10794 | }
|
10795 | g.attr("transform", $$.getTranslate(id, i + 1));
|
10796 | });
|
10797 | });
|
10798 | };
|
10799 | |
10800 |
|
10801 |
|
10802 |
|
10803 |
|
10804 |
|
10805 |
|
10806 |
|
10807 |
|
10808 | Axis.prototype.setAxis = function (id, scale, outerTick, noTransition) {
|
10809 | var $$ = this.owner;
|
10810 | if (id !== "subX") {
|
10811 | this.tick[id] = this.getTickValues(id);
|
10812 | }
|
10813 |
|
10814 | this[id] = this.getAxis(id, scale, outerTick,
|
10815 |
|
10816 |
|
10817 | id === "x" && ($$.scale.zoom || $$.config.subchart_show || $$.state.resizing) ? true : noTransition);
|
10818 | };
|
10819 |
|
10820 | Axis.prototype.getAxis = function (id, scale, outerTick, noTransition, noTickTextRotate) {
|
10821 | var $$ = this.owner;
|
10822 | var config = $$.config;
|
10823 | var isX = /^(x|subX)$/.test(id);
|
10824 | var type = isX ? "x" : id;
|
10825 | var isCategory = isX && this.isCategorized();
|
10826 | var orient = this.orient[id];
|
10827 | var tickTextRotate = noTickTextRotate ? 0 : $$.getAxisTickRotate(type);
|
10828 | var tickFormat;
|
10829 | if (isX) {
|
10830 | tickFormat = $$.format.xAxisTick;
|
10831 | }
|
10832 | else {
|
10833 | var fn = config["axis_" + id + "_tick_format"];
|
10834 | if (isFunction(fn)) {
|
10835 | tickFormat = fn.bind($$.api);
|
10836 | }
|
10837 | }
|
10838 | var tickValues = this.tick[type];
|
10839 | var axisParams = mergeObj({
|
10840 | outerTick: outerTick,
|
10841 | noTransition: noTransition,
|
10842 | config: config,
|
10843 | id: id,
|
10844 | tickTextRotate: tickTextRotate
|
10845 | }, isX && {
|
10846 | isCategory: isCategory,
|
10847 | tickMultiline: config.axis_x_tick_multiline,
|
10848 | tickWidth: config.axis_x_tick_width,
|
10849 | tickTitle: isCategory && config.axis_x_tick_tooltip && $$.api.categories(),
|
10850 | orgXScale: $$.scale.x
|
10851 | });
|
10852 | if (!isX) {
|
10853 | axisParams.tickStepSize = config["axis_" + type + "_tick_stepSize"];
|
10854 | }
|
10855 | var axis = new AxisRenderer(axisParams)
|
10856 | .scale((isX && $$.scale.zoom) || scale)
|
10857 | .orient(orient);
|
10858 | if (isX && this.isTimeSeries() && tickValues && !isFunction(tickValues)) {
|
10859 | var fn_1 = parseDate.bind($$);
|
10860 | tickValues = tickValues.map(function (v) { return fn_1(v); });
|
10861 | }
|
10862 | else if (!isX && this.isTimeSeriesY()) {
|
10863 |
|
10864 | axis.ticks(config.axis_y_tick_time_value);
|
10865 | tickValues = null;
|
10866 | }
|
10867 | tickValues && axis.tickValues(tickValues);
|
10868 |
|
10869 | axis.tickFormat(tickFormat || (!isX && ($$.isStackNormalized() && (function (x) { return x + "%"; }))));
|
10870 | if (isCategory) {
|
10871 | axis.tickCentered(config.axis_x_tick_centered);
|
10872 | if (isEmpty(config.axis_x_tick_culling)) {
|
10873 | config.axis_x_tick_culling = false;
|
10874 | }
|
10875 | }
|
10876 | var tickCount = config["axis_" + type + "_tick_count"];
|
10877 | tickCount && axis.ticks(tickCount);
|
10878 | return axis;
|
10879 | };
|
10880 | Axis.prototype.updateXAxisTickValues = function (targets, axis) {
|
10881 | var $$ = this.owner;
|
10882 | var config = $$.config;
|
10883 | var fit = config.axis_x_tick_fit;
|
10884 | var count = config.axis_x_tick_count;
|
10885 | var values;
|
10886 | if (fit || (count && fit)) {
|
10887 | values = $$.mapTargetsToUniqueXs(targets);
|
10888 |
|
10889 | if (this.isCategorized() && count > values.length) {
|
10890 | count = values.length;
|
10891 | }
|
10892 | values = this.generateTickValues(values, count, this.isTimeSeries());
|
10893 | }
|
10894 | if (axis) {
|
10895 | axis.tickValues(values);
|
10896 | }
|
10897 | else if (this.x) {
|
10898 | this.x.tickValues(values);
|
10899 | this.subX && this.subX.tickValues(values);
|
10900 | }
|
10901 | return values;
|
10902 | };
|
10903 | Axis.prototype.getId = function (id) {
|
10904 | var _a = this.owner, config = _a.config, scale = _a.scale;
|
10905 | var axis = config.data_axes[id];
|
10906 |
|
10907 | if (!axis || !scale[axis]) {
|
10908 | axis = "y";
|
10909 | }
|
10910 | return axis;
|
10911 | };
|
10912 | Axis.prototype.getXAxisTickFormat = function () {
|
10913 | var $$ = this.owner;
|
10914 | var config = $$.config, format = $$.format;
|
10915 | var tickFormat = config.axis_x_tick_format;
|
10916 | var isTimeSeries = this.isTimeSeries();
|
10917 | var isCategorized = this.isCategorized();
|
10918 | var currFormat;
|
10919 | if (tickFormat) {
|
10920 | if (isFunction(tickFormat)) {
|
10921 | currFormat = tickFormat.bind($$.api);
|
10922 | }
|
10923 | else if (isTimeSeries) {
|
10924 | currFormat = function (date) { return (date ? format.axisTime(tickFormat)(date) : ""); };
|
10925 | }
|
10926 | }
|
10927 | else {
|
10928 | currFormat = isTimeSeries ? format.defaultAxisTime : (isCategorized ?
|
10929 | $$.categoryName : function (v) { return (v < 0 ? v.toFixed(0) : v); });
|
10930 | }
|
10931 | return isFunction(currFormat) ? function (v) {
|
10932 | return currFormat.apply($$, isCategorized ?
|
10933 | [v, $$.categoryName(v)] : [v]);
|
10934 | } : currFormat;
|
10935 | };
|
10936 | Axis.prototype.getTickValues = function (id) {
|
10937 | var $$ = this.owner;
|
10938 | var tickValues = $$.config["axis_" + id + "_tick_values"];
|
10939 | var axis = $$[id + "Axis"];
|
10940 | return (isFunction(tickValues) ? tickValues.call($$.api) : tickValues) ||
|
10941 | (axis ? axis.tickValues() : undefined);
|
10942 | };
|
10943 | Axis.prototype.getLabelOptionByAxisId = function (id) {
|
10944 | return this.owner.config["axis_" + id + "_label"];
|
10945 | };
|
10946 | Axis.prototype.getLabelText = function (id) {
|
10947 | var option = this.getLabelOptionByAxisId(id);
|
10948 | return isString(option) ? option : (option ? option.text : null);
|
10949 | };
|
10950 | Axis.prototype.setLabelText = function (id, text) {
|
10951 | var $$ = this.owner;
|
10952 | var config = $$.config;
|
10953 | var option = this.getLabelOptionByAxisId(id);
|
10954 | if (isString(option)) {
|
10955 | config["axis_" + id + "_label"] = text;
|
10956 | }
|
10957 | else if (option) {
|
10958 | option.text = text;
|
10959 | }
|
10960 | };
|
10961 | Axis.prototype.getLabelPosition = function (id, defaultPosition) {
|
10962 | var isRotated = this.owner.config.axis_rotated;
|
10963 | var option = this.getLabelOptionByAxisId(id);
|
10964 | var position = (isObjectType(option) && option.position) ?
|
10965 | option.position : defaultPosition[+!isRotated];
|
10966 | var has = function (v) { return !!~position.indexOf(v); };
|
10967 | return {
|
10968 | isInner: has("inner"),
|
10969 | isOuter: has("outer"),
|
10970 | isLeft: has("left"),
|
10971 | isCenter: has("center"),
|
10972 | isRight: has("right"),
|
10973 | isTop: has("top"),
|
10974 | isMiddle: has("middle"),
|
10975 | isBottom: has("bottom")
|
10976 | };
|
10977 | };
|
10978 | Axis.prototype.getAxisLabelPosition = function (id) {
|
10979 | return this.getLabelPosition(id, id === "x" ? ["inner-top", "inner-right"] : ["inner-right", "inner-top"]);
|
10980 | };
|
10981 | Axis.prototype.getLabelPositionById = function (id) {
|
10982 | return this.getAxisLabelPosition(id);
|
10983 | };
|
10984 | Axis.prototype.xForAxisLabel = function (id) {
|
10985 | var $$ = this.owner;
|
10986 | var _a = $$.state, width = _a.width, height = _a.height;
|
10987 | var position = this.getAxisLabelPosition(id);
|
10988 | var x = position.isMiddle ? -height / 2 : 0;
|
10989 | if (this.isHorizontal($$, id !== "x")) {
|
10990 | x = position.isLeft ? 0 : (position.isCenter ? width / 2 : width);
|
10991 | }
|
10992 | else if (position.isBottom) {
|
10993 | x = -height;
|
10994 | }
|
10995 | return x;
|
10996 | };
|
10997 | Axis.prototype.dxForAxisLabel = function (id) {
|
10998 | var $$ = this.owner;
|
10999 | var position = this.getAxisLabelPosition(id);
|
11000 | var dx = position.isBottom ? "0.5em" : "0";
|
11001 | if (this.isHorizontal($$, id !== "x")) {
|
11002 | dx = position.isLeft ? "0.5em" : (position.isRight ? "-0.5em" : "0");
|
11003 | }
|
11004 | else if (position.isTop) {
|
11005 | dx = "-0.5em";
|
11006 | }
|
11007 | return dx;
|
11008 | };
|
11009 | Axis.prototype.textAnchorForAxisLabel = function (id) {
|
11010 | var $$ = this.owner;
|
11011 | var position = this.getAxisLabelPosition(id);
|
11012 | var anchor = position.isMiddle ? "middle" : "end";
|
11013 | if (this.isHorizontal($$, id !== "x")) {
|
11014 | anchor = position.isLeft ? "start" : (position.isCenter ? "middle" : "end");
|
11015 | }
|
11016 | else if (position.isBottom) {
|
11017 | anchor = "start";
|
11018 | }
|
11019 | return anchor;
|
11020 | };
|
11021 | Axis.prototype.dyForAxisLabel = function (id) {
|
11022 | var $$ = this.owner;
|
11023 | var config = $$.config;
|
11024 | var isRotated = config.axis_rotated;
|
11025 | var isInner = this.getAxisLabelPosition(id).isInner;
|
11026 | var tickRotate = config["axis_" + id + "_tick_rotate"] ? $$.getHorizontalAxisHeight(id) : 0;
|
11027 | var maxTickWidth = this.getMaxTickWidth(id);
|
11028 | var dy;
|
11029 | if (id === "x") {
|
11030 | var xHeight = config.axis_x_height;
|
11031 | if (isRotated) {
|
11032 | dy = isInner ? "1.2em" : -25 - maxTickWidth;
|
11033 | }
|
11034 | else if (isInner) {
|
11035 | dy = "-0.5em";
|
11036 | }
|
11037 | else if (xHeight) {
|
11038 | dy = xHeight - 10;
|
11039 | }
|
11040 | else if (tickRotate) {
|
11041 | dy = tickRotate - 10;
|
11042 | }
|
11043 | else {
|
11044 | dy = "3em";
|
11045 | }
|
11046 | }
|
11047 | else {
|
11048 | dy = {
|
11049 | y: ["-0.5em", 10, "3em", "1.2em", 10],
|
11050 | y2: ["1.2em", -20, "-2.2em", "-0.5em", 15]
|
11051 | }[id];
|
11052 | if (isRotated) {
|
11053 | if (isInner) {
|
11054 | dy = dy[0];
|
11055 | }
|
11056 | else if (tickRotate) {
|
11057 | dy = tickRotate * (id === "y2" ? -1 : 1) - dy[1];
|
11058 | }
|
11059 | else {
|
11060 | dy = dy[2];
|
11061 | }
|
11062 | }
|
11063 | else {
|
11064 | dy = isInner ?
|
11065 | dy[3] : (dy[4] + (config["axis_" + id + "_inner"] ? 0 : (maxTickWidth + dy[4]))) * (id === "y" ? -1 : 1);
|
11066 | }
|
11067 | }
|
11068 | return dy;
|
11069 | };
|
11070 | Axis.prototype.getMaxTickWidth = function (id, withoutRecompute) {
|
11071 | var $$ = this.owner;
|
11072 | var config = $$.config, current = $$.state.current, _a = $$.$el, svg = _a.svg, chart = _a.chart;
|
11073 | var currentTickMax = current.maxTickWidths[id];
|
11074 | var maxWidth = 0;
|
11075 | if (withoutRecompute || !config["axis_" + id + "_show"] || $$.filterTargetsToShow().length === 0) {
|
11076 | return currentTickMax.size;
|
11077 | }
|
11078 | if (svg) {
|
11079 | var isYAxis_1 = /^y2?$/.test(id);
|
11080 | var targetsToShow = $$.filterTargetsToShow($$.data.targets);
|
11081 | var scale = $$.scale[id].copy().domain($$["get" + (isYAxis_1 ? "Y" : "X") + "Domain"](targetsToShow, id));
|
11082 | var domain = scale.domain();
|
11083 | var isDomainSame = domain[0] === domain[1] && domain.every(function (v) { return v > 0; });
|
11084 | var isCurrentMaxTickDomainSame = isArray(currentTickMax.domain) &&
|
11085 | currentTickMax.domain[0] === currentTickMax.domain[1] &&
|
11086 | currentTickMax.domain.every(function (v) { return v > 0; });
|
11087 |
|
11088 | if (isDomainSame || isCurrentMaxTickDomainSame) {
|
11089 | return currentTickMax.size;
|
11090 | }
|
11091 | else {
|
11092 | currentTickMax.domain = domain;
|
11093 | }
|
11094 |
|
11095 | if (!isYAxis_1) {
|
11096 | currentTickMax.ticks.splice(0);
|
11097 | }
|
11098 | var axis = this.getAxis(id, scale, false, false, true);
|
11099 | var tickCount = config["axis_" + id + "_tick_count"];
|
11100 | var tickValues = config["axis_" + id + "_tick_values"];
|
11101 |
|
11102 |
|
11103 |
|
11104 |
|
11105 | if (!tickValues && tickCount) {
|
11106 | axis.tickValues(this.generateTickValues(domain, tickCount, isYAxis_1 ? this.isTimeSeriesY() : this.isTimeSeries()));
|
11107 | }
|
11108 | !isYAxis_1 && this.updateXAxisTickValues(targetsToShow, axis);
|
11109 | var dummy = chart.append("svg")
|
11110 | .style("visibility", "hidden")
|
11111 | .style("position", "fixed")
|
11112 | .style("top", "0px")
|
11113 | .style("left", "0px");
|
11114 | axis.create(dummy);
|
11115 | dummy.selectAll("text")
|
11116 | .each(function (d, i) {
|
11117 | var currentTextWidth = this.getBoundingClientRect().width;
|
11118 | maxWidth = Math.max(maxWidth, currentTextWidth);
|
11119 |
|
11120 | if (!isYAxis_1) {
|
11121 | currentTickMax.ticks[i] = currentTextWidth;
|
11122 | }
|
11123 | });
|
11124 | dummy.remove();
|
11125 | }
|
11126 | if (maxWidth > 0) {
|
11127 | currentTickMax.size = maxWidth;
|
11128 | }
|
11129 | return currentTickMax.size;
|
11130 | };
|
11131 | Axis.prototype.getXAxisTickTextY2Overflow = function (defaultPadding) {
|
11132 | var $$ = this.owner;
|
11133 | var axis = $$.axis, config = $$.config, state = $$.state;
|
11134 | var xAxisTickRotate = $$.getAxisTickRotate("x");
|
11135 | var positiveRotation = xAxisTickRotate > 0 && xAxisTickRotate < 90;
|
11136 | if ((axis.isCategorized() || axis.isTimeSeries()) &&
|
11137 | config.axis_x_tick_fit &&
|
11138 | !config.axis_x_tick_culling &&
|
11139 | !config.axis_x_tick_multiline &&
|
11140 | positiveRotation) {
|
11141 | var widthWithoutCurrentPaddingLeft = state.current.width - $$.getCurrentPaddingLeft();
|
11142 | var maxOverflow = this.getXAxisTickMaxOverflow(xAxisTickRotate, widthWithoutCurrentPaddingLeft - defaultPadding);
|
11143 | var xAxisTickTextY2Overflow = Math.max(0, maxOverflow) +
|
11144 | defaultPadding;
|
11145 | return Math.min(xAxisTickTextY2Overflow, widthWithoutCurrentPaddingLeft / 2);
|
11146 | }
|
11147 | return 0;
|
11148 | };
|
11149 | Axis.prototype.getXAxisTickMaxOverflow = function (xAxisTickRotate, widthWithoutCurrentPaddingLeft) {
|
11150 | var $$ = this.owner;
|
11151 | var axis = $$.axis, config = $$.config, state = $$.state;
|
11152 | var isTimeSeries = axis.isTimeSeries();
|
11153 | var tickTextWidths = state.current.maxTickWidths.x.ticks;
|
11154 | var tickCount = tickTextWidths.length;
|
11155 | var _a = state.axis.x.padding, left = _a.left, right = _a.right;
|
11156 | var maxOverflow = 0;
|
11157 | var remaining = tickCount - (isTimeSeries && config.axis_x_tick_fit ? 0.5 : 0);
|
11158 | for (var i = 0; i < tickCount; i++) {
|
11159 | var tickIndex = i + 1;
|
11160 | var rotatedTickTextWidth = Math.cos(Math.PI * xAxisTickRotate / 180) * tickTextWidths[i];
|
11161 | var ticksBeforeTickText = tickIndex - (isTimeSeries ? 1 : 0.5) + left;
|
11162 |
|
11163 | if (ticksBeforeTickText <= 0) {
|
11164 | continue;
|
11165 | }
|
11166 | var xAxisLengthWithoutTickTextWidth = widthWithoutCurrentPaddingLeft - rotatedTickTextWidth;
|
11167 | var tickLength = xAxisLengthWithoutTickTextWidth / ticksBeforeTickText;
|
11168 | var remainingTicks = remaining - tickIndex;
|
11169 | var paddingRightLength = right * tickLength;
|
11170 | var remainingTickWidth = (remainingTicks * tickLength) + paddingRightLength;
|
11171 | var overflow = rotatedTickTextWidth - (tickLength / 2) - remainingTickWidth;
|
11172 | maxOverflow = Math.max(maxOverflow, overflow);
|
11173 | }
|
11174 | var filteredTargets = $$.filterTargetsToShow($$.data.targets);
|
11175 | var tickOffset = 0;
|
11176 | if (!isTimeSeries &&
|
11177 | config.axis_x_tick_count <= filteredTargets.length && filteredTargets[0].values.length) {
|
11178 | var scale = getScale($$.axis.getAxisType("x"), 0, widthWithoutCurrentPaddingLeft - maxOverflow)
|
11179 | .domain([
|
11180 | left * -1,
|
11181 | $$.getXDomainMax($$.data.targets) + 1 + right
|
11182 | ]);
|
11183 | tickOffset = (Math.ceil((scale(1) - scale(0)) / 2));
|
11184 | }
|
11185 | return maxOverflow + tickOffset;
|
11186 | };
|
11187 | |
11188 |
|
11189 |
|
11190 |
|
11191 |
|
11192 |
|
11193 | Axis.prototype.getXAxisPadding = function (tickCount) {
|
11194 | var $$ = this.owner;
|
11195 | var padding = $$.config.axis_x_padding;
|
11196 | if (isEmpty(padding)) {
|
11197 | padding = { left: 0, right: 0 };
|
11198 | }
|
11199 | else {
|
11200 | padding.left = padding.left || 0;
|
11201 | padding.right = padding.right || 0;
|
11202 | }
|
11203 | if ($$.axis.isTimeSeries()) {
|
11204 | var firstX = +$$.getXDomainMin($$.data.targets);
|
11205 | var lastX = +$$.getXDomainMax($$.data.targets);
|
11206 | var timeDiff = lastX - firstX;
|
11207 | var range = timeDiff + padding.left + padding.right;
|
11208 | var left = 0;
|
11209 | var right = 0;
|
11210 | if (tickCount && range) {
|
11211 | var relativeTickWidth = (timeDiff / tickCount) / range;
|
11212 | left = padding.left / range / relativeTickWidth;
|
11213 | right = padding.right / range / relativeTickWidth;
|
11214 | }
|
11215 | padding = { left: left, right: right };
|
11216 | }
|
11217 | return padding;
|
11218 | };
|
11219 | Axis.prototype.updateLabels = function (withTransition) {
|
11220 | var _this = this;
|
11221 | var $$ = this.owner;
|
11222 | var main = $$.$el.main;
|
11223 | var labels = {
|
11224 | x: main.select("." + CLASS.axisX + " ." + CLASS.axisXLabel),
|
11225 | y: main.select("." + CLASS.axisY + " ." + CLASS.axisYLabel),
|
11226 | y2: main.select("." + CLASS.axisY2 + " ." + CLASS.axisY2Label)
|
11227 | };
|
11228 | Object.keys(labels).filter(function (id) { return !labels[id].empty(); })
|
11229 | .forEach(function (v) {
|
11230 | var node = labels[v];
|
11231 | (withTransition ? node.transition() : node)
|
11232 | .attr("x", function () { return _this.xForAxisLabel(v); })
|
11233 | .attr("dx", function () { return _this.dxForAxisLabel(v); })
|
11234 | .attr("dy", function () { return _this.dyForAxisLabel(v); })
|
11235 | .text(function () { return _this.getLabelText(v); });
|
11236 | });
|
11237 | };
|
11238 | Axis.prototype.getPadding = function (padding, key, defaultValue, domainLength) {
|
11239 | var p = isNumber(padding) ? padding : padding[key];
|
11240 | if (!isValue(p)) {
|
11241 | return defaultValue;
|
11242 | }
|
11243 | return this.convertPixelsToAxisPadding(p, domainLength);
|
11244 | };
|
11245 | Axis.prototype.convertPixelsToAxisPadding = function (pixels, domainLength) {
|
11246 | var $$ = this.owner;
|
11247 | var config = $$.config, _a = $$.state, width = _a.width, height = _a.height;
|
11248 | var length = config.axis_rotated ? width : height;
|
11249 | return domainLength * (pixels / length);
|
11250 | };
|
11251 | Axis.prototype.generateTickValues = function (values, tickCount, forTimeSeries) {
|
11252 | var tickValues = values;
|
11253 | if (tickCount) {
|
11254 | var targetCount = isFunction(tickCount) ? tickCount() : tickCount;
|
11255 |
|
11256 | if (targetCount === 1) {
|
11257 | tickValues = [values[0]];
|
11258 | }
|
11259 | else if (targetCount === 2) {
|
11260 | tickValues = [values[0], values[values.length - 1]];
|
11261 | }
|
11262 | else if (targetCount > 2) {
|
11263 | var isCategorized = this.isCategorized();
|
11264 | var count = targetCount - 2;
|
11265 | var start = values[0];
|
11266 | var end = values[values.length - 1];
|
11267 | var interval = (end - start) / (count + 1);
|
11268 | var tickValue = void 0;
|
11269 |
|
11270 | tickValues = [start];
|
11271 | for (var i = 0; i < count; i++) {
|
11272 | tickValue = +start + interval * (i + 1);
|
11273 | tickValues.push(forTimeSeries ? new Date(tickValue) : (isCategorized ? Math.round(tickValue) : tickValue));
|
11274 | }
|
11275 | tickValues.push(end);
|
11276 | }
|
11277 | }
|
11278 | if (!forTimeSeries) {
|
11279 | tickValues = tickValues.sort(function (a, b) { return a - b; });
|
11280 | }
|
11281 | return tickValues;
|
11282 | };
|
11283 | Axis.prototype.generateTransitions = function (duration) {
|
11284 | var $$ = this.owner;
|
11285 | var axis = $$.$el.axis;
|
11286 | var _a = ["x", "y", "y2", "subX"]
|
11287 | .map(function (v) {
|
11288 | var ax = axis[v];
|
11289 | if (ax && duration) {
|
11290 | ax = ax.transition().duration(duration);
|
11291 | }
|
11292 | return ax;
|
11293 | }), axisX = _a[0], axisY = _a[1], axisY2 = _a[2], axisSubX = _a[3];
|
11294 | return { axisX: axisX, axisY: axisY, axisY2: axisY2, axisSubX: axisSubX };
|
11295 | };
|
11296 | Axis.prototype.redraw = function (transitions, isHidden, isInit) {
|
11297 | var _this = this;
|
11298 | var $$ = this.owner;
|
11299 | var config = $$.config, $el = $$.$el;
|
11300 | var opacity = isHidden ? "0" : "1";
|
11301 | ["x", "y", "y2", "subX"].forEach(function (id) {
|
11302 | var axis = _this[id];
|
11303 | var $axis = $el.axis[id];
|
11304 | if (axis && $axis) {
|
11305 | if (!isInit && !config.transition_duration) {
|
11306 | axis.config.withoutTransition = true;
|
11307 | }
|
11308 | $axis.style("opacity", opacity);
|
11309 | axis.create(transitions["axis" + capitalize(id)]);
|
11310 | }
|
11311 | });
|
11312 | this.updateAxes();
|
11313 | };
|
11314 | |
11315 |
|
11316 |
|
11317 |
|
11318 |
|
11319 |
|
11320 |
|
11321 |
|
11322 |
|
11323 | Axis.prototype.redrawAxis = function (targetsToShow, wth, transitions, flow, isInit) {
|
11324 | var _this = this;
|
11325 | var $$ = this.owner;
|
11326 | var config = $$.config, scale = $$.scale, $el = $$.$el;
|
11327 | var hasZoom = !!scale.zoom;
|
11328 | var xDomainForZoom;
|
11329 | if (!hasZoom && this.isCategorized() && targetsToShow.length === 0) {
|
11330 | scale.x.domain([0, $el.axis.x.selectAll(".tick").size()]);
|
11331 | }
|
11332 | if (scale.x && targetsToShow.length) {
|
11333 | !hasZoom &&
|
11334 | $$.updateXDomain(targetsToShow, wth.UpdateXDomain, wth.UpdateOrgXDomain, wth.TrimXDomain);
|
11335 | if (!config.axis_x_tick_values) {
|
11336 | this.updateXAxisTickValues(targetsToShow);
|
11337 | }
|
11338 | }
|
11339 | else if (this.x) {
|
11340 | this.x.tickValues([]);
|
11341 | this.subX && this.subX.tickValues([]);
|
11342 | }
|
11343 | if (config.zoom_rescale && !flow) {
|
11344 | xDomainForZoom = scale.x.orgDomain();
|
11345 | }
|
11346 | ["y", "y2"].forEach(function (key) {
|
11347 | var axisScale = scale[key];
|
11348 | if (axisScale) {
|
11349 | var tickValues = config["axis_" + key + "_tick_values"];
|
11350 | var tickCount = config["axis_" + key + "_tick_count"];
|
11351 | axisScale.domain($$.getYDomain(targetsToShow, key, xDomainForZoom));
|
11352 | if (!tickValues && tickCount) {
|
11353 | var axis = $$.axis[key];
|
11354 | var domain = axisScale.domain();
|
11355 | axis.tickValues(_this.generateTickValues(domain, domain.every(function (v) { return v === 0; }) ? 1 : tickCount, _this.isTimeSeriesY()));
|
11356 | }
|
11357 | }
|
11358 | });
|
11359 |
|
11360 | this.redraw(transitions, $$.hasArcType(), isInit);
|
11361 |
|
11362 | this.updateLabels(wth.Transition);
|
11363 |
|
11364 | if ((wth.UpdateXDomain || wth.UpdateXAxis || wth.Y) && targetsToShow.length) {
|
11365 | this.setCulling();
|
11366 | }
|
11367 |
|
11368 | if (wth.Y) {
|
11369 | scale.subY && scale.subY.domain($$.getYDomain(targetsToShow, "y"));
|
11370 | scale.subY2 && scale.subY2.domain($$.getYDomain(targetsToShow, "y2"));
|
11371 | }
|
11372 | };
|
11373 | |
11374 |
|
11375 |
|
11376 |
|
11377 | Axis.prototype.setCulling = function () {
|
11378 | var $$ = this.owner;
|
11379 | var config = $$.config, _a = $$.state, clip = _a.clip, current = _a.current, $el = $$.$el;
|
11380 | ["subX", "x", "y", "y2"].forEach(function (type) {
|
11381 | var axis = $el.axis[type];
|
11382 |
|
11383 | var id = type === "subX" ? "x" : type;
|
11384 | var toCull = config["axis_" + id + "_tick_culling"];
|
11385 | if (axis && toCull) {
|
11386 | var tickText = axis.selectAll(".tick text");
|
11387 | var tickValues_1 = sortValue(tickText.data());
|
11388 | var tickSize = tickValues_1.length;
|
11389 | var cullingMax = config["axis_" + id + "_tick_culling_max"];
|
11390 | var intervalForCulling_1;
|
11391 | if (tickSize) {
|
11392 | for (var i = 1; i < tickSize; i++) {
|
11393 | if (tickSize / i < cullingMax) {
|
11394 | intervalForCulling_1 = i;
|
11395 | break;
|
11396 | }
|
11397 | }
|
11398 | tickText.each(function (d) {
|
11399 | this.style.display = tickValues_1.indexOf(d) % intervalForCulling_1 ? "none" : "block";
|
11400 | });
|
11401 | }
|
11402 | else {
|
11403 | tickText.style("display", "block");
|
11404 | }
|
11405 |
|
11406 | if (type === "x") {
|
11407 | var clipPath = current.maxTickWidths.x.clipPath ? clip.pathXAxisTickTexts : null;
|
11408 | $el.svg.selectAll("." + CLASS.axisX + " .tick text")
|
11409 | .attr("clip-path", clipPath);
|
11410 | }
|
11411 | }
|
11412 | });
|
11413 | };
|
11414 | return Axis;
|
11415 | }());
|
11416 |
|
11417 |
|
11418 |
|
11419 |
|
11420 |
|
11421 | var eventrect = {
|
11422 | |
11423 |
|
11424 |
|
11425 |
|
11426 |
|
11427 | initEventRect: function () {
|
11428 | var $$ = this;
|
11429 | $$.$el.main.select("." + CLASS.chart)
|
11430 | .append("g")
|
11431 | .attr("class", CLASS.eventRects)
|
11432 | .style("fill-opacity", "0");
|
11433 | },
|
11434 | |
11435 |
|
11436 |
|
11437 |
|
11438 | redrawEventRect: function () {
|
11439 | var $$ = this;
|
11440 | var config = $$.config, state = $$.state, $el = $$.$el;
|
11441 | var isMultipleX = $$.isMultipleX();
|
11442 | if ($el.eventRect) {
|
11443 | $$.updateEventRect($el.eventRect, true);
|
11444 | }
|
11445 | else {
|
11446 | var eventRects = $$.$el.main.select("." + CLASS.eventRects)
|
11447 | .style("cursor", config.zoom_enabled && config.zoom_type !== "drag" ? (config.axis_rotated ? "ns-resize" : "ew-resize") : null)
|
11448 | .classed(CLASS.eventRectsMultiple, isMultipleX)
|
11449 | .classed(CLASS.eventRectsSingle, !isMultipleX);
|
11450 |
|
11451 | var eventRectUpdate = eventRects.selectAll("." + CLASS.eventRect)
|
11452 | .data([0])
|
11453 | .enter()
|
11454 | .append("rect");
|
11455 | $$.updateEventRect(eventRectUpdate);
|
11456 |
|
11457 | isMultipleX ?
|
11458 | $$.generateEventRectsForMultipleXs(eventRectUpdate) :
|
11459 | $$.generateEventRectsForSingleX(eventRectUpdate);
|
11460 |
|
11461 | eventRectUpdate.call($$.getDraggableSelection());
|
11462 | $el.eventRect = eventRectUpdate;
|
11463 | if ($$.state.inputType === "touch" && !$el.svg.on("touchstart.eventRect") && !$$.hasArcType()) {
|
11464 | $$.bindTouchOnEventRect(isMultipleX);
|
11465 | }
|
11466 | }
|
11467 | if (!isMultipleX) {
|
11468 |
|
11469 | var xAxisTickValues = $$.getMaxDataCountTarget();
|
11470 |
|
11471 | $$.updateDataIndexByX(xAxisTickValues);
|
11472 | $$.updateXs(xAxisTickValues);
|
11473 | $$.updatePointClass && $$.updatePointClass(true);
|
11474 | state.eventReceiver.data = xAxisTickValues;
|
11475 | }
|
11476 | $$.updateEventRectData();
|
11477 | },
|
11478 | bindTouchOnEventRect: function (isMultipleX) {
|
11479 | var $$ = this;
|
11480 | var config = $$.config, state = $$.state, _a = $$.$el, eventRect = _a.eventRect, svg = _a.svg;
|
11481 | var selectRect = function (context) {
|
11482 | if (isMultipleX) {
|
11483 | $$.selectRectForMultipleXs(context);
|
11484 | }
|
11485 | else {
|
11486 | var index = $$.getDataIndexFromEvent(state.event);
|
11487 | $$.callOverOutForTouch(index);
|
11488 | index === -1 ?
|
11489 | $$.unselectRect() :
|
11490 | $$.selectRectForSingle(context, eventRect, index);
|
11491 | }
|
11492 | };
|
11493 | var unselectRect = function () {
|
11494 | $$.unselectRect();
|
11495 | $$.callOverOutForTouch();
|
11496 | };
|
11497 |
|
11498 |
|
11499 | var preventDefault = config.interaction_inputType_touch.preventDefault;
|
11500 | var isPrevented = (isboolean(preventDefault) && preventDefault) || false;
|
11501 | var preventThreshold = (!isNaN(preventDefault) && preventDefault) || null;
|
11502 | var startPx;
|
11503 | var preventEvent = function (event) {
|
11504 | var eventType = event.type;
|
11505 | var touch = event.changedTouches[0];
|
11506 | var currentXY = touch["client" + (config.axis_rotated ? "Y" : "X")];
|
11507 |
|
11508 | if (eventType === "touchstart") {
|
11509 | if (isPrevented) {
|
11510 | event.preventDefault();
|
11511 | }
|
11512 | else if (preventThreshold !== null) {
|
11513 | startPx = currentXY;
|
11514 | }
|
11515 | }
|
11516 | else if (eventType === "touchmove") {
|
11517 | if (isPrevented || startPx === true || (preventThreshold !== null && Math.abs(startPx - currentXY) >= preventThreshold)) {
|
11518 |
|
11519 | startPx = true;
|
11520 | event.preventDefault();
|
11521 | }
|
11522 | }
|
11523 | };
|
11524 |
|
11525 | eventRect
|
11526 | .on("touchstart", function (event) {
|
11527 | state.event = event;
|
11528 | $$.updateEventRect();
|
11529 | })
|
11530 | .on("touchstart.eventRect touchmove.eventRect", function (event) {
|
11531 | state.event = event;
|
11532 | if (!eventRect.empty() && eventRect.classed(CLASS.eventRect)) {
|
11533 |
|
11534 | if (state.dragging || state.flowing || $$.hasArcType() || event.touches.length > 1) {
|
11535 | return;
|
11536 | }
|
11537 | preventEvent(event);
|
11538 | selectRect(eventRect.node());
|
11539 | }
|
11540 | else {
|
11541 | unselectRect();
|
11542 | }
|
11543 | }, true)
|
11544 | .on("touchend.eventRect", function (event) {
|
11545 | state.event = event;
|
11546 | if (!eventRect.empty() && eventRect.classed(CLASS.eventRect)) {
|
11547 | if ($$.hasArcType() || !$$.toggleShape || state.cancelClick) {
|
11548 | state.cancelClick && (state.cancelClick = false);
|
11549 | }
|
11550 | }
|
11551 | }, true);
|
11552 | svg.on("touchstart", function (event) {
|
11553 | state.event = event;
|
11554 | var target = event.target;
|
11555 | if (target && target !== eventRect.node()) {
|
11556 | unselectRect();
|
11557 | }
|
11558 | });
|
11559 | },
|
11560 | |
11561 |
|
11562 |
|
11563 |
|
11564 |
|
11565 |
|
11566 | updateEventRect: function (eventRect, force) {
|
11567 | if (force === void 0) { force = false; }
|
11568 | var $$ = this;
|
11569 | var state = $$.state, $el = $$.$el;
|
11570 | var eventReceiver = state.eventReceiver, width = state.width, height = state.height, rendered = state.rendered, resizing = state.resizing;
|
11571 | var rectElement = eventRect || $el.eventRect;
|
11572 | var updateClientRect = function () {
|
11573 | eventReceiver && (eventReceiver.rect = rectElement.node().getBoundingClientRect());
|
11574 | };
|
11575 | if (!rendered || resizing || force) {
|
11576 | rectElement
|
11577 | .attr("x", 0)
|
11578 | .attr("y", 0)
|
11579 | .attr("width", width)
|
11580 | .attr("height", height);
|
11581 |
|
11582 | if (!rendered) {
|
11583 | rectElement.attr("class", CLASS.eventRect);
|
11584 | }
|
11585 | }
|
11586 | updateClientRect();
|
11587 | },
|
11588 | |
11589 |
|
11590 |
|
11591 |
|
11592 | updateEventRectData: function () {
|
11593 | var $$ = this;
|
11594 | var config = $$.config, scale = $$.scale, state = $$.state;
|
11595 | var xScale = scale.zoom || scale.x;
|
11596 | var isRotated = config.axis_rotated;
|
11597 | var x;
|
11598 | var y;
|
11599 | var w;
|
11600 | var h;
|
11601 | if ($$.isMultipleX()) {
|
11602 |
|
11603 | x = 0;
|
11604 | y = 0;
|
11605 | w = state.width;
|
11606 | h = state.height;
|
11607 | }
|
11608 | else {
|
11609 | var rectW_1;
|
11610 | var rectX = void 0;
|
11611 | if ($$.axis.isCategorized()) {
|
11612 | rectW_1 = $$.getEventRectWidth();
|
11613 | rectX = function (d) { return xScale(d.x) - (rectW_1 / 2); };
|
11614 | }
|
11615 | else {
|
11616 | var getPrevNextX_1 = function (_a) {
|
11617 | var index = _a.index;
|
11618 | return ({
|
11619 | prev: $$.getPrevX(index),
|
11620 | next: $$.getNextX(index)
|
11621 | });
|
11622 | };
|
11623 | rectW_1 = function (d) {
|
11624 | var x = getPrevNextX_1(d);
|
11625 |
|
11626 | if (x.prev === null && x.next === null) {
|
11627 | return isRotated ? state.height : state.width;
|
11628 | }
|
11629 | if (x.prev === null) {
|
11630 | x.prev = xScale.domain()[0];
|
11631 | }
|
11632 | if (x.next === null) {
|
11633 | x.next = xScale.domain()[1];
|
11634 | }
|
11635 | return Math.max(0, (xScale(x.next) - xScale(x.prev)) / 2);
|
11636 | };
|
11637 | rectX = function (d) {
|
11638 | var x = getPrevNextX_1(d);
|
11639 | var thisX = d.x;
|
11640 |
|
11641 | if (x.prev === null && x.next === null) {
|
11642 | return 0;
|
11643 | }
|
11644 | if (x.prev === null) {
|
11645 | x.prev = xScale.domain()[0];
|
11646 | }
|
11647 | return (xScale(thisX) + xScale(x.prev)) / 2;
|
11648 | };
|
11649 | }
|
11650 | x = isRotated ? 0 : rectX;
|
11651 | y = isRotated ? rectX : 0;
|
11652 | w = isRotated ? state.width : rectW_1;
|
11653 | h = isRotated ? rectW_1 : state.height;
|
11654 | }
|
11655 | var eventReceiver = state.eventReceiver;
|
11656 | var call = function (fn, v) { return (isFunction(fn) ? fn(v) : fn); };
|
11657 |
|
11658 | eventReceiver.coords.splice(eventReceiver.data.length);
|
11659 | eventReceiver.data.forEach(function (d, i) {
|
11660 | eventReceiver.coords[i] = {
|
11661 | x: call(x, d),
|
11662 | y: call(y, d),
|
11663 | w: call(w, d),
|
11664 | h: call(h, d)
|
11665 | };
|
11666 | });
|
11667 | },
|
11668 | selectRectForMultipleXs: function (context) {
|
11669 | var $$ = this;
|
11670 | var config = $$.config, state = $$.state;
|
11671 | var targetsToShow = $$.filterTargetsToShow($$.data.targets);
|
11672 |
|
11673 | if (state.dragging || $$.hasArcType(targetsToShow)) {
|
11674 | return;
|
11675 | }
|
11676 | var mouse = getPointer(state.event, context);
|
11677 | var closest = $$.findClosestFromTargets(targetsToShow, mouse);
|
11678 | if (state.mouseover && (!closest || closest.id !== state.mouseover.id)) {
|
11679 | config.data_onout.call($$.api, state.mouseover);
|
11680 | state.mouseover = undefined;
|
11681 | }
|
11682 | if (!closest) {
|
11683 | $$.unselectRect();
|
11684 | return;
|
11685 | }
|
11686 | var sameXData = ($$.isBubbleType(closest) || $$.isScatterType(closest) || !config.tooltip_grouped) ? [closest] : $$.filterByX(targetsToShow, closest.x);
|
11687 |
|
11688 | var selectedData = sameXData.map(function (d) { return $$.addName(d); });
|
11689 | $$.showTooltip(selectedData, context);
|
11690 |
|
11691 | $$.expandCirclesBars(closest.index, closest.id, true);
|
11692 |
|
11693 | $$.showGridFocus(selectedData);
|
11694 |
|
11695 | if ($$.isBarType(closest.id) || $$.dist(closest, mouse) < config.point_sensitivity) {
|
11696 | $$.$el.svg.select("." + CLASS.eventRect).style("cursor", "pointer");
|
11697 | if (!state.mouseover) {
|
11698 | config.data_onover.call($$.api, closest);
|
11699 | state.mouseover = closest;
|
11700 | }
|
11701 | }
|
11702 | },
|
11703 | |
11704 |
|
11705 |
|
11706 |
|
11707 | unselectRect: function () {
|
11708 | var $$ = this;
|
11709 | var config = $$.config, _a = $$.$el, bar = _a.bar, circle = _a.circle, tooltip = _a.tooltip;
|
11710 | $$.$el.svg.select("." + CLASS.eventRect).style("cursor", null);
|
11711 | $$.hideGridFocus();
|
11712 | if (tooltip) {
|
11713 | $$.hideTooltip();
|
11714 | $$._handleLinkedCharts(false);
|
11715 | }
|
11716 | circle && !config.point_focus_only && $$.unexpandCircles();
|
11717 | bar && $$.unexpandBars();
|
11718 | },
|
11719 | |
11720 |
|
11721 |
|
11722 |
|
11723 |
|
11724 |
|
11725 |
|
11726 | generateEventRectsForSingleX: function (eventRectEnter) {
|
11727 | var $$ = this;
|
11728 | var config = $$.config, state = $$.state;
|
11729 | var eventReceiver = state.eventReceiver;
|
11730 | var rect = eventRectEnter
|
11731 | .style("cursor", config.data_selection_enabled && config.data_selection_grouped ? "pointer" : null)
|
11732 | .on("click", function (event) {
|
11733 | state.event = event;
|
11734 | var currentIdx = eventReceiver.currentIdx, data = eventReceiver.data;
|
11735 | var d = data[currentIdx === -1 ?
|
11736 | $$.getDataIndexFromEvent(event) : currentIdx];
|
11737 | $$.clickHandlerForSingleX.bind(this)(d, $$);
|
11738 | });
|
11739 | if (state.inputType === "mouse") {
|
11740 | var getData_1 = function (event) {
|
11741 | var index = event ? $$.getDataIndexFromEvent(event) : eventReceiver.currentIdx;
|
11742 | return index > -1 ? eventReceiver.data[index] : null;
|
11743 | };
|
11744 | rect
|
11745 | .on("mouseover", function (event) {
|
11746 | state.event = event;
|
11747 | $$.updateEventRect();
|
11748 | })
|
11749 | .on("mousemove", function (event) {
|
11750 | var d = getData_1(event);
|
11751 | state.event = event;
|
11752 |
|
11753 | if (state.dragging || state.flowing || $$.hasArcType() ||
|
11754 | !d || (config.tooltip_grouped && d && d.index === eventReceiver.currentIdx)) {
|
11755 | return;
|
11756 | }
|
11757 | var index = d.index;
|
11758 | if ($$.isStepType(d) &&
|
11759 | config.line_step_type === "step-after" &&
|
11760 | getPointer(event, this)[0] < $$.scale.x($$.getXValue(d.id, index))) {
|
11761 | index -= 1;
|
11762 | }
|
11763 | if (index !== eventReceiver.currentIdx) {
|
11764 | $$.setOverOut(false, eventReceiver.currentIdx);
|
11765 | eventReceiver.currentIdx = index;
|
11766 | }
|
11767 | index === -1 ?
|
11768 | $$.unselectRect() : $$.selectRectForSingle(this, rect, index);
|
11769 |
|
11770 |
|
11771 | $$.setOverOut(index !== -1, index);
|
11772 | })
|
11773 | .on("mouseout", function (event) {
|
11774 | state.event = event;
|
11775 |
|
11776 | if (!config || $$.hasArcType() || eventReceiver.currentIdx === -1) {
|
11777 | return;
|
11778 | }
|
11779 | $$.unselectRect();
|
11780 | $$.setOverOut(false, eventReceiver.currentIdx);
|
11781 |
|
11782 | eventReceiver.currentIdx = -1;
|
11783 | });
|
11784 | }
|
11785 | return rect;
|
11786 | },
|
11787 | clickHandlerForSingleX: function (d, ctx) {
|
11788 | var $$ = ctx;
|
11789 | var config = $$.config, state = $$.state, main = $$.$el.main;
|
11790 | if (!d || $$.hasArcType() || state.cancelClick) {
|
11791 | state.cancelClick && (state.cancelClick = false);
|
11792 | return;
|
11793 | }
|
11794 | var index = d.index;
|
11795 | main.selectAll("." + CLASS.shape + "-" + index)
|
11796 | .each(function (d2) {
|
11797 | if (config.data_selection_grouped || $$.isWithinShape(this, d2)) {
|
11798 | $$.toggleShape && $$.toggleShape(this, d2, index);
|
11799 | config.data_onclick.bind($$.api)(d2, this);
|
11800 | }
|
11801 | });
|
11802 | },
|
11803 | |
11804 |
|
11805 |
|
11806 |
|
11807 |
|
11808 |
|
11809 | generateEventRectsForMultipleXs: function (eventRectEnter) {
|
11810 | var $$ = this;
|
11811 | var state = $$.state;
|
11812 | eventRectEnter
|
11813 | .on("click", function (event) {
|
11814 | state.event = event;
|
11815 | $$.clickHandlerForMultipleXS.bind(this)($$);
|
11816 | });
|
11817 | if (state.inputType === "mouse") {
|
11818 | eventRectEnter
|
11819 | .on("mouseover mousemove", function (event) {
|
11820 | state.event = event;
|
11821 | $$.selectRectForMultipleXs(this);
|
11822 | })
|
11823 | .on("mouseout", function (event) {
|
11824 | state.event = event;
|
11825 |
|
11826 | if (!$$.config || $$.hasArcType()) {
|
11827 | return;
|
11828 | }
|
11829 | $$.unselectRect();
|
11830 | });
|
11831 | }
|
11832 | },
|
11833 | clickHandlerForMultipleXS: function (ctx) {
|
11834 | var $$ = ctx;
|
11835 | var config = $$.config, state = $$.state;
|
11836 | var targetsToShow = $$.filterTargetsToShow($$.data.targets);
|
11837 | if ($$.hasArcType(targetsToShow)) {
|
11838 | return;
|
11839 | }
|
11840 | var mouse = getPointer(state.event, this);
|
11841 | var closest = $$.findClosestFromTargets(targetsToShow, mouse);
|
11842 | if (!closest) {
|
11843 | return;
|
11844 | }
|
11845 |
|
11846 | if ($$.isBarType(closest.id) || $$.dist(closest, mouse) < config.point_sensitivity) {
|
11847 | $$.$el.main.selectAll("." + CLASS.shapes + $$.getTargetSelectorSuffix(closest.id))
|
11848 | .selectAll("." + CLASS.shape + "-" + closest.index)
|
11849 | .each(function () {
|
11850 | if (config.data_selection_grouped || $$.isWithinShape(this, closest)) {
|
11851 | $$.toggleShape && $$.toggleShape(this, closest, closest.index);
|
11852 | config.data_onclick.bind($$.api)(closest, this);
|
11853 | }
|
11854 | });
|
11855 | }
|
11856 | }
|
11857 | };
|
11858 |
|
11859 |
|
11860 |
|
11861 |
|
11862 |
|
11863 | var flow = {
|
11864 | |
11865 |
|
11866 |
|
11867 |
|
11868 |
|
11869 |
|
11870 | generateFlow: function (args) {
|
11871 | var $$ = this;
|
11872 | var data = $$.data, state = $$.state, $el = $$.$el;
|
11873 | return function () {
|
11874 | var flowLength = args.flow.length;
|
11875 |
|
11876 | state.flowing = true;
|
11877 |
|
11878 | data.targets.forEach(function (d) {
|
11879 | d.values.splice(0, flowLength);
|
11880 | });
|
11881 |
|
11882 | if ($$.updateXGrid) {
|
11883 | $$.updateXGrid(true);
|
11884 | }
|
11885 |
|
11886 | var elements = {};
|
11887 | ["axis.x", "grid.x", "gridLines.x", "region.list", "text", "bar", "line", "area", "circle"]
|
11888 | .forEach(function (v) {
|
11889 | var name = v.split(".");
|
11890 | var node = $el[name[0]];
|
11891 | if (node && name.length > 1) {
|
11892 | node = node[name[1]];
|
11893 | }
|
11894 | if (node && node.size()) {
|
11895 | elements[v] = node;
|
11896 | }
|
11897 | });
|
11898 | $$.hideGridFocus();
|
11899 | $$.setFlowList(elements, args);
|
11900 | };
|
11901 | },
|
11902 | |
11903 |
|
11904 |
|
11905 |
|
11906 |
|
11907 |
|
11908 | setFlowList: function (elements, args) {
|
11909 | var $$ = this;
|
11910 | var flow = args.flow, targets = args.targets;
|
11911 | var _a = flow.duration, duration = _a === void 0 ? args.duration : _a, flowIndex = flow.index, flowLength = flow.length, orgDataCount = flow.orgDataCount;
|
11912 | var transform = $$.getFlowTransform(targets, orgDataCount, flowIndex, flowLength);
|
11913 | var wait = generateWait();
|
11914 | var n;
|
11915 | wait.add(Object.keys(elements).map(function (v) {
|
11916 | n = elements[v]
|
11917 | .transition()
|
11918 | .ease(easeLinear)
|
11919 | .duration(duration);
|
11920 | if (v === "axis.x") {
|
11921 | n = n.call(function (g) {
|
11922 | $$.axis.x.setTransition(g).create(g);
|
11923 | });
|
11924 | }
|
11925 | else if (v === "region.list") {
|
11926 | n = n.filter($$.isRegionOnX)
|
11927 | .attr("transform", transform);
|
11928 | }
|
11929 | else {
|
11930 | n = n.attr("transform", transform);
|
11931 | }
|
11932 | return n;
|
11933 | }));
|
11934 | n.call(wait, function () {
|
11935 | $$.cleanUpFlow(elements, args);
|
11936 | });
|
11937 | },
|
11938 | |
11939 |
|
11940 |
|
11941 |
|
11942 |
|
11943 |
|
11944 | cleanUpFlow: function (elements, args) {
|
11945 | var $$ = this;
|
11946 | var config = $$.config, state = $$.state, svg = $$.$el.svg;
|
11947 | var isRotated = config.axis_rotated;
|
11948 | var flow = args.flow, shape = args.shape, xv = args.xv;
|
11949 | var _a = shape.pos, cx = _a.cx, cy = _a.cy, xForText = _a.xForText, yForText = _a.yForText;
|
11950 | var _b = flow.done, done = _b === void 0 ? function () { } : _b, flowLength = flow.length;
|
11951 |
|
11952 | if (flowLength) {
|
11953 | ["circle", "text", "shape", "eventRect"].forEach(function (v) {
|
11954 | var target = [];
|
11955 | for (var i = 0; i < flowLength; i++) {
|
11956 | target.push("." + CLASS[v] + "-" + i);
|
11957 | }
|
11958 | svg.selectAll("." + CLASS[v + "s"])
|
11959 | .selectAll(target)
|
11960 | .remove();
|
11961 | });
|
11962 | svg.select("." + CLASS.xgrid)
|
11963 | .remove();
|
11964 | }
|
11965 |
|
11966 | Object.keys(elements).forEach(function (v) {
|
11967 | var n = elements[v];
|
11968 | if (v !== "axis.x") {
|
11969 | n.attr("transform", null);
|
11970 | }
|
11971 | if (v === "grid.x") {
|
11972 | n.attr(state.xgridAttr);
|
11973 | }
|
11974 | else if (v === "gridLines.x") {
|
11975 | n.attr("x1", isRotated ? 0 : xv)
|
11976 | .attr("x2", isRotated ? state.width : xv);
|
11977 | }
|
11978 | else if (v === "gridLines.x") {
|
11979 | n.select("line").attr("x1", isRotated ? 0 : xv)
|
11980 | .attr("x2", isRotated ? state.width : xv);
|
11981 | n.select("text")
|
11982 | .attr("x", isRotated ? state.width : 0)
|
11983 | .attr("y", xv);
|
11984 | }
|
11985 | else if (/^(area|bar|line)$/.test(v)) {
|
11986 | n.attr("d", shape.type[v]);
|
11987 | }
|
11988 | else if (v === "text") {
|
11989 | n.attr("x", xForText)
|
11990 | .attr("y", yForText)
|
11991 | .style("fill-opacity", $$.opacityForText.bind($$));
|
11992 | }
|
11993 | else if (v === "circle") {
|
11994 | if ($$.isCirclePoint()) {
|
11995 | n.attr("cx", cx).attr("cy", cy);
|
11996 | }
|
11997 | else {
|
11998 | var xFunc = function (d) { return cx(d) - config.point_r; };
|
11999 | var yFunc = function (d) { return cy(d) - config.point_r; };
|
12000 | n.attr("x", xFunc)
|
12001 | .attr("y", yFunc)
|
12002 | .attr("cx", cx)
|
12003 | .attr("cy", cy);
|
12004 | }
|
12005 | }
|
12006 | else if (v === "region.list") {
|
12007 | n.select("rect").filter($$.isRegionOnX)
|
12008 | .attr("x", $$.regionX.bind($$))
|
12009 | .attr("width", $$.regionWidth.bind($$));
|
12010 | }
|
12011 | });
|
12012 | config.interaction_enabled && $$.redrawEventRect();
|
12013 |
|
12014 | done.call($$.api);
|
12015 | state.flowing = false;
|
12016 | },
|
12017 | |
12018 |
|
12019 |
|
12020 |
|
12021 |
|
12022 |
|
12023 |
|
12024 |
|
12025 |
|
12026 | getFlowTransform: function (targets, orgDataCount, flowIndex, flowLength) {
|
12027 | var $$ = this;
|
12028 | var data = $$.data, x = $$.scale.x;
|
12029 | var dataValues = data.targets[0].values;
|
12030 | var flowStart = $$.getValueOnIndex(dataValues, flowIndex);
|
12031 | var flowEnd = $$.getValueOnIndex(dataValues, flowIndex + flowLength);
|
12032 | var translateX;
|
12033 |
|
12034 | var orgDomain = x.domain();
|
12035 | var domain = $$.updateXDomain(targets, true, true);
|
12036 |
|
12037 | if (!orgDataCount) {
|
12038 | if (dataValues.length !== 1) {
|
12039 | translateX = x(orgDomain[0]) - x(domain[0]);
|
12040 | }
|
12041 | else {
|
12042 | if ($$.axis.isTimeSeries()) {
|
12043 | flowStart = $$.getValueOnIndex(dataValues, 0);
|
12044 | flowEnd = $$.getValueOnIndex(dataValues, dataValues.length - 1);
|
12045 | translateX = x(flowStart.x) - x(flowEnd.x);
|
12046 | }
|
12047 | else {
|
12048 | translateX = diffDomain(domain) / 2;
|
12049 | }
|
12050 | }
|
12051 | }
|
12052 | else if (orgDataCount === 1 || (flowStart && flowStart.x) === (flowEnd && flowEnd.x)) {
|
12053 | translateX = x(orgDomain[0]) - x(domain[0]);
|
12054 | }
|
12055 | else {
|
12056 | translateX = $$.axis.isTimeSeries() ?
|
12057 | x(orgDomain[0]) - x(domain[0]) :
|
12058 | x(flowStart.x) - x(flowEnd.x);
|
12059 | }
|
12060 | var scaleX = (diffDomain(orgDomain) / diffDomain(domain));
|
12061 | return "translate(" + translateX + ",0) scale(" + scaleX + ",1)";
|
12062 | }
|
12063 | };
|
12064 |
|
12065 |
|
12066 |
|
12067 |
|
12068 |
|
12069 | var clip = {
|
12070 | initClip: function () {
|
12071 | var $$ = this;
|
12072 | var clip = $$.state.clip;
|
12073 |
|
12074 | clip.id = $$.state.datetimeId + "-clip";
|
12075 | clip.idXAxis = clip.id + "-xaxis";
|
12076 | clip.idYAxis = clip.id + "-yaxis";
|
12077 | clip.idGrid = clip.id + "-grid";
|
12078 |
|
12079 | clip.path = $$.getClipPath(clip.id);
|
12080 | clip.pathXAxis = $$.getClipPath(clip.idXAxis);
|
12081 | clip.pathYAxis = $$.getClipPath(clip.idYAxis);
|
12082 | clip.pathGrid = $$.getClipPath(clip.idGrid);
|
12083 | },
|
12084 | getClipPath: function (id) {
|
12085 | var $$ = this;
|
12086 | var config = $$.config;
|
12087 | if ((!config.clipPath && /-clip$/.test(id)) ||
|
12088 | (!config.axis_x_clipPath && /-clip-xaxis$/.test(id)) ||
|
12089 | (!config.axis_y_clipPath && /-clip-yaxis$/.test(id))) {
|
12090 | return null;
|
12091 | }
|
12092 | var isIE9 = win.navigator ?
|
12093 | win.navigator.appVersion
|
12094 | .toLowerCase().indexOf("msie 9.") >= 0 : false;
|
12095 | return "url(" + (isIE9 ? "" : doc.URL.split("#")[0]) + "#" + id + ")";
|
12096 | },
|
12097 | appendClip: function (parent, id) {
|
12098 | id && parent.append("clipPath")
|
12099 | .attr("id", id)
|
12100 | .append("rect");
|
12101 | },
|
12102 | |
12103 |
|
12104 |
|
12105 |
|
12106 |
|
12107 | setXAxisClipPath: function (node) {
|
12108 | var $$ = this;
|
12109 | var config = $$.config, _a = $$.state, margin = _a.margin, width = _a.width, height = _a.height;
|
12110 | var isRotated = config.axis_rotated;
|
12111 | var left = Math.max(30, margin.left) - (isRotated ? 0 : 20);
|
12112 | var x = isRotated ? -(1 + left) : -(left - 1);
|
12113 | var y = -Math.max(15, margin.top);
|
12114 | var w = isRotated ? margin.left + 20 : width + 10 + left;
|
12115 |
|
12116 | var h = (isRotated ? (margin.top + height) + 10 : margin.bottom) + 20;
|
12117 | node
|
12118 | .attr("x", x)
|
12119 | .attr("y", y)
|
12120 | .attr("width", w)
|
12121 | .attr("height", h);
|
12122 | },
|
12123 | |
12124 |
|
12125 |
|
12126 |
|
12127 |
|
12128 | setYAxisClipPath: function (node) {
|
12129 | var $$ = this;
|
12130 | var config = $$.config, _a = $$.state, margin = _a.margin, width = _a.width, height = _a.height;
|
12131 | var isRotated = config.axis_rotated;
|
12132 | var left = Math.max(30, margin.left) - (isRotated ? 20 : 0);
|
12133 | var isInner = config.axis_y_inner;
|
12134 | var x = isInner ? -1 : (isRotated ? -(1 + left) : -(left - 1));
|
12135 | var y = -(isRotated ? 20 : margin.top);
|
12136 | var w = (isRotated ? width + 15 + left : margin.left + 20) + (isInner ? 20 : 0);
|
12137 | var h = (isRotated ? margin.bottom : (margin.top + height)) + 10;
|
12138 | node
|
12139 | .attr("x", x)
|
12140 | .attr("y", y)
|
12141 | .attr("width", w)
|
12142 | .attr("height", h);
|
12143 | },
|
12144 | updateXAxisTickClip: function () {
|
12145 | var $$ = this;
|
12146 | var config = $$.config, _a = $$.state, clip = _a.clip, xAxisHeight = _a.xAxisHeight, defs = $$.$el.defs;
|
12147 | var newXAxisHeight = $$.getHorizontalAxisHeight("x");
|
12148 | if (defs && !clip.idXAxisTickTexts) {
|
12149 | var clipId = clip.id + "-xaxisticktexts";
|
12150 | $$.appendClip(defs, clipId);
|
12151 | clip.pathXAxisTickTexts = $$.getClipPath(clip.idXAxisTickTexts);
|
12152 | clip.idXAxisTickTexts = clipId;
|
12153 | }
|
12154 | if (!config.axis_x_tick_multiline &&
|
12155 | $$.getAxisTickRotate("x") &&
|
12156 | newXAxisHeight !== xAxisHeight) {
|
12157 | $$.setXAxisTickClipWidth();
|
12158 | $$.setXAxisTickTextClipPathWidth();
|
12159 | }
|
12160 | $$.state.xAxisHeight = newXAxisHeight;
|
12161 | },
|
12162 | setXAxisTickClipWidth: function () {
|
12163 | var $$ = this;
|
12164 | var config = $$.config, maxTickWidths = $$.state.current.maxTickWidths;
|
12165 | var xAxisTickRotate = $$.getAxisTickRotate("x");
|
12166 | if (!config.axis_x_tick_multiline && xAxisTickRotate) {
|
12167 | var sinRotation = Math.sin(Math.PI / 180 * Math.abs(xAxisTickRotate));
|
12168 | maxTickWidths.x.clipPath = ($$.getHorizontalAxisHeight("x") - 20) / sinRotation;
|
12169 | }
|
12170 | else {
|
12171 | maxTickWidths.x.clipPath = null;
|
12172 | }
|
12173 | },
|
12174 | setXAxisTickTextClipPathWidth: function () {
|
12175 | var $$ = this;
|
12176 | var _a = $$.state, clip = _a.clip, current = _a.current, svg = $$.$el.svg;
|
12177 | if (svg) {
|
12178 | svg.select("#" + clip.idXAxisTickTexts + " rect")
|
12179 | .attr("width", current.maxTickWidths.x.clipPath)
|
12180 | .attr("height", 30);
|
12181 | }
|
12182 | }
|
12183 | };
|
12184 |
|
12185 |
|
12186 |
|
12187 |
|
12188 |
|
12189 |
|
12190 | var getGridTextAnchor = function (d) { return isValue(d.position) || "end"; };
|
12191 | var getGridTextDx = function (d) { return (d.position === "start" ? 4 : (d.position === "middle" ? 0 : -4)); };
|
12192 |
|
12193 |
|
12194 |
|
12195 |
|
12196 |
|
12197 |
|
12198 |
|
12199 |
|
12200 | function getGridTextX(isX, width, height) {
|
12201 | return function (d) {
|
12202 | var x = isX ? 0 : width;
|
12203 | if (d.position === "start") {
|
12204 | x = isX ? -height : 0;
|
12205 | }
|
12206 | else if (d.position === "middle") {
|
12207 | x = (isX ? -height : width) / 2;
|
12208 | }
|
12209 | return x;
|
12210 | };
|
12211 | }
|
12212 |
|
12213 |
|
12214 |
|
12215 |
|
12216 |
|
12217 |
|
12218 | function smoothLines(el, type) {
|
12219 | if (type === "grid") {
|
12220 | el.each(function () {
|
12221 | var g = select(this);
|
12222 | ["x1", "x2", "y1", "y2"]
|
12223 | .forEach(function (v) { return g.attr(v, Math.ceil(+g.attr(v))); });
|
12224 | });
|
12225 | }
|
12226 | }
|
12227 | var grid = {
|
12228 | hasGrid: function () {
|
12229 | var config = this.config;
|
12230 | return ["x", "y"]
|
12231 | .some(function (v) { return config["grid_" + v + "_show"] || config["grid_" + v + "_lines"].length; });
|
12232 | },
|
12233 | initGrid: function () {
|
12234 | var $$ = this;
|
12235 | $$.hasGrid() && $$.initGridLines();
|
12236 | $$.initFocusGrid();
|
12237 | },
|
12238 | initGridLines: function () {
|
12239 | var $$ = this;
|
12240 | var config = $$.config, clip = $$.state.clip, $el = $$.$el;
|
12241 | if (config.grid_x_lines.length || config.grid_y_lines.length) {
|
12242 | $el.gridLines.main = $el.main.insert("g", "." + CLASS.chart + (config.grid_lines_front ? " + *" : ""))
|
12243 | .attr("clip-path", clip.pathGrid)
|
12244 | .attr("class", CLASS.grid + " " + CLASS.gridLines);
|
12245 | $el.gridLines.main.append("g").attr("class", CLASS.xgridLines);
|
12246 | $el.gridLines.main.append("g").attr("class", CLASS.ygridLines);
|
12247 | $el.gridLines.x = selectAll([]);
|
12248 | }
|
12249 | },
|
12250 | updateXGrid: function (withoutUpdate) {
|
12251 | var $$ = this;
|
12252 | var config = $$.config, scale = $$.scale, state = $$.state, _a = $$.$el, main = _a.main, grid = _a.grid;
|
12253 | var isRotated = config.axis_rotated;
|
12254 | var xgridData = $$.generateGridData(config.grid_x_type, scale.x);
|
12255 | var tickOffset = $$.axis.isCategorized() ? $$.axis.x.tickOffset() : 0;
|
12256 | var pos = function (d) { return ((scale.zoom || scale.x)(d) + (tickOffset * (isRotated ? -1 : 1))); };
|
12257 | state.xgridAttr = isRotated ? {
|
12258 | "x1": 0,
|
12259 | "x2": state.width,
|
12260 | "y1": pos,
|
12261 | "y2": pos
|
12262 | } : {
|
12263 | "x1": pos,
|
12264 | "x2": pos,
|
12265 | "y1": 0,
|
12266 | "y2": state.height
|
12267 | };
|
12268 | grid.x = main.select("." + CLASS.xgrids)
|
12269 | .selectAll("." + CLASS.xgrid)
|
12270 | .data(xgridData);
|
12271 | grid.x.exit().remove();
|
12272 | grid.x = grid.x.enter()
|
12273 | .append("line")
|
12274 | .attr("class", CLASS.xgrid)
|
12275 | .merge(grid.x);
|
12276 | if (!withoutUpdate) {
|
12277 | grid.x.each(function () {
|
12278 | var grid = select(this);
|
12279 | Object.keys(state.xgridAttr).forEach(function (id) {
|
12280 | grid.attr(id, state.xgridAttr[id])
|
12281 | .style("opacity", function () { return (grid.attr(isRotated ? "y1" : "x1") === (isRotated ? state.height : 0) ?
|
12282 | "0" : "1"); });
|
12283 | });
|
12284 | });
|
12285 | }
|
12286 | },
|
12287 | updateYGrid: function () {
|
12288 | var $$ = this;
|
12289 | var config = $$.config, state = $$.state, _a = $$.$el, grid = _a.grid, main = _a.main;
|
12290 | var isRotated = config.axis_rotated;
|
12291 | var gridValues = $$.axis.y.tickValues() || $$.scale.y.ticks(config.grid_y_ticks);
|
12292 | var pos = function (d) { return Math.ceil($$.scale.y(d)); };
|
12293 | grid.y = main.select("." + CLASS.ygrids)
|
12294 | .selectAll("." + CLASS.ygrid)
|
12295 | .data(gridValues);
|
12296 | grid.y.exit().remove();
|
12297 | grid.y = grid.y
|
12298 | .enter()
|
12299 | .append("line")
|
12300 | .attr("class", CLASS.ygrid)
|
12301 | .merge(grid.y);
|
12302 | grid.y.attr("x1", isRotated ? pos : 0)
|
12303 | .attr("x2", isRotated ? pos : state.width)
|
12304 | .attr("y1", isRotated ? 0 : pos)
|
12305 | .attr("y2", isRotated ? state.height : pos);
|
12306 | smoothLines(grid.y, "grid");
|
12307 | },
|
12308 | updateGrid: function (duration) {
|
12309 | var $$ = this;
|
12310 | var _a = $$.$el, grid = _a.grid, gridLines = _a.gridLines;
|
12311 | !gridLines.main && $$.initGridLines();
|
12312 |
|
12313 | grid.main.style("visibility", $$.hasArcType() ? "hidden" : "visible");
|
12314 | $$.hideGridFocus();
|
12315 | $$.updateXGridLines(duration);
|
12316 | $$.updateYGridLines(duration);
|
12317 | },
|
12318 | |
12319 |
|
12320 |
|
12321 |
|
12322 |
|
12323 | updateXGridLines: function (duration) {
|
12324 | var $$ = this;
|
12325 | var config = $$.config, _a = $$.$el, gridLines = _a.gridLines, main = _a.main;
|
12326 | var isRotated = config.axis_rotated;
|
12327 | config.grid_x_show && $$.updateXGrid();
|
12328 | var xLines = main.select("." + CLASS.xgridLines)
|
12329 | .selectAll("." + CLASS.xgridLine)
|
12330 | .data(config.grid_x_lines);
|
12331 |
|
12332 | xLines.exit().transition()
|
12333 | .duration(duration)
|
12334 | .style("opacity", "0")
|
12335 | .remove();
|
12336 |
|
12337 | var xgridLine = xLines.enter().append("g");
|
12338 | xgridLine.append("line")
|
12339 | .style("opacity", "0");
|
12340 | xgridLine.append("text")
|
12341 | .attr("transform", isRotated ? "" : "rotate(-90)")
|
12342 | .attr("dy", -5)
|
12343 | .style("opacity", "0");
|
12344 | xLines = xgridLine.merge(xLines);
|
12345 | xLines
|
12346 | .attr("class", function (d) { return (CLASS.xgridLine + " " + (d["class"] || "")).trim(); })
|
12347 | .select("text")
|
12348 | .attr("text-anchor", getGridTextAnchor)
|
12349 | .attr("dx", getGridTextDx)
|
12350 | .transition()
|
12351 | .duration(duration)
|
12352 | .text(function (d) { return d.text; })
|
12353 | .transition()
|
12354 | .style("opacity", "1");
|
12355 | gridLines.x = xLines;
|
12356 | },
|
12357 | |
12358 |
|
12359 |
|
12360 |
|
12361 |
|
12362 | updateYGridLines: function (duration) {
|
12363 | var $$ = this;
|
12364 | var config = $$.config, _a = $$.state, width = _a.width, height = _a.height, $el = $$.$el;
|
12365 | var isRotated = config.axis_rotated;
|
12366 | config.grid_y_show && $$.updateYGrid();
|
12367 | var ygridLines = $el.main.select("." + CLASS.ygridLines)
|
12368 | .selectAll("." + CLASS.ygridLine)
|
12369 | .data(config.grid_y_lines);
|
12370 |
|
12371 | ygridLines.exit()
|
12372 | .transition()
|
12373 | .duration(duration)
|
12374 | .style("opacity", "0")
|
12375 | .remove();
|
12376 |
|
12377 | var ygridLine = ygridLines.enter().append("g");
|
12378 | ygridLine.append("line")
|
12379 | .style("opacity", "0");
|
12380 | ygridLine.append("text")
|
12381 | .attr("transform", isRotated ? "rotate(-90)" : "")
|
12382 | .style("opacity", "0");
|
12383 | ygridLines = ygridLine.merge(ygridLines);
|
12384 |
|
12385 | var yv = $$.yv.bind($$);
|
12386 | ygridLines
|
12387 | .attr("class", function (d) { return (CLASS.ygridLine + " " + (d["class"] || "")).trim(); })
|
12388 | .select("line")
|
12389 | .transition()
|
12390 | .duration(duration)
|
12391 | .attr("x1", isRotated ? yv : 0)
|
12392 | .attr("x2", isRotated ? yv : width)
|
12393 | .attr("y1", isRotated ? 0 : yv)
|
12394 | .attr("y2", isRotated ? height : yv)
|
12395 | .transition()
|
12396 | .style("opacity", "1");
|
12397 | ygridLines.select("text")
|
12398 | .attr("text-anchor", getGridTextAnchor)
|
12399 | .attr("dx", getGridTextDx)
|
12400 | .transition()
|
12401 | .duration(duration)
|
12402 | .attr("dy", -5)
|
12403 | .attr("x", getGridTextX(isRotated, width, height))
|
12404 | .attr("y", yv)
|
12405 | .text(function (d) { return d.text; })
|
12406 | .transition()
|
12407 | .style("opacity", "1");
|
12408 | $el.gridLines.y = ygridLines;
|
12409 | },
|
12410 | redrawGrid: function (withTransition) {
|
12411 | var $$ = this;
|
12412 | var isRotated = $$.config.axis_rotated, _a = $$.state, width = _a.width, height = _a.height, gridLines = $$.$el.gridLines;
|
12413 | var xv = $$.xv.bind($$);
|
12414 | var lines = gridLines.x.select("line");
|
12415 | var texts = gridLines.x.select("text");
|
12416 | lines = (withTransition ? lines.transition() : lines)
|
12417 | .attr("x1", isRotated ? 0 : xv)
|
12418 | .attr("x2", isRotated ? width : xv)
|
12419 | .attr("y1", isRotated ? xv : 0)
|
12420 | .attr("y2", isRotated ? xv : height);
|
12421 | texts = (withTransition ? texts.transition() : texts)
|
12422 | .attr("x", getGridTextX(!isRotated, width, height))
|
12423 | .attr("y", xv)
|
12424 | .text(function (d) { return d.text; });
|
12425 | return [
|
12426 | lines.style("opacity", "1"),
|
12427 | texts.style("opacity", "1")
|
12428 | ];
|
12429 | },
|
12430 | initFocusGrid: function () {
|
12431 | var $$ = this;
|
12432 | var config = $$.config, clip = $$.state.clip, $el = $$.$el;
|
12433 | var isFront = config.grid_front;
|
12434 | var className = "." + CLASS[isFront && $el.gridLines.main ? "gridLines" : "chart"] + (isFront ? " + *" : "");
|
12435 | var grid = $el.main.insert("g", className)
|
12436 | .attr("clip-path", clip.pathGrid)
|
12437 | .attr("class", CLASS.grid);
|
12438 | $el.grid.main = grid;
|
12439 | config.grid_x_show &&
|
12440 | grid.append("g").attr("class", CLASS.xgrids);
|
12441 | config.grid_y_show &&
|
12442 | grid.append("g").attr("class", CLASS.ygrids);
|
12443 | if (config.interaction_enabled && config.grid_focus_show) {
|
12444 | grid.append("g")
|
12445 | .attr("class", CLASS.xgridFocus)
|
12446 | .append("line")
|
12447 | .attr("class", CLASS.xgridFocus);
|
12448 |
|
12449 | if (config.grid_focus_y && !config.tooltip_grouped) {
|
12450 | grid.append("g")
|
12451 | .attr("class", CLASS.ygridFocus)
|
12452 | .append("line")
|
12453 | .attr("class", CLASS.ygridFocus);
|
12454 | }
|
12455 | }
|
12456 | },
|
12457 | |
12458 |
|
12459 |
|
12460 |
|
12461 |
|
12462 | showGridFocus: function (data) {
|
12463 | var $$ = this;
|
12464 | var config = $$.config, _a = $$.state, width = _a.width, height = _a.height;
|
12465 | var isRotated = config.axis_rotated;
|
12466 | var focusEl = $$.$el.main.selectAll("line." + CLASS.xgridFocus + ", line." + CLASS.ygridFocus);
|
12467 | var dataToShow = (data || [focusEl.datum()]).filter(function (d) { return d && isValue($$.getBaseValue(d)); });
|
12468 |
|
12469 | if (!config.tooltip_show || dataToShow.length === 0 || $$.hasType("bubble") || $$.hasArcType()) {
|
12470 | return;
|
12471 | }
|
12472 | var isEdge = config.grid_focus_edge && !config.tooltip_grouped;
|
12473 | var xx = $$.xx.bind($$);
|
12474 | focusEl
|
12475 | .style("visibility", "visible")
|
12476 | .data(dataToShow.concat(dataToShow))
|
12477 | .each(function (d) {
|
12478 | var el = select(this);
|
12479 | var pos = {
|
12480 | x: xx(d),
|
12481 | y: $$.getYScaleById(d.id)(d.value)
|
12482 | };
|
12483 | var xy;
|
12484 | if (el.classed(CLASS.xgridFocus)) {
|
12485 |
|
12486 | xy = isRotated ?
|
12487 | [
|
12488 | null,
|
12489 | pos.x,
|
12490 | isEdge ? pos.y : width,
|
12491 | pos.x
|
12492 | ] : [
|
12493 | pos.x,
|
12494 | isEdge ? pos.y : null,
|
12495 | pos.x,
|
12496 | height
|
12497 | ];
|
12498 | }
|
12499 | else {
|
12500 | var isY2 = $$.axis.getId(d.id) === "y2";
|
12501 | xy = isRotated ?
|
12502 | [
|
12503 | pos.y,
|
12504 | isEdge && !isY2 ? pos.x : null,
|
12505 | pos.y,
|
12506 | isEdge && isY2 ? pos.x : height
|
12507 | ] : [
|
12508 | isEdge && isY2 ? pos.x : null,
|
12509 | pos.y,
|
12510 | isEdge && !isY2 ? pos.x : width,
|
12511 | pos.y
|
12512 | ];
|
12513 | }
|
12514 | ["x1", "y1", "x2", "y2"]
|
12515 | .forEach(function (v, i) { return el.attr(v, xy[i]); });
|
12516 | });
|
12517 | smoothLines(focusEl, "grid");
|
12518 | $$.showCircleFocus && $$.showCircleFocus(data);
|
12519 | },
|
12520 | hideGridFocus: function () {
|
12521 | var $$ = this;
|
12522 | var _a = $$.state, inputType = _a.inputType, resizing = _a.resizing, main = $$.$el.main;
|
12523 | if (inputType === "mouse" || !resizing) {
|
12524 | main.selectAll("line." + CLASS.xgridFocus + ", line." + CLASS.ygridFocus)
|
12525 | .style("visibility", "hidden");
|
12526 | $$.hideCircleFocus && $$.hideCircleFocus();
|
12527 | }
|
12528 | },
|
12529 | updateGridFocus: function () {
|
12530 | var $$ = this;
|
12531 | var _a = $$.state, inputType = _a.inputType, width = _a.width, height = _a.height, resizing = _a.resizing, grid = $$.$el.grid;
|
12532 | var xgridFocus = grid.main.select("line." + CLASS.xgridFocus);
|
12533 | if (inputType === "touch") {
|
12534 | if (xgridFocus.empty()) {
|
12535 | resizing && $$.showCircleFocus();
|
12536 | }
|
12537 | else {
|
12538 | $$.showGridFocus();
|
12539 | }
|
12540 | }
|
12541 | else {
|
12542 | var isRotated = $$.config.axis_rotated;
|
12543 | xgridFocus
|
12544 | .attr("x1", isRotated ? 0 : -10)
|
12545 | .attr("x2", isRotated ? width : -10)
|
12546 | .attr("y1", isRotated ? -10 : 0)
|
12547 | .attr("y2", isRotated ? -10 : height);
|
12548 | }
|
12549 |
|
12550 |
|
12551 | return true;
|
12552 | },
|
12553 | generateGridData: function (type, scale) {
|
12554 | var $$ = this;
|
12555 | var tickNum = $$.$el.main.select("." + CLASS.axisX)
|
12556 | .selectAll(".tick")
|
12557 | .size();
|
12558 | var gridData = [];
|
12559 | if (type === "year") {
|
12560 | var xDomain = $$.getXDomain();
|
12561 | var firstYear = xDomain[0].getFullYear();
|
12562 | var lastYear = xDomain[1].getFullYear();
|
12563 | for (var i = firstYear; i <= lastYear; i++) {
|
12564 | gridData.push(new Date(i + "-01-01 00:00:00"));
|
12565 | }
|
12566 | }
|
12567 | else {
|
12568 | gridData = scale.ticks(10);
|
12569 | if (gridData.length > tickNum) {
|
12570 | gridData = gridData.filter(function (d) { return String(d).indexOf(".") < 0; });
|
12571 | }
|
12572 | }
|
12573 | return gridData;
|
12574 | },
|
12575 | getGridFilterToRemove: function (params) {
|
12576 | return params ? function (line) {
|
12577 | var found = false;
|
12578 | (isArray(params) ? params.concat() : [params]).forEach(function (param) {
|
12579 | if ((("value" in param && line.value === param.value) || ("class" in param && line["class"] === param["class"]))) {
|
12580 | found = true;
|
12581 | }
|
12582 | });
|
12583 | return found;
|
12584 | } : function () { return true; };
|
12585 | },
|
12586 | removeGridLines: function (params, forX) {
|
12587 | var $$ = this;
|
12588 | var config = $$.config;
|
12589 | var toRemove = $$.getGridFilterToRemove(params);
|
12590 | var toShow = function (line) { return !toRemove(line); };
|
12591 | var classLines = forX ? CLASS.xgridLines : CLASS.ygridLines;
|
12592 | var classLine = forX ? CLASS.xgridLine : CLASS.ygridLine;
|
12593 | $$.$el.main.select("." + classLines)
|
12594 | .selectAll("." + classLine)
|
12595 | .filter(toRemove)
|
12596 | .transition()
|
12597 | .duration(config.transition_duration)
|
12598 | .style("opacity", "0")
|
12599 | .remove();
|
12600 | var gridLines = "grid_" + (forX ? "x" : "y") + "_lines";
|
12601 | config[gridLines] = config[gridLines].filter(toShow);
|
12602 | }
|
12603 | };
|
12604 |
|
12605 |
|
12606 |
|
12607 |
|
12608 |
|
12609 | var region = {
|
12610 | initRegion: function () {
|
12611 | var $$ = this;
|
12612 | var $el = $$.$el;
|
12613 | $el.region.main = $el.main.append("g")
|
12614 | .attr("clip-path", $$.state.clip.path)
|
12615 | .attr("class", CLASS.regions);
|
12616 | },
|
12617 | updateRegion: function (duration) {
|
12618 | var $$ = this;
|
12619 | var config = $$.config, $el = $$.$el;
|
12620 | if (!$el.region.main) {
|
12621 | $$.initRegion();
|
12622 | }
|
12623 |
|
12624 | $el.region.main.style("visibility", $$.hasArcType() ? "hidden" : "visible");
|
12625 |
|
12626 | var list = $el.main.select("." + CLASS.regions)
|
12627 | .selectAll("." + CLASS.region)
|
12628 | .data(config.regions);
|
12629 | list.exit()
|
12630 | .transition()
|
12631 | .duration(duration)
|
12632 | .style("opacity", "0")
|
12633 | .remove();
|
12634 | list = list.enter()
|
12635 | .append("g")
|
12636 | .merge(list)
|
12637 | .attr("class", $$.classRegion.bind($$));
|
12638 | list
|
12639 | .append("rect")
|
12640 | .style("fill-opacity", "0");
|
12641 | $el.region.list = list;
|
12642 | },
|
12643 | redrawRegion: function (withTransition) {
|
12644 | var $$ = this;
|
12645 | var regions = $$.$el.region.list.select("rect");
|
12646 | regions = (withTransition ? regions.transition() : regions)
|
12647 | .attr("x", $$.regionX.bind($$))
|
12648 | .attr("y", $$.regionY.bind($$))
|
12649 | .attr("width", $$.regionWidth.bind($$))
|
12650 | .attr("height", $$.regionHeight.bind($$));
|
12651 | return [
|
12652 | (withTransition ? regions.transition() : regions)
|
12653 | .style("fill-opacity", function (d) { return (isValue(d.opacity) ? d.opacity : "0.1"); })
|
12654 | .on("end", function () {
|
12655 |
|
12656 | select(this.parentNode)
|
12657 | .selectAll("rect:not([x])")
|
12658 | .remove();
|
12659 | })
|
12660 | ];
|
12661 | },
|
12662 | getRegionXY: function (type, d) {
|
12663 | var $$ = this;
|
12664 | var config = $$.config, scale = $$.scale;
|
12665 | var isRotated = config.axis_rotated;
|
12666 | var isX = type === "x";
|
12667 | var key = "start";
|
12668 | var currScale;
|
12669 | var pos = 0;
|
12670 | if (d.axis === "y" || d.axis === "y2") {
|
12671 | if (!isX) {
|
12672 | key = "end";
|
12673 | }
|
12674 | if ((isX ? isRotated : !isRotated) && key in d) {
|
12675 | currScale = scale[d.axis];
|
12676 | pos = currScale(d[key]);
|
12677 | }
|
12678 | }
|
12679 | else if ((isX ? !isRotated : isRotated) && key in d) {
|
12680 | currScale = scale.zoom || scale.x;
|
12681 | pos = currScale($$.axis.isTimeSeries() ? parseDate.call($$, d[key]) : d[key]);
|
12682 | }
|
12683 | return pos;
|
12684 | },
|
12685 | regionX: function (d) {
|
12686 | return this.getRegionXY("x", d);
|
12687 | },
|
12688 | regionY: function (d) {
|
12689 | return this.getRegionXY("y", d);
|
12690 | },
|
12691 | getRegionSize: function (type, d) {
|
12692 | var $$ = this;
|
12693 | var config = $$.config, scale = $$.scale, state = $$.state;
|
12694 | var isRotated = config.axis_rotated;
|
12695 | var isWidth = type === "width";
|
12696 | var start = $$[isWidth ? "regionX" : "regionY"](d);
|
12697 | var currScale;
|
12698 | var key = "end";
|
12699 | var end = state[type];
|
12700 | if (d.axis === "y" || d.axis === "y2") {
|
12701 | if (!isWidth) {
|
12702 | key = "start";
|
12703 | }
|
12704 | if ((isWidth ? isRotated : !isRotated) && key in d) {
|
12705 | currScale = scale[d.axis];
|
12706 | end = currScale(d[key]);
|
12707 | }
|
12708 | }
|
12709 | else if ((isWidth ? !isRotated : isRotated) && key in d) {
|
12710 | currScale = scale.zoom || scale.x;
|
12711 | end = currScale($$.axis.isTimeSeries() ? parseDate.call($$, d[key]) : d[key]);
|
12712 | }
|
12713 | return end < start ? 0 : end - start;
|
12714 | },
|
12715 | regionWidth: function (d) {
|
12716 | return this.getRegionSize("width", d);
|
12717 | },
|
12718 | regionHeight: function (d) {
|
12719 | return this.getRegionSize("height", d);
|
12720 | },
|
12721 | isRegionOnX: function (d) {
|
12722 | return !d.axis || d.axis === "x";
|
12723 | }
|
12724 | };
|
12725 |
|
12726 | var sizeAxis = {
|
12727 | |
12728 |
|
12729 |
|
12730 |
|
12731 |
|
12732 |
|
12733 | getAxisSize: function (id) {
|
12734 | var $$ = this;
|
12735 | var isRotated = $$.config.axis_rotated;
|
12736 | return (isRotated && id === "x") || (!isRotated && /y2?/.test(id)) ?
|
12737 | $$.getAxisWidthByAxisId(id, true) :
|
12738 | $$.getHorizontalAxisHeight(id);
|
12739 | },
|
12740 | getAxisWidthByAxisId: function (id, withoutRecompute) {
|
12741 | var $$ = this;
|
12742 | if ($$.axis) {
|
12743 | var position = $$.axis && $$.axis.getLabelPositionById(id);
|
12744 | return $$.axis.getMaxTickWidth(id, withoutRecompute) +
|
12745 | (position.isInner ? 20 : 40);
|
12746 | }
|
12747 | else {
|
12748 | return 40;
|
12749 | }
|
12750 | },
|
12751 | getHorizontalAxisHeight: function (id) {
|
12752 | var $$ = this;
|
12753 | var config = $$.config, state = $$.state;
|
12754 | var current = state.current, rotatedPadding = state.rotatedPadding, isLegendRight = state.isLegendRight, isLegendInset = state.isLegendInset;
|
12755 | var isRotated = config.axis_rotated;
|
12756 | var h = 30;
|
12757 | if (id === "x" && !config.axis_x_show) {
|
12758 | return 8;
|
12759 | }
|
12760 | if (id === "x" && config.axis_x_height) {
|
12761 | return config.axis_x_height;
|
12762 | }
|
12763 | if (id === "y" && !config.axis_y_show) {
|
12764 | return config.legend_show &&
|
12765 | !isLegendRight &&
|
12766 | !isLegendInset ? 10 : 1;
|
12767 | }
|
12768 | if (id === "y2" && !config.axis_y2_show) {
|
12769 | return rotatedPadding.top;
|
12770 | }
|
12771 | var rotate = $$.getAxisTickRotate(id);
|
12772 |
|
12773 | if (((id === "x" && !isRotated) || (/y2?/.test(id) && isRotated)) && rotate) {
|
12774 | h = 30 +
|
12775 | $$.axis.getMaxTickWidth(id) *
|
12776 | Math.cos(Math.PI * (90 - Math.abs(rotate)) / 180);
|
12777 | if (!config.axis_x_tick_multiline && current.height) {
|
12778 | if (h > current.height / 2) {
|
12779 | h = current.height / 2;
|
12780 | }
|
12781 | }
|
12782 | }
|
12783 | return h +
|
12784 | ($$.axis.getLabelPositionById(id).isInner ? 0 : 10) +
|
12785 | (id === "y2" && !isRotated ? -10 : 0);
|
12786 | },
|
12787 | getEventRectWidth: function () {
|
12788 | return Math.max(0, this.axis.x.tickInterval());
|
12789 | },
|
12790 | |
12791 |
|
12792 |
|
12793 |
|
12794 |
|
12795 |
|
12796 | getAxisTickRotate: function (id) {
|
12797 | var $$ = this;
|
12798 | var axis = $$.axis, config = $$.config, state = $$.state, $el = $$.$el;
|
12799 | var rotate = config["axis_" + id + "_tick_rotate"];
|
12800 | if (id === "x") {
|
12801 | var allowedXAxisTypes = axis.isCategorized() || axis.isTimeSeries();
|
12802 | if (config.axis_x_tick_fit && allowedXAxisTypes) {
|
12803 | var xTickCount = config.axis_x_tick_count;
|
12804 | var currentXTicksLength = state.current.maxTickWidths.x.ticks.length;
|
12805 | var tickCount = 0;
|
12806 | if (xTickCount) {
|
12807 | tickCount = xTickCount > currentXTicksLength ? currentXTicksLength : xTickCount;
|
12808 | }
|
12809 | else if (currentXTicksLength) {
|
12810 | tickCount = currentXTicksLength;
|
12811 | }
|
12812 | if (tickCount !== state.axis.x.tickCount) {
|
12813 | state.axis.x.padding = $$.axis.getXAxisPadding(tickCount);
|
12814 | }
|
12815 | state.axis.x.tickCount = tickCount;
|
12816 | }
|
12817 | if ($el.svg &&
|
12818 | config.axis_x_tick_fit &&
|
12819 | !config.axis_x_tick_multiline &&
|
12820 | !config.axis_x_tick_culling &&
|
12821 | config.axis_x_tick_autorotate &&
|
12822 | allowedXAxisTypes) {
|
12823 | rotate = $$.needToRotateXAxisTickTexts() ?
|
12824 | config.axis_x_tick_rotate : 0;
|
12825 | }
|
12826 | }
|
12827 | return rotate;
|
12828 | },
|
12829 | |
12830 |
|
12831 |
|
12832 |
|
12833 |
|
12834 | needToRotateXAxisTickTexts: function () {
|
12835 | var $$ = this;
|
12836 | var _a = $$.state, axis = _a.axis, current = _a.current;
|
12837 | var xAxisLength = current.width -
|
12838 | $$.getCurrentPaddingLeft(false) - $$.getCurrentPaddingRight();
|
12839 | var tickCountWithPadding = axis.x.tickCount +
|
12840 | axis.x.padding.left + axis.x.padding.right;
|
12841 | var maxTickWidth = $$.axis.getMaxTickWidth("x");
|
12842 | var tickLength = tickCountWithPadding ? xAxisLength / tickCountWithPadding : 0;
|
12843 | return maxTickWidth > tickLength;
|
12844 | }
|
12845 | };
|
12846 |
|
12847 |
|
12848 |
|
12849 |
|
12850 |
|
12851 |
|
12852 |
|
12853 |
|
12854 | var optDataAxis = {
|
12855 | |
12856 |
|
12857 |
|
12858 |
|
12859 |
|
12860 |
|
12861 |
|
12862 |
|
12863 |
|
12864 |
|
12865 |
|
12866 |
|
12867 |
|
12868 |
|
12869 |
|
12870 | data_xs: {},
|
12871 | |
12872 |
|
12873 |
|
12874 |
|
12875 |
|
12876 |
|
12877 |
|
12878 |
|
12879 |
|
12880 |
|
12881 |
|
12882 |
|
12883 |
|
12884 |
|
12885 |
|
12886 |
|
12887 |
|
12888 |
|
12889 |
|
12890 |
|
12891 |
|
12892 |
|
12893 |
|
12894 | data_xFormat: "%Y-%m-%d",
|
12895 | |
12896 |
|
12897 |
|
12898 |
|
12899 |
|
12900 |
|
12901 |
|
12902 |
|
12903 |
|
12904 |
|
12905 |
|
12906 | data_xLocaltime: true,
|
12907 | |
12908 |
|
12909 |
|
12910 |
|
12911 |
|
12912 |
|
12913 |
|
12914 |
|
12915 |
|
12916 |
|
12917 |
|
12918 | data_xSort: true,
|
12919 | |
12920 |
|
12921 |
|
12922 |
|
12923 |
|
12924 |
|
12925 |
|
12926 |
|
12927 |
|
12928 |
|
12929 |
|
12930 |
|
12931 |
|
12932 |
|
12933 |
|
12934 | data_axes: {},
|
12935 | |
12936 |
|
12937 |
|
12938 |
|
12939 |
|
12940 |
|
12941 |
|
12942 |
|
12943 |
|
12944 |
|
12945 |
|
12946 |
|
12947 |
|
12948 |
|
12949 |
|
12950 |
|
12951 |
|
12952 |
|
12953 |
|
12954 |
|
12955 |
|
12956 |
|
12957 |
|
12958 |
|
12959 |
|
12960 |
|
12961 |
|
12962 |
|
12963 | data_regions: {},
|
12964 | |
12965 |
|
12966 |
|
12967 |
|
12968 |
|
12969 |
|
12970 |
|
12971 |
|
12972 |
|
12973 |
|
12974 |
|
12975 |
|
12976 |
|
12977 |
|
12978 |
|
12979 |
|
12980 |
|
12981 |
|
12982 | data_stack_normalize: false
|
12983 | };
|
12984 |
|
12985 |
|
12986 |
|
12987 |
|
12988 |
|
12989 |
|
12990 |
|
12991 |
|
12992 | var x = {
|
12993 | |
12994 |
|
12995 |
|
12996 |
|
12997 |
|
12998 |
|
12999 |
|
13000 |
|
13001 |
|
13002 |
|
13003 |
|
13004 | axis_x_clipPath: true,
|
13005 | |
13006 |
|
13007 |
|
13008 |
|
13009 |
|
13010 |
|
13011 |
|
13012 |
|
13013 |
|
13014 |
|
13015 |
|
13016 |
|
13017 |
|
13018 | axis_x_show: true,
|
13019 | |
13020 |
|
13021 |
|
13022 |
|
13023 |
|
13024 |
|
13025 |
|
13026 |
|
13027 |
|
13028 |
|
13029 |
|
13030 |
|
13031 |
|
13032 |
|
13033 |
|
13034 |
|
13035 |
|
13036 |
|
13037 |
|
13038 |
|
13039 |
|
13040 |
|
13041 |
|
13042 |
|
13043 |
|
13044 |
|
13045 |
|
13046 |
|
13047 | axis_x_type: "indexed",
|
13048 | |
13049 |
|
13050 |
|
13051 |
|
13052 |
|
13053 |
|
13054 |
|
13055 |
|
13056 |
|
13057 |
|
13058 |
|
13059 |
|
13060 |
|
13061 |
|
13062 | axis_x_localtime: true,
|
13063 | |
13064 |
|
13065 |
|
13066 |
|
13067 |
|
13068 |
|
13069 |
|
13070 |
|
13071 |
|
13072 |
|
13073 |
|
13074 |
|
13075 |
|
13076 |
|
13077 | axis_x_categories: [],
|
13078 | |
13079 |
|
13080 |
|
13081 |
|
13082 |
|
13083 |
|
13084 |
|
13085 |
|
13086 |
|
13087 |
|
13088 |
|
13089 |
|
13090 |
|
13091 |
|
13092 |
|
13093 | axis_x_tick_centered: false,
|
13094 | |
13095 |
|
13096 |
|
13097 |
|
13098 |
|
13099 |
|
13100 |
|
13101 |
|
13102 |
|
13103 |
|
13104 |
|
13105 |
|
13106 |
|
13107 |
|
13108 |
|
13109 |
|
13110 |
|
13111 |
|
13112 |
|
13113 |
|
13114 |
|
13115 |
|
13116 |
|
13117 |
|
13118 |
|
13119 |
|
13120 |
|
13121 | axis_x_tick_format: undefined,
|
13122 | |
13123 |
|
13124 |
|
13125 |
|
13126 |
|
13127 |
|
13128 |
|
13129 |
|
13130 |
|
13131 |
|
13132 |
|
13133 |
|
13134 |
|
13135 |
|
13136 |
|
13137 |
|
13138 |
|
13139 |
|
13140 |
|
13141 | axis_x_tick_culling: {},
|
13142 | |
13143 |
|
13144 |
|
13145 |
|
13146 |
|
13147 |
|
13148 |
|
13149 |
|
13150 |
|
13151 |
|
13152 |
|
13153 |
|
13154 |
|
13155 |
|
13156 |
|
13157 |
|
13158 |
|
13159 | axis_x_tick_culling_max: 10,
|
13160 | |
13161 |
|
13162 |
|
13163 |
|
13164 |
|
13165 |
|
13166 |
|
13167 |
|
13168 |
|
13169 |
|
13170 |
|
13171 |
|
13172 |
|
13173 |
|
13174 |
|
13175 |
|
13176 | axis_x_tick_count: undefined,
|
13177 | |
13178 |
|
13179 |
|
13180 |
|
13181 |
|
13182 |
|
13183 |
|
13184 |
|
13185 |
|
13186 |
|
13187 |
|
13188 |
|
13189 |
|
13190 |
|
13191 |
|
13192 |
|
13193 | axis_x_tick_show: true,
|
13194 | |
13195 |
|
13196 |
|
13197 |
|
13198 |
|
13199 |
|
13200 |
|
13201 |
|
13202 |
|
13203 |
|
13204 |
|
13205 |
|
13206 |
|
13207 |
|
13208 |
|
13209 |
|
13210 |
|
13211 |
|
13212 | axis_x_tick_text_show: true,
|
13213 | |
13214 |
|
13215 |
|
13216 |
|
13217 |
|
13218 |
|
13219 |
|
13220 |
|
13221 |
|
13222 |
|
13223 |
|
13224 |
|
13225 |
|
13226 |
|
13227 |
|
13228 |
|
13229 |
|
13230 |
|
13231 |
|
13232 |
|
13233 | axis_x_tick_text_position: { x: 0, y: 0 },
|
13234 | |
13235 |
|
13236 |
|
13237 |
|
13238 |
|
13239 |
|
13240 |
|
13241 |
|
13242 |
|
13243 |
|
13244 |
|
13245 |
|
13246 |
|
13247 |
|
13248 |
|
13249 |
|
13250 |
|
13251 |
|
13252 |
|
13253 | axis_x_tick_fit: true,
|
13254 | |
13255 |
|
13256 |
|
13257 |
|
13258 |
|
13259 |
|
13260 |
|
13261 |
|
13262 |
|
13263 |
|
13264 |
|
13265 |
|
13266 |
|
13267 |
|
13268 |
|
13269 |
|
13270 |
|
13271 |
|
13272 |
|
13273 |
|
13274 |
|
13275 |
|
13276 | axis_x_tick_values: null,
|
13277 | |
13278 |
|
13279 |
|
13280 |
|
13281 |
|
13282 |
|
13283 |
|
13284 |
|
13285 |
|
13286 |
|
13287 |
|
13288 |
|
13289 |
|
13290 |
|
13291 |
|
13292 |
|
13293 |
|
13294 |
|
13295 |
|
13296 |
|
13297 |
|
13298 |
|
13299 |
|
13300 |
|
13301 |
|
13302 |
|
13303 |
|
13304 | axis_x_tick_autorotate: false,
|
13305 | |
13306 |
|
13307 |
|
13308 |
|
13309 |
|
13310 |
|
13311 |
|
13312 |
|
13313 |
|
13314 |
|
13315 |
|
13316 |
|
13317 |
|
13318 |
|
13319 |
|
13320 |
|
13321 |
|
13322 |
|
13323 |
|
13324 | axis_x_tick_rotate: 0,
|
13325 | |
13326 |
|
13327 |
|
13328 |
|
13329 |
|
13330 |
|
13331 |
|
13332 |
|
13333 |
|
13334 |
|
13335 |
|
13336 |
|
13337 |
|
13338 |
|
13339 |
|
13340 | axis_x_tick_outer: true,
|
13341 | |
13342 |
|
13343 |
|
13344 |
|
13345 |
|
13346 |
|
13347 |
|
13348 |
|
13349 |
|
13350 |
|
13351 |
|
13352 |
|
13353 |
|
13354 |
|
13355 |
|
13356 |
|
13357 |
|
13358 |
|
13359 |
|
13360 |
|
13361 |
|
13362 |
|
13363 |
|
13364 |
|
13365 |
|
13366 |
|
13367 |
|
13368 |
|
13369 | axis_x_tick_multiline: true,
|
13370 | |
13371 |
|
13372 |
|
13373 |
|
13374 |
|
13375 |
|
13376 |
|
13377 |
|
13378 |
|
13379 |
|
13380 |
|
13381 |
|
13382 |
|
13383 |
|
13384 |
|
13385 |
|
13386 |
|
13387 | axis_x_tick_width: null,
|
13388 | |
13389 |
|
13390 |
|
13391 |
|
13392 |
|
13393 |
|
13394 |
|
13395 |
|
13396 |
|
13397 |
|
13398 |
|
13399 |
|
13400 |
|
13401 |
|
13402 |
|
13403 |
|
13404 | axis_x_tick_tooltip: false,
|
13405 | |
13406 |
|
13407 |
|
13408 |
|
13409 |
|
13410 |
|
13411 |
|
13412 |
|
13413 |
|
13414 |
|
13415 |
|
13416 |
|
13417 |
|
13418 |
|
13419 |
|
13420 |
|
13421 |
|
13422 |
|
13423 |
|
13424 |
|
13425 |
|
13426 |
|
13427 |
|
13428 | axis_x_max: undefined,
|
13429 | |
13430 |
|
13431 |
|
13432 |
|
13433 |
|
13434 |
|
13435 |
|
13436 |
|
13437 |
|
13438 |
|
13439 |
|
13440 |
|
13441 |
|
13442 |
|
13443 |
|
13444 |
|
13445 |
|
13446 |
|
13447 |
|
13448 |
|
13449 |
|
13450 |
|
13451 |
|
13452 | axis_x_min: undefined,
|
13453 | |
13454 |
|
13455 |
|
13456 |
|
13457 |
|
13458 |
|
13459 |
|
13460 |
|
13461 |
|
13462 |
|
13463 |
|
13464 |
|
13465 |
|
13466 |
|
13467 |
|
13468 |
|
13469 |
|
13470 |
|
13471 |
|
13472 |
|
13473 |
|
13474 |
|
13475 |
|
13476 |
|
13477 |
|
13478 |
|
13479 |
|
13480 |
|
13481 |
|
13482 |
|
13483 |
|
13484 |
|
13485 | axis_x_padding: {},
|
13486 | |
13487 |
|
13488 |
|
13489 |
|
13490 |
|
13491 |
|
13492 |
|
13493 |
|
13494 |
|
13495 |
|
13496 |
|
13497 |
|
13498 |
|
13499 |
|
13500 | axis_x_height: undefined,
|
13501 | |
13502 |
|
13503 |
|
13504 |
|
13505 |
|
13506 |
|
13507 |
|
13508 |
|
13509 |
|
13510 |
|
13511 |
|
13512 |
|
13513 |
|
13514 |
|
13515 |
|
13516 |
|
13517 |
|
13518 |
|
13519 |
|
13520 |
|
13521 |
|
13522 |
|
13523 |
|
13524 |
|
13525 |
|
13526 |
|
13527 |
|
13528 |
|
13529 | axis_x_extent: undefined,
|
13530 | |
13531 |
|
13532 |
|
13533 |
|
13534 |
|
13535 |
|
13536 |
|
13537 |
|
13538 |
|
13539 |
|
13540 |
|
13541 |
|
13542 |
|
13543 |
|
13544 |
|
13545 |
|
13546 |
|
13547 |
|
13548 |
|
13549 |
|
13550 |
|
13551 |
|
13552 |
|
13553 |
|
13554 |
|
13555 |
|
13556 |
|
13557 |
|
13558 |
|
13559 |
|
13560 |
|
13561 |
|
13562 |
|
13563 |
|
13564 |
|
13565 |
|
13566 |
|
13567 |
|
13568 |
|
13569 |
|
13570 |
|
13571 | axis_x_label: {},
|
13572 | |
13573 |
|
13574 |
|
13575 |
|
13576 |
|
13577 |
|
13578 |
|
13579 |
|
13580 |
|
13581 |
|
13582 |
|
13583 |
|
13584 |
|
13585 |
|
13586 |
|
13587 |
|
13588 |
|
13589 |
|
13590 |
|
13591 |
|
13592 |
|
13593 |
|
13594 |
|
13595 |
|
13596 |
|
13597 |
|
13598 |
|
13599 |
|
13600 |
|
13601 |
|
13602 |
|
13603 |
|
13604 |
|
13605 |
|
13606 |
|
13607 |
|
13608 |
|
13609 | axis_x_axes: []
|
13610 | };
|
13611 |
|
13612 |
|
13613 |
|
13614 |
|
13615 |
|
13616 |
|
13617 |
|
13618 |
|
13619 | var y = {
|
13620 | |
13621 |
|
13622 |
|
13623 |
|
13624 |
|
13625 |
|
13626 |
|
13627 |
|
13628 |
|
13629 |
|
13630 |
|
13631 | axis_y_clipPath: true,
|
13632 | |
13633 |
|
13634 |
|
13635 |
|
13636 |
|
13637 |
|
13638 |
|
13639 |
|
13640 |
|
13641 |
|
13642 |
|
13643 |
|
13644 |
|
13645 | axis_y_show: true,
|
13646 | |
13647 |
|
13648 |
|
13649 |
|
13650 |
|
13651 |
|
13652 |
|
13653 |
|
13654 |
|
13655 |
|
13656 |
|
13657 |
|
13658 |
|
13659 |
|
13660 |
|
13661 |
|
13662 |
|
13663 |
|
13664 |
|
13665 |
|
13666 |
|
13667 |
|
13668 |
|
13669 |
|
13670 |
|
13671 | axis_y_type: "indexed",
|
13672 | |
13673 |
|
13674 |
|
13675 |
|
13676 |
|
13677 |
|
13678 |
|
13679 |
|
13680 |
|
13681 |
|
13682 |
|
13683 |
|
13684 |
|
13685 |
|
13686 | axis_y_max: undefined,
|
13687 | |
13688 |
|
13689 |
|
13690 |
|
13691 |
|
13692 |
|
13693 |
|
13694 |
|
13695 |
|
13696 |
|
13697 |
|
13698 |
|
13699 |
|
13700 |
|
13701 |
|
13702 | axis_y_min: undefined,
|
13703 | |
13704 |
|
13705 |
|
13706 |
|
13707 |
|
13708 |
|
13709 |
|
13710 |
|
13711 |
|
13712 |
|
13713 |
|
13714 |
|
13715 |
|
13716 |
|
13717 | axis_y_inverted: false,
|
13718 | |
13719 |
|
13720 |
|
13721 |
|
13722 |
|
13723 |
|
13724 |
|
13725 |
|
13726 |
|
13727 |
|
13728 |
|
13729 |
|
13730 |
|
13731 | axis_y_center: undefined,
|
13732 | |
13733 |
|
13734 |
|
13735 |
|
13736 |
|
13737 |
|
13738 |
|
13739 |
|
13740 |
|
13741 |
|
13742 |
|
13743 |
|
13744 |
|
13745 | axis_y_inner: false,
|
13746 | |
13747 |
|
13748 |
|
13749 |
|
13750 |
|
13751 |
|
13752 |
|
13753 |
|
13754 |
|
13755 |
|
13756 |
|
13757 |
|
13758 |
|
13759 |
|
13760 |
|
13761 |
|
13762 |
|
13763 |
|
13764 |
|
13765 |
|
13766 |
|
13767 |
|
13768 |
|
13769 |
|
13770 | axis_y_label: {},
|
13771 | |
13772 |
|
13773 |
|
13774 |
|
13775 |
|
13776 |
|
13777 |
|
13778 |
|
13779 |
|
13780 |
|
13781 |
|
13782 |
|
13783 |
|
13784 |
|
13785 |
|
13786 |
|
13787 |
|
13788 |
|
13789 | axis_y_tick_format: undefined,
|
13790 | |
13791 |
|
13792 |
|
13793 |
|
13794 |
|
13795 |
|
13796 |
|
13797 |
|
13798 |
|
13799 |
|
13800 |
|
13801 |
|
13802 |
|
13803 |
|
13804 |
|
13805 |
|
13806 |
|
13807 | axis_y_tick_culling: false,
|
13808 | |
13809 |
|
13810 |
|
13811 |
|
13812 |
|
13813 |
|
13814 |
|
13815 |
|
13816 |
|
13817 |
|
13818 |
|
13819 |
|
13820 |
|
13821 |
|
13822 |
|
13823 |
|
13824 |
|
13825 | axis_y_tick_culling_max: 5,
|
13826 | |
13827 |
|
13828 |
|
13829 |
|
13830 |
|
13831 |
|
13832 |
|
13833 |
|
13834 |
|
13835 |
|
13836 |
|
13837 |
|
13838 |
|
13839 |
|
13840 |
|
13841 | axis_y_tick_outer: true,
|
13842 | |
13843 |
|
13844 |
|
13845 |
|
13846 |
|
13847 |
|
13848 |
|
13849 |
|
13850 |
|
13851 |
|
13852 |
|
13853 |
|
13854 |
|
13855 |
|
13856 |
|
13857 |
|
13858 |
|
13859 |
|
13860 |
|
13861 |
|
13862 | axis_y_tick_values: null,
|
13863 | |
13864 |
|
13865 |
|
13866 |
|
13867 |
|
13868 |
|
13869 |
|
13870 |
|
13871 |
|
13872 |
|
13873 |
|
13874 |
|
13875 |
|
13876 |
|
13877 |
|
13878 |
|
13879 |
|
13880 | axis_y_tick_rotate: 0,
|
13881 | |
13882 |
|
13883 |
|
13884 |
|
13885 |
|
13886 |
|
13887 |
|
13888 |
|
13889 |
|
13890 |
|
13891 |
|
13892 |
|
13893 |
|
13894 |
|
13895 |
|
13896 |
|
13897 | axis_y_tick_count: undefined,
|
13898 | |
13899 |
|
13900 |
|
13901 |
|
13902 |
|
13903 |
|
13904 |
|
13905 |
|
13906 |
|
13907 |
|
13908 |
|
13909 |
|
13910 |
|
13911 |
|
13912 |
|
13913 |
|
13914 | axis_y_tick_show: true,
|
13915 | |
13916 |
|
13917 |
|
13918 |
|
13919 |
|
13920 |
|
13921 |
|
13922 |
|
13923 |
|
13924 |
|
13925 |
|
13926 |
|
13927 |
|
13928 |
|
13929 |
|
13930 |
|
13931 |
|
13932 |
|
13933 | axis_y_tick_stepSize: null,
|
13934 | |
13935 |
|
13936 |
|
13937 |
|
13938 |
|
13939 |
|
13940 |
|
13941 |
|
13942 |
|
13943 |
|
13944 |
|
13945 |
|
13946 |
|
13947 |
|
13948 |
|
13949 |
|
13950 |
|
13951 |
|
13952 | axis_y_tick_text_show: true,
|
13953 | |
13954 |
|
13955 |
|
13956 |
|
13957 |
|
13958 |
|
13959 |
|
13960 |
|
13961 |
|
13962 |
|
13963 |
|
13964 |
|
13965 |
|
13966 |
|
13967 |
|
13968 |
|
13969 |
|
13970 |
|
13971 |
|
13972 |
|
13973 | axis_y_tick_text_position: { x: 0, y: 0 },
|
13974 | |
13975 |
|
13976 |
|
13977 |
|
13978 |
|
13979 |
|
13980 |
|
13981 |
|
13982 |
|
13983 |
|
13984 |
|
13985 |
|
13986 |
|
13987 |
|
13988 |
|
13989 |
|
13990 |
|
13991 |
|
13992 |
|
13993 |
|
13994 |
|
13995 |
|
13996 |
|
13997 | axis_y_tick_time_value: undefined,
|
13998 | |
13999 |
|
14000 |
|
14001 |
|
14002 |
|
14003 |
|
14004 |
|
14005 |
|
14006 |
|
14007 |
|
14008 |
|
14009 |
|
14010 |
|
14011 |
|
14012 |
|
14013 |
|
14014 |
|
14015 |
|
14016 |
|
14017 |
|
14018 |
|
14019 |
|
14020 |
|
14021 |
|
14022 |
|
14023 | axis_y_padding: {},
|
14024 | |
14025 |
|
14026 |
|
14027 |
|
14028 |
|
14029 |
|
14030 |
|
14031 |
|
14032 |
|
14033 |
|
14034 |
|
14035 |
|
14036 |
|
14037 |
|
14038 | axis_y_default: undefined,
|
14039 | |
14040 |
|
14041 |
|
14042 |
|
14043 |
|
14044 |
|
14045 |
|
14046 |
|
14047 |
|
14048 |
|
14049 |
|
14050 |
|
14051 |
|
14052 |
|
14053 |
|
14054 |
|
14055 |
|
14056 |
|
14057 |
|
14058 |
|
14059 |
|
14060 |
|
14061 |
|
14062 |
|
14063 |
|
14064 |
|
14065 |
|
14066 |
|
14067 |
|
14068 |
|
14069 |
|
14070 |
|
14071 |
|
14072 |
|
14073 |
|
14074 |
|
14075 |
|
14076 | axis_y_axes: []
|
14077 | };
|
14078 |
|
14079 |
|
14080 |
|
14081 |
|
14082 |
|
14083 |
|
14084 |
|
14085 |
|
14086 | var y2 = {
|
14087 | |
14088 |
|
14089 |
|
14090 |
|
14091 |
|
14092 |
|
14093 |
|
14094 |
|
14095 |
|
14096 |
|
14097 |
|
14098 |
|
14099 |
|
14100 |
|
14101 |
|
14102 |
|
14103 | axis_y2_show: false,
|
14104 | |
14105 |
|
14106 |
|
14107 |
|
14108 |
|
14109 |
|
14110 |
|
14111 |
|
14112 |
|
14113 |
|
14114 |
|
14115 |
|
14116 |
|
14117 |
|
14118 |
|
14119 |
|
14120 |
|
14121 |
|
14122 |
|
14123 |
|
14124 |
|
14125 |
|
14126 |
|
14127 |
|
14128 |
|
14129 | axis_y2_type: "indexed",
|
14130 | |
14131 |
|
14132 |
|
14133 |
|
14134 |
|
14135 |
|
14136 |
|
14137 |
|
14138 |
|
14139 |
|
14140 |
|
14141 |
|
14142 |
|
14143 | axis_y2_max: undefined,
|
14144 | |
14145 |
|
14146 |
|
14147 |
|
14148 |
|
14149 |
|
14150 |
|
14151 |
|
14152 |
|
14153 |
|
14154 |
|
14155 |
|
14156 |
|
14157 | axis_y2_min: undefined,
|
14158 | |
14159 |
|
14160 |
|
14161 |
|
14162 |
|
14163 |
|
14164 |
|
14165 |
|
14166 |
|
14167 |
|
14168 |
|
14169 |
|
14170 |
|
14171 |
|
14172 | axis_y2_inverted: false,
|
14173 | |
14174 |
|
14175 |
|
14176 |
|
14177 |
|
14178 |
|
14179 |
|
14180 |
|
14181 |
|
14182 |
|
14183 |
|
14184 |
|
14185 |
|
14186 | axis_y2_center: undefined,
|
14187 | |
14188 |
|
14189 |
|
14190 |
|
14191 |
|
14192 |
|
14193 |
|
14194 |
|
14195 |
|
14196 |
|
14197 |
|
14198 |
|
14199 |
|
14200 | axis_y2_inner: false,
|
14201 | |
14202 |
|
14203 |
|
14204 |
|
14205 |
|
14206 |
|
14207 |
|
14208 |
|
14209 |
|
14210 |
|
14211 |
|
14212 |
|
14213 |
|
14214 |
|
14215 |
|
14216 |
|
14217 |
|
14218 |
|
14219 |
|
14220 |
|
14221 |
|
14222 |
|
14223 |
|
14224 |
|
14225 | axis_y2_label: {},
|
14226 | |
14227 |
|
14228 |
|
14229 |
|
14230 |
|
14231 |
|
14232 |
|
14233 |
|
14234 |
|
14235 |
|
14236 |
|
14237 |
|
14238 |
|
14239 |
|
14240 |
|
14241 |
|
14242 |
|
14243 | axis_y2_tick_format: undefined,
|
14244 | |
14245 |
|
14246 |
|
14247 |
|
14248 |
|
14249 |
|
14250 |
|
14251 |
|
14252 |
|
14253 |
|
14254 |
|
14255 |
|
14256 |
|
14257 |
|
14258 |
|
14259 |
|
14260 |
|
14261 | axis_y2_tick_culling: false,
|
14262 | |
14263 |
|
14264 |
|
14265 |
|
14266 |
|
14267 |
|
14268 |
|
14269 |
|
14270 |
|
14271 |
|
14272 |
|
14273 |
|
14274 |
|
14275 |
|
14276 |
|
14277 |
|
14278 |
|
14279 | axis_y2_tick_culling_max: 5,
|
14280 | |
14281 |
|
14282 |
|
14283 |
|
14284 |
|
14285 |
|
14286 |
|
14287 |
|
14288 |
|
14289 |
|
14290 |
|
14291 |
|
14292 |
|
14293 |
|
14294 |
|
14295 | axis_y2_tick_outer: true,
|
14296 | |
14297 |
|
14298 |
|
14299 |
|
14300 |
|
14301 |
|
14302 |
|
14303 |
|
14304 |
|
14305 |
|
14306 |
|
14307 |
|
14308 |
|
14309 |
|
14310 |
|
14311 |
|
14312 |
|
14313 |
|
14314 |
|
14315 |
|
14316 | axis_y2_tick_values: null,
|
14317 | |
14318 |
|
14319 |
|
14320 |
|
14321 |
|
14322 |
|
14323 |
|
14324 |
|
14325 |
|
14326 |
|
14327 |
|
14328 |
|
14329 |
|
14330 |
|
14331 |
|
14332 |
|
14333 |
|
14334 | axis_y2_tick_rotate: 0,
|
14335 | |
14336 |
|
14337 |
|
14338 |
|
14339 |
|
14340 |
|
14341 |
|
14342 |
|
14343 |
|
14344 |
|
14345 |
|
14346 |
|
14347 |
|
14348 |
|
14349 |
|
14350 |
|
14351 | axis_y2_tick_count: undefined,
|
14352 | |
14353 |
|
14354 |
|
14355 |
|
14356 |
|
14357 |
|
14358 |
|
14359 |
|
14360 |
|
14361 |
|
14362 |
|
14363 |
|
14364 |
|
14365 |
|
14366 |
|
14367 |
|
14368 | axis_y2_tick_show: true,
|
14369 | |
14370 |
|
14371 |
|
14372 |
|
14373 |
|
14374 |
|
14375 |
|
14376 |
|
14377 |
|
14378 |
|
14379 |
|
14380 |
|
14381 |
|
14382 |
|
14383 |
|
14384 |
|
14385 |
|
14386 |
|
14387 | axis_y2_tick_stepSize: null,
|
14388 | |
14389 |
|
14390 |
|
14391 |
|
14392 |
|
14393 |
|
14394 |
|
14395 |
|
14396 |
|
14397 |
|
14398 |
|
14399 |
|
14400 |
|
14401 |
|
14402 |
|
14403 |
|
14404 |
|
14405 |
|
14406 | axis_y2_tick_text_show: true,
|
14407 | |
14408 |
|
14409 |
|
14410 |
|
14411 |
|
14412 |
|
14413 |
|
14414 |
|
14415 |
|
14416 |
|
14417 |
|
14418 |
|
14419 |
|
14420 |
|
14421 |
|
14422 |
|
14423 |
|
14424 |
|
14425 |
|
14426 |
|
14427 | axis_y2_tick_text_position: { x: 0, y: 0 },
|
14428 | |
14429 |
|
14430 |
|
14431 |
|
14432 |
|
14433 |
|
14434 |
|
14435 |
|
14436 |
|
14437 |
|
14438 |
|
14439 |
|
14440 |
|
14441 |
|
14442 |
|
14443 |
|
14444 |
|
14445 |
|
14446 |
|
14447 |
|
14448 |
|
14449 |
|
14450 |
|
14451 |
|
14452 | axis_y2_padding: {},
|
14453 | |
14454 |
|
14455 |
|
14456 |
|
14457 |
|
14458 |
|
14459 |
|
14460 |
|
14461 |
|
14462 |
|
14463 |
|
14464 |
|
14465 |
|
14466 |
|
14467 | axis_y2_default: undefined,
|
14468 | |
14469 |
|
14470 |
|
14471 |
|
14472 |
|
14473 |
|
14474 |
|
14475 |
|
14476 |
|
14477 |
|
14478 |
|
14479 |
|
14480 |
|
14481 |
|
14482 |
|
14483 |
|
14484 |
|
14485 |
|
14486 |
|
14487 |
|
14488 |
|
14489 |
|
14490 |
|
14491 |
|
14492 |
|
14493 |
|
14494 |
|
14495 |
|
14496 |
|
14497 |
|
14498 |
|
14499 |
|
14500 |
|
14501 |
|
14502 |
|
14503 |
|
14504 |
|
14505 | axis_y2_axes: []
|
14506 | };
|
14507 |
|
14508 |
|
14509 |
|
14510 |
|
14511 | var optAxis = _assign(_assign(_assign({
|
14512 | |
14513 |
|
14514 |
|
14515 |
|
14516 |
|
14517 |
|
14518 |
|
14519 |
|
14520 |
|
14521 |
|
14522 |
|
14523 | axis_rotated: false }, x), y), y2);
|
14524 |
|
14525 | var optGrid = {
|
14526 | |
14527 |
|
14528 |
|
14529 |
|
14530 |
|
14531 |
|
14532 |
|
14533 |
|
14534 |
|
14535 |
|
14536 |
|
14537 |
|
14538 |
|
14539 |
|
14540 |
|
14541 |
|
14542 |
|
14543 |
|
14544 |
|
14545 |
|
14546 |
|
14547 |
|
14548 |
|
14549 |
|
14550 |
|
14551 |
|
14552 |
|
14553 |
|
14554 |
|
14555 |
|
14556 |
|
14557 |
|
14558 |
|
14559 |
|
14560 |
|
14561 |
|
14562 |
|
14563 |
|
14564 |
|
14565 |
|
14566 |
|
14567 |
|
14568 |
|
14569 |
|
14570 |
|
14571 |
|
14572 |
|
14573 |
|
14574 |
|
14575 |
|
14576 |
|
14577 |
|
14578 |
|
14579 |
|
14580 |
|
14581 |
|
14582 |
|
14583 |
|
14584 | grid_x_show: false,
|
14585 | grid_x_type: "tick",
|
14586 | grid_x_lines: [],
|
14587 | grid_y_show: false,
|
14588 | grid_y_lines: [],
|
14589 | grid_y_ticks: 10,
|
14590 | grid_focus_edge: false,
|
14591 | grid_focus_show: true,
|
14592 | grid_focus_y: false,
|
14593 | grid_front: false,
|
14594 | grid_lines_front: true
|
14595 | };
|
14596 |
|
14597 |
|
14598 |
|
14599 |
|
14600 |
|
14601 | var api = [
|
14602 | apiAxis,
|
14603 | apiCategory,
|
14604 | apiXGrid,
|
14605 | apiYGrid,
|
14606 | apiFlow,
|
14607 | apiGroup,
|
14608 | apiRegion,
|
14609 | apiX
|
14610 | ];
|
14611 | var internal = [
|
14612 | axis,
|
14613 | clip,
|
14614 | eventrect,
|
14615 | flow,
|
14616 | grid,
|
14617 | region,
|
14618 | sizeAxis,
|
14619 | ];
|
14620 | var options = [
|
14621 | optDataAxis,
|
14622 | optAxis,
|
14623 | optGrid,
|
14624 | ];
|
14625 |
|
14626 |
|
14627 |
|
14628 |
|
14629 |
|
14630 | var shapeArc = {
|
14631 | initPie: function () {
|
14632 | var $$ = this;
|
14633 | var config = $$.config;
|
14634 | var dataType = config.data_type;
|
14635 | var padding = config.pie_padding;
|
14636 | var startingAngle = config[dataType + "_startingAngle"] || 0;
|
14637 | var padAngle = ($$.hasType("pie") && padding ? padding * 0.01 :
|
14638 | config[dataType + "_padAngle"]) || 0;
|
14639 | $$.pie = pie$1()
|
14640 | .startAngle(startingAngle)
|
14641 | .endAngle(startingAngle + (2 * Math.PI))
|
14642 | .padAngle(padAngle)
|
14643 | .value(function (d) { return d.values.reduce(function (a, b) { return a + b.value; }, 0); })
|
14644 | .sort($$.getSortCompareFn.bind($$)(true));
|
14645 | },
|
14646 | updateRadius: function () {
|
14647 | var $$ = this;
|
14648 | var config = $$.config, state = $$.state;
|
14649 | var padding = config.pie_padding;
|
14650 | var w = config.gauge_width || config.donut_width;
|
14651 | var gaugeArcWidth = $$.filterTargetsToShow($$.data.targets).length *
|
14652 | config.gauge_arcs_minWidth;
|
14653 |
|
14654 | state.radiusExpanded = Math.min(state.arcWidth, state.arcHeight) / 2 * ($$.hasMultiArcGauge() ? 0.85 : 1);
|
14655 | state.radius = state.radiusExpanded * 0.95;
|
14656 | state.innerRadiusRatio = w ? (state.radius - w) / state.radius : 0.6;
|
14657 | state.gaugeArcWidth = w || (gaugeArcWidth <= state.radius - state.innerRadius ?
|
14658 | state.radius - state.innerRadius :
|
14659 | (gaugeArcWidth <= state.radius ? gaugeArcWidth : state.radius));
|
14660 | var innerRadius = config.pie_innerRadius || (padding ? padding * (state.innerRadiusRatio + 0.1) : 0);
|
14661 |
|
14662 | state.outerRadius = config.pie_outerRadius;
|
14663 | state.innerRadius = $$.hasType("donut") || $$.hasType("gauge") ?
|
14664 | state.radius * state.innerRadiusRatio : innerRadius;
|
14665 | },
|
14666 | |
14667 |
|
14668 |
|
14669 |
|
14670 |
|
14671 |
|
14672 | getRadius: function (d) {
|
14673 | var $$ = this;
|
14674 | var data = d && d.data;
|
14675 | var _a = $$.state, innerRadius = _a.innerRadius, outerRadius = _a.outerRadius;
|
14676 | if (!isNumber(innerRadius) && data) {
|
14677 | innerRadius = innerRadius[data.id] || 0;
|
14678 | }
|
14679 | if (isObject(outerRadius) && data && data.id in outerRadius) {
|
14680 | outerRadius = outerRadius[data.id];
|
14681 | }
|
14682 | else if (!isNumber(outerRadius)) {
|
14683 | outerRadius = $$.state.radius;
|
14684 | }
|
14685 | return { innerRadius: innerRadius, outerRadius: outerRadius };
|
14686 | },
|
14687 | updateArc: function () {
|
14688 | var $$ = this;
|
14689 | $$.updateRadius();
|
14690 | $$.svgArc = $$.getSvgArc();
|
14691 | $$.svgArcExpanded = $$.getSvgArcExpanded();
|
14692 | },
|
14693 | getArcLength: function () {
|
14694 | var $$ = this;
|
14695 | var config = $$.config;
|
14696 | var arcLengthInPercent = config.gauge_arcLength * 3.6;
|
14697 | var len = (2 * (arcLengthInPercent / 360));
|
14698 | if (arcLengthInPercent < -360) {
|
14699 | len = -2;
|
14700 | }
|
14701 | else if (arcLengthInPercent > 360) {
|
14702 | len = 2;
|
14703 | }
|
14704 | return len * Math.PI;
|
14705 | },
|
14706 | getStartAngle: function () {
|
14707 | var $$ = this;
|
14708 | var config = $$.config;
|
14709 | var isFullCircle = config.gauge_fullCircle;
|
14710 | var defaultStartAngle = -1 * Math.PI / 2;
|
14711 | var defaultEndAngle = Math.PI / 2;
|
14712 | var startAngle = config.gauge_startingAngle;
|
14713 | if (!isFullCircle && startAngle <= defaultStartAngle) {
|
14714 | startAngle = defaultStartAngle;
|
14715 | }
|
14716 | else if (!isFullCircle && startAngle >= defaultEndAngle) {
|
14717 | startAngle = defaultEndAngle;
|
14718 | }
|
14719 | else if (startAngle > Math.PI || startAngle < -1 * Math.PI) {
|
14720 | startAngle = Math.PI;
|
14721 | }
|
14722 | return startAngle;
|
14723 | },
|
14724 | updateAngle: function (dValue) {
|
14725 | var $$ = this;
|
14726 | var config = $$.config, state = $$.state;
|
14727 | var pie = $$.pie;
|
14728 | var d = dValue;
|
14729 | var found = false;
|
14730 | if (!config) {
|
14731 | return null;
|
14732 | }
|
14733 | var gStart = $$.getStartAngle();
|
14734 | var radius = config.gauge_fullCircle ? $$.getArcLength() : gStart * -2;
|
14735 | if (d.data && $$.isGaugeType(d.data) && !$$.hasMultiArcGauge()) {
|
14736 |
|
14737 | var totalSum = $$.getTotalDataSum(state.rendered);
|
14738 | var gEnd = radius * (totalSum / (config.gauge_max - config.gauge_min));
|
14739 | pie = pie
|
14740 | .startAngle(gStart)
|
14741 | .endAngle(gEnd + gStart);
|
14742 | }
|
14743 | pie($$.filterTargetsToShow())
|
14744 | .forEach(function (t, i) {
|
14745 | if (!found && t.data.id === d.data.id) {
|
14746 | found = true;
|
14747 | d = t;
|
14748 | d.index = i;
|
14749 | }
|
14750 | });
|
14751 | if (isNaN(d.startAngle)) {
|
14752 | d.startAngle = 0;
|
14753 | }
|
14754 | if (isNaN(d.endAngle)) {
|
14755 | d.endAngle = d.startAngle;
|
14756 | }
|
14757 | if (d.data && $$.hasMultiArcGauge()) {
|
14758 | var gMin = config.gauge_min;
|
14759 | var gMax = config.gauge_max;
|
14760 | var gTic = radius / (gMax - gMin);
|
14761 | var gValue = d.value < gMin ? 0 : d.value < gMax ? d.value - gMin : (gMax - gMin);
|
14762 | d.startAngle = gStart;
|
14763 | d.endAngle = gStart + gTic * gValue;
|
14764 | }
|
14765 | return found ? d : null;
|
14766 | },
|
14767 | getSvgArc: function () {
|
14768 | var $$ = this;
|
14769 | var state = $$.state;
|
14770 | var singleArcWidth = state.gaugeArcWidth / $$.filterTargetsToShow($$.data.targets).length;
|
14771 | var hasMultiArcGauge = $$.hasMultiArcGauge();
|
14772 | var arc$1 = arc()
|
14773 | .innerRadius(function (d) {
|
14774 | var innerRadius = $$.getRadius(d).innerRadius;
|
14775 | return hasMultiArcGauge ?
|
14776 | state.radius - singleArcWidth * (d.index + 1) :
|
14777 | isNumber(innerRadius) ? innerRadius : 0;
|
14778 | })
|
14779 | .outerRadius(function (d) {
|
14780 | var outerRadius = $$.getRadius(d).outerRadius;
|
14781 | return hasMultiArcGauge ? (state.radius - singleArcWidth * d.index) : outerRadius;
|
14782 | });
|
14783 | var newArc = function (d, withoutUpdate) {
|
14784 | var path = "M 0 0";
|
14785 | if (d.value || d.data) {
|
14786 | var updated = !withoutUpdate && $$.updateAngle(d);
|
14787 | if (withoutUpdate) {
|
14788 | path = arc$1(d);
|
14789 | }
|
14790 | else if (updated) {
|
14791 | path = arc$1(updated);
|
14792 | }
|
14793 | }
|
14794 | return path;
|
14795 | };
|
14796 |
|
14797 | newArc.centroid = arc$1.centroid;
|
14798 | return newArc;
|
14799 | },
|
14800 | getSvgArcExpanded: function (rate) {
|
14801 | var $$ = this;
|
14802 | var state = $$.state;
|
14803 | var newRate = rate || 1;
|
14804 | var singleArcWidth = state.gaugeArcWidth / $$.filterTargetsToShow($$.data.targets).length;
|
14805 | var hasMultiArcGauge = $$.hasMultiArcGauge();
|
14806 | var expandWidth = Math.min(state.radiusExpanded * newRate - state.radius, singleArcWidth * 0.8 - (1 - newRate) * 100);
|
14807 | var arc$1 = arc()
|
14808 | .innerRadius(function (d) { return (hasMultiArcGauge ?
|
14809 | state.radius - singleArcWidth * (d.index + 1) : $$.getRadius(d).innerRadius); })
|
14810 | .outerRadius(function (d) {
|
14811 | var radius;
|
14812 | if (hasMultiArcGauge) {
|
14813 | radius = state.radius - singleArcWidth * d.index + expandWidth;
|
14814 | }
|
14815 | else {
|
14816 | var outerRadius = $$.getRadius(d).outerRadius;
|
14817 | var radiusExpanded = state.radiusExpanded;
|
14818 | if (state.radius !== outerRadius) {
|
14819 | radiusExpanded -= Math.abs(state.radius - outerRadius);
|
14820 | }
|
14821 | radius = radiusExpanded * newRate;
|
14822 | }
|
14823 | return radius;
|
14824 | });
|
14825 | return function (d) {
|
14826 | var updated = $$.updateAngle(d);
|
14827 | return updated ? arc$1(updated) : "M 0 0";
|
14828 | };
|
14829 | },
|
14830 | getArc: function (d, withoutUpdate, force) {
|
14831 | return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0";
|
14832 | },
|
14833 | transformForArcLabel: function (d) {
|
14834 | var $$ = this;
|
14835 | var config = $$.config, radiusExpanded = $$.state.radiusExpanded;
|
14836 | var updated = $$.updateAngle(d);
|
14837 | var translate = "";
|
14838 | if (updated) {
|
14839 | if ($$.hasMultiArcGauge()) {
|
14840 | var y1 = Math.sin(updated.endAngle - Math.PI / 2);
|
14841 | var x = Math.cos(updated.endAngle - Math.PI / 2) * (radiusExpanded + 25);
|
14842 | var y = y1 * (radiusExpanded + 15 - Math.abs(y1 * 10)) + 3;
|
14843 | translate = "translate(" + x + "," + y + ")";
|
14844 | }
|
14845 | else if (!$$.hasType("gauge") || $$.data.targets.length > 1) {
|
14846 | var outerRadius = $$.getRadius(d).outerRadius;
|
14847 | var c = this.svgArc.centroid(updated);
|
14848 | var x = isNaN(c[0]) ? 0 : c[0];
|
14849 | var y = isNaN(c[1]) ? 0 : c[1];
|
14850 | var h = Math.sqrt(x * x + y * y);
|
14851 | var ratio = ($$.hasType("donut") && config.donut_label_ratio) ||
|
14852 | ($$.hasType("pie") && config.pie_label_ratio);
|
14853 | if (ratio) {
|
14854 | ratio = isFunction(ratio) ? ratio.bind($$.api)(d, outerRadius, h) : ratio;
|
14855 | }
|
14856 | else {
|
14857 | ratio = outerRadius && (h ? (36 / outerRadius > 0.375 ? 1.175 - 36 / outerRadius : 0.8) * outerRadius / h : 0);
|
14858 | }
|
14859 | translate = "translate(" + x * ratio + "," + y * ratio + ")";
|
14860 | }
|
14861 | }
|
14862 | return translate;
|
14863 | },
|
14864 | convertToArcData: function (d) {
|
14865 | return this.addName({
|
14866 | id: d.data ? d.data.id : d.id,
|
14867 | value: d.value,
|
14868 | ratio: this.getRatio("arc", d),
|
14869 | index: d.index
|
14870 | });
|
14871 | },
|
14872 | textForArcLabel: function (selection) {
|
14873 | var $$ = this;
|
14874 | var hasGauge = $$.hasType("gauge");
|
14875 | if ($$.shouldShowArcLabel()) {
|
14876 | selection
|
14877 | .style("fill", $$.updateTextColor.bind($$))
|
14878 | .each(function (d) {
|
14879 | var node = select(this);
|
14880 | var updated = $$.updateAngle(d);
|
14881 | var ratio = $$.getRatio("arc", updated);
|
14882 | var isUnderThreshold = $$.meetsLabelThreshold(ratio, ($$.hasType("donut") && "donut") || ($$.hasType("gauge") && "gauge") || ($$.hasType("pie") && "pie"));
|
14883 | if (isUnderThreshold) {
|
14884 | var value = (updated || d).value;
|
14885 | var text = ($$.getArcLabelFormat() || $$.defaultArcValueFormat)(value, ratio, d.data.id).toString();
|
14886 | setTextValue(node, text, [-1, 1], hasGauge);
|
14887 | }
|
14888 | else {
|
14889 | node.text("");
|
14890 | }
|
14891 | });
|
14892 | }
|
14893 | },
|
14894 | expandArc: function (targetIds) {
|
14895 | var $$ = this;
|
14896 | var transiting = $$.state.transiting, $el = $$.$el;
|
14897 |
|
14898 | if (transiting) {
|
14899 | var interval_1 = setInterval(function () {
|
14900 | if (!transiting) {
|
14901 | clearInterval(interval_1);
|
14902 | $el.legend.selectAll("." + CLASS.legendItemFocused).size() > 0 &&
|
14903 | $$.expandArc(targetIds);
|
14904 | }
|
14905 | }, 10);
|
14906 | return;
|
14907 | }
|
14908 | var newTargetIds = $$.mapToTargetIds(targetIds);
|
14909 | $el.svg.selectAll($$.selectorTargets(newTargetIds, "." + CLASS.chartArc))
|
14910 | .each(function (d) {
|
14911 | if (!$$.shouldExpand(d.data.id)) {
|
14912 | return;
|
14913 | }
|
14914 | var expandDuration = $$.getExpandConfig(d.data.id, "duration");
|
14915 | var svgArcExpandedSub = $$.getSvgArcExpanded($$.getExpandConfig(d.data.id, "rate"));
|
14916 | select(this).selectAll("path")
|
14917 | .transition()
|
14918 | .duration(expandDuration)
|
14919 | .attr("d", $$.svgArcExpanded)
|
14920 | .transition()
|
14921 | .duration(expandDuration * 2)
|
14922 | .attr("d", svgArcExpandedSub);
|
14923 | });
|
14924 | },
|
14925 | unexpandArc: function (targetIds) {
|
14926 | var $$ = this;
|
14927 | var transiting = $$.state.transiting, svg = $$.$el.svg;
|
14928 | if (transiting) {
|
14929 | return;
|
14930 | }
|
14931 | var newTargetIds = $$.mapToTargetIds(targetIds);
|
14932 | svg.selectAll($$.selectorTargets(newTargetIds, "." + CLASS.chartArc))
|
14933 | .selectAll("path")
|
14934 | .transition()
|
14935 | .duration(function (d) { return $$.getExpandConfig(d.data.id, "duration"); })
|
14936 | .attr("d", $$.svgArc);
|
14937 | svg.selectAll("" + CLASS.arc)
|
14938 | .style("opacity", "1");
|
14939 | },
|
14940 | |
14941 |
|
14942 |
|
14943 |
|
14944 |
|
14945 |
|
14946 |
|
14947 | getExpandConfig: function (id, key) {
|
14948 | var $$ = this;
|
14949 | var config = $$.config;
|
14950 | var def = {
|
14951 | duration: 50,
|
14952 | rate: 0.98
|
14953 | };
|
14954 | var type;
|
14955 | if ($$.isDonutType(id)) {
|
14956 | type = "donut";
|
14957 | }
|
14958 | else if ($$.isGaugeType(id)) {
|
14959 | type = "gauge";
|
14960 | }
|
14961 | else if ($$.isPieType(id)) {
|
14962 | type = "pie";
|
14963 | }
|
14964 | return type ? config[type + "_expand_" + key] : def[key];
|
14965 | },
|
14966 | shouldExpand: function (id) {
|
14967 | var $$ = this;
|
14968 | var config = $$.config;
|
14969 | return ($$.isDonutType(id) && config.donut_expand) ||
|
14970 | ($$.isGaugeType(id) && config.gauge_expand) ||
|
14971 | ($$.isPieType(id) && config.pie_expand);
|
14972 | },
|
14973 | shouldShowArcLabel: function () {
|
14974 | var $$ = this;
|
14975 | var config = $$.config;
|
14976 | return ["pie", "donut", "gauge"]
|
14977 | .some(function (v) { return $$.hasType(v) && config[v + "_label_show"]; });
|
14978 | },
|
14979 | getArcLabelFormat: function () {
|
14980 | var $$ = this;
|
14981 | var config = $$.config;
|
14982 | var format = config.pie_label_format;
|
14983 | if ($$.hasType("gauge")) {
|
14984 | format = config.gauge_label_format;
|
14985 | }
|
14986 | else if ($$.hasType("donut")) {
|
14987 | format = config.donut_label_format;
|
14988 | }
|
14989 | return isFunction(format) ? format.bind($$.api) : format;
|
14990 | },
|
14991 | getArcTitle: function () {
|
14992 | var $$ = this;
|
14993 | var type = ($$.hasType("donut") && "donut") || ($$.hasType("gauge") && "gauge");
|
14994 | return type ? $$.config[type + "_title"] : "";
|
14995 | },
|
14996 | updateTargetsForArc: function (targets) {
|
14997 | var $$ = this;
|
14998 | var $el = $$.$el;
|
14999 | var hasGauge = $$.hasType("gauge");
|
15000 | var classChartArc = $$.getChartClass("Arc");
|
15001 | var classArcs = $$.getClass("arcs", true);
|
15002 | var classFocus = $$.classFocus.bind($$);
|
15003 | var chartArcs = $el.main.select("." + CLASS.chartArcs);
|
15004 | var mainPieUpdate = chartArcs
|
15005 | .selectAll("." + CLASS.chartArc)
|
15006 | .data($$.pie(targets))
|
15007 | .attr("class", function (d) { return classChartArc(d) + classFocus(d.data); });
|
15008 | var mainPieEnter = mainPieUpdate.enter().append("g")
|
15009 | .attr("class", classChartArc);
|
15010 | mainPieEnter.append("g")
|
15011 | .attr("class", classArcs)
|
15012 | .merge(mainPieUpdate);
|
15013 | mainPieEnter.append("text")
|
15014 | .attr("dy", hasGauge && !$$.hasMultiTargets() ? "-.1em" : ".35em")
|
15015 | .style("opacity", "0")
|
15016 | .style("text-anchor", "middle")
|
15017 | .style("pointer-events", "none");
|
15018 | $el.text = chartArcs.selectAll("." + CLASS.target + " text");
|
15019 |
|
15020 |
|
15021 | },
|
15022 | initArc: function () {
|
15023 | var $$ = this;
|
15024 | var $el = $$.$el;
|
15025 | $el.arcs = $el.main.select("." + CLASS.chart)
|
15026 | .append("g")
|
15027 | .attr("class", CLASS.chartArcs)
|
15028 | .attr("transform", $$.getTranslate("arc"));
|
15029 | $$.setArcTitle();
|
15030 | },
|
15031 | |
15032 |
|
15033 |
|
15034 |
|
15035 | setArcTitle: function () {
|
15036 | var $$ = this;
|
15037 | var title = $$.getArcTitle();
|
15038 | var hasGauge = $$.hasType("gauge");
|
15039 | if (title) {
|
15040 | var text = $$.$el.arcs.append("text")
|
15041 | .attr("class", CLASS[hasGauge ? "chartArcsGaugeTitle" : "chartArcsTitle"])
|
15042 | .style("text-anchor", "middle");
|
15043 | if (hasGauge) {
|
15044 | text
|
15045 | .attr("dy", "-0.3em")
|
15046 | .style("font-size", "27px");
|
15047 | }
|
15048 | setTextValue(text, title, hasGauge ? undefined : [-0.6, 1.35], true);
|
15049 | }
|
15050 | },
|
15051 | redrawArc: function (duration, durationForExit, withTransform) {
|
15052 | var $$ = this;
|
15053 | var config = $$.config, state = $$.state, main = $$.$el.main;
|
15054 | var hasInteraction = config.interaction_enabled;
|
15055 | var isSelectable = hasInteraction && config.data_selection_isselectable;
|
15056 | var mainArc = main.selectAll("." + CLASS.arcs)
|
15057 | .selectAll("." + CLASS.arc)
|
15058 | .data($$.arcData.bind($$));
|
15059 | mainArc.exit().transition()
|
15060 | .duration(durationForExit)
|
15061 | .style("opacity", "0")
|
15062 | .remove();
|
15063 | mainArc = mainArc.enter().append("path")
|
15064 | .attr("class", $$.getClass("arc", true))
|
15065 | .style("fill", function (d) { return $$.color(d.data); })
|
15066 | .style("cursor", function (d) { return (isSelectable && isSelectable.bind($$.api)(d) ? "pointer" : null); })
|
15067 | .style("opacity", "0")
|
15068 | .each(function (d) {
|
15069 | if ($$.isGaugeType(d.data)) {
|
15070 | d.startAngle = config.gauge_startingAngle;
|
15071 | d.endAngle = config.gauge_startingAngle;
|
15072 | }
|
15073 | this._current = d;
|
15074 | })
|
15075 | .merge(mainArc);
|
15076 | if ($$.hasType("gauge")) {
|
15077 | $$.updateGaugeMax();
|
15078 | $$.hasMultiArcGauge() && $$.redrawMultiArcGauge();
|
15079 | }
|
15080 | mainArc
|
15081 | .attr("transform", function (d) { return (!$$.isGaugeType(d.data) && withTransform ? "scale(0)" : ""); })
|
15082 | .style("opacity", function (d) {
|
15083 | return d === this._current ? "0" : "1";
|
15084 | })
|
15085 | .each(function () {
|
15086 | state.transiting = true;
|
15087 | })
|
15088 | .transition()
|
15089 | .duration(duration)
|
15090 | .attrTween("d", function (d) {
|
15091 | var updated = $$.updateAngle(d);
|
15092 | if (!updated) {
|
15093 | return function () { return "M 0 0"; };
|
15094 | }
|
15095 | if (isNaN(this._current.startAngle)) {
|
15096 | this._current.startAngle = 0;
|
15097 | }
|
15098 | if (isNaN(this._current.endAngle)) {
|
15099 | this._current.endAngle = this._current.startAngle;
|
15100 | }
|
15101 | var interpolate$1 = interpolate(this._current, updated);
|
15102 | this._current = interpolate$1(0);
|
15103 | return function (t) {
|
15104 | var interpolated = interpolate$1(t);
|
15105 | interpolated.data = d.data;
|
15106 | return $$.getArc(interpolated, true);
|
15107 | };
|
15108 | })
|
15109 | .attr("transform", withTransform ? "scale(1)" : "")
|
15110 | .style("fill", function (d) {
|
15111 | var color;
|
15112 | if ($$.levelColor) {
|
15113 | color = $$.levelColor(d.data.values[0].value);
|
15114 |
|
15115 | config.data_colors[d.data.id] = color;
|
15116 | }
|
15117 | else {
|
15118 | color = $$.color(d.data);
|
15119 | }
|
15120 | return color;
|
15121 | })
|
15122 |
|
15123 | .style("opacity", "1")
|
15124 | .call(endall, function () {
|
15125 | if ($$.levelColor) {
|
15126 | var path = select(this);
|
15127 | var d = path.datum();
|
15128 | $$.updateLegendItemColor(d.data.id, path.style("fill"));
|
15129 | }
|
15130 | state.transiting = false;
|
15131 | callFn(config.onrendered, $$.api);
|
15132 | });
|
15133 |
|
15134 | hasInteraction && $$.bindArcEvent(mainArc);
|
15135 | $$.hasType("gauge") && $$.redrawBackgroundArcs();
|
15136 | $$.redrawArcText(duration);
|
15137 | },
|
15138 | redrawBackgroundArcs: function () {
|
15139 | var $$ = this;
|
15140 | var config = $$.config, state = $$.state;
|
15141 | var hasMultiArcGauge = $$.hasMultiArcGauge();
|
15142 | var isFullCircle = config.gauge_fullCircle;
|
15143 | var startAngle = $$.getStartAngle();
|
15144 | var endAngle = isFullCircle ? startAngle + $$.getArcLength() : startAngle * -1;
|
15145 | var backgroundArc = $$.$el.arcs.select((hasMultiArcGauge ? "g" : "") + "." + CLASS.chartArcsBackground);
|
15146 | if (hasMultiArcGauge) {
|
15147 | var index_1 = 0;
|
15148 | backgroundArc = backgroundArc
|
15149 | .selectAll("path." + CLASS.chartArcsBackground)
|
15150 | .data($$.data.targets);
|
15151 | backgroundArc.enter()
|
15152 | .append("path")
|
15153 | .attr("class", function (d, i) { return CLASS.chartArcsBackground + " " + CLASS.chartArcsBackground + "-" + i; })
|
15154 | .merge(backgroundArc)
|
15155 | .style("fill", (config.gauge_background) || null)
|
15156 | .attr("d", function (_a) {
|
15157 | var id = _a.id;
|
15158 | if (state.hiddenTargetIds.indexOf(id) >= 0) {
|
15159 | return "M 0 0";
|
15160 | }
|
15161 | var d = {
|
15162 | data: [{ value: config.gauge_max }],
|
15163 | startAngle: startAngle,
|
15164 | endAngle: endAngle,
|
15165 | index: index_1++
|
15166 | };
|
15167 | return $$.getArc(d, true, true);
|
15168 | });
|
15169 | backgroundArc.exit().remove();
|
15170 | }
|
15171 | else {
|
15172 | backgroundArc.attr("d", function () {
|
15173 | var d = {
|
15174 | data: [{ value: config.gauge_max }],
|
15175 | startAngle: startAngle,
|
15176 | endAngle: endAngle
|
15177 | };
|
15178 | return $$.getArc(d, true, true);
|
15179 | });
|
15180 | }
|
15181 | },
|
15182 | bindArcEvent: function (arc) {
|
15183 | var $$ = this;
|
15184 | var config = $$.config, state = $$.state;
|
15185 | var isTouch = state.inputType === "touch";
|
15186 | var isMouse = state.inputType === "mouse";
|
15187 |
|
15188 | function selectArc(_this, arcData, id) {
|
15189 |
|
15190 | $$.expandArc(id);
|
15191 | $$.api.focus(id);
|
15192 | $$.toggleFocusLegend(id, true);
|
15193 | $$.showTooltip([arcData], _this);
|
15194 | }
|
15195 |
|
15196 | function unselectArc(arcData) {
|
15197 | var id = (arcData && arcData.id) || undefined;
|
15198 | $$.unexpandArc(id);
|
15199 | $$.api.revert();
|
15200 | $$.revertLegend();
|
15201 | $$.hideTooltip();
|
15202 | }
|
15203 | arc
|
15204 | .on("click", function (event, d, i) {
|
15205 | var updated = $$.updateAngle(d);
|
15206 | var arcData;
|
15207 | if (updated) {
|
15208 | arcData = $$.convertToArcData(updated);
|
15209 | $$.toggleShape && $$.toggleShape(this, arcData, i);
|
15210 | config.data_onclick.bind($$.api)(arcData, this);
|
15211 | }
|
15212 | });
|
15213 |
|
15214 | if (isMouse) {
|
15215 | arc
|
15216 | .on("mouseover", function (event, d) {
|
15217 | if (state.transiting) {
|
15218 | return;
|
15219 | }
|
15220 | state.event = event;
|
15221 | var updated = $$.updateAngle(d);
|
15222 | var arcData = updated ? $$.convertToArcData(updated) : null;
|
15223 | var id = (arcData && arcData.id) || undefined;
|
15224 | selectArc(this, arcData, id);
|
15225 | $$.setOverOut(true, arcData);
|
15226 | })
|
15227 | .on("mouseout", function (event, d) {
|
15228 | if (state.transiting) {
|
15229 | return;
|
15230 | }
|
15231 | state.event = event;
|
15232 | var updated = $$.updateAngle(d);
|
15233 | var arcData = updated ? $$.convertToArcData(updated) : null;
|
15234 | unselectArc();
|
15235 | $$.setOverOut(false, arcData);
|
15236 | })
|
15237 | .on("mousemove", function (event, d) {
|
15238 | var updated = $$.updateAngle(d);
|
15239 | var arcData = updated ? $$.convertToArcData(updated) : null;
|
15240 | state.event = event;
|
15241 | $$.showTooltip([arcData], this);
|
15242 | });
|
15243 | }
|
15244 |
|
15245 | if (isTouch && $$.hasArcType() && !$$.radars) {
|
15246 | var getEventArc_1 = function (event) {
|
15247 | var touch = event.changedTouches[0];
|
15248 | var eventArc = select(doc.elementFromPoint(touch.clientX, touch.clientY));
|
15249 | return eventArc;
|
15250 | };
|
15251 | $$.$el.svg
|
15252 | .on("touchstart touchmove", function (event) {
|
15253 | if (state.transiting) {
|
15254 | return;
|
15255 | }
|
15256 | var eventArc = getEventArc_1(event);
|
15257 | var datum = eventArc.datum();
|
15258 | var updated = (datum && datum.data && datum.data.id) ? $$.updateAngle(datum) : null;
|
15259 | var arcData = updated ? $$.convertToArcData(updated) : null;
|
15260 | var id = (arcData && arcData.id) || undefined;
|
15261 | $$.callOverOutForTouch(arcData);
|
15262 | isUndefined(id) ?
|
15263 | unselectArc() : selectArc(this, arcData, id);
|
15264 | });
|
15265 | }
|
15266 | },
|
15267 | redrawArcText: function (duration) {
|
15268 | var $$ = this;
|
15269 | var config = $$.config, state = $$.state, _a = $$.$el, main = _a.main, arcs = _a.arcs;
|
15270 | var hasGauge = $$.hasType("gauge");
|
15271 | var hasMultiArcGauge = $$.hasMultiArcGauge();
|
15272 | var text;
|
15273 |
|
15274 | if (!(hasGauge && $$.data.targets.length === 1 && config.gauge_title)) {
|
15275 | text = main.selectAll("." + CLASS.chartArc)
|
15276 | .select("text")
|
15277 | .style("opacity", "0")
|
15278 | .attr("class", function (d) { return ($$.isGaugeType(d.data) ? CLASS.gaugeValue : null); })
|
15279 | .call($$.textForArcLabel.bind($$))
|
15280 | .attr("transform", $$.transformForArcLabel.bind($$))
|
15281 | .style("font-size", function (d) { return ($$.isGaugeType(d.data) && $$.data.targets.length === 1 && !hasMultiArcGauge ?
|
15282 | Math.round(state.radius / 5) + "px" : null); })
|
15283 | .transition()
|
15284 | .duration(duration)
|
15285 | .style("opacity", function (d) { return ($$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? "1" : "0"); });
|
15286 | hasMultiArcGauge && text.attr("dy", "-.1em");
|
15287 | }
|
15288 | main.select("." + CLASS.chartArcsTitle)
|
15289 | .style("opacity", $$.hasType("donut") || hasGauge ? "1" : "0");
|
15290 | if (hasGauge) {
|
15291 | var isFullCircle = config.gauge_fullCircle;
|
15292 | isFullCircle && text && text.attr("dy", "" + (hasMultiArcGauge ? 0 : Math.round(state.radius / 14)));
|
15293 | if (config.gauge_label_show) {
|
15294 | arcs.select("." + CLASS.chartArcsGaugeUnit)
|
15295 | .attr("dy", (isFullCircle ? 1.5 : 0.75) + "em")
|
15296 | .text(config.gauge_units);
|
15297 | arcs.select("." + CLASS.chartArcsGaugeMin)
|
15298 | .attr("dx", -1 * (state.innerRadius + ((state.radius - state.innerRadius) / (isFullCircle ? 1 : 2))) + "px")
|
15299 | .attr("dy", "1.2em")
|
15300 | .text($$.textForGaugeMinMax(config.gauge_min, false));
|
15301 |
|
15302 | !isFullCircle && arcs.select("." + CLASS.chartArcsGaugeMax)
|
15303 | .attr("dx", state.innerRadius + ((state.radius - state.innerRadius) / 2) + "px")
|
15304 | .attr("dy", "1.2em")
|
15305 | .text($$.textForGaugeMinMax(config.gauge_max, true));
|
15306 | }
|
15307 | }
|
15308 | }
|
15309 | };
|
15310 |
|
15311 |
|
15312 |
|
15313 |
|
15314 |
|
15315 | var shapeArea = {
|
15316 | initArea: function (mainLine) {
|
15317 | var $$ = this;
|
15318 | var config = $$.config;
|
15319 | mainLine
|
15320 | .insert("g", "." + CLASS[config.area_front ? "circles" : "lines"])
|
15321 | .attr("class", $$.getClass("areas", true));
|
15322 | },
|
15323 | updateAreaGradient: function () {
|
15324 | var $$ = this;
|
15325 | var config = $$.config, datetimeId = $$.state.datetimeId, defs = $$.$el.defs;
|
15326 | $$.data.targets.forEach(function (d) {
|
15327 | var id = datetimeId + "-areaGradient" + $$.getTargetSelectorSuffix(d.id);
|
15328 | if ($$.isAreaType(d) && defs.select("#" + id).empty()) {
|
15329 | var color_1 = $$.color(d);
|
15330 | var _a = config.area_linearGradient, _b = _a.x, x = _b === void 0 ? [0, 0] : _b, _c = _a.y, y = _c === void 0 ? [0, 1] : _c, _d = _a.stops, stops = _d === void 0 ? [[0, color_1, 1], [1, color_1, 0]] : _d;
|
15331 | var linearGradient_1 = defs.append("linearGradient")
|
15332 | .attr("id", "" + id)
|
15333 | .attr("x1", x[0])
|
15334 | .attr("x2", x[1])
|
15335 | .attr("y1", y[0])
|
15336 | .attr("y2", y[1]);
|
15337 | stops.forEach(function (v) {
|
15338 | var stopColor = isFunction(v[1]) ? v[1].bind($$.api)(d.id) : v[1];
|
15339 | linearGradient_1.append("stop")
|
15340 | .attr("offset", v[0])
|
15341 | .attr("stop-color", stopColor || color_1)
|
15342 | .attr("stop-opacity", v[2]);
|
15343 | });
|
15344 | }
|
15345 | });
|
15346 | },
|
15347 | updateAreaColor: function (d) {
|
15348 | var $$ = this;
|
15349 | return $$.config.area_linearGradient ?
|
15350 | "url(#" + $$.state.datetimeId + "-areaGradient" + $$.getTargetSelectorSuffix(d.id) + ")" :
|
15351 | $$.color(d);
|
15352 | },
|
15353 | |
15354 |
|
15355 |
|
15356 |
|
15357 |
|
15358 |
|
15359 | updateArea: function (durationForExit, isSub) {
|
15360 | if (isSub === void 0) { isSub = false; }
|
15361 | var $$ = this;
|
15362 | var config = $$.config, state = $$.state, $el = $$.$el;
|
15363 | var $root = isSub ? $el.subchart : $el;
|
15364 | config.area_linearGradient && $$.updateAreaGradient();
|
15365 | var area = $root.main.selectAll("." + CLASS.areas)
|
15366 | .selectAll("." + CLASS.area)
|
15367 | .data($$.lineData.bind($$));
|
15368 | area.exit().transition()
|
15369 | .duration(durationForExit)
|
15370 | .style("opacity", "0")
|
15371 | .remove();
|
15372 | $root.area = area.enter().append("path")
|
15373 | .attr("class", $$.getClass("area", true))
|
15374 | .style("fill", $$.updateAreaColor.bind($$))
|
15375 | .style("opacity", function () {
|
15376 | state.orgAreaOpacity = select(this).style("opacity");
|
15377 | return "0";
|
15378 | })
|
15379 | .merge(area);
|
15380 | area.style("opacity", state.orgAreaOpacity);
|
15381 | },
|
15382 | |
15383 |
|
15384 |
|
15385 |
|
15386 |
|
15387 |
|
15388 |
|
15389 | redrawArea: function (drawFn, withTransition, isSub) {
|
15390 | if (isSub === void 0) { isSub = false; }
|
15391 | var $$ = this;
|
15392 | var area = (isSub ? this.$el.subchart : this.$el).area;
|
15393 | var orgAreaOpacity = $$.state.orgAreaOpacity;
|
15394 | return [
|
15395 | (withTransition ? area.transition(getRandom()) : area)
|
15396 | .attr("d", drawFn)
|
15397 | .style("fill", $$.updateAreaColor.bind($$))
|
15398 | .style("opacity", function (d) { return String($$.isAreaRangeType(d) ? orgAreaOpacity / 1.75 : orgAreaOpacity); })
|
15399 | ];
|
15400 | },
|
15401 | |
15402 |
|
15403 |
|
15404 |
|
15405 |
|
15406 |
|
15407 |
|
15408 | generateDrawArea: function (areaIndices, isSub) {
|
15409 | var $$ = this;
|
15410 | var config = $$.config;
|
15411 | var lineConnectNull = config.line_connectNull;
|
15412 | var isRotated = config.axis_rotated;
|
15413 | var getPoints = $$.generateGetAreaPoints(areaIndices, isSub);
|
15414 | var yScale = $$.getYScaleById.bind($$);
|
15415 | var xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); };
|
15416 | var value0 = function (d, i) { return ($$.isGrouped(d.id) ?
|
15417 | getPoints(d, i)[0][1] :
|
15418 | yScale(d.id, isSub)($$.isAreaRangeType(d) ?
|
15419 | $$.getRangedData(d, "high") : $$.getShapeYMin(d.id))); };
|
15420 | var value1 = function (d, i) { return ($$.isGrouped(d.id) ?
|
15421 | getPoints(d, i)[1][1] :
|
15422 | yScale(d.id, isSub)($$.isAreaRangeType(d) ?
|
15423 | $$.getRangedData(d, "low") : d.value)); };
|
15424 | return function (d) {
|
15425 | var values = lineConnectNull ? $$.filterRemoveNull(d.values) : d.values;
|
15426 | var x0 = 0;
|
15427 | var y0 = 0;
|
15428 | var path;
|
15429 | if ($$.isAreaType(d)) {
|
15430 | var area = area$1();
|
15431 | area = isRotated ?
|
15432 | area.y(xValue)
|
15433 | .x0(value0)
|
15434 | .x1(value1) :
|
15435 | area.x(xValue)
|
15436 |
|
15437 | .y0(config.area_above ? 0 : value0)
|
15438 | .y1(value1);
|
15439 | if (!lineConnectNull) {
|
15440 | area = area.defined(function (d) { return $$.getBaseValue(d) !== null; });
|
15441 | }
|
15442 | if ($$.isStepType(d)) {
|
15443 | values = $$.convertValuesToStep(values);
|
15444 | }
|
15445 | path = area.curve($$.getCurve(d))(values);
|
15446 | }
|
15447 | else {
|
15448 | if (values[0]) {
|
15449 | x0 = $$.scale.x(values[0].x);
|
15450 | y0 = $$.getYScaleById(d.id)(values[0].value);
|
15451 | }
|
15452 | path = isRotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0;
|
15453 | }
|
15454 | return path || "M 0 0";
|
15455 | };
|
15456 | },
|
15457 | generateGetAreaPoints: function (areaIndices, isSub) {
|
15458 |
|
15459 | var $$ = this;
|
15460 | var config = $$.config;
|
15461 | var x = $$.getShapeX(0, areaIndices, isSub);
|
15462 | var y = $$.getShapeY(!!isSub);
|
15463 | var areaOffset = $$.getShapeOffset($$.isAreaType, areaIndices, isSub);
|
15464 | var yScale = $$.getYScaleById.bind($$);
|
15465 | return function (d, i) {
|
15466 | var y0 = yScale.call($$, d.id, isSub)($$.getShapeYMin(d.id));
|
15467 | var offset = areaOffset(d, i) || y0;
|
15468 | var posX = x(d);
|
15469 | var posY = y(d);
|
15470 |
|
15471 | if (config.axis_rotated && ((d.value > 0 && posY < y0) || (d.value < 0 && y0 < posY))) {
|
15472 | posY = y0;
|
15473 | }
|
15474 |
|
15475 | return [
|
15476 | [posX, offset],
|
15477 | [posX, posY - (y0 - offset)],
|
15478 | [posX, posY - (y0 - offset)],
|
15479 | [posX, offset]
|
15480 | ];
|
15481 | };
|
15482 | }
|
15483 | };
|
15484 |
|
15485 |
|
15486 |
|
15487 |
|
15488 |
|
15489 | var shapeBar = {
|
15490 | initBar: function () {
|
15491 | var $el = this.$el;
|
15492 | $el.bar = $el.main.select("." + CLASS.chart)
|
15493 |
|
15494 | .insert("g", ":first-child")
|
15495 | .attr("class", CLASS.chartBars);
|
15496 | },
|
15497 | updateTargetsForBar: function (targets) {
|
15498 | var $$ = this;
|
15499 | var config = $$.config, $el = $$.$el;
|
15500 | var classChartBar = $$.getChartClass("Bar");
|
15501 | var classBars = $$.getClass("bars", true);
|
15502 | var classFocus = $$.classFocus.bind($$);
|
15503 | var isSelectable = config.interaction_enabled && config.data_selection_isselectable;
|
15504 | if (!$el.bar) {
|
15505 | $$.initBar();
|
15506 | }
|
15507 | var mainBarUpdate = $$.$el.main.select("." + CLASS.chartBars)
|
15508 | .selectAll("." + CLASS.chartBar)
|
15509 | .data(targets)
|
15510 | .attr("class", function (d) { return classChartBar(d) + classFocus(d); });
|
15511 | var mainBarEnter = mainBarUpdate.enter().append("g")
|
15512 | .attr("class", classChartBar)
|
15513 | .style("opacity", "0")
|
15514 | .style("pointer-events", "none");
|
15515 |
|
15516 | mainBarEnter.append("g")
|
15517 | .attr("class", classBars)
|
15518 | .style("cursor", function (d) { return (isSelectable && isSelectable.bind($$.api)(d) ? "pointer" : null); });
|
15519 | },
|
15520 | |
15521 |
|
15522 |
|
15523 |
|
15524 |
|
15525 |
|
15526 | updateBar: function (durationForExit, isSub) {
|
15527 | if (isSub === void 0) { isSub = false; }
|
15528 | var $$ = this;
|
15529 | var $root = isSub ? $$.$el.subchart : $$.$el;
|
15530 | var classBar = $$.getClass("bar", true);
|
15531 | var initialOpacity = $$.initialOpacity.bind($$);
|
15532 | var bar = $root.main.selectAll("." + CLASS.bars)
|
15533 | .selectAll("." + CLASS.bar)
|
15534 | .data($$.labelishData.bind($$));
|
15535 | bar.exit().transition()
|
15536 | .duration(durationForExit)
|
15537 | .style("opacity", "0")
|
15538 | .remove();
|
15539 | $root.bar = bar.enter().append("path")
|
15540 | .attr("class", classBar)
|
15541 | .style("fill", $$.color)
|
15542 | .merge(bar)
|
15543 | .style("opacity", initialOpacity);
|
15544 | },
|
15545 | |
15546 |
|
15547 |
|
15548 |
|
15549 |
|
15550 |
|
15551 |
|
15552 | redrawBar: function (drawFn, withTransition, isSub) {
|
15553 | if (isSub === void 0) { isSub = false; }
|
15554 | var bar = (isSub ? this.$el.subchart : this.$el).bar;
|
15555 | return [
|
15556 | (withTransition ? bar.transition(getRandom()) : bar)
|
15557 | .attr("d", drawFn)
|
15558 | .style("fill", this.color)
|
15559 | .style("opacity", "1")
|
15560 | ];
|
15561 | },
|
15562 | getBars: function (i, id) {
|
15563 | var $$ = this;
|
15564 | var main = $$.$el.main;
|
15565 | var suffix = (isValue(i) ? "-" + i : "");
|
15566 | return (id ? main
|
15567 | .selectAll("." + CLASS.bars + $$.getTargetSelectorSuffix(id)) : main)
|
15568 | .selectAll("." + CLASS.bar + suffix);
|
15569 | },
|
15570 | expandBars: function (i, id, reset) {
|
15571 | var $$ = this;
|
15572 | reset && $$.unexpandBars();
|
15573 | $$.getBars(i, id).classed(CLASS.EXPANDED, true);
|
15574 | },
|
15575 | unexpandBars: function (i) {
|
15576 | this.getBars(i).classed(CLASS.EXPANDED, false);
|
15577 | },
|
15578 | generateDrawBar: function (barIndices, isSub) {
|
15579 | var $$ = this;
|
15580 | var config = $$.config;
|
15581 | var getPoints = $$.generateGetBarPoints(barIndices, isSub);
|
15582 | var isRotated = config.axis_rotated;
|
15583 | var isGrouped = config.data_groups.length;
|
15584 | var barRadius = config.bar_radius;
|
15585 | var barRadiusRatio = config.bar_radius_ratio;
|
15586 |
|
15587 | var getRadius = isNumber(barRadius) && barRadius > 0 ?
|
15588 | function () { return barRadius; } : (isNumber(barRadiusRatio) ? function (w) { return w * barRadiusRatio; } : null);
|
15589 | return function (d, i) {
|
15590 |
|
15591 | var points = getPoints(d, i);
|
15592 |
|
15593 | var indexX = +isRotated;
|
15594 | var indexY = +!indexX;
|
15595 | var isNegative = d.value < 0;
|
15596 | var pathRadius = ["", ""];
|
15597 | var radius = 0;
|
15598 | if (getRadius && !isGrouped) {
|
15599 | var index = isRotated ? indexY : indexX;
|
15600 | var barW = points[2][index] - points[0][index];
|
15601 | radius = getRadius(barW);
|
15602 | var arc = "a" + radius + "," + radius + " " + (isNegative ? "1 0 0" : "0 0 1") + " ";
|
15603 | pathRadius[+!isRotated] = "" + arc + radius + "," + radius;
|
15604 | pathRadius[+isRotated] = "" + arc + [-radius, radius][isRotated ? "sort" : "reverse"]();
|
15605 | isNegative && pathRadius.reverse();
|
15606 | }
|
15607 |
|
15608 |
|
15609 | var path = isRotated ?
|
15610 | "H" + (points[1][indexX] - radius) + " " + pathRadius[0] + "V" + (points[2][indexY] - radius) + " " + pathRadius[1] + "H" + points[3][indexX] :
|
15611 | "V" + (points[1][indexY] + (isNegative ? -radius : radius)) + " " + pathRadius[0] + "H" + (points[2][indexX] - radius) + " " + pathRadius[1] + "V" + points[3][indexY];
|
15612 | return "M" + points[0][indexX] + "," + points[0][indexY] + path + "z";
|
15613 | };
|
15614 | },
|
15615 | generateGetBarPoints: function (barIndices, isSub) {
|
15616 | var $$ = this;
|
15617 | var config = $$.config;
|
15618 | var axis = isSub ? $$.axis.subX : $$.axis.x;
|
15619 | var barTargetsNum = $$.getIndicesMax(barIndices) + 1;
|
15620 | var barW = $$.getBarW("bar", axis, barTargetsNum);
|
15621 | var barX = $$.getShapeX(barW, barIndices, !!isSub);
|
15622 | var barY = $$.getShapeY(!!isSub);
|
15623 | var barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub);
|
15624 | var yScale = $$.getYScaleById.bind($$);
|
15625 | return function (d, i) {
|
15626 | var y0 = yScale.call($$, d.id, isSub)($$.getShapeYMin(d.id));
|
15627 | var offset = barOffset(d, i) || y0;
|
15628 | var width = isNumber(barW) ? barW : barW[d.id] || barW._$width;
|
15629 | var posX = barX(d);
|
15630 | var posY = barY(d);
|
15631 |
|
15632 | if (config.axis_rotated && ((d.value > 0 && posY < y0) || (d.value < 0 && y0 < posY))) {
|
15633 | posY = y0;
|
15634 | }
|
15635 | posY -= (y0 - offset);
|
15636 | var startPosX = posX + width;
|
15637 |
|
15638 | return [
|
15639 | [posX, offset],
|
15640 | [posX, posY],
|
15641 | [startPosX, posY],
|
15642 | [startPosX, offset]
|
15643 | ];
|
15644 | };
|
15645 | },
|
15646 | isWithinBar: function (that) {
|
15647 | var mouse = getPointer(this.state.event, that);
|
15648 | var list = getRectSegList(that);
|
15649 | var seg0 = list[0], seg1 = list[1];
|
15650 | var x = Math.min(seg0.x, seg1.x);
|
15651 | var y = Math.min(seg0.y, seg1.y);
|
15652 | var offset = this.config.bar_sensitivity;
|
15653 | var _a = that.getBBox(), width = _a.width, height = _a.height;
|
15654 | var sx = x - offset;
|
15655 | var ex = x + width + offset;
|
15656 | var sy = y + height + offset;
|
15657 | var ey = y - offset;
|
15658 | var isWithin = sx < mouse[0] &&
|
15659 | mouse[0] < ex &&
|
15660 | ey < mouse[1] &&
|
15661 | mouse[1] < sy;
|
15662 | return isWithin;
|
15663 | }
|
15664 | };
|
15665 |
|
15666 | var shapeCandlestick = {
|
15667 | initCandlestick: function () {
|
15668 | var $el = this.$el;
|
15669 | $el.candlestick = $el.main.select("." + CLASS.chart)
|
15670 |
|
15671 | .append("g")
|
15672 | .attr("class", CLASS.chartCandlesticks);
|
15673 | },
|
15674 | |
15675 |
|
15676 |
|
15677 |
|
15678 |
|
15679 |
|
15680 | updateTargetsForCandlestick: function (targets) {
|
15681 | var $$ = this;
|
15682 | var $el = $$.$el;
|
15683 | var classChart = $$.getChartClass("Candlestick");
|
15684 | var classFocus = $$.classFocus.bind($$);
|
15685 | if (!$el.candlestick) {
|
15686 | $$.initCandlestick();
|
15687 | }
|
15688 | var mainUpdate = $$.$el.main.select("." + CLASS.chartCandlesticks)
|
15689 | .selectAll("." + CLASS.chartCandlestick)
|
15690 | .data(targets)
|
15691 | .attr("class", function (d) { return classChart(d) + classFocus(d); });
|
15692 | mainUpdate.enter().append("g")
|
15693 | .attr("class", classChart)
|
15694 | .style("pointer-events", "none");
|
15695 | },
|
15696 | |
15697 |
|
15698 |
|
15699 |
|
15700 |
|
15701 |
|
15702 | updateCandlestick: function (durationForExit, isSub) {
|
15703 | if (isSub === void 0) { isSub = false; }
|
15704 | var $$ = this;
|
15705 | var $el = $$.$el;
|
15706 | var $root = isSub ? $el.subchart : $el;
|
15707 | var classSetter = $$.getClass("candlestick", true);
|
15708 | var initialOpacity = $$.initialOpacity.bind($$);
|
15709 | var candlestick = $root.main.selectAll("." + CLASS.chartCandlestick)
|
15710 | .selectAll("." + CLASS.candlestick)
|
15711 | .data($$.labelishData.bind($$));
|
15712 | candlestick.exit().transition()
|
15713 | .duration(durationForExit)
|
15714 | .style("opacity", "0")
|
15715 | .remove();
|
15716 | var candlestickEnter = candlestick.enter()
|
15717 | .filter(function (d) { return d.value; })
|
15718 | .append("g")
|
15719 | .attr("class", classSetter);
|
15720 | candlestickEnter.append("line");
|
15721 | candlestickEnter.append("path");
|
15722 | if (!$root.candlestick) {
|
15723 | $root.candlestick = {};
|
15724 | }
|
15725 | $root.candlestick = candlestick.merge(candlestickEnter)
|
15726 | .style("opacity", initialOpacity);
|
15727 | },
|
15728 | |
15729 |
|
15730 |
|
15731 |
|
15732 |
|
15733 |
|
15734 |
|
15735 | generateDrawCandlestick: function (indices, isSub) {
|
15736 | var $$ = this;
|
15737 | var config = $$.config;
|
15738 | var getPoints = $$.generateGetCandlestickPoints(indices, isSub);
|
15739 | var isRotated = config.axis_rotated;
|
15740 | var downColor = config.candlestick_color_down;
|
15741 | return function (d, i, g) {
|
15742 | var points = getPoints(d, i);
|
15743 | var value = $$.getCandlestickData(d);
|
15744 | var isUp = value === null || value === void 0 ? void 0 : value._isUp;
|
15745 |
|
15746 | var indexX = +isRotated;
|
15747 | var indexY = +!indexX;
|
15748 | if (g.classed) {
|
15749 | g.classed(CLASS[isUp ? "valueUp" : "valueDown"], true);
|
15750 | }
|
15751 | var path = isRotated ?
|
15752 | "H" + points[1][1] + " V" + points[1][0] + " H" + points[0][1] :
|
15753 | "V" + points[1][1] + " H" + points[1][0] + " V" + points[0][1];
|
15754 | g.select("path")
|
15755 | .attr("d", "M" + points[0][indexX] + "," + points[0][indexY] + path + "z")
|
15756 | .style("fill", function (d) {
|
15757 | var color = isUp ? $$.color(d) : (isObject(downColor) ? downColor[d.id] : downColor);
|
15758 | return color || $$.color(d);
|
15759 | });
|
15760 |
|
15761 | var line = g.select("line");
|
15762 | var pos = isRotated ? {
|
15763 | x1: points[2][1],
|
15764 | x2: points[2][2],
|
15765 | y1: points[2][0],
|
15766 | y2: points[2][0]
|
15767 | } : {
|
15768 | x1: points[2][0],
|
15769 | x2: points[2][0],
|
15770 | y1: points[2][1],
|
15771 | y2: points[2][2]
|
15772 | };
|
15773 | for (var x in pos) {
|
15774 | line.attr(x, pos[x]);
|
15775 | }
|
15776 | };
|
15777 | },
|
15778 | |
15779 |
|
15780 |
|
15781 |
|
15782 |
|
15783 |
|
15784 | generateGetCandlestickPoints: function (indices, isSub) {
|
15785 | if (isSub === void 0) { isSub = false; }
|
15786 | var $$ = this;
|
15787 | var config = $$.config;
|
15788 | var axis = isSub ? $$.axis.subX : $$.axis.x;
|
15789 | var targetsNum = $$.getIndicesMax(indices) + 1;
|
15790 | var barW = $$.getBarW("candlestick", axis, targetsNum);
|
15791 | var x = $$.getShapeX(barW, indices, !!isSub);
|
15792 | var y = $$.getShapeY(!!isSub);
|
15793 | var shapeOffset = $$.getShapeOffset($$.isBarType, indices, !!isSub);
|
15794 | var yScale = $$.getYScaleById.bind($$);
|
15795 | return function (d, i) {
|
15796 | var y0 = yScale.call($$, d.id, isSub)($$.getShapeYMin(d.id));
|
15797 | var offset = shapeOffset(d, i) || y0;
|
15798 | var width = isNumber(barW) ? barW : barW[d.id] || barW._$width;
|
15799 | var value = $$.getCandlestickData(d);
|
15800 | var points;
|
15801 | if (value) {
|
15802 | var posX = {
|
15803 | start: x(d),
|
15804 | end: 0
|
15805 | };
|
15806 | posX.end = posX.start + width;
|
15807 | var posY = {
|
15808 | start: y(value.open),
|
15809 | end: y(value.close)
|
15810 | };
|
15811 | var posLine = {
|
15812 | x: posX.start + (width / 2),
|
15813 | high: y(value.high),
|
15814 | low: y(value.low)
|
15815 | };
|
15816 |
|
15817 | if (config.axis_rotated && ((d.value > 0 && posY.start < y0) || (d.value < 0 && y0 < posY.start))) {
|
15818 | posY.start = y0;
|
15819 | }
|
15820 | posY.start -= (y0 - offset);
|
15821 | points = [
|
15822 | [posX.start, posY.start],
|
15823 | [posX.end, posY.end],
|
15824 | [posLine.x, posLine.low, posLine.high]
|
15825 | ];
|
15826 | }
|
15827 | else {
|
15828 | points = [[0, 0], [0, 0], [0, 0, 0]];
|
15829 | }
|
15830 | return points;
|
15831 | };
|
15832 | },
|
15833 | |
15834 |
|
15835 |
|
15836 |
|
15837 |
|
15838 |
|
15839 |
|
15840 | redrawCandlestick: function (drawFn, withTransition, isSub) {
|
15841 | if (isSub === void 0) { isSub = false; }
|
15842 | var candlestick = (isSub ? this.$el.subchart : this.$el).candlestick;
|
15843 | var rand = getRandom(true);
|
15844 | return [
|
15845 | candlestick
|
15846 | .each(function (d, i) {
|
15847 | var g = withTransition ?
|
15848 | select(this).transition(rand) : select(this);
|
15849 | drawFn(d, i, g);
|
15850 | })
|
15851 | .style("opacity", "1")
|
15852 | ];
|
15853 | },
|
15854 | |
15855 |
|
15856 |
|
15857 |
|
15858 |
|
15859 |
|
15860 |
|
15861 | getCandlestickData: function (_a) {
|
15862 | var value = _a.value;
|
15863 | var d;
|
15864 | if (isArray(value)) {
|
15865 | var open_1 = value[0], high = value[1], low = value[2], close_1 = value[3], _b = value[4], volume = _b === void 0 ? false : _b;
|
15866 | d = { open: open_1, high: high, low: low, close: close_1 };
|
15867 | if (volume !== false) {
|
15868 | d.volume = volume;
|
15869 | }
|
15870 | }
|
15871 | else if (isObject(value)) {
|
15872 | d = _assign({}, value);
|
15873 | }
|
15874 | if (d) {
|
15875 | d._isUp = d.close >= d.open;
|
15876 | }
|
15877 | return d || null;
|
15878 | }
|
15879 | };
|
15880 |
|
15881 |
|
15882 |
|
15883 |
|
15884 |
|
15885 | var shapeGauge = {
|
15886 | initGauge: function () {
|
15887 | var $$ = this;
|
15888 | var config = $$.config, arcs = $$.$el.arcs;
|
15889 | var appendText = function (className) {
|
15890 | arcs.append("text")
|
15891 | .attr("class", className)
|
15892 | .style("text-anchor", "middle")
|
15893 | .style("pointer-events", "none");
|
15894 | };
|
15895 | if ($$.hasType("gauge")) {
|
15896 | var hasMulti = $$.hasMultiArcGauge();
|
15897 | arcs.append(hasMulti ? "g" : "path")
|
15898 | .attr("class", CLASS.chartArcsBackground)
|
15899 | .style("fill", (!hasMulti && config.gauge_background) || null);
|
15900 | config.gauge_units && appendText(CLASS.chartArcsGaugeUnit);
|
15901 | if (config.gauge_label_show) {
|
15902 | appendText(CLASS.chartArcsGaugeMin);
|
15903 | !config.gauge_fullCircle && appendText(CLASS.chartArcsGaugeMax);
|
15904 | }
|
15905 | }
|
15906 | },
|
15907 | updateGaugeMax: function () {
|
15908 | var $$ = this;
|
15909 | var config = $$.config, state = $$.state;
|
15910 | var hasMultiGauge = $$.hasMultiArcGauge();
|
15911 |
|
15912 | var max = hasMultiGauge ?
|
15913 | $$.getMinMaxData().max[0].value : $$.getTotalDataSum(state.rendered);
|
15914 |
|
15915 | if (max > config.gauge_max) {
|
15916 | config.gauge_max = max;
|
15917 | }
|
15918 | },
|
15919 | redrawMultiArcGauge: function () {
|
15920 | var $$ = this;
|
15921 | var config = $$.config, state = $$.state, $el = $$.$el;
|
15922 | var hiddenTargetIds = $$.state.hiddenTargetIds;
|
15923 | var arcLabelLines = $el.main.selectAll("." + CLASS.arcs)
|
15924 | .selectAll("." + CLASS.arcLabelLine)
|
15925 | .data($$.arcData.bind($$));
|
15926 | var mainArcLabelLine = arcLabelLines.enter()
|
15927 | .append("rect")
|
15928 | .attr("class", function (d) { return CLASS.arcLabelLine + " " + CLASS.target + " " + CLASS.target + "-" + d.data.id; })
|
15929 | .merge(arcLabelLines);
|
15930 | mainArcLabelLine
|
15931 | .style("fill", function (d) { return ($$.levelColor ? $$.levelColor(d.data.values[0].value) : $$.color(d.data)); })
|
15932 | .style("display", config.gauge_label_show ? "" : "none")
|
15933 | .each(function (d) {
|
15934 | var lineLength = 0;
|
15935 | var lineThickness = 2;
|
15936 | var x = 0;
|
15937 | var y = 0;
|
15938 | var transform = "";
|
15939 | if (hiddenTargetIds.indexOf(d.data.id) < 0) {
|
15940 | var updated = $$.updateAngle(d);
|
15941 | var innerLineLength = state.gaugeArcWidth / $$.filterTargetsToShow($$.data.targets).length *
|
15942 | (updated.index + 1);
|
15943 | var lineAngle = updated.endAngle - Math.PI / 2;
|
15944 | var arcInnerRadius = state.radius - innerLineLength;
|
15945 | var linePositioningAngle = lineAngle - (arcInnerRadius === 0 ? 0 : (1 / arcInnerRadius));
|
15946 | lineLength = state.radiusExpanded - state.radius + innerLineLength;
|
15947 | x = Math.cos(linePositioningAngle) * arcInnerRadius;
|
15948 | y = Math.sin(linePositioningAngle) * arcInnerRadius;
|
15949 | transform = "rotate(" + lineAngle * 180 / Math.PI + ", " + x + ", " + y + ")";
|
15950 | }
|
15951 | select(this)
|
15952 | .attr("x", x)
|
15953 | .attr("y", y)
|
15954 | .attr("width", lineLength)
|
15955 | .attr("height", lineThickness)
|
15956 | .attr("transform", transform)
|
15957 | .style("stroke-dasharray", "0, " + (lineLength + lineThickness) + ", 0");
|
15958 | });
|
15959 | },
|
15960 | textForGaugeMinMax: function (value, isMax) {
|
15961 | var $$ = this;
|
15962 | var config = $$.config;
|
15963 | var format = config.gauge_label_extents;
|
15964 | return isFunction(format) ? format.bind($$.api)(value, isMax) : value;
|
15965 | },
|
15966 | getGaugeLabelHeight: function () {
|
15967 | var config = this.config;
|
15968 | return this.config.gauge_label_show && !config.gauge_fullCircle ? 20 : 0;
|
15969 | },
|
15970 | getPaddingBottomForGauge: function () {
|
15971 | var $$ = this;
|
15972 | return $$.getGaugeLabelHeight() * ($$.config.gauge_label_show ? 2 : 2.5);
|
15973 | }
|
15974 | };
|
15975 |
|
15976 |
|
15977 |
|
15978 |
|
15979 |
|
15980 | var shapeBubble = {
|
15981 | |
15982 |
|
15983 |
|
15984 |
|
15985 | initBubble: function () {
|
15986 | var $$ = this;
|
15987 | var config = $$.config;
|
15988 | if ($$.hasType("bubble")) {
|
15989 | config.point_show = true;
|
15990 | config.point_type = "circle";
|
15991 | config.point_sensitivity = 25;
|
15992 | }
|
15993 | },
|
15994 | |
15995 |
|
15996 |
|
15997 |
|
15998 |
|
15999 | getBaseLength: function () {
|
16000 | var $$ = this;
|
16001 | var _a = $$.state, width = _a.width, height = _a.height;
|
16002 | var cacheKey = KEY.bubbleBaseLength;
|
16003 | var baseLength = $$.cache.get(cacheKey);
|
16004 | if (!baseLength) {
|
16005 | $$.cache.add(cacheKey, baseLength = getMinMax$1("min", [width, height]));
|
16006 | }
|
16007 | return baseLength;
|
16008 | },
|
16009 | |
16010 |
|
16011 |
|
16012 |
|
16013 |
|
16014 |
|
16015 | getBubbleR: function (d) {
|
16016 | var $$ = this;
|
16017 | var maxR = $$.config.bubble_maxR;
|
16018 | if (isFunction(maxR)) {
|
16019 | maxR = maxR.bind($$.api)(d);
|
16020 | }
|
16021 | else if (!isNumber(maxR)) {
|
16022 | maxR = ($$.getBaseLength() / ($$.getMaxDataCount() * 2)) + 12;
|
16023 | }
|
16024 | var max = getMinMax$1("max", $$.getMinMaxData().max.map(function (d) { return ($$.isBubbleZType(d) ?
|
16025 | $$.getBubbleZData(d.value, "y") : (isObject(d.value) ? d.value.mid : d.value)); }));
|
16026 | var maxArea = maxR * maxR * Math.PI;
|
16027 | var area = ($$.isBubbleZType(d) ? $$.getBubbleZData(d.value, "z") : d.value) * (maxArea / max);
|
16028 | return Math.sqrt(area / Math.PI);
|
16029 | },
|
16030 | |
16031 |
|
16032 |
|
16033 |
|
16034 |
|
16035 |
|
16036 |
|
16037 | getBubbleZData: function (d, type) {
|
16038 | return isObject(d) ? d[type] : d[type === "y" ? 0 : 1];
|
16039 | }
|
16040 | };
|
16041 |
|
16042 |
|
16043 |
|
16044 |
|
16045 |
|
16046 | var shapeLine = {
|
16047 | initLine: function () {
|
16048 | var $el = this.$el;
|
16049 | $el.line = $el.main.select("." + CLASS.chart).append("g")
|
16050 | .attr("class", CLASS.chartLines);
|
16051 | },
|
16052 | updateTargetsForLine: function (t) {
|
16053 | var $$ = this;
|
16054 | var _a = $$.$el, area = _a.area, line = _a.line, main = _a.main;
|
16055 | var classChartLine = $$.getChartClass("Line");
|
16056 | var classLines = $$.getClass("lines", true);
|
16057 | var classFocus = $$.classFocus.bind($$);
|
16058 | if (!line) {
|
16059 | $$.initLine();
|
16060 | }
|
16061 | var targets = t.filter(function (d) { return !($$.isScatterType(d) || $$.isBubbleType(d)); });
|
16062 | var mainLineUpdate = main.select("." + CLASS.chartLines)
|
16063 | .selectAll("." + CLASS.chartLine)
|
16064 | .data(targets)
|
16065 | .attr("class", function (d) { return classChartLine(d) + classFocus(d); });
|
16066 | var mainLineEnter = mainLineUpdate.enter().append("g")
|
16067 | .attr("class", classChartLine)
|
16068 | .style("opacity", "0")
|
16069 | .style("pointer-events", "none");
|
16070 |
|
16071 | mainLineEnter.append("g")
|
16072 | .attr("class", classLines);
|
16073 |
|
16074 | if ($$.hasTypeOf("Area")) {
|
16075 | $$.initArea(!area && mainLineEnter.empty() ? mainLineUpdate : mainLineEnter);
|
16076 | }
|
16077 | $$.updateTargetForCircle(targets, mainLineEnter);
|
16078 | },
|
16079 | |
16080 |
|
16081 |
|
16082 |
|
16083 |
|
16084 |
|
16085 | updateLine: function (durationForExit, isSub) {
|
16086 | if (isSub === void 0) { isSub = false; }
|
16087 | var $$ = this;
|
16088 | var extraLineClasses = $$.format.extraLineClasses, $el = $$.$el;
|
16089 | var $root = isSub ? $el.subchart : $el;
|
16090 | var line = $root.main
|
16091 | .selectAll("." + CLASS.lines)
|
16092 | .selectAll("." + CLASS.line)
|
16093 | .data($$.lineData.bind($$));
|
16094 | line.exit().transition()
|
16095 | .duration(durationForExit)
|
16096 | .style("opacity", "0")
|
16097 | .remove();
|
16098 | $root.line = line.enter()
|
16099 | .append("path")
|
16100 | .attr("class", function (d) { return $$.getClass("line", true)(d) + " " + (extraLineClasses(d) || ""); })
|
16101 | .style("stroke", $$.color)
|
16102 | .merge(line)
|
16103 | .style("opacity", $$.initialOpacity.bind($$))
|
16104 | .style("shape-rendering", function (d) { return ($$.isStepType(d) ? "crispEdges" : ""); })
|
16105 | .attr("transform", null);
|
16106 | },
|
16107 | |
16108 |
|
16109 |
|
16110 |
|
16111 |
|
16112 |
|
16113 |
|
16114 | redrawLine: function (drawFn, withTransition, isSub) {
|
16115 | if (isSub === void 0) { isSub = false; }
|
16116 | var line = (isSub ? this.$el.subchart : this.$el).line;
|
16117 | return [
|
16118 | (withTransition ? line.transition(getRandom()) : line)
|
16119 | .attr("d", drawFn)
|
16120 | .style("stroke", this.color)
|
16121 | .style("opacity", "1")
|
16122 | ];
|
16123 | },
|
16124 | |
16125 |
|
16126 |
|
16127 |
|
16128 |
|
16129 |
|
16130 | getCurve: function (d) {
|
16131 | var $$ = this;
|
16132 | var isRotatedStepType = $$.config.axis_rotated && $$.isStepType(d);
|
16133 |
|
16134 |
|
16135 | return isRotatedStepType ? function (context) {
|
16136 | var step = $$.getInterpolate(d)(context);
|
16137 |
|
16138 | step.orgPoint = step.point;
|
16139 |
|
16140 | step.pointRotated = function (x, y) {
|
16141 | this._point === 1 && (this._point = 2);
|
16142 | var y1 = this._y * (1 - this._t) + y * this._t;
|
16143 | this._context.lineTo(this._x, y1);
|
16144 | this._context.lineTo(x, y1);
|
16145 | this._x = x;
|
16146 | this._y = y;
|
16147 | };
|
16148 | step.point = function (x, y) {
|
16149 | this._point === 0 ? this.orgPoint(x, y) : this.pointRotated(x, y);
|
16150 | };
|
16151 | return step;
|
16152 | } : $$.getInterpolate(d);
|
16153 | },
|
16154 | generateDrawLine: function (lineIndices, isSub) {
|
16155 | var $$ = this;
|
16156 | var config = $$.config, scale = $$.scale;
|
16157 | var lineConnectNull = config.line_connectNull;
|
16158 | var isRotated = config.axis_rotated;
|
16159 | var getPoints = $$.generateGetLinePoints(lineIndices, isSub);
|
16160 | var yScale = $$.getYScaleById.bind($$);
|
16161 | var xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); };
|
16162 | var yValue = function (d, i) { return ($$.isGrouped(d.id) ?
|
16163 | getPoints(d, i)[0][1] :
|
16164 | yScale(d.id, isSub)($$.getBaseValue(d))); };
|
16165 | var line = line$1();
|
16166 | line = isRotated ?
|
16167 | line.x(yValue).y(xValue) : line.x(xValue).y(yValue);
|
16168 | if (!lineConnectNull) {
|
16169 | line = line.defined(function (d) { return $$.getBaseValue(d) !== null; });
|
16170 | }
|
16171 | var x = isSub ? scale.subX : scale.x;
|
16172 | return function (d) {
|
16173 | var y = yScale(d.id, isSub);
|
16174 | var values = lineConnectNull ? $$.filterRemoveNull(d.values) : d.values;
|
16175 | var x0 = 0;
|
16176 | var y0 = 0;
|
16177 | var path;
|
16178 | if ($$.isLineType(d)) {
|
16179 | var regions = config.data_regions[d.id];
|
16180 | if (regions) {
|
16181 | path = $$.lineWithRegions(values, x, y, regions);
|
16182 | }
|
16183 | else {
|
16184 | if ($$.isStepType(d)) {
|
16185 | values = $$.convertValuesToStep(values);
|
16186 | }
|
16187 | path = line.curve($$.getCurve(d))(values);
|
16188 | }
|
16189 | }
|
16190 | else {
|
16191 | if (values[0]) {
|
16192 | x0 = x(values[0].x);
|
16193 | y0 = y(values[0].value);
|
16194 | }
|
16195 | path = isRotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0;
|
16196 | }
|
16197 | return path || "M 0 0";
|
16198 | };
|
16199 | },
|
16200 | lineWithRegions: function (d, x, y, _regions) {
|
16201 | var $$ = this;
|
16202 | var config = $$.config;
|
16203 | var isRotated = config.axis_rotated;
|
16204 | var isTimeSeries = $$.axis.isTimeSeries();
|
16205 | var xOffset = $$.axis.isCategorized() ? 0.5 : 0;
|
16206 | var regions = [];
|
16207 | var dasharray = "2 2";
|
16208 | var xp;
|
16209 | var yp;
|
16210 | var diff;
|
16211 | var diffx2;
|
16212 |
|
16213 | var isWithinRegions = function (withinX, withinRegions) {
|
16214 | for (var i = 0, reg = void 0; (reg = withinRegions[i]); i++) {
|
16215 | if (reg.start < withinX && withinX <= reg.end) {
|
16216 | return reg.style;
|
16217 | }
|
16218 | }
|
16219 | return false;
|
16220 | };
|
16221 |
|
16222 | if (isDefined(_regions)) {
|
16223 | var getValue = function (v, def) { return (isUndefined(v) ? def : (isTimeSeries ? parseDate.call($$, v) : v)); };
|
16224 | for (var i = 0, reg = void 0; (reg = _regions[i]); i++) {
|
16225 | var start = getValue(reg.start, d[0].x);
|
16226 | var end = getValue(reg.end, d[d.length - 1].x);
|
16227 | var style = reg.style || { dasharray: dasharray };
|
16228 | regions[i] = { start: start, end: end, style: style };
|
16229 | }
|
16230 | }
|
16231 |
|
16232 | var xValue = isRotated ? function (dt) { return y(dt.value); } : function (dt) { return x(dt.x); };
|
16233 | var yValue = isRotated ? function (dt) { return x(dt.x); } : function (dt) { return y(dt.value); };
|
16234 |
|
16235 | var generateM = function (points) { return "M" + points[0][0] + "," + points[0][1] + "L" + points[1][0] + "," + points[1][1]; };
|
16236 | var sWithRegion = isTimeSeries ? function (d0, d1, k, timeseriesDiff) {
|
16237 | var x0 = d0.x.getTime();
|
16238 | var xDiff = d1.x - d0.x;
|
16239 | var xv0 = new Date(x0 + xDiff * k);
|
16240 | var xv1 = new Date(x0 + xDiff * (k + timeseriesDiff));
|
16241 | var points = isRotated ?
|
16242 | [[y(yp(k)), x(xv0)], [y(yp(k + diff)), x(xv1)]] :
|
16243 | [[x(xv0), y(yp(k))], [x(xv1), y(yp(k + diff))]];
|
16244 | return generateM(points);
|
16245 | } : function (d0, d1, k, otherDiff) {
|
16246 | var points = isRotated ?
|
16247 | [[y(yp(k), true), x(xp(k))], [y(yp(k + otherDiff), true), x(xp(k + otherDiff))]] :
|
16248 | [[x(xp(k), true), y(yp(k))], [x(xp(k + otherDiff), true), y(yp(k + otherDiff))]];
|
16249 | return generateM(points);
|
16250 | };
|
16251 |
|
16252 | var axisType = { x: $$.axis.getAxisType("x"), y: $$.axis.getAxisType("y") };
|
16253 | var path = "";
|
16254 | for (var i = 0, data = void 0; (data = d[i]); i++) {
|
16255 | var prevData = d[i - 1];
|
16256 | var hasPrevData = prevData && isValue(prevData.value);
|
16257 | var style = isWithinRegions(data.x, regions);
|
16258 |
|
16259 | if (!isValue(data.value)) {
|
16260 | continue;
|
16261 | }
|
16262 |
|
16263 | if (isUndefined(regions) || !style || !hasPrevData) {
|
16264 | path += "" + (i && hasPrevData ? "L" : "M") + xValue(data) + "," + yValue(data);
|
16265 | }
|
16266 | else if (hasPrevData) {
|
16267 | try {
|
16268 | style = style.dasharray.split(" ");
|
16269 | }
|
16270 | catch (e) {
|
16271 | style = dasharray.split(" ");
|
16272 | }
|
16273 |
|
16274 | xp = getScale(axisType.x, prevData.x + xOffset, data.x + xOffset);
|
16275 | yp = getScale(axisType.y, prevData.value, data.value);
|
16276 | var dx = x(data.x) - x(prevData.x);
|
16277 | var dy = y(data.value) - y(prevData.value);
|
16278 | var dd = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
|
16279 | diff = style[0] / dd;
|
16280 | diffx2 = diff * style[1];
|
16281 | for (var j = diff; j <= 1; j += diffx2) {
|
16282 | path += sWithRegion(prevData, data, j, diff);
|
16283 |
|
16284 | if (j + diffx2 >= 1) {
|
16285 | path += sWithRegion(prevData, data, 1, 0);
|
16286 | }
|
16287 | }
|
16288 | }
|
16289 | }
|
16290 | return path;
|
16291 | },
|
16292 | isWithinStep: function (that, y) {
|
16293 | return Math.abs(y - getPointer(this.state.event, that)[1]) < 30;
|
16294 | },
|
16295 | shouldDrawPointsForLine: function (d) {
|
16296 | var linePoint = this.config.line_point;
|
16297 | return linePoint === true ||
|
16298 | (isArray(linePoint) && linePoint.indexOf(d.id) !== -1);
|
16299 | }
|
16300 | };
|
16301 |
|
16302 | var getTransitionName = function () { return getRandom(); };
|
16303 | var shapePoint = {
|
16304 | hasValidPointType: function (type) {
|
16305 | return /^(circle|rect(angle)?|polygon|ellipse|use)$/i.test(type || this.config.point_type);
|
16306 | },
|
16307 | hasValidPointDrawMethods: function (type) {
|
16308 | var pointType = type || this.config.point_type;
|
16309 | return isObjectType(pointType) &&
|
16310 | isFunction(pointType.create) && isFunction(pointType.update);
|
16311 | },
|
16312 | initialOpacityForCircle: function (d) {
|
16313 | var _a = this, config = _a.config, withoutFadeIn = _a.state.withoutFadeIn;
|
16314 | var opacity = config.point_opacity;
|
16315 | if (isUndefined(opacity)) {
|
16316 | opacity = this.getBaseValue(d) !== null &&
|
16317 | withoutFadeIn[d.id] ? this.opacityForCircle(d) : "0";
|
16318 | }
|
16319 | return opacity;
|
16320 | },
|
16321 | opacityForCircle: function (d) {
|
16322 | var config = this.config;
|
16323 | var opacity = config.point_opacity;
|
16324 | if (isUndefined(opacity)) {
|
16325 | opacity = config.point_show && !config.point_focus_only ? "1" : "0";
|
16326 | opacity = isValue(this.getBaseValue(d)) ?
|
16327 | (this.isBubbleType(d) || this.isScatterType(d) ?
|
16328 | "0.5" : opacity) : "0";
|
16329 | }
|
16330 | return opacity;
|
16331 | },
|
16332 | initCircle: function () {
|
16333 | var $$ = this;
|
16334 | var main = $$.$el.main;
|
16335 | $$.point = $$.generatePoint();
|
16336 | if (($$.hasType("bubble") || $$.hasType("scatter")) && main.select("." + CLASS.chartCircles).empty()) {
|
16337 | main.select("." + CLASS.chart)
|
16338 | .append("g")
|
16339 | .attr("class", CLASS.chartCircles);
|
16340 | }
|
16341 | },
|
16342 | updateTargetForCircle: function (targetsValue, enterNodeValue) {
|
16343 | var _this = this;
|
16344 | var $$ = this;
|
16345 | var config = $$.config, data = $$.data, $el = $$.$el;
|
16346 | var selectionEnabled = config.interaction_enabled && config.data_selection_enabled;
|
16347 | var isSelectable = selectionEnabled && config.data_selection_isselectable;
|
16348 | var classCircles = $$.getClass("circles", true);
|
16349 | if (!config.point_show) {
|
16350 | return;
|
16351 | }
|
16352 | !$el.circle && $$.initCircle();
|
16353 | var targets = targetsValue;
|
16354 | var enterNode = enterNodeValue;
|
16355 |
|
16356 | if (!targets) {
|
16357 | targets = (data.targets)
|
16358 | .filter(function (d) { return _this.isScatterType(d) || _this.isBubbleType(d); });
|
16359 | var mainCircle = $el.main.select("." + CLASS.chartCircles)
|
16360 | .style("pointer-events", "none")
|
16361 | .selectAll("." + CLASS.circles)
|
16362 | .data(targets)
|
16363 | .attr("class", classCircles);
|
16364 | mainCircle.exit().remove();
|
16365 | enterNode = mainCircle.enter();
|
16366 | }
|
16367 |
|
16368 | selectionEnabled && enterNode.append("g")
|
16369 | .attr("class", function (d) { return $$.generateClass(CLASS.selectedCircles, d.id); });
|
16370 | enterNode.append("g")
|
16371 | .attr("class", classCircles)
|
16372 | .style("cursor", function (d) { return (isSelectable && isSelectable(d) ? "pointer" : null); });
|
16373 |
|
16374 | selectionEnabled && targets.forEach(function (t) {
|
16375 | $el.main.selectAll("." + CLASS.selectedCircles + $$.getTargetSelectorSuffix(t.id))
|
16376 | .selectAll("" + CLASS.selectedCircle)
|
16377 | .each(function (d) {
|
16378 | d.value = t.values[d.index].value;
|
16379 | });
|
16380 | });
|
16381 | },
|
16382 | updateCircle: function (isSub) {
|
16383 | if (isSub === void 0) { isSub = false; }
|
16384 | var $$ = this;
|
16385 | var config = $$.config, state = $$.state, $el = $$.$el;
|
16386 | var focusOnly = config.point_focus_only;
|
16387 | var $root = isSub ? $el.subchart : $el;
|
16388 | if (config.point_show && !state.toggling) {
|
16389 | var circles = $root.main.selectAll("." + CLASS.circles)
|
16390 | .selectAll("." + CLASS.circle)
|
16391 | .data(function (d) { return (($$.isLineType(d) && $$.shouldDrawPointsForLine(d)) ||
|
16392 | $$.isBubbleType(d) || $$.isRadarType(d) || $$.isScatterType(d) ?
|
16393 | (focusOnly ? [d.values[0]] : d.values) : []); });
|
16394 | circles.exit().remove();
|
16395 | circles.enter()
|
16396 | .filter(Boolean)
|
16397 | .append($$.point("create", this, $$.pointR.bind($$), $$.color));
|
16398 | $root.circle = $root.main.selectAll("." + CLASS.circles + " ." + CLASS.circle)
|
16399 | .style("stroke", $$.color)
|
16400 | .style("opacity", $$.initialOpacityForCircle.bind($$));
|
16401 | }
|
16402 | },
|
16403 | redrawCircle: function (cx, cy, withTransition, flow, isSub) {
|
16404 | if (isSub === void 0) { isSub = false; }
|
16405 | var $$ = this;
|
16406 | var rendered = $$.state.rendered, $el = $$.$el;
|
16407 | var $root = isSub ? $el.subchart : $el;
|
16408 | var selectedCircles = $root.main.selectAll("." + CLASS.selectedCircle);
|
16409 | if (!$$.config.point_show) {
|
16410 | return [];
|
16411 | }
|
16412 | var fn = $$.point("update", $$, cx, cy, $$.color, withTransition, flow, selectedCircles);
|
16413 | var posAttr = $$.isCirclePoint() ? "c" : "";
|
16414 | var t = getRandom();
|
16415 | var opacityStyleFn = $$.opacityForCircle.bind($$);
|
16416 | var mainCircles = [];
|
16417 | $root.circle.each(function (d) {
|
16418 | var result = fn.bind(this)(d);
|
16419 | result = ((withTransition || !rendered) ? result.transition(t) : result)
|
16420 | .style("opacity", opacityStyleFn);
|
16421 | mainCircles.push(result);
|
16422 | });
|
16423 | return [
|
16424 | mainCircles,
|
16425 | (withTransition ? selectedCircles.transition() : selectedCircles)
|
16426 | .attr(posAttr + "x", cx)
|
16427 | .attr(posAttr + "y", cy)
|
16428 | ];
|
16429 | },
|
16430 | |
16431 |
|
16432 |
|
16433 |
|
16434 |
|
16435 | showCircleFocus: function (d) {
|
16436 | var $$ = this;
|
16437 | var config = $$.config, _a = $$.state, hasRadar = _a.hasRadar, resizing = _a.resizing, toggling = _a.toggling, transiting = _a.transiting, $el = $$.$el;
|
16438 | var circle = $el.circle;
|
16439 | if (transiting === false && config.point_focus_only && circle) {
|
16440 | var cx = (hasRadar ? $$.radarCircleX : $$.circleX).bind($$);
|
16441 | var cy = (hasRadar ? $$.radarCircleY : $$.circleY).bind($$);
|
16442 | var withTransition = toggling || isUndefined(d);
|
16443 | var fn_1 = $$.point("update", $$, cx, cy, $$.color, resizing ? false : withTransition);
|
16444 | if (d) {
|
16445 | circle = circle
|
16446 | .filter(function (t) {
|
16447 | var data = d.filter(function (v) { return v.id === t.id; });
|
16448 | return data.length ?
|
16449 | select(this).datum(data[0]) : false;
|
16450 | });
|
16451 | }
|
16452 | circle
|
16453 | .attr("class", this.updatePointClass.bind(this))
|
16454 | .style("opacity", "1")
|
16455 | .each(function (d) {
|
16456 | var id = d.id, index = d.index, value = d.value;
|
16457 | var visibility = "hidden";
|
16458 | if (isValue(value)) {
|
16459 | fn_1.bind(this)(d);
|
16460 | $$.expandCircles(index, id);
|
16461 | visibility = "";
|
16462 | }
|
16463 | this.style.visibility = visibility;
|
16464 | });
|
16465 | }
|
16466 | },
|
16467 | |
16468 |
|
16469 |
|
16470 |
|
16471 | hideCircleFocus: function () {
|
16472 | var $$ = this;
|
16473 | var config = $$.config, circle = $$.$el.circle;
|
16474 | if (config.point_focus_only && circle) {
|
16475 | $$.unexpandCircles();
|
16476 | circle.style("visibility", "hidden");
|
16477 | }
|
16478 | },
|
16479 | circleX: function (d) {
|
16480 | return this.xx(d);
|
16481 | },
|
16482 | updateCircleY: function (isSub) {
|
16483 | if (isSub === void 0) { isSub = false; }
|
16484 | var $$ = this;
|
16485 | var getPoints = $$.generateGetLinePoints($$.getShapeIndices($$.isLineType), isSub);
|
16486 | return function (d, i) {
|
16487 | var id = d.id;
|
16488 | return $$.isGrouped(id) ?
|
16489 | getPoints(d, i)[0][1] :
|
16490 | $$.getYScaleById(id, isSub)($$.getBaseValue(d));
|
16491 | };
|
16492 | },
|
16493 | getCircles: function (i, id) {
|
16494 | var $$ = this;
|
16495 | var suffix = (isValue(i) ? "-" + i : "");
|
16496 | return (id ? $$.$el.main.selectAll("." + CLASS.circles + $$.getTargetSelectorSuffix(id)) : $$.$el.main)
|
16497 | .selectAll("." + CLASS.circle + suffix);
|
16498 | },
|
16499 | expandCircles: function (i, id, reset) {
|
16500 | var $$ = this;
|
16501 | var r = $$.pointExpandedR.bind($$);
|
16502 | reset && $$.unexpandCircles();
|
16503 | var circles = $$.getCircles(i, id).classed(CLASS.EXPANDED, true);
|
16504 | var scale = r(circles) / $$.config.point_r;
|
16505 | var ratio = 1 - scale;
|
16506 | if ($$.isCirclePoint()) {
|
16507 | circles.attr("r", r);
|
16508 | }
|
16509 | else {
|
16510 |
|
16511 | circles.each(function () {
|
16512 | var point = select(this);
|
16513 | if (this.tagName === "circle") {
|
16514 | point.attr("r", r);
|
16515 | }
|
16516 | else {
|
16517 | var _a = this.getBBox(), width = _a.width, height = _a.height;
|
16518 | var x = ratio * (+point.attr("x") + width / 2);
|
16519 | var y = ratio * (+point.attr("y") + height / 2);
|
16520 | point.attr("transform", "translate(" + x + " " + y + ") scale(" + scale + ")");
|
16521 | }
|
16522 | });
|
16523 | }
|
16524 | },
|
16525 | unexpandCircles: function (i) {
|
16526 | var $$ = this;
|
16527 | var r = $$.pointR.bind($$);
|
16528 | var circles = $$.getCircles(i)
|
16529 | .filter(function () {
|
16530 | return select(this).classed(CLASS.EXPANDED);
|
16531 | })
|
16532 | .classed(CLASS.EXPANDED, false);
|
16533 | circles.attr("r", r);
|
16534 | !$$.isCirclePoint() &&
|
16535 | circles.attr("transform", "scale(" + r(circles) / $$.config.point_r + ")");
|
16536 | },
|
16537 | pointR: function (d) {
|
16538 | var $$ = this;
|
16539 | var config = $$.config;
|
16540 | var pointR = config.point_r;
|
16541 | var r = pointR;
|
16542 | if ($$.isBubbleType(d)) {
|
16543 | r = $$.getBubbleR(d);
|
16544 | }
|
16545 | else if (isFunction(pointR)) {
|
16546 | r = pointR.bind($$.api)(d);
|
16547 | }
|
16548 | return r;
|
16549 | },
|
16550 | pointExpandedR: function (d) {
|
16551 | var $$ = this;
|
16552 | var config = $$.config;
|
16553 | var scale = $$.isBubbleType(d) ? 1.15 : 1.75;
|
16554 | return config.point_focus_expand_enabled ?
|
16555 | (config.point_focus_expand_r || $$.pointR(d) * scale) : $$.pointR(d);
|
16556 | },
|
16557 | pointSelectR: function (d) {
|
16558 | var $$ = this;
|
16559 | var selectR = $$.config.point_select_r;
|
16560 | return isFunction(selectR) ?
|
16561 | selectR(d) : (selectR || $$.pointR(d) * 4);
|
16562 | },
|
16563 | isWithinCircle: function (node, r) {
|
16564 | var mouse = getPointer(this.state.event, node);
|
16565 | var element = select(node);
|
16566 | var prefix = this.isCirclePoint(node) ? "c" : "";
|
16567 | var cx = +element.attr(prefix + "x");
|
16568 | var cy = +element.attr(prefix + "y");
|
16569 |
|
16570 | if (!(cx || cy) && node.nodeType === 1) {
|
16571 | var _a = getBoundingRect(node), x = _a.x, y = _a.y;
|
16572 | cx = x;
|
16573 | cy = y;
|
16574 | }
|
16575 | return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < (r || this.config.point_sensitivity);
|
16576 | },
|
16577 | insertPointInfoDefs: function (point, id) {
|
16578 | var $$ = this;
|
16579 | var copyAttr = function (from, target) {
|
16580 | var attribs = from.attributes;
|
16581 | for (var i = 0, name_1; (name_1 = attribs[i]); i++) {
|
16582 | name_1 = name_1.name;
|
16583 | target.setAttribute(name_1, from.getAttribute(name_1));
|
16584 | }
|
16585 | };
|
16586 | var doc$1 = new DOMParser().parseFromString(point, "image/svg+xml");
|
16587 | var node = doc$1.documentElement;
|
16588 | var clone = doc.createElementNS(namespaces.svg, node.nodeName.toLowerCase());
|
16589 | clone.id = id;
|
16590 | clone.style.fill = "inherit";
|
16591 | clone.style.stroke = "inherit";
|
16592 | copyAttr(node, clone);
|
16593 | if (node.childNodes && node.childNodes.length) {
|
16594 | var parent_1 = select(clone);
|
16595 | if ("innerHTML" in clone) {
|
16596 | parent_1.html(node.innerHTML);
|
16597 | }
|
16598 | else {
|
16599 | toArray(node.childNodes).forEach(function (v) {
|
16600 | copyAttr(v, parent_1.append(v.tagName).node());
|
16601 | });
|
16602 | }
|
16603 | }
|
16604 | $$.$el.defs.node().appendChild(clone);
|
16605 | },
|
16606 | pointFromDefs: function (id) {
|
16607 | return this.$el.defs.select("#" + id);
|
16608 | },
|
16609 | updatePointClass: function (d) {
|
16610 | var $$ = this;
|
16611 | var circle = $$.$el.circle;
|
16612 | var pointClass = false;
|
16613 | if (isObject(d) || circle) {
|
16614 | pointClass = d === true ?
|
16615 | circle.each(function (d) {
|
16616 | var className = $$.getClass("circle", true)(d);
|
16617 | if (this.getAttribute("class").indexOf(CLASS.EXPANDED) > -1) {
|
16618 | className += " " + CLASS.EXPANDED;
|
16619 | }
|
16620 | this.setAttribute("class", className);
|
16621 | }) : $$.getClass("circle", true)(d);
|
16622 | }
|
16623 | return pointClass;
|
16624 | },
|
16625 | generateGetLinePoints: function (lineIndices, isSub) {
|
16626 | var $$ = this;
|
16627 | var config = $$.config;
|
16628 | var x = $$.getShapeX(0, lineIndices, isSub);
|
16629 | var y = $$.getShapeY(isSub);
|
16630 | var lineOffset = $$.getShapeOffset($$.isLineType, lineIndices, isSub);
|
16631 | var yScale = $$.getYScaleById.bind($$);
|
16632 | return function (d, i) {
|
16633 | var y0 = yScale.call($$, d.id, isSub)($$.getShapeYMin(d.id));
|
16634 | var offset = lineOffset(d, i) || y0;
|
16635 | var posX = x(d);
|
16636 | var posY = y(d);
|
16637 |
|
16638 | if (config.axis_rotated && ((d.value > 0 && posY < y0) || (d.value < 0 && y0 < posY))) {
|
16639 | posY = y0;
|
16640 | }
|
16641 |
|
16642 | var point = [posX, posY - (y0 - offset)];
|
16643 | return [
|
16644 | point,
|
16645 | point,
|
16646 | point,
|
16647 | point
|
16648 | ];
|
16649 | };
|
16650 | },
|
16651 | generatePoint: function () {
|
16652 | var $$ = this;
|
16653 | var config = $$.config, datetimeId = $$.state.datetimeId;
|
16654 | var ids = [];
|
16655 | var pattern = notEmpty(config.point_pattern) ? config.point_pattern : [config.point_type];
|
16656 | return function (method, context) {
|
16657 | var args = [];
|
16658 | for (var _i = 2; _i < arguments.length; _i++) {
|
16659 | args[_i - 2] = arguments[_i];
|
16660 | }
|
16661 | return function (d) {
|
16662 | var id = $$.getTargetSelectorSuffix(d.id || (d.data && d.data.id) || d);
|
16663 | var element = select(this);
|
16664 | ids.indexOf(id) < 0 && ids.push(id);
|
16665 | var point = pattern[ids.indexOf(id) % pattern.length];
|
16666 | if ($$.hasValidPointType(point)) {
|
16667 | point = $$[point];
|
16668 | }
|
16669 | else if (!$$.hasValidPointDrawMethods(point)) {
|
16670 | var pointId = datetimeId + "-point" + id;
|
16671 | var pointFromDefs = $$.pointFromDefs(pointId);
|
16672 | if (pointFromDefs.size() < 1) {
|
16673 | $$.insertPointInfoDefs(point, pointId);
|
16674 | }
|
16675 | if (method === "create") {
|
16676 | return $$.custom.create.bind(context).apply(void 0, __spreadArray([element, pointId], args));
|
16677 | }
|
16678 | else if (method === "update") {
|
16679 | return $$.custom.update.bind(context).apply(void 0, __spreadArray([element], args));
|
16680 | }
|
16681 | }
|
16682 | return point[method].bind(context).apply(void 0, __spreadArray([element], args));
|
16683 | };
|
16684 | };
|
16685 | },
|
16686 | custom: {
|
16687 | create: function (element, id, sizeFn, fillStyleFn) {
|
16688 | return element.append("use")
|
16689 | .attr("xlink:href", "#" + id)
|
16690 | .attr("class", this.updatePointClass.bind(this))
|
16691 | .style("fill", fillStyleFn)
|
16692 | .node();
|
16693 | },
|
16694 | update: function (element, xPosFn, yPosFn, fillStyleFn, withTransition, flow, selectedCircles) {
|
16695 | var _a = element.node().getBBox(), width = _a.width, height = _a.height;
|
16696 | var xPosFn2 = function (d) { return xPosFn(d) - width / 2; };
|
16697 | var yPosFn2 = function (d) { return yPosFn(d) - height / 2; };
|
16698 | var mainCircles = element;
|
16699 | if (withTransition) {
|
16700 | var transitionName = getTransitionName();
|
16701 | flow && mainCircles.attr("x", xPosFn2);
|
16702 | mainCircles = mainCircles.transition(transitionName);
|
16703 | selectedCircles && selectedCircles.transition(getTransitionName());
|
16704 | }
|
16705 | return mainCircles
|
16706 | .attr("x", xPosFn2)
|
16707 | .attr("y", yPosFn2)
|
16708 | .style("fill", fillStyleFn);
|
16709 | }
|
16710 | },
|
16711 |
|
16712 | circle: {
|
16713 | create: function (element, sizeFn, fillStyleFn) {
|
16714 | return element.append("circle")
|
16715 | .attr("class", this.updatePointClass.bind(this))
|
16716 | .attr("r", sizeFn)
|
16717 | .style("fill", fillStyleFn)
|
16718 | .node();
|
16719 | },
|
16720 | update: function (element, xPosFn, yPosFn, fillStyleFn, withTransition, flow, selectedCircles) {
|
16721 | var $$ = this;
|
16722 | var mainCircles = element;
|
16723 |
|
16724 | if ($$.hasType("bubble")) {
|
16725 | mainCircles.attr("r", $$.pointR.bind($$));
|
16726 | }
|
16727 | if (withTransition) {
|
16728 | var transitionName = getTransitionName();
|
16729 | flow && mainCircles.attr("cx", xPosFn);
|
16730 | if (mainCircles.attr("cx")) {
|
16731 | mainCircles = mainCircles.transition(transitionName);
|
16732 | }
|
16733 | selectedCircles && selectedCircles.transition(getTransitionName());
|
16734 | }
|
16735 | return mainCircles
|
16736 | .attr("cx", xPosFn)
|
16737 | .attr("cy", yPosFn)
|
16738 | .style("fill", fillStyleFn);
|
16739 | }
|
16740 | },
|
16741 |
|
16742 | rectangle: {
|
16743 | create: function (element, sizeFn, fillStyleFn) {
|
16744 | var rectSizeFn = function (d) { return sizeFn(d) * 2.0; };
|
16745 | return element.append("rect")
|
16746 | .attr("class", this.updatePointClass.bind(this))
|
16747 | .attr("width", rectSizeFn)
|
16748 | .attr("height", rectSizeFn)
|
16749 | .style("fill", fillStyleFn)
|
16750 | .node();
|
16751 | },
|
16752 | update: function (element, xPosFn, yPosFn, fillStyleFn, withTransition, flow, selectedCircles) {
|
16753 | var $$ = this;
|
16754 | var r = $$.config.point_r;
|
16755 | var rectXPosFn = function (d) { return xPosFn(d) - r; };
|
16756 | var rectYPosFn = function (d) { return yPosFn(d) - r; };
|
16757 | var mainCircles = element;
|
16758 | if (withTransition) {
|
16759 | var transitionName = getTransitionName();
|
16760 | flow && mainCircles.attr("x", rectXPosFn);
|
16761 | mainCircles = mainCircles.transition(transitionName);
|
16762 | selectedCircles && selectedCircles.transition(getTransitionName());
|
16763 | }
|
16764 | return mainCircles
|
16765 | .attr("x", rectXPosFn)
|
16766 | .attr("y", rectYPosFn)
|
16767 | .style("fill", fillStyleFn);
|
16768 | }
|
16769 | }
|
16770 | };
|
16771 |
|
16772 |
|
16773 |
|
16774 |
|
16775 |
|
16776 |
|
16777 |
|
16778 |
|
16779 |
|
16780 |
|
16781 |
|
16782 |
|
16783 |
|
16784 |
|
16785 |
|
16786 |
|
16787 | function getPosition(isClockwise, type, edge, pos, range, ratio) {
|
16788 | var index = isClockwise && pos > 0 ? edge - pos : pos;
|
16789 | var r = 2 * Math.PI;
|
16790 | var func = type === "x" ? Math.sin : Math.cos;
|
16791 | return range * (1 - ratio * func(index * r / edge));
|
16792 | }
|
16793 |
|
16794 | var cacheKey = KEY.radarPoints;
|
16795 | var shapeRadar = {
|
16796 | initRadar: function () {
|
16797 | var $$ = this;
|
16798 | var config = $$.config, current = $$.state.current, $el = $$.$el;
|
16799 | if ($$.hasType("radar")) {
|
16800 | $el.radar = $el.main.select("." + CLASS.chart).append("g")
|
16801 | .attr("class", CLASS.chartRadars);
|
16802 |
|
16803 | $el.radar.levels = $el.radar.append("g")
|
16804 | .attr("class", CLASS.levels);
|
16805 |
|
16806 | $el.radar.axes = $el.radar.append("g")
|
16807 | .attr("class", CLASS.axis);
|
16808 |
|
16809 | $el.radar.shapes = $el.radar.append("g")
|
16810 | .attr("class", CLASS.shapes);
|
16811 | current.dataMax = config.radar_axis_max || $$.getMinMaxData().max[0].value;
|
16812 | }
|
16813 | },
|
16814 | getRadarSize: function () {
|
16815 | var $$ = this;
|
16816 | var config = $$.config, _a = $$.state, arcWidth = _a.arcWidth, arcHeight = _a.arcHeight;
|
16817 | var padding = config.axis_x_categories.length < 4 ? -20 : 10;
|
16818 | var size = (Math.min(arcWidth, arcHeight) - padding) / 2;
|
16819 | return [size, size];
|
16820 | },
|
16821 | updateTargetsForRadar: function (targets) {
|
16822 | var $$ = this;
|
16823 | var config = $$.config;
|
16824 | if (isEmpty(config.axis_x_categories)) {
|
16825 | config.axis_x_categories = getRange(0, getMinMax$1("max", targets.map(function (v) { return v.values.length; })));
|
16826 | }
|
16827 | $$.generateRadarPoints();
|
16828 | },
|
16829 | getRadarPosition: function (type, index, range, ratio) {
|
16830 | var $$ = this;
|
16831 | var config = $$.config;
|
16832 | var _a = $$.getRadarSize(), width = _a[0], height = _a[1];
|
16833 | var edge = config.axis_x_categories.length;
|
16834 | var isClockwise = config.radar_direction_clockwise;
|
16835 | var pos = toArray(type).map(function (v) { return getPosition(isClockwise, v, edge, index, isDefined(range) ? range : (type === "x" ? width : height), isNumber(ratio) ? ratio : config.radar_size_ratio); });
|
16836 | return pos.length === 1 ? pos[0] : pos;
|
16837 | },
|
16838 | |
16839 |
|
16840 |
|
16841 |
|
16842 | generateRadarPoints: function () {
|
16843 | var $$ = this;
|
16844 | var targets = $$.data.targets;
|
16845 | var _a = $$.getRadarSize(), width = _a[0], height = _a[1];
|
16846 | var points = $$.cache.get(cacheKey) || {};
|
16847 | var size = points._size;
|
16848 |
|
16849 | if (!size || (size.width !== width && size.height !== height)) {
|
16850 | targets.forEach(function (d) {
|
16851 | points[d.id] = d.values.map(function (v, i) { return ($$.getRadarPosition(["x", "y"], i, undefined, $$.getRatio("radar", v))); });
|
16852 | });
|
16853 | points._size = { width: width, height: height };
|
16854 | $$.cache.add(cacheKey, points);
|
16855 | }
|
16856 | },
|
16857 | redrawRadar: function (durationForExit) {
|
16858 | var $$ = this;
|
16859 | var _a = $$.$el, radar = _a.radar, main = _a.main;
|
16860 | var translate = $$.getTranslate("radar");
|
16861 |
|
16862 | if (translate) {
|
16863 | radar.attr("transform", translate);
|
16864 | main.select("." + CLASS.chartTexts).attr("transform", translate);
|
16865 | $$.generateRadarPoints();
|
16866 | $$.updateRadarLevel();
|
16867 | $$.updateRadarAxes();
|
16868 | $$.updateRadarShape(durationForExit);
|
16869 | }
|
16870 | },
|
16871 | generateGetRadarPoints: function () {
|
16872 | var points = this.cache.get(cacheKey);
|
16873 | return function (d, i) {
|
16874 | var point = points[d.id][i];
|
16875 | return [
|
16876 | point,
|
16877 | point,
|
16878 | point,
|
16879 | point
|
16880 | ];
|
16881 | };
|
16882 | },
|
16883 | updateRadarLevel: function () {
|
16884 | var $$ = this;
|
16885 | var config = $$.config, state = $$.state, radar = $$.$el.radar;
|
16886 | var _a = $$.getRadarSize(), width = _a[0], height = _a[1];
|
16887 | var depth = config.radar_level_depth;
|
16888 | var edge = config.axis_x_categories.length;
|
16889 | var showText = config.radar_level_text_show;
|
16890 | var radarLevels = radar.levels;
|
16891 | var levelData = getRange(0, depth);
|
16892 | var radius = config.radar_size_ratio * Math.min(width, height);
|
16893 | var levelRatio = levelData.map(function (l) { return radius * ((l + 1) / depth); });
|
16894 | var levelTextFormat = (config.radar_level_text_format || function () { }).bind($$.api);
|
16895 |
|
16896 | var points = levelData.map(function (v) {
|
16897 | var range = levelRatio[v];
|
16898 | var pos = getRange(0, edge).map(function (i) { return ($$.getRadarPosition(["x", "y"], i, range, 1)).join(","); });
|
16899 | return pos.join(" ");
|
16900 | });
|
16901 | var level = radarLevels
|
16902 | .selectAll("." + CLASS.level)
|
16903 | .data(levelData);
|
16904 | level.exit().remove();
|
16905 | var levelEnter = level.enter().append("g")
|
16906 | .attr("class", function (d, i) { return CLASS.level + " " + CLASS.level + "-" + i; });
|
16907 | levelEnter.append("polygon")
|
16908 | .style("visibility", config.radar_level_show ? null : "hidden");
|
16909 | if (showText) {
|
16910 | if (radarLevels.select("text").empty()) {
|
16911 | radarLevels
|
16912 | .append("text")
|
16913 | .attr("dx", "-.5em")
|
16914 | .attr("dy", "-.7em")
|
16915 | .style("text-anchor", "end")
|
16916 | .text(function () { return levelTextFormat(0); });
|
16917 | }
|
16918 | levelEnter.append("text")
|
16919 | .attr("dx", "-.5em")
|
16920 | .style("text-anchor", "end")
|
16921 | .text(function (d) { return levelTextFormat(state.current.dataMax / levelData.length * (d + 1)); });
|
16922 | }
|
16923 | levelEnter
|
16924 | .merge(level)
|
16925 | .attr("transform", function (d) { return "translate(" + (width - levelRatio[d]) + ", " + (height - levelRatio[d]) + ")"; })
|
16926 | .selectAll("polygon")
|
16927 | .attr("points", function (d) { return points[d]; });
|
16928 |
|
16929 | if (showText) {
|
16930 | radarLevels.selectAll("text")
|
16931 | .attr("x", function (d) { return (isUndefined(d) ? width : points[d].split(",")[0]); })
|
16932 | .attr("y", function (d) { return (isUndefined(d) ? height : 0); });
|
16933 | }
|
16934 | },
|
16935 | updateRadarAxes: function () {
|
16936 | var $$ = this;
|
16937 | var config = $$.config, radar = $$.$el.radar;
|
16938 | var _a = $$.getRadarSize(), width = _a[0], height = _a[1];
|
16939 | var categories = config.axis_x_categories;
|
16940 | var axis = radar.axes.selectAll("g")
|
16941 | .data(categories);
|
16942 | axis.exit().remove();
|
16943 | var axisEnter = axis.enter().append("g")
|
16944 | .attr("class", function (d, i) { return CLASS.axis + "-" + i; });
|
16945 | config.radar_axis_line_show && axisEnter.append("line");
|
16946 | config.radar_axis_text_show && axisEnter.append("text");
|
16947 | axis = axisEnter.merge(axis);
|
16948 |
|
16949 | if (config.radar_axis_line_show) {
|
16950 | axis.select("line")
|
16951 | .attr("x1", width)
|
16952 | .attr("y1", height)
|
16953 | .attr("x2", function (d, i) { return $$.getRadarPosition("x", i); })
|
16954 | .attr("y2", function (d, i) { return $$.getRadarPosition("y", i); });
|
16955 | }
|
16956 |
|
16957 | if (config.radar_axis_text_show) {
|
16958 | var _b = config.radar_axis_text_position, _c = _b.x, x_1 = _c === void 0 ? 0 : _c, _d = _b.y, y_1 = _d === void 0 ? 0 : _d;
|
16959 | axis.select("text")
|
16960 | .style("text-anchor", "middle")
|
16961 | .attr("dy", ".5em")
|
16962 | .call(function (selection) {
|
16963 | selection.each(function (d) {
|
16964 | setTextValue(select(this), String(d), [-0.6, 1.2]);
|
16965 | });
|
16966 | })
|
16967 | .datum(function (d, i) { return ({ index: i }); })
|
16968 | .attr("transform", function (d) {
|
16969 | if (isUndefined(this.width)) {
|
16970 |
|
16971 | this.width = this.getBoundingClientRect().width / 2;
|
16972 | }
|
16973 | var posX = $$.getRadarPosition("x", d.index, undefined, 1);
|
16974 | var posY = Math.round($$.getRadarPosition("y", d.index, undefined, 1));
|
16975 | if (posX > width) {
|
16976 | posX += this.width + x_1;
|
16977 | }
|
16978 | else if (Math.round(posX) < width) {
|
16979 | posX -= this.width + x_1;
|
16980 | }
|
16981 | if (posY > height) {
|
16982 |
|
16983 | if (posY / 2 === height && this.firstChild.tagName === "tspan") {
|
16984 | this.firstChild.setAttribute("dy", "0em");
|
16985 | }
|
16986 | posY += y_1;
|
16987 | }
|
16988 | else if (posY < height) {
|
16989 | posY -= y_1;
|
16990 | }
|
16991 | return "translate(" + posX + " " + posY + ")";
|
16992 | });
|
16993 | }
|
16994 | $$.bindEvent();
|
16995 | },
|
16996 | bindEvent: function () {
|
16997 | var $$ = this;
|
16998 | var config = $$.config, state = $$.state, _a = $$.$el, radar = _a.radar, svg = _a.svg;
|
16999 | var focusOnly = config.point_focus_only;
|
17000 | var inputType = state.inputType, transiting = state.transiting;
|
17001 | if (config.interaction_enabled) {
|
17002 | var isMouse_1 = inputType === "mouse";
|
17003 | var getIndex_1 = function (event) {
|
17004 | var target = event.target;
|
17005 |
|
17006 | if (/tspan/i.test(target.tagName)) {
|
17007 | target = target.parentNode;
|
17008 | }
|
17009 | var d = select(target).datum();
|
17010 | return d && Object.keys(d).length === 1 ? d.index : undefined;
|
17011 | };
|
17012 | var hide = function (event) {
|
17013 | var index = getIndex_1(event);
|
17014 | var noIndex = isUndefined(index);
|
17015 | if (isMouse_1 || noIndex) {
|
17016 | $$.hideTooltip();
|
17017 | focusOnly ?
|
17018 | $$.hideCircleFocus() :
|
17019 | $$.unexpandCircles();
|
17020 | if (isMouse_1) {
|
17021 | $$.setOverOut(false, index);
|
17022 | }
|
17023 | else if (noIndex) {
|
17024 | $$.callOverOutForTouch();
|
17025 | }
|
17026 | }
|
17027 | };
|
17028 | radar.axes.selectAll("text")
|
17029 | .on(isMouse_1 ? "mouseover " : "touchstart", function (event) {
|
17030 | if (transiting) {
|
17031 | return;
|
17032 | }
|
17033 | state.event = event;
|
17034 | var index = getIndex_1(event);
|
17035 | $$.selectRectForSingle(svg.node(), null, index);
|
17036 | isMouse_1 ? $$.setOverOut(true, index) : $$.callOverOutForTouch(index);
|
17037 | })
|
17038 | .on("mouseout", isMouse_1 ? hide : null);
|
17039 | if (!isMouse_1) {
|
17040 | svg.on("touchstart", hide);
|
17041 | }
|
17042 | }
|
17043 | },
|
17044 | updateRadarShape: function (durationForExit) {
|
17045 | var $$ = this;
|
17046 | var targets = $$.data.targets.filter(function (d) { return $$.isRadarType(d); });
|
17047 | var points = $$.cache.get(cacheKey);
|
17048 | var areas = $$.$el.radar.shapes
|
17049 | .selectAll("polygon")
|
17050 | .data(targets);
|
17051 | var areasEnter = areas.enter().append("g")
|
17052 | .attr("class", $$.getChartClass("Radar"));
|
17053 | areas.exit().transition()
|
17054 | .duration(durationForExit)
|
17055 | .remove();
|
17056 | areasEnter
|
17057 | .append("polygon")
|
17058 | .merge(areas)
|
17059 | .style("fill", $$.color)
|
17060 | .style("stroke", $$.color)
|
17061 | .attr("points", function (d) { return points[d.id].join(" "); });
|
17062 | $$.updateTargetForCircle(targets, areasEnter);
|
17063 | },
|
17064 | |
17065 |
|
17066 |
|
17067 |
|
17068 |
|
17069 |
|
17070 | radarCircleX: function (d) {
|
17071 | return this.cache.get(cacheKey)[d.id][d.index][0];
|
17072 | },
|
17073 | |
17074 |
|
17075 |
|
17076 |
|
17077 |
|
17078 |
|
17079 | radarCircleY: function (d) {
|
17080 | return this.cache.get(cacheKey)[d.id][d.index][1];
|
17081 | }
|
17082 | };
|
17083 |
|
17084 |
|
17085 |
|
17086 |
|
17087 |
|
17088 |
|
17089 |
|
17090 |
|
17091 | var optPoint = {
|
17092 | |
17093 |
|
17094 |
|
17095 |
|
17096 |
|
17097 |
|
17098 |
|
17099 |
|
17100 |
|
17101 |
|
17102 |
|
17103 |
|
17104 |
|
17105 |
|
17106 |
|
17107 |
|
17108 |
|
17109 |
|
17110 |
|
17111 |
|
17112 |
|
17113 |
|
17114 |
|
17115 |
|
17116 |
|
17117 |
|
17118 |
|
17119 |
|
17120 |
|
17121 |
|
17122 |
|
17123 |
|
17124 |
|
17125 |
|
17126 |
|
17127 |
|
17128 |
|
17129 |
|
17130 |
|
17131 |
|
17132 |
|
17133 |
|
17134 |
|
17135 |
|
17136 |
|
17137 |
|
17138 |
|
17139 |
|
17140 |
|
17141 |
|
17142 |
|
17143 |
|
17144 |
|
17145 |
|
17146 |
|
17147 |
|
17148 |
|
17149 |
|
17150 |
|
17151 |
|
17152 |
|
17153 |
|
17154 |
|
17155 |
|
17156 |
|
17157 |
|
17158 |
|
17159 |
|
17160 |
|
17161 |
|
17162 |
|
17163 |
|
17164 |
|
17165 |
|
17166 |
|
17167 |
|
17168 |
|
17169 |
|
17170 |
|
17171 |
|
17172 |
|
17173 | point_show: true,
|
17174 | point_r: 2.5,
|
17175 | point_sensitivity: 10,
|
17176 | point_focus_expand_enabled: true,
|
17177 | point_focus_expand_r: undefined,
|
17178 | point_focus_only: false,
|
17179 | point_opacity: undefined,
|
17180 | point_pattern: [],
|
17181 | point_select_r: undefined,
|
17182 | point_type: "circle"
|
17183 | };
|
17184 |
|
17185 |
|
17186 |
|
17187 |
|
17188 |
|
17189 |
|
17190 |
|
17191 |
|
17192 | var optArea = {
|
17193 | |
17194 |
|
17195 |
|
17196 |
|
17197 |
|
17198 |
|
17199 |
|
17200 |
|
17201 |
|
17202 |
|
17203 |
|
17204 |
|
17205 |
|
17206 |
|
17207 |
|
17208 |
|
17209 |
|
17210 |
|
17211 |
|
17212 |
|
17213 |
|
17214 |
|
17215 |
|
17216 |
|
17217 |
|
17218 |
|
17219 |
|
17220 |
|
17221 |
|
17222 |
|
17223 |
|
17224 |
|
17225 |
|
17226 |
|
17227 |
|
17228 |
|
17229 |
|
17230 |
|
17231 |
|
17232 |
|
17233 |
|
17234 |
|
17235 |
|
17236 |
|
17237 |
|
17238 |
|
17239 |
|
17240 |
|
17241 |
|
17242 |
|
17243 |
|
17244 | area_above: false,
|
17245 | area_front: true,
|
17246 | area_linearGradient: false,
|
17247 | area_zerobased: true
|
17248 | };
|
17249 |
|
17250 |
|
17251 |
|
17252 |
|
17253 |
|
17254 |
|
17255 |
|
17256 |
|
17257 | var optBar = {
|
17258 | |
17259 |
|
17260 |
|
17261 |
|
17262 |
|
17263 |
|
17264 |
|
17265 |
|
17266 |
|
17267 |
|
17268 |
|
17269 |
|
17270 |
|
17271 |
|
17272 |
|
17273 |
|
17274 |
|
17275 |
|
17276 |
|
17277 |
|
17278 |
|
17279 |
|
17280 |
|
17281 |
|
17282 |
|
17283 |
|
17284 |
|
17285 |
|
17286 |
|
17287 |
|
17288 |
|
17289 |
|
17290 |
|
17291 |
|
17292 |
|
17293 |
|
17294 |
|
17295 |
|
17296 |
|
17297 |
|
17298 |
|
17299 |
|
17300 |
|
17301 |
|
17302 |
|
17303 |
|
17304 |
|
17305 |
|
17306 |
|
17307 |
|
17308 |
|
17309 |
|
17310 |
|
17311 |
|
17312 |
|
17313 |
|
17314 |
|
17315 |
|
17316 |
|
17317 |
|
17318 |
|
17319 |
|
17320 |
|
17321 |
|
17322 |
|
17323 |
|
17324 | bar_label_threshold: 0,
|
17325 | bar_padding: 0,
|
17326 | bar_radius: undefined,
|
17327 | bar_radius_ratio: undefined,
|
17328 | bar_sensitivity: 2,
|
17329 | bar_width: undefined,
|
17330 | bar_width_ratio: 0.6,
|
17331 | bar_width_max: undefined,
|
17332 | bar_zerobased: true
|
17333 | };
|
17334 |
|
17335 |
|
17336 |
|
17337 |
|
17338 |
|
17339 |
|
17340 |
|
17341 |
|
17342 | var optBubble = {
|
17343 | |
17344 |
|
17345 |
|
17346 |
|
17347 |
|
17348 |
|
17349 |
|
17350 |
|
17351 |
|
17352 |
|
17353 |
|
17354 |
|
17355 |
|
17356 |
|
17357 |
|
17358 |
|
17359 |
|
17360 |
|
17361 |
|
17362 |
|
17363 |
|
17364 |
|
17365 |
|
17366 | bubble_maxR: 35,
|
17367 | bubble_zerobased: false
|
17368 | };
|
17369 |
|
17370 |
|
17371 |
|
17372 |
|
17373 |
|
17374 |
|
17375 |
|
17376 |
|
17377 | var optCandlestick = {
|
17378 | |
17379 |
|
17380 |
|
17381 |
|
17382 |
|
17383 |
|
17384 |
|
17385 |
|
17386 |
|
17387 |
|
17388 |
|
17389 |
|
17390 |
|
17391 |
|
17392 |
|
17393 |
|
17394 |
|
17395 |
|
17396 |
|
17397 |
|
17398 |
|
17399 |
|
17400 |
|
17401 |
|
17402 |
|
17403 |
|
17404 |
|
17405 |
|
17406 |
|
17407 |
|
17408 |
|
17409 |
|
17410 |
|
17411 |
|
17412 |
|
17413 |
|
17414 |
|
17415 |
|
17416 |
|
17417 |
|
17418 |
|
17419 |
|
17420 |
|
17421 |
|
17422 |
|
17423 |
|
17424 |
|
17425 | candlestick_width: undefined,
|
17426 | candlestick_width_ratio: 0.6,
|
17427 | candlestick_width_max: undefined,
|
17428 | candlestick_color_down: "red"
|
17429 | };
|
17430 |
|
17431 |
|
17432 |
|
17433 |
|
17434 |
|
17435 |
|
17436 |
|
17437 |
|
17438 | var optLine = {
|
17439 | |
17440 |
|
17441 |
|
17442 |
|
17443 |
|
17444 |
|
17445 |
|
17446 |
|
17447 |
|
17448 |
|
17449 |
|
17450 |
|
17451 |
|
17452 |
|
17453 |
|
17454 |
|
17455 |
|
17456 |
|
17457 |
|
17458 |
|
17459 |
|
17460 |
|
17461 |
|
17462 |
|
17463 |
|
17464 |
|
17465 |
|
17466 |
|
17467 |
|
17468 |
|
17469 |
|
17470 |
|
17471 |
|
17472 |
|
17473 |
|
17474 |
|
17475 |
|
17476 |
|
17477 | line_connectNull: false,
|
17478 | line_step_type: "step",
|
17479 | line_zerobased: false,
|
17480 | line_classes: undefined,
|
17481 | line_point: true
|
17482 | };
|
17483 |
|
17484 |
|
17485 |
|
17486 |
|
17487 |
|
17488 |
|
17489 |
|
17490 |
|
17491 | var optScatter = {
|
17492 | |
17493 |
|
17494 |
|
17495 |
|
17496 |
|
17497 |
|
17498 |
|
17499 |
|
17500 |
|
17501 |
|
17502 |
|
17503 |
|
17504 |
|
17505 |
|
17506 |
|
17507 |
|
17508 |
|
17509 |
|
17510 |
|
17511 |
|
17512 |
|
17513 |
|
17514 |
|
17515 |
|
17516 |
|
17517 | scatter_zerobased: false
|
17518 | };
|
17519 |
|
17520 |
|
17521 |
|
17522 |
|
17523 |
|
17524 |
|
17525 |
|
17526 |
|
17527 | var optSpline = {
|
17528 | |
17529 |
|
17530 |
|
17531 |
|
17532 |
|
17533 |
|
17534 |
|
17535 |
|
17536 |
|
17537 |
|
17538 |
|
17539 |
|
17540 |
|
17541 |
|
17542 |
|
17543 |
|
17544 |
|
17545 |
|
17546 |
|
17547 |
|
17548 |
|
17549 |
|
17550 |
|
17551 |
|
17552 |
|
17553 |
|
17554 |
|
17555 |
|
17556 |
|
17557 |
|
17558 |
|
17559 |
|
17560 |
|
17561 |
|
17562 |
|
17563 | spline_interpolation_type: "cardinal"
|
17564 | };
|
17565 |
|
17566 |
|
17567 |
|
17568 |
|
17569 |
|
17570 |
|
17571 |
|
17572 |
|
17573 | var optDonut = {
|
17574 | |
17575 |
|
17576 |
|
17577 |
|
17578 |
|
17579 |
|
17580 |
|
17581 |
|
17582 |
|
17583 |
|
17584 |
|
17585 |
|
17586 |
|
17587 |
|
17588 |
|
17589 |
|
17590 |
|
17591 |
|
17592 |
|
17593 |
|
17594 |
|
17595 |
|
17596 |
|
17597 |
|
17598 |
|
17599 |
|
17600 |
|
17601 |
|
17602 |
|
17603 |
|
17604 |
|
17605 |
|
17606 |
|
17607 |
|
17608 |
|
17609 |
|
17610 |
|
17611 |
|
17612 |
|
17613 |
|
17614 |
|
17615 |
|
17616 |
|
17617 |
|
17618 |
|
17619 |
|
17620 |
|
17621 |
|
17622 |
|
17623 |
|
17624 |
|
17625 |
|
17626 |
|
17627 |
|
17628 |
|
17629 |
|
17630 |
|
17631 |
|
17632 |
|
17633 |
|
17634 |
|
17635 | donut_label_show: true,
|
17636 | donut_label_format: undefined,
|
17637 | donut_label_threshold: 0.05,
|
17638 | donut_label_ratio: undefined,
|
17639 | donut_width: undefined,
|
17640 | donut_title: "",
|
17641 | donut_expand: {},
|
17642 | donut_expand_rate: 0.98,
|
17643 | donut_expand_duration: 50,
|
17644 | donut_padAngle: 0,
|
17645 | donut_startingAngle: 0
|
17646 | };
|
17647 |
|
17648 |
|
17649 |
|
17650 |
|
17651 |
|
17652 |
|
17653 |
|
17654 |
|
17655 | var optGauge = {
|
17656 | |
17657 |
|
17658 |
|
17659 |
|
17660 |
|
17661 |
|
17662 |
|
17663 |
|
17664 |
|
17665 |
|
17666 |
|
17667 |
|
17668 |
|
17669 |
|
17670 |
|
17671 |
|
17672 |
|
17673 |
|
17674 |
|
17675 |
|
17676 |
|
17677 |
|
17678 |
|
17679 |
|
17680 |
|
17681 |
|
17682 |
|
17683 |
|
17684 |
|
17685 |
|
17686 |
|
17687 |
|
17688 |
|
17689 |
|
17690 |
|
17691 |
|
17692 |
|
17693 |
|
17694 |
|
17695 |
|
17696 |
|
17697 |
|
17698 |
|
17699 |
|
17700 |
|
17701 |
|
17702 |
|
17703 |
|
17704 |
|
17705 |
|
17706 |
|
17707 |
|
17708 |
|
17709 |
|
17710 |
|
17711 |
|
17712 |
|
17713 |
|
17714 |
|
17715 |
|
17716 |
|
17717 |
|
17718 |
|
17719 |
|
17720 |
|
17721 |
|
17722 |
|
17723 |
|
17724 |
|
17725 |
|
17726 |
|
17727 |
|
17728 |
|
17729 |
|
17730 |
|
17731 |
|
17732 |
|
17733 |
|
17734 |
|
17735 |
|
17736 |
|
17737 |
|
17738 |
|
17739 |
|
17740 |
|
17741 |
|
17742 |
|
17743 |
|
17744 |
|
17745 |
|
17746 |
|
17747 | gauge_background: "",
|
17748 | gauge_fullCircle: false,
|
17749 | gauge_label_show: true,
|
17750 | gauge_label_format: undefined,
|
17751 | gauge_label_extents: undefined,
|
17752 | gauge_label_threshold: 0,
|
17753 | gauge_min: 0,
|
17754 | gauge_max: 100,
|
17755 | gauge_type: "single",
|
17756 | gauge_startingAngle: -1 * Math.PI / 2,
|
17757 | gauge_arcLength: 100,
|
17758 | gauge_title: "",
|
17759 | gauge_units: undefined,
|
17760 | gauge_width: undefined,
|
17761 | gauge_arcs_minWidth: 5,
|
17762 | gauge_expand: {},
|
17763 | gauge_expand_rate: 0.98,
|
17764 | gauge_expand_duration: 50
|
17765 | };
|
17766 |
|
17767 |
|
17768 |
|
17769 |
|
17770 |
|
17771 |
|
17772 |
|
17773 |
|
17774 | var optPie = {
|
17775 | |
17776 |
|
17777 |
|
17778 |
|
17779 |
|
17780 |
|
17781 |
|
17782 |
|
17783 |
|
17784 |
|
17785 |
|
17786 |
|
17787 |
|
17788 |
|
17789 |
|
17790 |
|
17791 |
|
17792 |
|
17793 |
|
17794 |
|
17795 |
|
17796 |
|
17797 |
|
17798 |
|
17799 |
|
17800 |
|
17801 |
|
17802 |
|
17803 |
|
17804 |
|
17805 |
|
17806 |
|
17807 |
|
17808 |
|
17809 |
|
17810 |
|
17811 |
|
17812 |
|
17813 |
|
17814 |
|
17815 |
|
17816 |
|
17817 |
|
17818 |
|
17819 |
|
17820 |
|
17821 |
|
17822 |
|
17823 |
|
17824 |
|
17825 |
|
17826 |
|
17827 |
|
17828 |
|
17829 |
|
17830 |
|
17831 |
|
17832 |
|
17833 |
|
17834 |
|
17835 |
|
17836 |
|
17837 |
|
17838 |
|
17839 |
|
17840 |
|
17841 |
|
17842 |
|
17843 |
|
17844 |
|
17845 |
|
17846 |
|
17847 |
|
17848 |
|
17849 |
|
17850 |
|
17851 |
|
17852 |
|
17853 | pie_label_show: true,
|
17854 | pie_label_format: undefined,
|
17855 | pie_label_threshold: 0.05,
|
17856 | pie_label_ratio: undefined,
|
17857 | pie_expand: {},
|
17858 | pie_expand_rate: 0.98,
|
17859 | pie_expand_duration: 50,
|
17860 | pie_innerRadius: 0,
|
17861 | pie_outerRadius: undefined,
|
17862 | pie_padAngle: 0,
|
17863 | pie_padding: 0,
|
17864 | pie_startingAngle: 0
|
17865 | };
|
17866 |
|
17867 |
|
17868 |
|
17869 |
|
17870 |
|
17871 |
|
17872 |
|
17873 |
|
17874 | var optRadar = {
|
17875 | |
17876 |
|
17877 |
|
17878 |
|
17879 |
|
17880 |
|
17881 |
|
17882 |
|
17883 |
|
17884 |
|
17885 |
|
17886 |
|
17887 |
|
17888 |
|
17889 |
|
17890 |
|
17891 |
|
17892 |
|
17893 |
|
17894 |
|
17895 |
|
17896 |
|
17897 |
|
17898 |
|
17899 |
|
17900 |
|
17901 |
|
17902 |
|
17903 |
|
17904 |
|
17905 |
|
17906 |
|
17907 |
|
17908 |
|
17909 |
|
17910 |
|
17911 |
|
17912 |
|
17913 |
|
17914 |
|
17915 |
|
17916 |
|
17917 |
|
17918 |
|
17919 |
|
17920 |
|
17921 |
|
17922 |
|
17923 |
|
17924 |
|
17925 |
|
17926 |
|
17927 |
|
17928 |
|
17929 |
|
17930 |
|
17931 | radar_axis_max: undefined,
|
17932 | radar_axis_line_show: true,
|
17933 | radar_axis_text_show: true,
|
17934 | radar_axis_text_position: {},
|
17935 | radar_level_depth: 3,
|
17936 | radar_level_show: true,
|
17937 | radar_level_text_format: function (x) { return (x % 1 === 0 ? x : x.toFixed(2)); },
|
17938 | radar_level_text_show: true,
|
17939 | radar_size_ratio: 0.87,
|
17940 | radar_direction_clockwise: false
|
17941 | };
|
17942 |
|
17943 |
|
17944 |
|
17945 |
|
17946 |
|
17947 |
|
17948 |
|
17949 |
|
17950 |
|
17951 |
|
17952 |
|
17953 | function extendAxis(module, option) {
|
17954 | extend(ChartInternal.prototype, internal.concat(module));
|
17955 | extend(Chart.prototype, api);
|
17956 | Options.setOptions(options.concat(option || []));
|
17957 | }
|
17958 |
|
17959 |
|
17960 |
|
17961 |
|
17962 |
|
17963 |
|
17964 | function extendLine(module, option) {
|
17965 | extendAxis([shapePoint, shapeLine].concat(module || []));
|
17966 | Options.setOptions([optPoint, optLine].concat(option || []));
|
17967 | }
|
17968 |
|
17969 |
|
17970 |
|
17971 |
|
17972 |
|
17973 |
|
17974 | function extendArc(module, option) {
|
17975 | extend(ChartInternal.prototype, [shapeArc].concat(module || []));
|
17976 | Options.setOptions(option);
|
17977 | }
|
17978 |
|
17979 | var area = function () { return (extendLine(shapeArea, [optArea]), (area = function () { return TYPE.AREA; })()); };
|
17980 | var areaLineRange = function () { return (extendLine(shapeArea, [optArea]), (areaLineRange = function () { return TYPE.AREA_LINE_RANGE; })()); };
|
17981 | var areaSpline = function () { return (extendLine(shapeArea, [optArea, optSpline]), (areaSpline = function () { return TYPE.AREA_SPLINE; })()); };
|
17982 | var areaSplineRange = function () { return (extendLine(shapeArea, [optArea, optSpline]), (areaSplineRange = function () { return TYPE.AREA_SPLINE_RANGE; })()); };
|
17983 | var areaStep = function () { return (extendLine(shapeArea, [optArea]), (areaStep = function () { return TYPE.AREA_STEP; })()); };
|
17984 |
|
17985 | var line = function () { return (extendLine(), (line = function () { return TYPE.LINE; })()); };
|
17986 | var spline = function () { return (extendLine(undefined, [optSpline]), (spline = function () { return TYPE.SPLINE; })()); };
|
17987 | var step = function () { return (extendLine(), (step = function () { return TYPE.STEP; })()); };
|
17988 |
|
17989 | var donut = function () { return (extendArc(undefined, [optDonut]), (donut = function () { return TYPE.DONUT; })()); };
|
17990 | var gauge = function () { return (extendArc([shapeGauge], [optGauge]), (gauge = function () { return TYPE.GAUGE; })()); };
|
17991 | var pie = function () { return (extendArc(undefined, [optPie]), (pie = function () { return TYPE.PIE; })()); };
|
17992 | var radar = function () { return (extendArc([shapePoint, shapeRadar], [optPoint, optRadar]), (radar = function () { return TYPE.RADAR; })()); };
|
17993 |
|
17994 | var bar = function () { return (extendAxis([shapeBar], optBar), (bar = function () { return TYPE.BAR; })()); };
|
17995 | var bubble = function () { return (extendAxis([shapePoint, shapeBubble], [optBubble, optPoint]), (bubble = function () { return TYPE.BUBBLE; })()); };
|
17996 | var candlestick = function () { return (extendAxis([shapeCandlestick], [optCandlestick]), (candlestick = function () { return TYPE.CANDLESTICK; })()); };
|
17997 | var scatter = function () { return (extendAxis([shapePoint], [optPoint, optScatter]), (scatter = function () { return TYPE.SCATTER; })()); };
|
17998 |
|
17999 |
|
18000 |
|
18001 |
|
18002 |
|
18003 | var apiSelection = {
|
18004 | |
18005 |
|
18006 |
|
18007 |
|
18008 |
|
18009 |
|
18010 |
|
18011 |
|
18012 |
|
18013 |
|
18014 |
|
18015 |
|
18016 |
|
18017 |
|
18018 |
|
18019 |
|
18020 | selected: function (targetId) {
|
18021 | var $$ = this.internal;
|
18022 | var dataPoint = [];
|
18023 | $$.$el.main.selectAll("." + (CLASS.shapes + $$.getTargetSelectorSuffix(targetId)))
|
18024 | .selectAll("." + CLASS.shape)
|
18025 | .filter(function () {
|
18026 | return select(this).classed(CLASS.SELECTED);
|
18027 | })
|
18028 | .each(function (d) { return dataPoint.push(d); });
|
18029 | return dataPoint;
|
18030 | },
|
18031 | |
18032 |
|
18033 |
|
18034 |
|
18035 |
|
18036 |
|
18037 |
|
18038 |
|
18039 |
|
18040 |
|
18041 |
|
18042 |
|
18043 |
|
18044 |
|
18045 |
|
18046 |
|
18047 |
|
18048 |
|
18049 |
|
18050 |
|
18051 |
|
18052 |
|
18053 |
|
18054 |
|
18055 | select: function (ids, indices, resetOther) {
|
18056 | var $$ = this.internal;
|
18057 | var config = $$.config, $el = $$.$el;
|
18058 | if (!config.data_selection_enabled) {
|
18059 | return;
|
18060 | }
|
18061 | $el.main.selectAll("." + CLASS.shapes)
|
18062 | .selectAll("." + CLASS.shape)
|
18063 | .each(function (d, i) {
|
18064 | var shape = select(this);
|
18065 | var id = d.data ? d.data.id : d.id;
|
18066 | var toggle = $$.getToggle(this, d).bind($$);
|
18067 | var isTargetId = config.data_selection_grouped || !ids || ids.indexOf(id) >= 0;
|
18068 | var isTargetIndex = !indices || indices.indexOf(i) >= 0;
|
18069 | var isSelected = shape.classed(CLASS.SELECTED);
|
18070 |
|
18071 | if (shape.classed(CLASS.line) || shape.classed(CLASS.area)) {
|
18072 | return;
|
18073 | }
|
18074 | if (isTargetId && isTargetIndex) {
|
18075 | if (config.data_selection_isselectable.bind($$.api)(d) && !isSelected) {
|
18076 | toggle(true, shape.classed(CLASS.SELECTED, true), d, i);
|
18077 | }
|
18078 | }
|
18079 | else if (isDefined(resetOther) && resetOther && isSelected) {
|
18080 | toggle(false, shape.classed(CLASS.SELECTED, false), d, i);
|
18081 | }
|
18082 | });
|
18083 | },
|
18084 | |
18085 |
|
18086 |
|
18087 |
|
18088 |
|
18089 |
|
18090 |
|
18091 |
|
18092 |
|
18093 |
|
18094 |
|
18095 |
|
18096 |
|
18097 |
|
18098 |
|
18099 |
|
18100 |
|
18101 | unselect: function (ids, indices) {
|
18102 | var $$ = this.internal;
|
18103 | var config = $$.config, $el = $$.$el;
|
18104 | if (!config.data_selection_enabled) {
|
18105 | return;
|
18106 | }
|
18107 | $el.main.selectAll("." + CLASS.shapes)
|
18108 | .selectAll("." + CLASS.shape)
|
18109 | .each(function (d, i) {
|
18110 | var shape = select(this);
|
18111 | var id = d.data ? d.data.id : d.id;
|
18112 | var toggle = $$.getToggle(this, d).bind($$);
|
18113 | var isTargetId = config.data_selection_grouped || !ids || ids.indexOf(id) >= 0;
|
18114 | var isTargetIndex = !indices || indices.indexOf(i) >= 0;
|
18115 | var isSelected = shape.classed(CLASS.SELECTED);
|
18116 |
|
18117 | if (shape.classed(CLASS.line) || shape.classed(CLASS.area)) {
|
18118 | return;
|
18119 | }
|
18120 | if (isTargetId &&
|
18121 | isTargetIndex &&
|
18122 | config.data_selection_isselectable.bind($$.api)(d) &&
|
18123 | isSelected) {
|
18124 | toggle(false, shape.classed(CLASS.SELECTED, false), d, i);
|
18125 | }
|
18126 | });
|
18127 | }
|
18128 | };
|
18129 |
|
18130 |
|
18131 |
|
18132 |
|
18133 |
|
18134 | var apiSubchart = {
|
18135 | subchart: {
|
18136 | |
18137 |
|
18138 |
|
18139 |
|
18140 |
|
18141 |
|
18142 |
|
18143 |
|
18144 |
|
18145 |
|
18146 |
|
18147 |
|
18148 |
|
18149 |
|
18150 |
|
18151 |
|
18152 |
|
18153 |
|
18154 |
|
18155 |
|
18156 |
|
18157 |
|
18158 |
|
18159 | show: function () {
|
18160 | var $$ = this.internal;
|
18161 | var subchart = $$.$el.subchart, config = $$.config;
|
18162 | var show = config.subchart_show;
|
18163 | if (!show) {
|
18164 | config.subchart_show = !show;
|
18165 | !subchart.main && $$.initSubchart();
|
18166 | var $target = subchart.main.selectAll("." + CLASS.target);
|
18167 |
|
18168 | if ($$.data.targets.length !== $target.size()) {
|
18169 | $$.updateSizes();
|
18170 | $$.updateTargetsForSubchart($$.data.targets);
|
18171 | $target = subchart.main.selectAll("." + CLASS.target);
|
18172 | }
|
18173 | $target.style("opacity", "1");
|
18174 | subchart.main.style("display", null);
|
18175 | this.flush();
|
18176 | }
|
18177 | },
|
18178 | |
18179 |
|
18180 |
|
18181 |
|
18182 |
|
18183 |
|
18184 |
|
18185 |
|
18186 |
|
18187 | hide: function () {
|
18188 | var $$ = this.internal;
|
18189 | var subchart = $$.$el.subchart, config = $$.config;
|
18190 | if (config.subchart_show && subchart.main.style("display") !== "none") {
|
18191 | config.subchart_show = false;
|
18192 | subchart.main.style("display", "none");
|
18193 | this.flush();
|
18194 | }
|
18195 | },
|
18196 | |
18197 |
|
18198 |
|
18199 |
|
18200 |
|
18201 |
|
18202 |
|
18203 |
|
18204 |
|
18205 |
|
18206 |
|
18207 | toggle: function () {
|
18208 | var $$ = this.internal;
|
18209 | var config = $$.config;
|
18210 | this.subchart[config.subchart_show ? "hide" : "show"]();
|
18211 | }
|
18212 | }
|
18213 | };
|
18214 |
|
18215 |
|
18216 |
|
18217 |
|
18218 |
|
18219 |
|
18220 |
|
18221 |
|
18222 |
|
18223 |
|
18224 |
|
18225 |
|
18226 | function withinRange(domain, range) {
|
18227 | var min = range[0], max = range[1];
|
18228 | return domain.every(function (v, i) { return (i === 0 ? (v >= min) : (v <= max)); });
|
18229 | }
|
18230 |
|
18231 |
|
18232 |
|
18233 |
|
18234 |
|
18235 |
|
18236 |
|
18237 |
|
18238 |
|
18239 |
|
18240 |
|
18241 |
|
18242 |
|
18243 |
|
18244 |
|
18245 |
|
18246 |
|
18247 | var zoom$1 = function (domainValue) {
|
18248 | var $$ = this.internal;
|
18249 | var config = $$.config, scale = $$.scale;
|
18250 | var domain = domainValue;
|
18251 | var resultDomain;
|
18252 | if (config.zoom_enabled && domain) {
|
18253 | if ($$.axis.isTimeSeries()) {
|
18254 | domain = domain.map(function (x) { return parseDate.bind($$)(x); });
|
18255 | }
|
18256 | if (withinRange(domain, $$.getZoomDomain())) {
|
18257 |
|
18258 | $$.api.tooltip.hide();
|
18259 | if (config.subchart_show) {
|
18260 | var xScale = scale.zoom || scale.x;
|
18261 | $$.brush.getSelection().call($$.brush.move, [xScale(domain[0]), xScale(domain[1])]);
|
18262 | resultDomain = domain;
|
18263 | }
|
18264 | else {
|
18265 | scale.x.domain(domain);
|
18266 | scale.zoom = scale.x;
|
18267 | $$.axis.x.scale(scale.zoom);
|
18268 | resultDomain = scale.zoom.orgDomain();
|
18269 | }
|
18270 | $$.redraw({
|
18271 | withTransition: true,
|
18272 | withY: config.zoom_rescale,
|
18273 | withDimension: false
|
18274 | });
|
18275 | $$.setZoomResetButton();
|
18276 | callFn(config.zoom_onzoom, $$.api, resultDomain);
|
18277 | }
|
18278 | }
|
18279 | else {
|
18280 | resultDomain = scale.zoom ?
|
18281 | scale.zoom.domain() : scale.x.orgDomain();
|
18282 | }
|
18283 | return resultDomain;
|
18284 | };
|
18285 | extend(zoom$1, {
|
18286 | |
18287 |
|
18288 |
|
18289 |
|
18290 |
|
18291 |
|
18292 |
|
18293 |
|
18294 |
|
18295 |
|
18296 |
|
18297 |
|
18298 |
|
18299 |
|
18300 |
|
18301 |
|
18302 |
|
18303 |
|
18304 | enable: function (enabled) {
|
18305 | var $$ = this.internal;
|
18306 | var config = $$.config;
|
18307 | if (/^(drag|wheel)$/.test(enabled)) {
|
18308 | config.zoom_type = enabled;
|
18309 | }
|
18310 | config.zoom_enabled = !!enabled;
|
18311 | if (!$$.zoom) {
|
18312 | $$.initZoom();
|
18313 | $$.bindZoomEvent();
|
18314 | }
|
18315 | else if (enabled === false) {
|
18316 | $$.bindZoomEvent(false);
|
18317 | }
|
18318 | $$.updateAndRedraw();
|
18319 | },
|
18320 | |
18321 |
|
18322 |
|
18323 |
|
18324 |
|
18325 |
|
18326 |
|
18327 |
|
18328 |
|
18329 |
|
18330 |
|
18331 | max: function (max) {
|
18332 | var $$ = this.internal;
|
18333 | var config = $$.config, xDomain = $$.org.xDomain;
|
18334 | if (max === 0 || max) {
|
18335 | config.zoom_x_max = getMinMax$1("max", [xDomain[1], max]);
|
18336 | }
|
18337 | return config.zoom_x_max;
|
18338 | },
|
18339 | |
18340 |
|
18341 |
|
18342 |
|
18343 |
|
18344 |
|
18345 |
|
18346 |
|
18347 |
|
18348 |
|
18349 |
|
18350 | min: function (min) {
|
18351 | var $$ = this.internal;
|
18352 | var config = $$.config, xDomain = $$.org.xDomain;
|
18353 | if (min === 0 || min) {
|
18354 | config.zoom_x_min = getMinMax$1("min", [xDomain[0], min]);
|
18355 | }
|
18356 | return config.zoom_x_min;
|
18357 | },
|
18358 | |
18359 |
|
18360 |
|
18361 |
|
18362 |
|
18363 |
|
18364 |
|
18365 |
|
18366 |
|
18367 |
|
18368 |
|
18369 |
|
18370 |
|
18371 |
|
18372 |
|
18373 |
|
18374 |
|
18375 | range: function (range) {
|
18376 | var zoom = this.zoom;
|
18377 | if (isObject(range)) {
|
18378 | var min = range.min, max = range.max;
|
18379 | isDefined(min) && zoom.min(min);
|
18380 | isDefined(max) && zoom.max(max);
|
18381 | }
|
18382 | return {
|
18383 | min: zoom.min(),
|
18384 | max: zoom.max()
|
18385 | };
|
18386 | }
|
18387 | });
|
18388 | var apiZoom = {
|
18389 | zoom: zoom$1,
|
18390 | |
18391 |
|
18392 |
|
18393 |
|
18394 |
|
18395 |
|
18396 |
|
18397 |
|
18398 | unzoom: function () {
|
18399 | var $$ = this.internal;
|
18400 | var config = $$.config;
|
18401 | if ($$.scale.zoom) {
|
18402 | config.subchart_show ?
|
18403 | $$.brush.getSelection().call($$.brush.move, null) :
|
18404 | $$.zoom.updateTransformScale(zoomIdentity);
|
18405 | $$.updateZoom(true);
|
18406 | $$.zoom.resetBtn && $$.zoom.resetBtn.style("display", "none");
|
18407 |
|
18408 | var eventRects = $$.$el.main.select("." + CLASS.eventRects);
|
18409 | if (zoomTransform(eventRects.node()) !== zoomIdentity) {
|
18410 | $$.zoom.transform(eventRects, zoomIdentity);
|
18411 | }
|
18412 | $$.redraw({
|
18413 | withTransition: true,
|
18414 | withUpdateXDomain: true,
|
18415 | withUpdateOrgXDomain: true,
|
18416 | withY: config.zoom_rescale
|
18417 | });
|
18418 | }
|
18419 | }
|
18420 | };
|
18421 |
|
18422 |
|
18423 |
|
18424 |
|
18425 |
|
18426 |
|
18427 |
|
18428 |
|
18429 | var drag = {
|
18430 | |
18431 |
|
18432 |
|
18433 |
|
18434 |
|
18435 |
|
18436 | drag: function (mouse) {
|
18437 | var $$ = this;
|
18438 | var config = $$.config, state = $$.state, main = $$.$el.main;
|
18439 | var isSelectionGrouped = config.data_selection_grouped;
|
18440 | var isSelectable = config.interaction_enabled && config.data_selection_isselectable;
|
18441 | if ($$.hasArcType() ||
|
18442 | !config.data_selection_enabled ||
|
18443 | (config.zoom_enabled && !$$.zoom.altDomain) ||
|
18444 | !config.data_selection_multiple
|
18445 | ) {
|
18446 | return;
|
18447 | }
|
18448 | var _a = state.dragStart || [0, 0], sx = _a[0], sy = _a[1];
|
18449 | var mx = mouse[0], my = mouse[1];
|
18450 | var minX = Math.min(sx, mx);
|
18451 | var maxX = Math.max(sx, mx);
|
18452 | var minY = isSelectionGrouped ? state.margin.top : Math.min(sy, my);
|
18453 | var maxY = isSelectionGrouped ? state.height : Math.max(sy, my);
|
18454 | main.select("." + CLASS.dragarea)
|
18455 | .attr("x", minX)
|
18456 | .attr("y", minY)
|
18457 | .attr("width", maxX - minX)
|
18458 | .attr("height", maxY - minY);
|
18459 |
|
18460 | main.selectAll("." + CLASS.shapes)
|
18461 | .selectAll("." + CLASS.shape)
|
18462 | .filter(function (d) { return isSelectable && isSelectable.bind($$.api)(d); })
|
18463 | .each(function (d, i) {
|
18464 | var shape = select(this);
|
18465 | var isSelected = shape.classed(CLASS.SELECTED);
|
18466 | var isIncluded = shape.classed(CLASS.INCLUDED);
|
18467 | var isWithin = false;
|
18468 | var toggle;
|
18469 | if (shape.classed(CLASS.circle)) {
|
18470 | var x = +shape.attr("cx") * 1;
|
18471 | var y = +shape.attr("cy") * 1;
|
18472 | toggle = $$.togglePoint;
|
18473 | isWithin = minX < x && x < maxX && minY < y && y < maxY;
|
18474 | }
|
18475 | else if (shape.classed(CLASS.bar)) {
|
18476 | var _a = getPathBox(this), x = _a.x, y = _a.y, width = _a.width, height = _a.height;
|
18477 | toggle = $$.togglePath;
|
18478 | isWithin = !(maxX < x || x + width < minX) && !(maxY < y || y + height < minY);
|
18479 | }
|
18480 | else {
|
18481 |
|
18482 | return;
|
18483 | }
|
18484 |
|
18485 | if (isWithin ^ isIncluded) {
|
18486 | shape.classed(CLASS.INCLUDED, !isIncluded);
|
18487 |
|
18488 | shape.classed(CLASS.SELECTED, !isSelected);
|
18489 | toggle.call($$, !isSelected, shape, d, i);
|
18490 | }
|
18491 | });
|
18492 | },
|
18493 | |
18494 |
|
18495 |
|
18496 |
|
18497 |
|
18498 |
|
18499 | dragstart: function (mouse) {
|
18500 | var $$ = this;
|
18501 | var config = $$.config, state = $$.state, main = $$.$el.main;
|
18502 | if ($$.hasArcType() || !config.data_selection_enabled) {
|
18503 | return;
|
18504 | }
|
18505 | state.dragStart = mouse;
|
18506 | main.select("." + CLASS.chart)
|
18507 | .append("rect")
|
18508 | .attr("class", CLASS.dragarea)
|
18509 | .style("opacity", "0.1");
|
18510 | $$.setDragStatus(true);
|
18511 | },
|
18512 | |
18513 |
|
18514 |
|
18515 |
|
18516 |
|
18517 | dragend: function () {
|
18518 | var $$ = this;
|
18519 | var config = $$.config, main = $$.$el.main;
|
18520 | if ($$.hasArcType() || !config.data_selection_enabled) {
|
18521 | return;
|
18522 | }
|
18523 | main.select("." + CLASS.dragarea)
|
18524 | .transition()
|
18525 | .duration(100)
|
18526 | .style("opacity", "0")
|
18527 | .remove();
|
18528 | main.selectAll("." + CLASS.shape)
|
18529 | .classed(CLASS.INCLUDED, false);
|
18530 | $$.setDragStatus(false);
|
18531 | }
|
18532 | };
|
18533 |
|
18534 | var selection = _assign(_assign({}, drag), {
|
18535 | |
18536 |
|
18537 |
|
18538 |
|
18539 |
|
18540 |
|
18541 |
|
18542 | selectPoint: function (target, d, i) {
|
18543 | var $$ = this;
|
18544 | var config = $$.config, main = $$.$el.main;
|
18545 | var isRotated = config.axis_rotated;
|
18546 | var cx = (isRotated ? $$.circleY : $$.circleX).bind($$);
|
18547 | var cy = (isRotated ? $$.circleX : $$.circleY).bind($$);
|
18548 | var r = $$.pointSelectR.bind($$);
|
18549 | callFn(config.data_onselected, $$.api, d, target.node());
|
18550 |
|
18551 | main.select("." + CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id))
|
18552 | .selectAll("." + CLASS.selectedCircle + "-" + i)
|
18553 | .data([d])
|
18554 | .enter()
|
18555 | .append("circle")
|
18556 | .attr("class", function () { return $$.generateClass(CLASS.selectedCircle, i); })
|
18557 | .attr("cx", cx)
|
18558 | .attr("cy", cy)
|
18559 | .attr("stroke", $$.color)
|
18560 | .attr("r", function (d2) { return $$.pointSelectR(d2) * 1.4; })
|
18561 | .transition()
|
18562 | .duration(100)
|
18563 | .attr("r", r);
|
18564 | },
|
18565 | |
18566 |
|
18567 |
|
18568 |
|
18569 |
|
18570 |
|
18571 |
|
18572 | unselectPoint: function (target, d, i) {
|
18573 | var $$ = this;
|
18574 | var config = $$.config, $el = $$.$el;
|
18575 | callFn(config.data_onunselected, $$.api, d, target.node());
|
18576 |
|
18577 | $el.main.select("." + CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id))
|
18578 | .selectAll("." + CLASS.selectedCircle + "-" + i)
|
18579 | .transition()
|
18580 | .duration(100)
|
18581 | .attr("r", 0)
|
18582 | .remove();
|
18583 | },
|
18584 | |
18585 |
|
18586 |
|
18587 |
|
18588 |
|
18589 |
|
18590 |
|
18591 |
|
18592 | togglePoint: function (selected, target, d, i) {
|
18593 | var method = (selected ? "" : "un") + "selectPoint";
|
18594 | this[method](target, d, i);
|
18595 | },
|
18596 | |
18597 |
|
18598 |
|
18599 |
|
18600 |
|
18601 |
|
18602 | selectPath: function (target, d) {
|
18603 | var $$ = this;
|
18604 | var config = $$.config;
|
18605 | callFn(config.data_onselected, $$.api, d, target.node());
|
18606 | if (config.interaction_brighten) {
|
18607 | target.transition().duration(100)
|
18608 | .style("fill", function () { return rgb($$.color(d)).brighter(0.75); });
|
18609 | }
|
18610 | },
|
18611 | |
18612 |
|
18613 |
|
18614 |
|
18615 |
|
18616 |
|
18617 | unselectPath: function (target, d) {
|
18618 | var $$ = this;
|
18619 | var config = $$.config;
|
18620 | callFn(config.data_onunselected, $$.api, d, target.node());
|
18621 | if (config.interaction_brighten) {
|
18622 | target.transition().duration(100)
|
18623 | .style("fill", function () { return $$.color(d); });
|
18624 | }
|
18625 | },
|
18626 | |
18627 |
|
18628 |
|
18629 |
|
18630 |
|
18631 |
|
18632 |
|
18633 |
|
18634 | togglePath: function (selected, target, d, i) {
|
18635 | this[(selected ? "" : "un") + "selectPath"](target, d, i);
|
18636 | },
|
18637 | |
18638 |
|
18639 |
|
18640 |
|
18641 |
|
18642 |
|
18643 |
|
18644 | getToggle: function (that, d) {
|
18645 | var $$ = this;
|
18646 | return that.nodeName === "path" ?
|
18647 | $$.togglePath : ($$.isStepType(d) ?
|
18648 | function () { } :
|
18649 | $$.togglePoint);
|
18650 | },
|
18651 | |
18652 |
|
18653 |
|
18654 |
|
18655 |
|
18656 |
|
18657 |
|
18658 | toggleShape: function (that, d, i) {
|
18659 | var $$ = this;
|
18660 | var config = $$.config, main = $$.$el.main;
|
18661 | var shape = select(that);
|
18662 | var isSelected = shape.classed(CLASS.SELECTED);
|
18663 | var toggle = $$.getToggle(that, d).bind($$);
|
18664 | var toggledShape;
|
18665 | if (config.data_selection_enabled && config.data_selection_isselectable.bind($$.api)(d)) {
|
18666 | if (!config.data_selection_multiple) {
|
18667 | var selector = "." + CLASS.shapes;
|
18668 | if (config.data_selection_grouped) {
|
18669 | selector += $$.getTargetSelectorSuffix(d.id);
|
18670 | }
|
18671 | main.selectAll(selector)
|
18672 | .selectAll("." + CLASS.shape)
|
18673 | .each(function (d, i) {
|
18674 | var shape = select(this);
|
18675 | if (shape.classed(CLASS.SELECTED)) {
|
18676 | toggledShape = shape;
|
18677 | toggle(false, shape.classed(CLASS.SELECTED, false), d, i);
|
18678 | }
|
18679 | });
|
18680 | }
|
18681 | if (!toggledShape || toggledShape.node() !== shape.node()) {
|
18682 | shape.classed(CLASS.SELECTED, !isSelected);
|
18683 | toggle(!isSelected, shape, d, i);
|
18684 | }
|
18685 | }
|
18686 | } });
|
18687 |
|
18688 |
|
18689 |
|
18690 |
|
18691 |
|
18692 | var subchart = {
|
18693 | |
18694 |
|
18695 |
|
18696 |
|
18697 | initBrush: function () {
|
18698 | var $$ = this;
|
18699 | var config = $$.config, scale = $$.scale, subchart = $$.$el.subchart;
|
18700 | var isRotated = config.axis_rotated;
|
18701 |
|
18702 | $$.brush = isRotated ? brushY() : brushX();
|
18703 |
|
18704 | var brushHandler = function () {
|
18705 | $$.redrawForBrush();
|
18706 | };
|
18707 | var getBrushSize = function () {
|
18708 | var brush = $$.$el.svg.select("." + CLASS.brush + " .overlay");
|
18709 | var brushSize = { width: 0, height: 0 };
|
18710 | if (brush.size()) {
|
18711 | brushSize.width = +brush.attr("width");
|
18712 | brushSize.height = +brush.attr("height");
|
18713 | }
|
18714 | return brushSize[isRotated ? "width" : "height"];
|
18715 | };
|
18716 | var lastDomain;
|
18717 | var timeout;
|
18718 | $$.brush
|
18719 | .on("start", function () {
|
18720 | $$.state.inputType === "touch" && $$.hideTooltip();
|
18721 | brushHandler();
|
18722 | })
|
18723 | .on("brush", brushHandler)
|
18724 | .on("end", function () {
|
18725 | lastDomain = scale.x.orgDomain();
|
18726 | });
|
18727 | $$.brush.updateResize = function () {
|
18728 | var _this = this;
|
18729 | timeout && clearTimeout(timeout);
|
18730 | timeout = setTimeout(function () {
|
18731 | var selection = _this.getSelection();
|
18732 | lastDomain && brushSelection(selection.node()) &&
|
18733 | _this.move(selection, lastDomain.map(scale.subX.orgScale()));
|
18734 | }, 0);
|
18735 | };
|
18736 | $$.brush.update = function () {
|
18737 | var extent = this.extent()();
|
18738 | if (extent[1].filter(function (v) { return isNaN(v); }).length === 0) {
|
18739 | subchart.main && subchart.main.select("." + CLASS.brush).call(this);
|
18740 | }
|
18741 | return this;
|
18742 | };
|
18743 |
|
18744 | $$.brush.scale = function (scale) {
|
18745 | var h = config.subchart_size_height || getBrushSize();
|
18746 | var extent = $$.getExtent();
|
18747 | if (!extent && scale.range) {
|
18748 | extent = [[0, 0], [scale.range()[1], h]];
|
18749 | }
|
18750 | else if (isArray(extent)) {
|
18751 | extent = extent.map(function (v, i) { return [v, i > 0 ? h : i]; });
|
18752 | }
|
18753 |
|
18754 | isRotated && extent[1].reverse();
|
18755 | this.extent(extent);
|
18756 |
|
18757 |
|
18758 | this.update();
|
18759 | };
|
18760 | $$.brush.getSelection = function () { return (
|
18761 |
|
18762 | subchart.main ? subchart.main.select("." + CLASS.brush) : select([])); };
|
18763 | },
|
18764 | |
18765 |
|
18766 |
|
18767 |
|
18768 | initSubchart: function () {
|
18769 | var $$ = this;
|
18770 | var config = $$.config, _a = $$.state, clip = _a.clip, hasAxis = _a.hasAxis, _b = $$.$el, defs = _b.defs, svg = _b.svg, subchart = _b.subchart, axis = _b.axis;
|
18771 | if (!hasAxis) {
|
18772 | return;
|
18773 | }
|
18774 | var visibility = config.subchart_show ? "visible" : "hidden";
|
18775 | var clipId = clip.id + "-subchart";
|
18776 | var clipPath = $$.getClipPath(clipId);
|
18777 | clip.idSubchart = clipId;
|
18778 | $$.appendClip(defs, clipId);
|
18779 | $$.initBrush();
|
18780 | subchart.main = svg.append("g")
|
18781 | .classed(CLASS.subchart, true)
|
18782 | .attr("transform", $$.getTranslate("context"));
|
18783 | var main = subchart.main;
|
18784 | main.style("visibility", visibility);
|
18785 |
|
18786 | main.append("g")
|
18787 | .attr("clip-path", clipPath)
|
18788 | .attr("class", CLASS.chart);
|
18789 |
|
18790 | ["bar", "line", "bubble", "candlestick", "scatter"].forEach(function (v) {
|
18791 | var type = capitalize(/^(bubble|scatter)$/.test(v) ? "circle" : v);
|
18792 | if ($$.hasType(v) || $$.hasTypeOf(type)) {
|
18793 | var chart = main.select("." + CLASS.chart);
|
18794 | var chartClassName = CLASS["chart" + type + "s"];
|
18795 | if (chart.select("." + chartClassName).empty()) {
|
18796 | chart
|
18797 | .append("g")
|
18798 | .attr("class", chartClassName);
|
18799 | }
|
18800 | }
|
18801 | });
|
18802 |
|
18803 | main.append("g")
|
18804 | .attr("clip-path", clipPath)
|
18805 | .attr("class", CLASS.brush)
|
18806 | .call($$.brush);
|
18807 |
|
18808 |
|
18809 | axis.subX = main.append("g")
|
18810 | .attr("class", CLASS.axisX)
|
18811 | .attr("transform", $$.getTranslate("subX"))
|
18812 | .attr("clip-path", config.axis_rotated ? "" : clip.pathXAxis)
|
18813 | .style("visibility", config.subchart_axis_x_show ? visibility : "hidden");
|
18814 | },
|
18815 | |
18816 |
|
18817 |
|
18818 |
|
18819 |
|
18820 | updateTargetsForSubchart: function (targets) {
|
18821 | var $$ = this;
|
18822 | var config = $$.config, state = $$.state, main = $$.$el.subchart.main;
|
18823 | if (config.subchart_show) {
|
18824 | ["bar", "line", "bubble", "candlestick", "scatter"]
|
18825 | .filter(function (v) { return $$.hasType(v) || $$.hasTypeOf(capitalize(v)); })
|
18826 | .forEach(function (v) {
|
18827 | var isPointType = /^(bubble|scatter)$/.test(v);
|
18828 | var name = capitalize(isPointType ? "circle" : v);
|
18829 | var chartClass = $$.getChartClass(name, true);
|
18830 | var shapeClass = $$.getClass(isPointType ? "circles" : v + "s", true);
|
18831 | var shapeChart = main.select("." + CLASS["chart" + (name + "s")]);
|
18832 | if (isPointType) {
|
18833 | var circle = shapeChart
|
18834 | .selectAll("." + CLASS.circles)
|
18835 | .data(targets.filter($$["is" + capitalize(v) + "Type"].bind($$)))
|
18836 | .attr("class", shapeClass);
|
18837 | circle.exit().remove();
|
18838 | circle.enter().append("g")
|
18839 | .attr("class", shapeClass);
|
18840 | }
|
18841 | else {
|
18842 | var shapeUpdate = shapeChart
|
18843 | .selectAll("." + CLASS["chart" + name])
|
18844 | .attr("class", chartClass)
|
18845 | .data(targets.filter($$["is" + name + "Type"].bind($$)));
|
18846 | var shapeEnter = shapeUpdate.enter()
|
18847 | .append("g")
|
18848 | .style("opacity", "0")
|
18849 | .attr("class", chartClass)
|
18850 | .append("g")
|
18851 | .attr("class", shapeClass);
|
18852 | shapeUpdate.exit().remove();
|
18853 |
|
18854 | v === "line" && $$.hasTypeOf("Area") &&
|
18855 | shapeEnter.append("g").attr("class", $$.getClass("areas", true));
|
18856 | }
|
18857 | });
|
18858 |
|
18859 | main.selectAll("." + CLASS.brush + " rect")
|
18860 | .attr(config.axis_rotated ? "width" : "height", config.axis_rotated ? state.width2 : state.height2);
|
18861 | }
|
18862 | },
|
18863 | |
18864 |
|
18865 |
|
18866 |
|
18867 |
|
18868 |
|
18869 |
|
18870 | redrawSubchart: function (withSubchart, duration, shape) {
|
18871 | var $$ = this;
|
18872 | var config = $$.config, main = $$.$el.subchart.main, state = $$.state;
|
18873 | var withTransition = !!duration;
|
18874 | main.style("visibility", config.subchart_show ? "visible" : "hidden");
|
18875 |
|
18876 | if (config.subchart_show) {
|
18877 |
|
18878 | if (state.event && state.event.type === "zoom") {
|
18879 | $$.brush.update();
|
18880 | }
|
18881 |
|
18882 | if (withSubchart) {
|
18883 |
|
18884 | !brushEmpty($$) && $$.brush.update();
|
18885 | Object.keys(shape.type).forEach(function (v) {
|
18886 | var name = capitalize(v);
|
18887 | var drawFn = $$["generateDraw" + name](shape.indices[v], true);
|
18888 |
|
18889 | $$["update" + name](duration, true);
|
18890 | $$["redraw" + name](drawFn, withTransition, true);
|
18891 | });
|
18892 | if ($$.hasType("bubble") || $$.hasType("scatter")) {
|
18893 | var cx = shape.pos.cx;
|
18894 | var cy = $$.updateCircleY(true);
|
18895 | $$.updateCircle(true);
|
18896 | $$.redrawCircle(cx, cy, withTransition, undefined, true);
|
18897 | }
|
18898 | }
|
18899 | }
|
18900 | },
|
18901 | |
18902 |
|
18903 |
|
18904 |
|
18905 | redrawForBrush: function () {
|
18906 | var $$ = this;
|
18907 | var _a = $$.config, onBrush = _a.subchart_onbrush, withY = _a.zoom_rescale, scale = $$.scale;
|
18908 | $$.redraw({
|
18909 | withTransition: false,
|
18910 | withY: withY,
|
18911 | withSubchart: false,
|
18912 | withUpdateXDomain: true,
|
18913 | withDimension: false
|
18914 | });
|
18915 | onBrush.bind($$.api)(scale.x.orgDomain());
|
18916 | },
|
18917 | |
18918 |
|
18919 |
|
18920 |
|
18921 |
|
18922 |
|
18923 | transformContext: function (withTransition, transitions) {
|
18924 | var $$ = this;
|
18925 | var main = $$.$el.subchart.main;
|
18926 | var subXAxis;
|
18927 | if (transitions && transitions.axisSubX) {
|
18928 | subXAxis = transitions.axisSubX;
|
18929 | }
|
18930 | else {
|
18931 | subXAxis = main.select("." + CLASS.axisX);
|
18932 | if (withTransition) {
|
18933 | subXAxis = subXAxis.transition();
|
18934 | }
|
18935 | }
|
18936 | main.attr("transform", $$.getTranslate("context"));
|
18937 | subXAxis.attr("transform", $$.getTranslate("subX"));
|
18938 | },
|
18939 | |
18940 |
|
18941 |
|
18942 |
|
18943 |
|
18944 | getExtent: function () {
|
18945 | var $$ = this;
|
18946 | var config = $$.config, scale = $$.scale;
|
18947 | var extent = config.axis_x_extent;
|
18948 | if (extent) {
|
18949 | if (isFunction(extent)) {
|
18950 | extent = extent.bind($$.api)($$.getXDomain($$.data.targets), scale.subX);
|
18951 | }
|
18952 | else if ($$.axis.isTimeSeries() && extent.every(isNaN)) {
|
18953 | var fn_1 = parseDate.bind($$);
|
18954 | extent = extent.map(function (v) { return scale.subX(fn_1(v)); });
|
18955 | }
|
18956 | }
|
18957 | return extent;
|
18958 | }
|
18959 | };
|
18960 |
|
18961 |
|
18962 |
|
18963 |
|
18964 |
|
18965 | var zoom = {
|
18966 | |
18967 |
|
18968 |
|
18969 |
|
18970 | initZoom: function () {
|
18971 | var $$ = this;
|
18972 | $$.scale.zoom = null;
|
18973 | $$.generateZoom();
|
18974 | $$.initZoomBehaviour();
|
18975 | },
|
18976 | |
18977 |
|
18978 |
|
18979 |
|
18980 |
|
18981 | bindZoomEvent: function (bind) {
|
18982 | if (bind === void 0) { bind = true; }
|
18983 | var $$ = this;
|
18984 | var config = $$.config, main = $$.$el.main;
|
18985 | var zoomEnabled = config.zoom_enabled;
|
18986 | var eventRects = main.select("." + CLASS.eventRects);
|
18987 | if (zoomEnabled && bind) {
|
18988 |
|
18989 | !config.subchart_show &&
|
18990 | $$.bindZoomOnEventRect(eventRects, config.zoom_type);
|
18991 | }
|
18992 | else if (bind === false) {
|
18993 | $$.api.unzoom();
|
18994 | eventRects
|
18995 | .on(".zoom", null)
|
18996 | .on(".drag", null);
|
18997 | }
|
18998 | },
|
18999 | |
19000 |
|
19001 |
|
19002 |
|
19003 | generateZoom: function () {
|
19004 | var $$ = this;
|
19005 | var config = $$.config, org = $$.org, scale = $$.scale;
|
19006 | var zoom = zoom$2().duration(0)
|
19007 | .on("start", $$.onZoomStart.bind($$))
|
19008 | .on("zoom", $$.onZoom.bind($$))
|
19009 | .on("end", $$.onZoomEnd.bind($$));
|
19010 |
|
19011 |
|
19012 | zoom.orgScaleExtent = function () {
|
19013 | var extent = config.zoom_extent || [1, 10];
|
19014 | return [extent[0], Math.max($$.getMaxDataCount() / extent[1], extent[1])];
|
19015 | };
|
19016 |
|
19017 | zoom.updateScaleExtent = function () {
|
19018 | var ratio = diffDomain($$.scale.x.orgDomain()) / diffDomain($$.getZoomDomain());
|
19019 | var extent = this.orgScaleExtent();
|
19020 | this.scaleExtent([extent[0] * ratio, extent[1] * ratio]);
|
19021 | return this;
|
19022 | };
|
19023 | |
19024 |
|
19025 |
|
19026 |
|
19027 |
|
19028 |
|
19029 | zoom.updateTransformScale = function (transform) {
|
19030 |
|
19031 | org.xScale && org.xScale.range(scale.x.range());
|
19032 |
|
19033 | var newScale = transform[config.axis_rotated ? "rescaleY" : "rescaleX"](org.xScale || scale.x);
|
19034 | var domain = $$.trimXDomain(newScale.domain());
|
19035 | var rescale = config.zoom_rescale;
|
19036 | newScale.domain(domain, org.xDomain);
|
19037 | scale.zoom = $$.getCustomizedScale(newScale);
|
19038 | $$.axis.x.scale(scale.zoom);
|
19039 | if (rescale) {
|
19040 |
|
19041 | !org.xScale && (org.xScale = scale.x.copy());
|
19042 | scale.x.domain(domain);
|
19043 | }
|
19044 | };
|
19045 | $$.zoom = zoom;
|
19046 | },
|
19047 | |
19048 |
|
19049 |
|
19050 |
|
19051 |
|
19052 | onZoomStart: function (event) {
|
19053 | var $$ = this;
|
19054 | var sourceEvent = event.sourceEvent;
|
19055 | if (!sourceEvent) {
|
19056 | return;
|
19057 | }
|
19058 | $$.zoom.startEvent = sourceEvent;
|
19059 | $$.state.zooming = true;
|
19060 | callFn($$.config.zoom_onzoomstart, $$.api, event);
|
19061 | },
|
19062 | |
19063 |
|
19064 |
|
19065 |
|
19066 |
|
19067 | onZoom: function (event) {
|
19068 | var $$ = this;
|
19069 | var config = $$.config, scale = $$.scale, org = $$.org;
|
19070 | var sourceEvent = event.sourceEvent;
|
19071 | if (!config.zoom_enabled ||
|
19072 | !event.sourceEvent ||
|
19073 | $$.filterTargetsToShow($$.data.targets).length === 0 ||
|
19074 | (!scale.zoom && sourceEvent.type.indexOf("touch") > -1 && sourceEvent.touches.length === 1)) {
|
19075 | return;
|
19076 | }
|
19077 | var isMousemove = sourceEvent.type === "mousemove";
|
19078 | var isZoomOut = sourceEvent.wheelDelta < 0;
|
19079 | var transform = event.transform;
|
19080 | if (!isMousemove && isZoomOut && scale.x.domain().every(function (v, i) { return v !== org.xDomain[i]; })) {
|
19081 | scale.x.domain(org.xDomain);
|
19082 | }
|
19083 | $$.zoom.updateTransformScale(transform);
|
19084 | if ($$.axis.isCategorized() && scale.x.orgDomain()[0] === org.xDomain[0]) {
|
19085 | scale.x.domain([org.xDomain[0] - 1e-10, scale.x.orgDomain()[1]]);
|
19086 | }
|
19087 | $$.redraw({
|
19088 | withTransition: false,
|
19089 | withY: config.zoom_rescale,
|
19090 | withSubchart: false,
|
19091 | withEventRect: false,
|
19092 | withDimension: false
|
19093 | });
|
19094 | $$.state.cancelClick = isMousemove;
|
19095 | callFn(config.zoom_onzoom, $$.api, scale.zoom.domain());
|
19096 | },
|
19097 | |
19098 |
|
19099 |
|
19100 |
|
19101 |
|
19102 | onZoomEnd: function (event) {
|
19103 | var $$ = this;
|
19104 | var config = $$.config, scale = $$.scale;
|
19105 | var startEvent = $$.zoom.startEvent;
|
19106 | var e = event && event.sourceEvent;
|
19107 | if ((startEvent && startEvent.type.indexOf("touch") > -1)) {
|
19108 | startEvent = startEvent.changedTouches[0];
|
19109 | e = e.changedTouches[0];
|
19110 | }
|
19111 |
|
19112 | if (!startEvent ||
|
19113 | (e && startEvent.clientX === e.clientX && startEvent.clientY === e.clientY)) {
|
19114 | return;
|
19115 | }
|
19116 | $$.redrawEventRect();
|
19117 | $$.updateZoom();
|
19118 | $$.state.zooming = false;
|
19119 | callFn(config.zoom_onzoomend, $$.api, scale[scale.zoom ? "zoom" : "subX"].domain());
|
19120 | },
|
19121 | |
19122 |
|
19123 |
|
19124 |
|
19125 |
|
19126 | getZoomDomain: function () {
|
19127 | var $$ = this;
|
19128 | var config = $$.config, org = $$.org;
|
19129 | var _a = org.xDomain, min = _a[0], max = _a[1];
|
19130 | if (isDefined(config.zoom_x_min)) {
|
19131 | min = getMinMax$1("min", [min, config.zoom_x_min]);
|
19132 | }
|
19133 | if (isDefined(config.zoom_x_max)) {
|
19134 | max = getMinMax$1("max", [max, config.zoom_x_max]);
|
19135 | }
|
19136 | return [min, max];
|
19137 | },
|
19138 | |
19139 |
|
19140 |
|
19141 |
|
19142 |
|
19143 | updateZoom: function (force) {
|
19144 | var $$ = this;
|
19145 | var _a = $$.scale, subX = _a.subX, x = _a.x, zoom = _a.zoom;
|
19146 | if (zoom) {
|
19147 | var zoomDomain = zoom.domain();
|
19148 | var xDomain = subX.domain();
|
19149 | var delta = 0.015;
|
19150 | var isfullyShown = (zoomDomain[0] <= xDomain[0] || (zoomDomain[0] - delta) <= xDomain[0]) &&
|
19151 | (xDomain[1] <= zoomDomain[1] || xDomain[1] <= (zoomDomain[1] - delta));
|
19152 |
|
19153 | if (force || isfullyShown) {
|
19154 | $$.axis.x.scale(subX);
|
19155 | x.domain(subX.orgDomain());
|
19156 | $$.scale.zoom = null;
|
19157 | }
|
19158 | }
|
19159 | },
|
19160 | |
19161 |
|
19162 |
|
19163 |
|
19164 |
|
19165 |
|
19166 | bindZoomOnEventRect: function (eventRects, type) {
|
19167 | var $$ = this;
|
19168 | var behaviour = type === "drag" ? $$.zoomBehaviour : $$.zoom;
|
19169 |
|
19170 |
|
19171 | $$.$el.svg.on("wheel", function () { });
|
19172 | eventRects
|
19173 | .call(behaviour)
|
19174 | .on("dblclick.zoom", null);
|
19175 | },
|
19176 | |
19177 |
|
19178 |
|
19179 |
|
19180 | initZoomBehaviour: function () {
|
19181 | var $$ = this;
|
19182 | var config = $$.config, state = $$.state;
|
19183 | var isRotated = config.axis_rotated;
|
19184 | var start = 0;
|
19185 | var end = 0;
|
19186 | var zoomRect;
|
19187 | var prop = {
|
19188 | axis: isRotated ? "y" : "x",
|
19189 | attr: isRotated ? "height" : "width",
|
19190 | index: isRotated ? 1 : 0
|
19191 | };
|
19192 | $$.zoomBehaviour = drag$1()
|
19193 | .clickDistance(4)
|
19194 | .on("start", function (event) {
|
19195 | state.event = event;
|
19196 | $$.setDragStatus(true);
|
19197 | $$.unselectRect();
|
19198 | if (!zoomRect) {
|
19199 | zoomRect = $$.$el.main.append("rect")
|
19200 | .attr("clip-path", state.clip.path)
|
19201 | .attr("class", CLASS.zoomBrush)
|
19202 | .attr("width", isRotated ? state.width : 0)
|
19203 | .attr("height", isRotated ? 0 : state.height);
|
19204 | }
|
19205 | start = getPointer(event, this)[prop.index];
|
19206 | end = start;
|
19207 | zoomRect
|
19208 | .attr(prop.axis, start)
|
19209 | .attr(prop.attr, 0);
|
19210 | $$.onZoomStart(event);
|
19211 | })
|
19212 | .on("drag", function (event) {
|
19213 | end = getPointer(event, this)[prop.index];
|
19214 | zoomRect
|
19215 | .attr(prop.axis, Math.min(start, end))
|
19216 | .attr(prop.attr, Math.abs(end - start));
|
19217 | })
|
19218 | .on("end", function (event) {
|
19219 | var _a;
|
19220 | var scale = $$.scale.zoom || $$.scale.x;
|
19221 | state.event = event;
|
19222 | $$.setDragStatus(false);
|
19223 | zoomRect
|
19224 | .attr(prop.axis, 0)
|
19225 | .attr(prop.attr, 0);
|
19226 | if (start > end) {
|
19227 | _a = [end, start], start = _a[0], end = _a[1];
|
19228 | }
|
19229 | if (start < 0) {
|
19230 | end += Math.abs(start);
|
19231 | start = 0;
|
19232 | }
|
19233 | if (start !== end) {
|
19234 | $$.api.zoom([start, end].map(function (v) { return scale.invert(v); }));
|
19235 | $$.onZoomEnd(event);
|
19236 | }
|
19237 | else {
|
19238 | if ($$.isMultipleX()) {
|
19239 | $$.clickHandlerForMultipleXS.bind(this)($$);
|
19240 | }
|
19241 | else {
|
19242 | var _b = getPointer(event), x = _b[0], y = _b[1];
|
19243 | var target = doc.elementFromPoint(x, y);
|
19244 | $$.clickHandlerForSingleX.bind(target)(select(target).datum(), $$);
|
19245 | }
|
19246 | }
|
19247 | });
|
19248 | },
|
19249 | setZoomResetButton: function () {
|
19250 | var $$ = this;
|
19251 | var config = $$.config;
|
19252 | var resetButton = config.zoom_resetButton;
|
19253 | if (resetButton && config.zoom_type === "drag") {
|
19254 | if (!$$.zoom.resetBtn) {
|
19255 | $$.zoom.resetBtn = $$.$el.chart.append("div")
|
19256 | .classed(CLASS.button, true)
|
19257 | .append("span")
|
19258 | .on("click", function () {
|
19259 | isFunction(resetButton.onclick) && resetButton.onclick.bind($$.api)(this);
|
19260 | $$.api.unzoom();
|
19261 | })
|
19262 | .classed(CLASS.buttonZoomReset, true)
|
19263 | .text(resetButton.text || "Reset Zoom");
|
19264 | }
|
19265 | else {
|
19266 | $$.zoom.resetBtn.style("display", null);
|
19267 | }
|
19268 | }
|
19269 | }
|
19270 | };
|
19271 |
|
19272 |
|
19273 |
|
19274 |
|
19275 |
|
19276 |
|
19277 |
|
19278 |
|
19279 | var optDataSelection = {
|
19280 | |
19281 |
|
19282 |
|
19283 |
|
19284 |
|
19285 |
|
19286 |
|
19287 |
|
19288 |
|
19289 |
|
19290 |
|
19291 |
|
19292 |
|
19293 |
|
19294 |
|
19295 |
|
19296 |
|
19297 |
|
19298 |
|
19299 |
|
19300 |
|
19301 |
|
19302 |
|
19303 |
|
19304 |
|
19305 |
|
19306 |
|
19307 | data_selection_enabled: false,
|
19308 | |
19309 |
|
19310 |
|
19311 |
|
19312 |
|
19313 |
|
19314 |
|
19315 |
|
19316 |
|
19317 |
|
19318 |
|
19319 |
|
19320 |
|
19321 |
|
19322 | data_selection_grouped: false,
|
19323 | |
19324 |
|
19325 |
|
19326 |
|
19327 |
|
19328 |
|
19329 |
|
19330 |
|
19331 |
|
19332 |
|
19333 |
|
19334 |
|
19335 |
|
19336 |
|
19337 | data_selection_isselectable: function () { return true; },
|
19338 | |
19339 |
|
19340 |
|
19341 |
|
19342 |
|
19343 |
|
19344 |
|
19345 |
|
19346 |
|
19347 |
|
19348 |
|
19349 |
|
19350 |
|
19351 |
|
19352 | data_selection_multiple: true,
|
19353 | |
19354 |
|
19355 |
|
19356 |
|
19357 |
|
19358 |
|
19359 |
|
19360 |
|
19361 |
|
19362 |
|
19363 |
|
19364 |
|
19365 |
|
19366 |
|
19367 |
|
19368 | data_selection_draggable: false,
|
19369 | |
19370 |
|
19371 |
|
19372 |
|
19373 |
|
19374 |
|
19375 |
|
19376 |
|
19377 |
|
19378 |
|
19379 |
|
19380 |
|
19381 |
|
19382 |
|
19383 |
|
19384 | data_onselected: function () { },
|
19385 | |
19386 |
|
19387 |
|
19388 |
|
19389 |
|
19390 |
|
19391 |
|
19392 |
|
19393 |
|
19394 |
|
19395 |
|
19396 |
|
19397 |
|
19398 |
|
19399 |
|
19400 | data_onunselected: function () { }
|
19401 | };
|
19402 |
|
19403 |
|
19404 |
|
19405 |
|
19406 |
|
19407 |
|
19408 |
|
19409 |
|
19410 | var optSubchart = {
|
19411 | |
19412 |
|
19413 |
|
19414 |
|
19415 |
|
19416 |
|
19417 |
|
19418 |
|
19419 |
|
19420 |
|
19421 |
|
19422 |
|
19423 |
|
19424 |
|
19425 |
|
19426 |
|
19427 |
|
19428 |
|
19429 |
|
19430 |
|
19431 |
|
19432 |
|
19433 |
|
19434 |
|
19435 |
|
19436 |
|
19437 |
|
19438 |
|
19439 |
|
19440 |
|
19441 |
|
19442 |
|
19443 |
|
19444 |
|
19445 |
|
19446 |
|
19447 |
|
19448 |
|
19449 |
|
19450 |
|
19451 |
|
19452 |
|
19453 |
|
19454 |
|
19455 |
|
19456 | subchart_show: false,
|
19457 | subchart_size_height: 60,
|
19458 | subchart_axis_x_show: true,
|
19459 | subchart_axis_x_tick_show: true,
|
19460 | subchart_axis_x_tick_text_show: true,
|
19461 | subchart_onbrush: function () { }
|
19462 | };
|
19463 |
|
19464 |
|
19465 |
|
19466 |
|
19467 |
|
19468 |
|
19469 |
|
19470 |
|
19471 | var optZoom = {
|
19472 | |
19473 |
|
19474 |
|
19475 |
|
19476 |
|
19477 |
|
19478 |
|
19479 |
|
19480 |
|
19481 |
|
19482 |
|
19483 |
|
19484 |
|
19485 |
|
19486 |
|
19487 |
|
19488 |
|
19489 |
|
19490 |
|
19491 |
|
19492 |
|
19493 |
|
19494 |
|
19495 |
|
19496 |
|
19497 |
|
19498 |
|
19499 |
|
19500 |
|
19501 |
|
19502 |
|
19503 |
|
19504 |
|
19505 |
|
19506 |
|
19507 |
|
19508 |
|
19509 |
|
19510 |
|
19511 |
|
19512 |
|
19513 |
|
19514 |
|
19515 |
|
19516 |
|
19517 |
|
19518 |
|
19519 |
|
19520 |
|
19521 |
|
19522 |
|
19523 |
|
19524 |
|
19525 |
|
19526 |
|
19527 |
|
19528 |
|
19529 |
|
19530 |
|
19531 |
|
19532 |
|
19533 |
|
19534 |
|
19535 |
|
19536 |
|
19537 |
|
19538 | zoom_enabled: false,
|
19539 | zoom_type: "wheel",
|
19540 | zoom_extent: undefined,
|
19541 | zoom_privileged: false,
|
19542 | zoom_rescale: false,
|
19543 | zoom_onzoom: undefined,
|
19544 | zoom_onzoomstart: undefined,
|
19545 | zoom_onzoomend: undefined,
|
19546 | zoom_resetButton: true,
|
19547 | zoom_x_min: undefined,
|
19548 | zoom_x_max: undefined
|
19549 | };
|
19550 |
|
19551 |
|
19552 |
|
19553 |
|
19554 |
|
19555 | var selectionModule = function () {
|
19556 | extend(ChartInternal.prototype, selection);
|
19557 | extend(Chart.prototype, apiSelection);
|
19558 | Options.setOptions([optDataSelection]);
|
19559 | return (selectionModule = function () { return true; })();
|
19560 | };
|
19561 | var subchartModule = function () {
|
19562 | extend(ChartInternal.prototype, subchart);
|
19563 | extend(Chart.prototype, apiSubchart);
|
19564 | Options.setOptions([optSubchart]);
|
19565 | return (subchartModule = function () { return true; })();
|
19566 | };
|
19567 | var zoomModule = function () {
|
19568 | extend(ChartInternal.prototype, zoom);
|
19569 | extend(Chart.prototype, apiZoom);
|
19570 | Options.setOptions([optZoom]);
|
19571 | return (zoomModule = function () { return true; })();
|
19572 | };
|
19573 |
|
19574 |
|
19575 |
|
19576 |
|
19577 |
|
19578 | var defaults = {};
|
19579 |
|
19580 |
|
19581 |
|
19582 |
|
19583 | var bb = {
|
19584 | |
19585 |
|
19586 |
|
19587 |
|
19588 |
|
19589 |
|
19590 |
|
19591 | version: "3.0.2",
|
19592 | |
19593 |
|
19594 |
|
19595 |
|
19596 |
|
19597 |
|
19598 |
|
19599 |
|
19600 |
|
19601 |
|
19602 |
|
19603 |
|
19604 |
|
19605 |
|
19606 |
|
19607 |
|
19608 |
|
19609 |
|
19610 |
|
19611 |
|
19612 |
|
19613 |
|
19614 |
|
19615 |
|
19616 |
|
19617 |
|
19618 |
|
19619 |
|
19620 |
|
19621 |
|
19622 |
|
19623 |
|
19624 |
|
19625 |
|
19626 |
|
19627 |
|
19628 |
|
19629 |
|
19630 |
|
19631 |
|
19632 |
|
19633 |
|
19634 |
|
19635 |
|
19636 |
|
19637 |
|
19638 |
|
19639 |
|
19640 |
|
19641 |
|
19642 |
|
19643 |
|
19644 |
|
19645 |
|
19646 |
|
19647 |
|
19648 |
|
19649 |
|
19650 |
|
19651 |
|
19652 |
|
19653 |
|
19654 |
|
19655 |
|
19656 |
|
19657 |
|
19658 |
|
19659 |
|
19660 |
|
19661 | generate: function (config) {
|
19662 | var options = mergeObj({}, defaults, config);
|
19663 | var inst = new Chart(options);
|
19664 | inst.internal.charts = this.instance;
|
19665 | this.instance.push(inst);
|
19666 | return inst;
|
19667 | },
|
19668 | |
19669 |
|
19670 |
|
19671 |
|
19672 |
|
19673 |
|
19674 |
|
19675 |
|
19676 |
|
19677 |
|
19678 |
|
19679 |
|
19680 |
|
19681 |
|
19682 |
|
19683 |
|
19684 |
|
19685 |
|
19686 |
|
19687 |
|
19688 |
|
19689 |
|
19690 | defaults: function (options) {
|
19691 | if (isObject(options)) {
|
19692 | defaults = options;
|
19693 | }
|
19694 | return defaults;
|
19695 | },
|
19696 | |
19697 |
|
19698 |
|
19699 |
|
19700 |
|
19701 |
|
19702 |
|
19703 |
|
19704 |
|
19705 |
|
19706 |
|
19707 | instance: [],
|
19708 | |
19709 |
|
19710 |
|
19711 |
|
19712 |
|
19713 |
|
19714 |
|
19715 |
|
19716 | plugin: {}
|
19717 | };
|
19718 |
|
19719 | export default bb;
|
19720 | export { area, areaLineRange, areaSpline, areaSplineRange, areaStep, bar, bb, bubble, candlestick, donut, gauge, line, pie, radar, scatter, selectionModule as selection, spline, step, subchartModule as subchart, zoomModule as zoom };
|