@pioneer-code/pioneer-charts 22.2.10 → 22.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -589,19 +589,27 @@ class PcacTooltipBuilder {
|
|
|
589
589
|
*/
|
|
590
590
|
view = null;
|
|
591
591
|
viewTemplate = null;
|
|
592
|
+
/** Space left between the tooltip and whatever it's placed next to (the cursor or an anchor). */
|
|
593
|
+
static GAP = 8;
|
|
592
594
|
/**
|
|
593
|
-
* Shows the tooltip for a hovered datum
|
|
594
|
-
*
|
|
595
|
-
* `
|
|
595
|
+
* Shows the tooltip for a hovered datum. Renders `template` when the chart has one projected;
|
|
596
|
+
* otherwise falls back to the default key/value content, formatted per `valueFormat`/`keyFormat`.
|
|
597
|
+
* Placed beside `anchor` when one is given (see `positionBeside`), else above the event's position.
|
|
596
598
|
*/
|
|
597
|
-
showTooltip(event, template, context, valueFormat, keyFormat) {
|
|
599
|
+
showTooltip(event, template, context, valueFormat, keyFormat, anchor) {
|
|
598
600
|
if (template) {
|
|
599
601
|
this.renderTemplate(template, context);
|
|
600
602
|
}
|
|
601
603
|
else {
|
|
602
604
|
this.renderDefault(context.$implicit, valueFormat, keyFormat);
|
|
603
605
|
}
|
|
604
|
-
this.
|
|
606
|
+
const shell = this.measurable();
|
|
607
|
+
if (anchor) {
|
|
608
|
+
this.positionBeside(shell, anchor);
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
this.positionAbove(shell, event);
|
|
612
|
+
}
|
|
605
613
|
}
|
|
606
614
|
/**
|
|
607
615
|
* @deprecated Builders should call `PcacChart.showTooltip()`, which routes through a chart's
|
|
@@ -658,14 +666,52 @@ class PcacTooltipBuilder {
|
|
|
658
666
|
this.tooltip.html(null);
|
|
659
667
|
}
|
|
660
668
|
/**
|
|
661
|
-
*
|
|
662
|
-
*
|
|
669
|
+
* Shows the (already rendered) shell at the page's top-left so it can be measured. Left where the
|
|
670
|
+
* last hover put it, a shell near the right edge would be squeezed by its containing block and
|
|
671
|
+
* measure narrower (wrapped) than the content really is once it's moved somewhere with room.
|
|
663
672
|
*/
|
|
664
|
-
|
|
665
|
-
|
|
673
|
+
measurable() {
|
|
674
|
+
return this.tooltip
|
|
675
|
+
.style('left', '0px')
|
|
676
|
+
.style('top', '0px')
|
|
677
|
+
.style('display', 'inline-block')
|
|
678
|
+
.node();
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Centers the tooltip horizontally on the cursor and sits it just above. Measured from the real
|
|
682
|
+
* box rather than fixed offsets so it works for content of any size.
|
|
683
|
+
*/
|
|
684
|
+
positionAbove(shell, event) {
|
|
666
685
|
this.tooltip
|
|
667
686
|
.style('left', event.pageX - shell.offsetWidth / 2 + 'px')
|
|
668
|
-
.style('top', event.pageY - shell.offsetHeight -
|
|
687
|
+
.style('top', event.pageY - shell.offsetHeight - PcacTooltipBuilder.GAP + 'px');
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Places the tooltip diagonally off one corner of `anchor`'s rendered box, so it never covers
|
|
691
|
+
* the anchor itself (e.g. a point's image). Prefers above-right - the tooltip's bottom-left
|
|
692
|
+
* corner at the anchor's top-right - and flips each axis independently when the tooltip wouldn't
|
|
693
|
+
* fit in the viewport that way: to the left when there's no room on the right, below when there's
|
|
694
|
+
* no room above. When neither side of an axis fits, it takes whichever side has more room.
|
|
695
|
+
*/
|
|
696
|
+
positionBeside(shell, anchor) {
|
|
697
|
+
const gap = PcacTooltipBuilder.GAP;
|
|
698
|
+
const box = anchor.getBoundingClientRect();
|
|
699
|
+
const width = shell.offsetWidth;
|
|
700
|
+
const height = shell.offsetHeight;
|
|
701
|
+
// `clientWidth`/`clientHeight` of the root, unlike `innerWidth`/`innerHeight`, exclude scrollbars.
|
|
702
|
+
const viewport = document.documentElement;
|
|
703
|
+
const right = viewport.clientWidth - box.right - gap;
|
|
704
|
+
const left = box.left - gap;
|
|
705
|
+
const above = box.top - gap;
|
|
706
|
+
const below = viewport.clientHeight - box.bottom - gap;
|
|
707
|
+
const toRight = width <= right || (width > left && right >= left);
|
|
708
|
+
const toTop = height <= above || (height > below && above >= below);
|
|
709
|
+
const x = toRight ? box.right + gap : box.left - gap - width;
|
|
710
|
+
const y = toTop ? box.top - gap - height : box.bottom + gap;
|
|
711
|
+
// The rect is in viewport coordinates; the shell is absolutely positioned against the page.
|
|
712
|
+
this.tooltip
|
|
713
|
+
.style('left', x + window.scrollX + 'px')
|
|
714
|
+
.style('top', y + window.scrollY + 'px');
|
|
669
715
|
}
|
|
670
716
|
getBarTipData(data, valueFormat, keyFormat) {
|
|
671
717
|
let value = data.value;
|
|
@@ -926,7 +972,7 @@ class PcacChart {
|
|
|
926
972
|
index: options.index,
|
|
927
973
|
parentIndex: options.parentIndex ?? null,
|
|
928
974
|
coincident: options.coincident ?? [],
|
|
929
|
-
}, options.valueFormat, options.keyFormat);
|
|
975
|
+
}, options.valueFormat, options.keyFormat, options.anchor);
|
|
930
976
|
}
|
|
931
977
|
hideTooltip() {
|
|
932
978
|
this.tooltipBuilder.hideTooltip();
|
|
@@ -1923,7 +1969,8 @@ class PcacLineAreaChartConfig extends PcacAxisChartConfig {
|
|
|
1923
1969
|
enableZoomX = false;
|
|
1924
1970
|
enableZoomY = false;
|
|
1925
1971
|
/**
|
|
1926
|
-
* Hex color codes to override the default colors
|
|
1972
|
+
* Hex color codes to override the default colors, one per series in order. Repeats from the
|
|
1973
|
+
* start when there are more series than colors, as the default palette does.
|
|
1927
1974
|
*/
|
|
1928
1975
|
colorOverride = [];
|
|
1929
1976
|
/**
|
|
@@ -2595,9 +2642,13 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2595
2642
|
}
|
|
2596
2643
|
// `?.length`, not a bare truthiness check: PcacLineAreaChartConfig defaults colorOverride to
|
|
2597
2644
|
// `[]`, and an empty array is truthy - a config built with `new` would otherwise replace the
|
|
2598
|
-
// theme palette with nothing and every series would render with no color at all.
|
|
2599
|
-
|
|
2600
|
-
|
|
2645
|
+
// theme palette with nothing and every series would render with no color at all. Cycled out to
|
|
2646
|
+
// as many entries as `initializeChartState` gave the theme palette, the same way that palette
|
|
2647
|
+
// cycles its own colors, so an override shorter than the data repeats rather than leaving every
|
|
2648
|
+
// series past its end with an `undefined` color (and so no line, dot stroke or range).
|
|
2649
|
+
const override = this.config.colorOverride;
|
|
2650
|
+
if (override?.length) {
|
|
2651
|
+
this.colors = Array.from({ length: Math.max(this.colors.length, override.length) }, (_, i) => override[i % override.length]);
|
|
2601
2652
|
}
|
|
2602
2653
|
this.scales = new PlaChartScalesBuilder().build(this.xAxis, this.yAxis, this.config.data, this.width, this.height);
|
|
2603
2654
|
this.lineGenerator = buildLineGenerator(this.xAxis.format, this.scales);
|
|
@@ -3010,6 +3061,8 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3010
3061
|
coincident: self.coincidentWith(d),
|
|
3011
3062
|
valueFormat: self.yAxis.format,
|
|
3012
3063
|
keyFormat: self.xAxis.format,
|
|
3064
|
+
// The dot or image itself rather than the group, so the tooltip clears what's drawn.
|
|
3065
|
+
anchor: select$1(this).select('.dot, .dot-image').node(),
|
|
3013
3066
|
});
|
|
3014
3067
|
// No-op for an image point (no circle inside to grow). Its own transition name, so it
|
|
3015
3068
|
// runs alongside the enter rise rather than cancelling it (see DOT_HOVER_TRANSITION);
|