@d3plus/core 4.11.0 → 4.12.0
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.
- package/es/internal.js +15 -5
- package/es/src/charts/Alluvial/emit.js +2 -2
- package/es/src/charts/Alluvial/index.js +7 -1
- package/es/src/charts/Alluvial/titles.js +24 -4
- package/es/src/charts/ArcDiagram/emit.js +27 -13
- package/es/src/charts/ArcDiagram/events.js +6 -2
- package/es/src/charts/ArcDiagram/index.js +2 -0
- package/es/src/charts/BarChart/index.js +3 -10
- package/es/src/charts/Calendar/index.js +2 -0
- package/es/src/charts/Candlestick/index.js +4 -10
- package/es/src/charts/Gantt/applyLayout.js +2 -4
- package/es/src/charts/Geomap/flowEmit.js +11 -6
- package/es/src/charts/Hexbin/index.js +2 -0
- package/es/src/charts/Icicle/index.js +3 -1
- package/es/src/charts/Matrix/applyLayout.js +20 -9
- package/es/src/charts/Matrix/index.js +19 -1
- package/es/src/charts/Network/applyLayout.js +36 -5
- package/es/src/charts/Network/bundle.js +5 -4
- package/es/src/charts/Network/emit.js +39 -40
- package/es/src/charts/Network/graph.js +34 -5
- package/es/src/charts/Network/graphFluent.js +5 -3
- package/es/src/charts/Network/index.js +6 -1
- package/es/src/charts/Pack/applyLayout.js +16 -5
- package/es/src/charts/Pack/emit.js +15 -8
- package/es/src/charts/Pack/groupRows.js +61 -0
- package/es/src/charts/Pack/index.js +3 -0
- package/es/src/charts/Pack/neutralPaint.js +20 -0
- package/es/src/charts/Pack/nodeNames.js +35 -0
- package/es/src/charts/ParallelCoordinates/axes.js +22 -22
- package/es/src/charts/ParallelCoordinates/chrome.js +18 -0
- package/es/src/charts/ParallelCoordinates/index.js +3 -1
- package/es/src/charts/ParallelCoordinates/titles.js +17 -9
- package/es/src/charts/Pie/emit.js +9 -1
- package/es/src/charts/Pie/index.js +10 -0
- package/es/src/charts/Plot/areaEnter.js +68 -0
- package/es/src/charts/Plot/draw.js +26 -12
- package/es/src/charts/Plot/index.js +4 -10
- package/es/src/charts/Plot/lineMarkerKeys.js +19 -0
- package/es/src/charts/Plot/plotInit.js +6 -0
- package/es/src/charts/Plot/shapeLabelLegend.js +67 -0
- package/es/src/charts/Plot/sharedHover.js +2 -1
- package/es/src/charts/Plot/sharedTooltip.js +13 -3
- package/es/src/charts/PolarArea/index.js +2 -1
- package/es/src/charts/Priestley/applyLayout.js +11 -7
- package/es/src/charts/Priestley/index.js +0 -2
- package/es/src/charts/Priestley/timeAxis.js +11 -8
- package/es/src/charts/Pyramid/gutter.js +52 -16
- package/es/src/charts/Pyramid/index.js +55 -7
- package/es/src/charts/Pyramid/scene.js +4 -4
- package/es/src/charts/Radar/applyLayout.js +31 -33
- package/es/src/charts/Radar/axisDecorations.js +29 -17
- package/es/src/charts/Radar/curvedLabels.js +43 -2
- package/es/src/charts/Radar/emit.js +30 -15
- package/es/src/charts/Radar/index.js +41 -2
- package/es/src/charts/Radar/points.js +85 -0
- package/es/src/charts/RadialBar/emit.js +6 -1
- package/es/src/charts/RadialBar/index.js +10 -0
- package/es/src/charts/RadialMatrix/applyLayout.js +115 -31
- package/es/src/charts/RadialMatrix/index.js +15 -2
- package/es/src/charts/Rings/applyLayout.js +11 -150
- package/es/src/charts/Rings/emit.js +80 -40
- package/es/src/charts/Rings/index.js +27 -4
- package/es/src/charts/Rings/ringsCurves.js +156 -0
- package/es/src/charts/Rings/ringsParallel.js +20 -3
- package/es/src/charts/Rings/ringsPlacement.js +152 -0
- package/es/src/charts/Rings/ringsSizing.js +61 -38
- package/es/src/charts/Sankey/applyLayout.js +18 -4
- package/es/src/charts/Sankey/index.js +7 -1
- package/es/src/charts/Sunburst/emit.js +9 -1
- package/es/src/charts/Sunburst/index.js +13 -1
- package/es/src/charts/Tree/applyLayout.js +44 -14
- package/es/src/charts/Tree/emit.js +5 -5
- package/es/src/charts/Tree/index.js +10 -12
- package/es/src/charts/Tree/keys.js +33 -0
- package/es/src/charts/Tree/nodeLabel.js +15 -0
- package/es/src/charts/Treemap/emitGroupHeaders.js +3 -5
- package/es/src/charts/definition/makeChart.js +6 -2
- package/es/src/charts/drawSteps/minimap.js +4 -20
- package/es/src/charts/drawSteps/zoomActions.js +36 -0
- package/es/src/charts/drawSteps/zoomControls.js +31 -18
- package/es/src/charts/drawSteps/zoomControlsMarkup.js +23 -4
- package/es/src/charts/drawSteps/zoomDrag.js +188 -0
- package/es/src/charts/drawSteps/zoomFit.js +69 -0
- package/es/src/charts/events/click.legend.js +4 -2
- package/es/src/charts/events/click.shape.js +5 -3
- package/es/src/charts/events/mouseenter.js +6 -16
- package/es/src/charts/events/mouseleave.js +9 -2
- package/es/src/charts/events/mousemove.legend.js +28 -32
- package/es/src/charts/events/mousemove.shape.js +44 -44
- package/es/src/charts/features/axes.js +15 -4
- package/es/src/charts/features/axesFinal.js +7 -2
- package/es/src/charts/features/axesMeasure.js +26 -8
- package/es/src/charts/features/axisTooltip.js +138 -0
- package/es/src/charts/features/centerLabel.js +177 -0
- package/es/src/charts/features/colorScaleBivariate.js +83 -0
- package/es/src/charts/features/colorScaleBucket.js +18 -0
- package/es/src/charts/features/colorScaleHover.js +30 -5
- package/es/src/charts/features/colorScaleLimit.js +73 -0
- package/es/src/charts/features/colorScaleTooltip.js +77 -0
- package/es/src/charts/features/colorScaleTop.js +61 -0
- package/es/src/charts/features/curvedArrows.js +33 -0
- package/es/src/charts/features/depthKey.js +26 -0
- package/es/src/charts/features/edgeArrows.js +61 -2
- package/es/src/charts/features/featuresColorScale.js +57 -16
- package/es/src/charts/features/hoverTicks.js +41 -0
- package/es/src/charts/features/idleQueue.js +72 -0
- package/es/src/charts/features/linkInteraction.js +59 -7
- package/es/src/charts/features/networkMeasures.js +241 -0
- package/es/src/charts/features/nodeStats.js +309 -0
- package/es/src/charts/features/plotEndLabels.js +28 -7
- package/es/src/charts/features/plotPaint.js +9 -2
- package/es/src/charts/features/shapeEmit.js +7 -1
- package/es/src/charts/features/textHalo.js +3 -2
- package/es/src/charts/partition/chartFields.js +12 -3
- package/es/src/charts/partition/interaction.js +10 -5
- package/es/src/charts/pipeline/insetPlacement.js +8 -3
- package/es/src/charts/polar/chrome.js +81 -9
- package/es/src/charts/polar/config.js +4 -0
- package/es/src/charts/polar/wedgeLayout.js +2 -1
- package/es/src/charts/viz/Viz.js +24 -15
- package/es/src/charts/viz/VizBase.js +39 -4
- package/es/src/charts/viz/backgroundInk.js +10 -0
- package/es/src/charts/viz/emphasis.js +14 -0
- package/es/src/charts/viz/fillStroke.js +10 -0
- package/es/src/charts/viz/interactionOpacity.js +115 -32
- package/es/src/charts/viz/reportDrawError.js +15 -0
- package/es/src/charts/viz/setCursor.js +29 -0
- package/es/src/charts/viz/tooltipEnabled.js +38 -0
- package/es/src/charts/viz/userClick.js +34 -0
- package/es/src/charts/viz/vizDataPolling.js +0 -1
- package/es/src/charts/viz/vizDefaults.js +13 -34
- package/es/src/charts/viz/vizFields.js +6 -1
- package/es/src/charts/viz/vizRender.js +35 -5
- package/es/src/charts/viz/vizVisibility.js +12 -2
- package/es/src/components/Axis/Axis.js +29 -2
- package/es/src/components/Axis/axisBreak.js +29 -7
- package/es/src/components/Axis/axisDefaults.js +11 -0
- package/es/src/components/Axis/axisLabelKinds.js +36 -0
- package/es/src/components/Axis/axisLabelLineHeight.js +19 -0
- package/es/src/components/Axis/axisLabelRoom.js +37 -0
- package/es/src/components/Axis/axisLabelSize.js +171 -0
- package/es/src/components/Axis/axisLabelThinning.js +98 -4
- package/es/src/components/Axis/axisLayout.js +71 -46
- package/es/src/components/Axis/axisLayoutLabels.js +82 -140
- package/es/src/components/Axis/axisLayoutScale.js +9 -10
- package/es/src/components/Axis/axisLimit.js +27 -0
- package/es/src/components/Axis/axisMaxSize.js +39 -0
- package/es/src/components/Axis/axisRender.js +20 -8
- package/es/src/components/Axis/axisRounding.js +16 -1
- package/es/src/components/Axis/axisScene.js +11 -2
- package/es/src/components/Axis/axisTitle.js +53 -0
- package/es/src/components/Axis/axisTooltipTargets.js +128 -0
- package/es/src/components/ColorScale/ColorScale.js +62 -18
- package/es/src/components/ColorScale/bivariateRender.js +353 -0
- package/es/src/components/ColorScale/bivariateScale.js +150 -0
- package/es/src/components/ColorScale/colorScaleRender.js +32 -2
- package/es/src/components/ColorScale/colorScaleSwatchTooltips.js +77 -0
- package/es/src/components/Legend/Legend.js +10 -2
- package/es/src/components/Legend/legendCut.js +108 -0
- package/es/src/components/Legend/legendRender.js +38 -13
- package/es/src/components/TextBox.js +5 -2
- package/es/src/components/Timeline/timelineRender.js +2 -1
- package/es/src/components/textBoxScene.js +3 -0
- package/es/src/components/textEllipsis.js +7 -0
- package/es/src/components/tooltipDom.js +8 -5
- package/es/src/fluent.js +48 -0
- package/es/src/utils/BaseClass.js +7 -2
- package/es/src/utils/configValue.js +9 -0
- package/package.json +10 -10
- package/types/index.d.ts +1 -1
- package/types/internal.d.ts +22 -5
- package/types/src/charts/Alluvial/titles.d.ts +16 -3
- package/types/src/charts/ArcDiagram/emit.d.ts +3 -2
- package/types/src/charts/ArcDiagram/events.d.ts +2 -1
- package/types/src/charts/Geomap/flowEmit.d.ts +3 -2
- package/types/src/charts/Matrix/applyLayout.d.ts +4 -2
- package/types/src/charts/Network/applyLayout.d.ts +11 -0
- package/types/src/charts/Network/bundle.d.ts +3 -1
- package/types/src/charts/Network/graph.d.ts +12 -4
- package/types/src/charts/Pack/applyLayout.d.ts +2 -0
- package/types/src/charts/Pack/groupRows.d.ts +46 -0
- package/types/src/charts/Pack/index.d.ts +3 -0
- package/types/src/charts/Pack/neutralPaint.d.ts +14 -0
- package/types/src/charts/Pack/nodeNames.d.ts +23 -0
- package/types/src/charts/ParallelCoordinates/chrome.d.ts +12 -0
- package/types/src/charts/ParallelCoordinates/index.d.ts +1 -0
- package/types/src/charts/ParallelCoordinates/titles.d.ts +7 -2
- package/types/src/charts/Plot/areaEnter.d.ts +34 -0
- package/types/src/charts/Plot/index.d.ts +4 -10
- package/types/src/charts/Plot/lineMarkerKeys.d.ts +11 -0
- package/types/src/charts/Plot/shapeLabelLegend.d.ts +19 -0
- package/types/src/charts/Plot/sharedTooltip.d.ts +7 -1
- package/types/src/charts/Priestley/timeAxis.d.ts +7 -4
- package/types/src/charts/Pyramid/gutter.d.ts +28 -6
- package/types/src/charts/Pyramid/scene.d.ts +1 -1
- package/types/src/charts/Radar/applyLayout.d.ts +2 -3
- package/types/src/charts/Radar/axisDecorations.d.ts +5 -2
- package/types/src/charts/Radar/curvedLabels.d.ts +35 -0
- package/types/src/charts/Radar/emit.d.ts +5 -2
- package/types/src/charts/Radar/index.d.ts +7 -2
- package/types/src/charts/Radar/points.d.ts +50 -0
- package/types/src/charts/RadialMatrix/applyLayout.d.ts +6 -4
- package/types/src/charts/Rings/emit.d.ts +24 -2
- package/types/src/charts/Rings/index.d.ts +4 -2
- package/types/src/charts/Rings/ringsCurves.d.ts +50 -0
- package/types/src/charts/Rings/ringsGraph.d.ts +29 -5
- package/types/src/charts/Rings/ringsParallel.d.ts +4 -2
- package/types/src/charts/Rings/ringsPlacement.d.ts +47 -0
- package/types/src/charts/Rings/ringsSizing.d.ts +36 -9
- package/types/src/charts/Tree/applyLayout.d.ts +20 -0
- package/types/src/charts/Tree/keys.d.ts +25 -0
- package/types/src/charts/Tree/nodeLabel.d.ts +11 -0
- package/types/src/charts/definition/ChartDefinition.d.ts +13 -0
- package/types/src/charts/definition/makeChart.d.ts +2 -2
- package/types/src/charts/drawSteps/zoomActions.d.ts +30 -0
- package/types/src/charts/drawSteps/zoomControls.d.ts +15 -0
- package/types/src/charts/drawSteps/zoomControlsMarkup.d.ts +16 -1
- package/types/src/charts/drawSteps/zoomDrag.d.ts +71 -0
- package/types/src/charts/drawSteps/zoomFit.d.ts +30 -0
- package/types/src/charts/features/axisTooltip.d.ts +49 -0
- package/types/src/charts/features/centerLabel.d.ts +75 -0
- package/types/src/charts/features/colorScaleBivariate.d.ts +50 -0
- package/types/src/charts/features/colorScaleBucket.d.ts +10 -0
- package/types/src/charts/features/colorScaleHover.d.ts +13 -3
- package/types/src/charts/features/colorScaleLimit.d.ts +60 -0
- package/types/src/charts/features/colorScaleTooltip.d.ts +43 -0
- package/types/src/charts/features/colorScaleTop.d.ts +30 -0
- package/types/src/charts/features/curvedArrows.d.ts +14 -0
- package/types/src/charts/features/depthKey.d.ts +19 -0
- package/types/src/charts/features/edgeArrows.d.ts +29 -2
- package/types/src/charts/features/hoverTicks.d.ts +30 -0
- package/types/src/charts/features/idleQueue.d.ts +46 -0
- package/types/src/charts/features/linkInteraction.d.ts +13 -4
- package/types/src/charts/features/networkMeasures.d.ts +53 -0
- package/types/src/charts/features/nodeStats.d.ts +93 -0
- package/types/src/charts/features/plotEndLabels.d.ts +14 -1
- package/types/src/charts/features/textHalo.d.ts +4 -3
- package/types/src/charts/partition/chartFields.d.ts +6 -1
- package/types/src/charts/pipeline/insetPlacement.d.ts +6 -0
- package/types/src/charts/polar/chrome.d.ts +19 -6
- package/types/src/charts/viz/Viz.d.ts +10 -3
- package/types/src/charts/viz/VizBase.d.ts +31 -2
- package/types/src/charts/viz/backgroundInk.d.ts +8 -0
- package/types/src/charts/viz/emphasis.d.ts +17 -0
- package/types/src/charts/viz/fillStroke.d.ts +7 -0
- package/types/src/charts/viz/reportDrawError.d.ts +12 -0
- package/types/src/charts/viz/setCursor.d.ts +26 -0
- package/types/src/charts/viz/tooltipEnabled.d.ts +31 -0
- package/types/src/charts/viz/userClick.d.ts +35 -0
- package/types/src/charts/viz/vizFields.d.ts +5 -0
- package/types/src/charts/viz/vizTypes.d.ts +16 -0
- package/types/src/charts/viz/vizVisibility.d.ts +7 -0
- package/types/src/components/Axis/Axis.d.ts +33 -3
- package/types/src/components/Axis/axisBreak.d.ts +19 -3
- package/types/src/components/Axis/axisDefaults.d.ts +12 -0
- package/types/src/components/Axis/axisLabelKinds.d.ts +22 -0
- package/types/src/components/Axis/axisLabelLineHeight.d.ts +27 -0
- package/types/src/components/Axis/axisLabelRoom.d.ts +17 -0
- package/types/src/components/Axis/axisLabelSize.d.ts +82 -0
- package/types/src/components/Axis/axisLabelThinning.d.ts +38 -2
- package/types/src/components/Axis/axisLayout.d.ts +9 -2
- package/types/src/components/Axis/axisLayoutLabels.d.ts +28 -33
- package/types/src/components/Axis/axisLayoutScale.d.ts +3 -1
- package/types/src/components/Axis/axisLimit.d.ts +18 -0
- package/types/src/components/Axis/axisMaxSize.d.ts +48 -0
- package/types/src/components/Axis/axisRounding.d.ts +8 -0
- package/types/src/components/Axis/axisTitle.d.ts +30 -0
- package/types/src/components/Axis/axisTooltipTargets.d.ts +82 -0
- package/types/src/components/ColorScale/ColorScale.d.ts +21 -11
- package/types/src/components/ColorScale/bivariateRender.d.ts +53 -0
- package/types/src/components/ColorScale/bivariateScale.d.ts +92 -0
- package/types/src/components/ColorScale/colorScaleSwatchTooltips.d.ts +48 -0
- package/types/src/components/Legend/Legend.d.ts +5 -0
- package/types/src/components/Legend/legendCut.d.ts +31 -0
- package/types/src/components/Legend/legendRender.d.ts +6 -1
- package/types/src/components/TextBox.d.ts +4 -0
- package/types/src/components/textEllipsis.d.ts +6 -0
- package/types/src/fluent.d.ts +18 -0
- package/types/src/shapes/emitLabels.d.ts +1 -1
- package/types/src/utils/D3plusConfig.d.ts +485 -609
- package/types/src/utils/configValue.d.ts +8 -0
- package/types/src/utils/index.d.ts +1 -1
- package/types/umd-entry.d.ts +4 -0
- package/umd/d3plus-core.full.js +22930 -17936
- package/umd/d3plus-core.full.min.js +2 -2
- package/umd/d3plus-core.js +21240 -16404
- package/umd/d3plus-core.min.js +2 -2
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { merge } from "d3-array";
|
|
2
|
-
import clickLegend from "./click.legend.js";
|
|
3
2
|
import { legendLabel } from "../features/legendLabel.js";
|
|
4
3
|
import { appendThresholdMembers } from "../features/thresholdMembers.js";
|
|
5
4
|
import { leadTitleWithSwatch, pickSwatch } from "../features/tooltipSwatch.js";
|
|
5
|
+
import { setCursor } from "../viz/setCursor.js";
|
|
6
|
+
import { tooltipEnabled } from "../viz/tooltipEnabled.js";
|
|
7
|
+
import { hasOwnClick, hasUserClick } from "../viz/userClick.js";
|
|
6
8
|
import { configPrep } from "../../utils/index.js";
|
|
7
9
|
/**
|
|
8
10
|
@module mouseMoveLegend
|
|
@@ -24,35 +26,29 @@ import { configPrep } from "../../utils/index.js";
|
|
|
24
26
|
];
|
|
25
27
|
return id;
|
|
26
28
|
})).length;
|
|
27
|
-
if (d
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
]).footer(hasDefaultClick ? invertedBehavior ? this._solo.length && !solo || hidden ? t("Click to Highlight") : this._solo.length === 1 && solo || this._hidden.length === dataLength - 1 ? t("Click to Show All") : `${t("Click to Highlight")}<br />${t("Shift+Click to Hide")}` : this._solo.length && !solo || hidden ? `${t("Click to Show")}<br />${t("Shift+Click to Highlight")}` : this._solo.length === 1 && solo || this._hidden.length === dataLength - 1 ? t("Click to Show All") : `${t("Click to Hide")}<br />${t("Shift+Click to Highlight")}` : false).title(this.schema.legendConfig.label ? this._legendClass.label() : legendLabel.bind(this)).titleSwatch(true).position(position).config(configPrep.bind(this)(this.schema.tooltipConfig)).config(configPrep.bind(this)(this.schema.legendTooltip));
|
|
53
|
-
// A threshold bucket's entry lists what it holds.
|
|
54
|
-
appendThresholdMembers(this._tooltipClass, this, d);
|
|
55
|
-
// The title leads with the hovered entry's swatch, as on the chart.
|
|
56
|
-
leadTitleWithSwatch(this._tooltipClass, pickSwatch(this, this._lastScenePick)).render();
|
|
57
|
-
}
|
|
29
|
+
if (!d) return;
|
|
30
|
+
let id = this._id(d, i);
|
|
31
|
+
if (id instanceof Array) id = id[0];
|
|
32
|
+
const t = this.schema.translate;
|
|
33
|
+
// does the legend have any user-defined click events?
|
|
34
|
+
const userClick = hasUserClick(this, "click.legend");
|
|
35
|
+
// does the legend still have our default "click.legend" event?
|
|
36
|
+
// (if the user only sets "click", both functions will fire)
|
|
37
|
+
const hasDefaultClick = hasOwnClick(this, "click.legend");
|
|
38
|
+
// can the viz show deeper data?
|
|
39
|
+
const hasDeeperLevel = this._drawDepth < this.schema.groupBy.length - 1;
|
|
40
|
+
// only show the hand cursor when the entry has a click event, whether or
|
|
41
|
+
// not it shows a tooltip
|
|
42
|
+
setCursor(this, userClick || hasDefaultClick && hasDeeperLevel ? "pointer" : "auto");
|
|
43
|
+
if (!tooltipEnabled(this, d, i, true)) return;
|
|
44
|
+
const invertedBehavior = this.schema.legendFilterInvert.bind(this)(this);
|
|
45
|
+
const solo = this._solo.includes(id);
|
|
46
|
+
const hidden = this._hidden.includes(id);
|
|
47
|
+
this._tooltipClass.data([
|
|
48
|
+
x || d
|
|
49
|
+
]).footer(hasDefaultClick ? invertedBehavior ? this._solo.length && !solo || hidden ? t("Click to Highlight") : this._solo.length === 1 && solo || this._hidden.length === dataLength - 1 ? t("Click to Show All") : `${t("Click to Highlight")}<br />${t("Shift+Click to Hide")}` : this._solo.length && !solo || hidden ? `${t("Click to Show")}<br />${t("Shift+Click to Highlight")}` : this._solo.length === 1 && solo || this._hidden.length === dataLength - 1 ? t("Click to Show All") : `${t("Click to Hide")}<br />${t("Shift+Click to Highlight")}` : false).title(this.schema.legendConfig.label ? this._legendClass.label() : legendLabel.bind(this)).titleSwatch(true).position(position).config(configPrep.bind(this)(this.schema.tooltipConfig)).config(configPrep.bind(this)(this.schema.legendTooltip));
|
|
50
|
+
// A threshold bucket's entry lists what it holds.
|
|
51
|
+
appendThresholdMembers(this._tooltipClass, this, d);
|
|
52
|
+
// The title leads with the hovered entry's swatch, as on the chart.
|
|
53
|
+
leadTitleWithSwatch(this._tooltipClass, pickSwatch(this, this._lastScenePick)).render();
|
|
58
54
|
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
1
|
import { configPrep } from "../../utils/index.js";
|
|
2
|
-
import clickShape from "./click.shape.js";
|
|
3
2
|
import { groupDepthOf, groupNarrows, groupPath } from "../viz/groupRow.js";
|
|
4
3
|
import { appendThresholdMembers } from "../features/thresholdMembers.js";
|
|
4
|
+
import { leadWithColorScaleRows } from "../features/colorScaleTooltip.js";
|
|
5
5
|
import { leadTitleWithSwatch, pickSwatch } from "../features/tooltipSwatch.js";
|
|
6
6
|
import { pointTooltipAnchor } from "../viz/pointTooltipAnchor.js";
|
|
7
|
+
import { setCursor } from "../viz/setCursor.js";
|
|
8
|
+
import { tooltipEnabled } from "../viz/tooltipEnabled.js";
|
|
9
|
+
import { hasOwnClick, hasUserClick } from "../viz/userClick.js";
|
|
7
10
|
/**
|
|
8
11
|
@module mouseMoveShape
|
|
9
12
|
Tooltip logic for a specified data point.
|
|
10
13
|
@param config Optional configuration methods for the Tooltip class.
|
|
11
14
|
@private
|
|
12
15
|
*/ export default function(d, i, x, event) {
|
|
13
|
-
if (d
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// The title leads with a swatch of the hovered mark, as in the legend.
|
|
54
|
-
leadTitleWithSwatch(this._tooltipClass, pickSwatch(this, this._lastScenePick)).render();
|
|
55
|
-
}
|
|
16
|
+
if (!d) return;
|
|
17
|
+
// does the shape have any user-defined click events?
|
|
18
|
+
const userClick = hasUserClick(this, "click.shape");
|
|
19
|
+
// does the shape still have our default "click.shape" event?
|
|
20
|
+
// (if the user only sets "click", both functions will fire)
|
|
21
|
+
const hasDefaultClick = hasOwnClick(this, "click.shape");
|
|
22
|
+
// can the viz show deeper data? A group row zooms into its group.
|
|
23
|
+
const groupDepth = groupDepthOf(d);
|
|
24
|
+
const hasDeeperLevel = groupDepth === undefined ? this._drawDepth < this.schema.groupBy.length - 1 : groupNarrows(this.schema.groupBy, groupPath(this.schema.groupBy, d, groupDepth), this._filteredData ?? []);
|
|
25
|
+
// only show the hand cursor when the shape has a click event, whether or
|
|
26
|
+
// not it shows a tooltip
|
|
27
|
+
setCursor(this, userClick || hasDefaultClick && hasDeeperLevel ? "pointer" : "auto");
|
|
28
|
+
if (!tooltipEnabled(this, d, i)) return;
|
|
29
|
+
// Plot's snapped hover (shared or single) owns the tooltip while active.
|
|
30
|
+
if (this._sharedHoverActive) return;
|
|
31
|
+
// A point mark's tooltip points at the mark, wherever the pointer is
|
|
32
|
+
// within reach of it; anything else follows the pointer.
|
|
33
|
+
const position = pointTooltipAnchor(this, this._lastScenePick?.node) ?? (event.touches ? [
|
|
34
|
+
event.touches[0].clientX,
|
|
35
|
+
event.touches[0].clientY
|
|
36
|
+
] : [
|
|
37
|
+
event.clientX,
|
|
38
|
+
event.clientY
|
|
39
|
+
]);
|
|
40
|
+
// Unwrap to the underlying source row so tooltip cell accessors (e.g.
|
|
41
|
+
// the Treemap "share" column) resolve regardless of whether the hovered
|
|
42
|
+
// scene node was the shape (datum = row) or its text label (datum = a
|
|
43
|
+
// wrapper whose `.data` chain leads back to the row).
|
|
44
|
+
let tooltipDatum = x || d;
|
|
45
|
+
while(tooltipDatum && tooltipDatum.__d3plus__ && tooltipDatum.data)tooltipDatum = tooltipDatum.data;
|
|
46
|
+
this._tooltipClass.data([
|
|
47
|
+
tooltipDatum
|
|
48
|
+
]).footer(hasDefaultClick && hasDeeperLevel ? this.schema.translate("Click to Expand") : false).title((dd, ii)=>this._drawLabel(dd, ii)).titleSwatch(true).position(position).config(configPrep.bind(this)(this.schema.tooltipConfig));
|
|
49
|
+
// The row's colorScale value (or a bivariate colorScale's two) leads
|
|
50
|
+
// the rows.
|
|
51
|
+
leadWithColorScaleRows(this._tooltipClass, this, tooltipDatum, i);
|
|
52
|
+
// A threshold bucket lists what it holds.
|
|
53
|
+
appendThresholdMembers(this._tooltipClass, this, tooltipDatum);
|
|
54
|
+
// The title leads with a swatch of the hovered mark, as in the legend.
|
|
55
|
+
leadTitleWithSwatch(this._tooltipClass, pickSwatch(this, this._lastScenePick)).render();
|
|
56
56
|
}
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
|
|
36
36
|
@module
|
|
37
37
|
*/ import { max } from "d3-array";
|
|
38
|
+
import { defaultMaxSize, pinMaxSize } from "../../components/Axis/axisMaxSize.js";
|
|
38
39
|
import { frozenAxis } from "./frozenAxis.js";
|
|
39
40
|
import { alignAxisLine, placeEndLabels } from "./plotEndLabels.js";
|
|
40
41
|
import { bumpLineLabels } from "./lineLabels.js";
|
|
@@ -101,11 +102,15 @@ import { solveFinalAxes } from "./axesFinal.js";
|
|
|
101
102
|
// Plot sets these before the axis pass runs.
|
|
102
103
|
const xAxis = viz._xAxis;
|
|
103
104
|
const x2Axis = viz._x2Axis;
|
|
105
|
+
const xPlotConfig = plotAxisConfig(viz, "x");
|
|
104
106
|
xAxis.renderMode("compute").select(null).domain(xDomain).height(height - (x2Height + topOffset + verticalMargin)).maxSize(height / 2).range(xRange).ticks(xTicks).width(width)// Rotate the labels as the test axis did when it claimed their height.
|
|
105
107
|
.labelRotation(testRotation(pCtx.xTest)).config({
|
|
106
108
|
...UNZOOMED_AXIS,
|
|
107
109
|
...xC
|
|
108
|
-
}).config(
|
|
110
|
+
}).config(xPlotConfig).config(pCtx.zoomAxes?.x ?? {}).scale(xConfigScale);
|
|
111
|
+
defaultMaxSize(xAxis, xC, xPlotConfig);
|
|
112
|
+
// A `maxSize` function reads the height the test axis measured with.
|
|
113
|
+
pinMaxSize(xAxis, height);
|
|
109
114
|
// Labeling its ends, the axis draws only its gridlines, up from the plot's bottom edge.
|
|
110
115
|
const gridOnly = Boolean(pCtx.xLabelMode && pCtx.xLabelMode !== "axis");
|
|
111
116
|
if (gridOnly) alignAxisLine(xAxis, plotBottom);
|
|
@@ -122,7 +127,8 @@ import { solveFinalAxes } from "./axesFinal.js";
|
|
|
122
127
|
x2Axis.renderMode("compute").select(null).domain(x2Domain).height(height - (pCtx.xHeight + topOffset + verticalMargin)).range(xRange).ticks(x2Ticks).width(width).labelRotation(testRotation(pCtx.x2Test)).config({
|
|
123
128
|
...UNZOOMED_AXIS,
|
|
124
129
|
...xC
|
|
125
|
-
}).config(defaultX2Config).config(viz._x2Config).config(pCtx.zoomAxes?.x2 ?? {}).scale(x2ConfigScale)
|
|
130
|
+
}).config(defaultX2Config).config(viz._x2Config).config(pCtx.zoomAxes?.x2 ?? {}).scale(x2ConfigScale);
|
|
131
|
+
pinMaxSize(x2Axis, height).render();
|
|
126
132
|
axisSceneQueue.push({
|
|
127
133
|
key: "plot-x2-axis",
|
|
128
134
|
transform: axisRelativeTransform("x2"),
|
|
@@ -152,10 +158,14 @@ import { solveFinalAxes } from "./axesFinal.js";
|
|
|
152
158
|
// Plot sets these before the axis pass runs.
|
|
153
159
|
const yAxis = viz._yAxis;
|
|
154
160
|
const y2Axis = viz._y2Axis;
|
|
161
|
+
const yPlotConfig = plotAxisConfig(viz, "y");
|
|
155
162
|
yAxis.renderMode("compute").select(null).domain(yDomain).height(height).maxSize(width / 2).range(yRange).ticks(yTicks).width(xRange[xRange.length - 1]).config({
|
|
156
163
|
...UNZOOMED_AXIS,
|
|
157
164
|
...yC
|
|
158
|
-
}).config(
|
|
165
|
+
}).config(yPlotConfig).config(pCtx.zoomAxes?.y ?? {}).scale(yConfigScale);
|
|
166
|
+
defaultMaxSize(yAxis, yC, yPlotConfig);
|
|
167
|
+
// A `maxSize` function reads the width the test axis measured with.
|
|
168
|
+
pinMaxSize(yAxis, width).render();
|
|
159
169
|
if (showY) {
|
|
160
170
|
axisSceneQueue.push({
|
|
161
171
|
key: "plot-y-axis",
|
|
@@ -170,7 +180,8 @@ import { solveFinalAxes } from "./axesFinal.js";
|
|
|
170
180
|
}).domain(y2Exists ? y2Domain : yDomain).gridSize(0).height(height).range(yRange).width(width - max([
|
|
171
181
|
0,
|
|
172
182
|
xOffsetRight - y2Width
|
|
173
|
-
])).title(false).config(viz._y2Config).config(defaultY2Config).config(pCtx.zoomAxes?.y2 ?? {}).scale(y2ConfigScale)
|
|
183
|
+
])).title(false).config(viz._y2Config).config(defaultY2Config).config(pCtx.zoomAxes?.y2 ?? {}).scale(y2ConfigScale);
|
|
184
|
+
pinMaxSize(y2Axis, width).render();
|
|
174
185
|
axisSceneQueue.push({
|
|
175
186
|
key: "plot-y2-axis",
|
|
176
187
|
transform: axisRelativeTransform("y2"),
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
@module
|
|
8
8
|
*/ import { max } from "d3-array";
|
|
9
|
+
import { defaultMaxSize, pinMaxSize } from "../../components/Axis/axisMaxSize.js";
|
|
9
10
|
import { plotAxisConfig } from "../Plot/baselineBreak.js";
|
|
10
11
|
/**
|
|
11
12
|
The room the plot leaves on its right for the y2 axis and for the x/x2
|
|
@@ -43,7 +44,9 @@ import { plotAxisConfig } from "../Plot/baselineBreak.js";
|
|
|
43
44
|
const { yTest, y2Test } = pCtx;
|
|
44
45
|
let { xOffsetRight } = pCtx;
|
|
45
46
|
if (showY) {
|
|
46
|
-
|
|
47
|
+
const yPlotConfig = plotAxisConfig(viz, "y");
|
|
48
|
+
yTest.domain(yDomain).height(height).maxSize(width / 2).range(yRange).ticks(yTicks).width(width).config(yC).config(yPlotConfig).scale(yConfigScale);
|
|
49
|
+
defaultMaxSize(yTest, yC, yPlotConfig).measure();
|
|
47
50
|
}
|
|
48
51
|
const yBounds = yTest.outerBounds();
|
|
49
52
|
const yWidth = yBounds.width ? yBounds.width + yTest.padding() : undefined;
|
|
@@ -60,7 +63,9 @@ import { plotAxisConfig } from "../Plot/baselineBreak.js";
|
|
|
60
63
|
y2Test.config(yC).domain(y2Domain).gridSize(0).height(height).range(yRange).width(width - max([
|
|
61
64
|
0,
|
|
62
65
|
xOffsetRight - pCtx.y2Width
|
|
63
|
-
])).title(false).config(viz._y2Config).config(defaultY2Config).scale(y2ConfigScale)
|
|
66
|
+
])).title(false).config(viz._y2Config).config(defaultY2Config).scale(y2ConfigScale);
|
|
67
|
+
// A `maxSize` function reads the width the axis first measured with.
|
|
68
|
+
pinMaxSize(y2Test, width).measure();
|
|
64
69
|
}
|
|
65
70
|
const y2Bounds = y2Test.outerBounds();
|
|
66
71
|
const y2Width = y2Bounds.width ? y2Bounds.width + y2Test.padding() : undefined;
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
`viz._padding.*`. Runs BEFORE the base `Viz` draw finalizes margins.
|
|
6
6
|
*/ import { max } from "d3-array";
|
|
7
7
|
import AxisBottom from "../../components/Axis/AxisBottom.js";
|
|
8
|
+
import configValue from "../../utils/configValue.js";
|
|
8
9
|
import { barLabelsNeedAxis } from "../Plot/barLabelFit.js";
|
|
10
|
+
import { defaultMaxSize } from "../../components/Axis/axisMaxSize.js";
|
|
9
11
|
import { plotAxisConfig } from "../Plot/baselineBreak.js";
|
|
10
12
|
import { xRightInset } from "./axesFinal.js";
|
|
11
13
|
import { cornerControlsHeight } from "./features.js";
|
|
@@ -14,10 +16,12 @@ import { buildXConfig } from "./xAxisConfig.js";
|
|
|
14
16
|
/** Measure the y/y2 test axes and report their bounds + claimed widths. */ function measureYTestAxes(viz, inputs) {
|
|
15
17
|
const { yTest, y2Test, yDomain, y2Domain, yTicks, y2Ticks, yConfigScale, y2ConfigScale, defaultY2Config, yC, showY, y2Exists, height, width } = inputs;
|
|
16
18
|
if (showY) {
|
|
19
|
+
const yPlotConfig = plotAxisConfig(viz, "y");
|
|
17
20
|
yTest.domain(yDomain).height(height).maxSize(width / 2).range([
|
|
18
21
|
undefined,
|
|
19
22
|
undefined
|
|
20
|
-
]).ticks(yTicks).width(width).config(yC).config(
|
|
23
|
+
]).ticks(yTicks).width(width).config(yC).config(yPlotConfig).scale(yConfigScale);
|
|
24
|
+
defaultMaxSize(yTest, yC, yPlotConfig).measure();
|
|
21
25
|
}
|
|
22
26
|
const yBounds = yTest.outerBounds();
|
|
23
27
|
const yWidth = yBounds.width ? yBounds.width + yTest.padding() : undefined;
|
|
@@ -44,18 +48,22 @@ import { buildXConfig } from "./xAxisConfig.js";
|
|
|
44
48
|
let xRangeMax = undefined;
|
|
45
49
|
const xOverrides = ends ? END_LABEL_AXIS_CONFIG : {};
|
|
46
50
|
if (showX) {
|
|
51
|
+
const xPlotConfig = plotAxisConfig(viz, "x");
|
|
47
52
|
xTest.domain(xDomain).height(height).maxSize(height / 2).range([
|
|
48
53
|
undefined,
|
|
49
54
|
xRangeMax
|
|
50
|
-
]).ticks(xTicks).width(width).config(xC).config(
|
|
55
|
+
]).ticks(xTicks).width(width).config(xC).config(xPlotConfig).config(xOverrides).scale(xConfigScale);
|
|
56
|
+
defaultMaxSize(xTest, xC, xPlotConfig, xOverrides).measure();
|
|
51
57
|
}
|
|
52
58
|
const { labelWidths, largestLabel, xRangeMax: measuredXRangeMax, startLabelSpace = 0 } = measureLineLabels();
|
|
53
59
|
if (measuredXRangeMax !== undefined) xRangeMax = measuredXRangeMax;
|
|
54
60
|
if (showX && xRangeMax) {
|
|
61
|
+
const xPlotConfig = plotAxisConfig(viz, "x");
|
|
55
62
|
xTest.domain(xDomain).height(height).maxSize(height / 2).range([
|
|
56
63
|
undefined,
|
|
57
64
|
xRangeMax
|
|
58
|
-
]).ticks(xTicks).width(width).config(xC).config(
|
|
65
|
+
]).ticks(xTicks).width(width).config(xC).config(xPlotConfig).config(xOverrides).scale(xConfigScale);
|
|
66
|
+
defaultMaxSize(xTest, xC, xPlotConfig, xOverrides).measure();
|
|
59
67
|
}
|
|
60
68
|
if (x2Exists) {
|
|
61
69
|
x2Test.domain(x2Domain).height(height).range([
|
|
@@ -87,8 +95,7 @@ import { buildXConfig } from "./xAxisConfig.js";
|
|
|
87
95
|
viz._plotMinLeft?.(),
|
|
88
96
|
startLabelSpace && (yWidth ?? 0) + startLabelSpace
|
|
89
97
|
]);
|
|
90
|
-
const
|
|
91
|
-
const topOffset = (showY ? yLabelConfig.fontSize() / 2 : 0) + (viz._plotInsetTop ?? 0);
|
|
98
|
+
const topOffset = yLabelTopOffset(viz, yTest, showY);
|
|
92
99
|
const xOffsetRight = xRightInset({
|
|
93
100
|
xTest,
|
|
94
101
|
x2Test,
|
|
@@ -179,15 +186,26 @@ import { buildXConfig } from "./xAxisConfig.js";
|
|
|
179
186
|
*/ function provisionalTopOffset(viz, inputs) {
|
|
180
187
|
const { yTest, yC, showY } = inputs;
|
|
181
188
|
if (showY) yTest.config(yC).config(plotAxisConfig(viz, "y"));
|
|
182
|
-
|
|
183
|
-
|
|
189
|
+
return yLabelTopOffset(viz, yTest, showY);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
The room above the plot for half of the y axis's top label: its font
|
|
193
|
+
size (a constant or a function, as label config accepts) over 2, plus
|
|
194
|
+
the chart's own top inset.
|
|
195
|
+
*/ function yLabelTopOffset(viz, yTest, showY) {
|
|
196
|
+
const { fontSize } = yTest.shapeConfig().labelConfig;
|
|
197
|
+
const half = showY ? configValue(fontSize) / 2 : 0;
|
|
198
|
+
return half + (viz._plotInsetTop ?? 0);
|
|
184
199
|
}
|
|
185
200
|
/** The x axis's height, from a throwaway measure ahead of the joint solve. */ function provisionalXHeight(viz, inputs) {
|
|
186
201
|
if (!inputs.showX) return 0;
|
|
187
202
|
const axis = new AxisBottom().align("end").gridSize(0);
|
|
203
|
+
const xC = buildXConfig(viz, inputs);
|
|
204
|
+
const xPlotConfig = plotAxisConfig(viz, "x");
|
|
188
205
|
axis.domain(inputs.xDomain).height(inputs.height).maxSize(inputs.height / 2).range([
|
|
189
206
|
undefined,
|
|
190
207
|
undefined
|
|
191
|
-
]).ticks(inputs.xTicks).width(inputs.width).config(
|
|
208
|
+
]).ticks(inputs.xTicks).width(inputs.width).config(xC).config(xPlotConfig).scale(inputs.xConfigScale);
|
|
209
|
+
defaultMaxSize(axis, xC, xPlotConfig).measure();
|
|
192
210
|
return axis.outerBounds().height + axis.padding();
|
|
193
211
|
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Axis tooltips: hovering an axis's title or one of its tick labels shows
|
|
3
|
+
the chart's tooltip, with the text the axis's `titleTooltip` or
|
|
4
|
+
`tickTooltip` gives. A label drawn cut short heads the tooltip with its
|
|
5
|
+
whole text, so an axis that sets neither option still shows what its
|
|
6
|
+
cut labels say.
|
|
7
|
+
*/ import { axisTooltipTarget } from "../../components/Axis/axisTooltipTargets.js";
|
|
8
|
+
import { isPlainObject } from "../../fluent.js";
|
|
9
|
+
import { configPrep } from "../../utils/index.js";
|
|
10
|
+
import { constantValue } from "../../utils/constant.js";
|
|
11
|
+
/**
|
|
12
|
+
A copy of a config value whose functions, at any depth, are called with
|
|
13
|
+
`args` whatever they are passed.
|
|
14
|
+
@param value A config object, or any value in one.
|
|
15
|
+
@param args What every function in it receives.
|
|
16
|
+
*/ export function bindAccessors(value, args) {
|
|
17
|
+
if (typeof value === "function") return function() {
|
|
18
|
+
return value.apply(this, args);
|
|
19
|
+
};
|
|
20
|
+
if (Array.isArray(value)) return value.map((v)=>bindAccessors(v, args));
|
|
21
|
+
if (isPlainObject(value)) return Object.fromEntries(Object.entries(value).map(([k, v])=>[
|
|
22
|
+
k,
|
|
23
|
+
bindAccessors(v, args)
|
|
24
|
+
]));
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
/** Whether a function's result is text to show. */ const hasText = (text)=>text !== undefined && text !== null && text !== false && text !== "";
|
|
28
|
+
/**
|
|
29
|
+
What hovering an axis label shows, from the axis's `titleTooltip` or
|
|
30
|
+
`tickTooltip`: a string is the body, a function returns it (given the
|
|
31
|
+
title, or the tick's value and index), and an object is a tooltip config
|
|
32
|
+
whose accessors receive the same. A label drawn cut short adds its whole
|
|
33
|
+
text as the title. Null when there is nothing to show: the option is
|
|
34
|
+
`false`, its function returns `false`, or the label is drawn whole and
|
|
35
|
+
the option is unset or its function returns nothing.
|
|
36
|
+
@param target The hovered label.
|
|
37
|
+
@param fullText Whether a cut label shows its whole text.
|
|
38
|
+
@param self The `this` the option's function is called with.
|
|
39
|
+
*/ export function resolveAxisTooltip(target, fullText = true, self) {
|
|
40
|
+
const { option, part, value, index } = target;
|
|
41
|
+
if (option === false) return null;
|
|
42
|
+
const title = target.truncated && fullText ? target.text : false;
|
|
43
|
+
const args = part === "title" ? [
|
|
44
|
+
value
|
|
45
|
+
] : [
|
|
46
|
+
value,
|
|
47
|
+
index
|
|
48
|
+
];
|
|
49
|
+
if (isPlainObject(option)) return {
|
|
50
|
+
title,
|
|
51
|
+
body: false,
|
|
52
|
+
config: bindAccessors(option, args)
|
|
53
|
+
};
|
|
54
|
+
const text = typeof option === "function" ? option.apply(self, args) : typeof option === "string" ? option : undefined;
|
|
55
|
+
if (text === false) return null;
|
|
56
|
+
const body = hasText(text) ? `${text}` : false;
|
|
57
|
+
return title === false && body === false ? null : {
|
|
58
|
+
title,
|
|
59
|
+
body
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** The data of the axis tooltips shown, which tell them from a mark's or legend's. */ const shownData = new WeakSet();
|
|
63
|
+
/**
|
|
64
|
+
Whether a tooltip datum is an axis tooltip's.
|
|
65
|
+
@param d The first of a tooltip's data.
|
|
66
|
+
*/ export function isAxisTooltipDatum(d) {
|
|
67
|
+
return typeof d === "object" && d !== null && shownData.has(d);
|
|
68
|
+
}
|
|
69
|
+
/** Whether the chart's tooltip is showing an axis tooltip. */ function showing(viz) {
|
|
70
|
+
return isAxisTooltipDatum(viz._tooltipClass?.data()[0]);
|
|
71
|
+
}
|
|
72
|
+
/** The client position of a pointer event: the tooltip's anchor. */ function pointer(event) {
|
|
73
|
+
const native = event.nativeEvent;
|
|
74
|
+
return native && native.touches && native.touches.length ? [
|
|
75
|
+
native.touches[0].clientX,
|
|
76
|
+
native.touches[0].clientY
|
|
77
|
+
] : native ? [
|
|
78
|
+
native.clientX,
|
|
79
|
+
native.clientY
|
|
80
|
+
] : event.point;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
Shows the chart's tooltip for an axis label at the pointer: the chart's
|
|
84
|
+
`tooltipConfig` for its styles, then the label's title and body in place
|
|
85
|
+
of a mark's, then the axis option's own config. The tooltip's settings
|
|
86
|
+
are put back once it is drawn, so a mark's or legend's tooltip never
|
|
87
|
+
inherits them.
|
|
88
|
+
*/ function renderAxisTooltip(viz, target, content, event) {
|
|
89
|
+
const tip = viz._tooltipClass;
|
|
90
|
+
const prep = configPrep.bind(viz);
|
|
91
|
+
const { part, value, index, text } = target;
|
|
92
|
+
const datum = {
|
|
93
|
+
part,
|
|
94
|
+
value,
|
|
95
|
+
index,
|
|
96
|
+
text
|
|
97
|
+
};
|
|
98
|
+
shownData.add(datum);
|
|
99
|
+
const saved = {
|
|
100
|
+
...tip.schema
|
|
101
|
+
};
|
|
102
|
+
tip.data([
|
|
103
|
+
datum
|
|
104
|
+
]).config(prep(viz.schema.tooltipConfig)).title(content.title).body(content.body).footer(false).thead([]).tbody([]).position(pointer(event));
|
|
105
|
+
// A title with nothing under it needs no gap below.
|
|
106
|
+
if (!content.config && content.body === false) tip.titleStyle({
|
|
107
|
+
"margin-bottom": "0"
|
|
108
|
+
});
|
|
109
|
+
if (content.config) tip.config(prep(content.config));
|
|
110
|
+
tip.render();
|
|
111
|
+
for (const key of Object.keys(tip.schema))if (!(key in saved)) delete tip.schema[key];
|
|
112
|
+
Object.assign(tip.schema, saved);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
Shows, moves, or hides the axis tooltip for a pointer event. Moving onto
|
|
116
|
+
a label with something to show (see `resolveAxisTooltip`) shows it at the
|
|
117
|
+
pointer; moving anywhere else, or leaving the chart, hides it when it is
|
|
118
|
+
still the tooltip showing. Charts with `tooltip: false` skip the whole
|
|
119
|
+
text of cut labels, and show only what an axis option gives. Labels show
|
|
120
|
+
nothing while a transition is in flight.
|
|
121
|
+
@param viz The chart.
|
|
122
|
+
@param event The pointer event.
|
|
123
|
+
@returns Whether an axis tooltip is showing for the event.
|
|
124
|
+
*/ export function handleAxisTooltip(viz, event) {
|
|
125
|
+
if (!viz._tooltipClass) return false;
|
|
126
|
+
const moving = event.type === "mousemove" || event.type === "mouseenter";
|
|
127
|
+
if (!moving && event.type !== "mouseleave") return false;
|
|
128
|
+
const settled = !viz._transitionEndsAt || Date.now() >= viz._transitionEndsAt;
|
|
129
|
+
const target = moving && settled ? axisTooltipTarget(event.pick?.node) : undefined;
|
|
130
|
+
const fullText = constantValue(viz.schema.tooltip)?.value !== false;
|
|
131
|
+
const content = target && resolveAxisTooltip(target, fullText, viz);
|
|
132
|
+
if (target && content) {
|
|
133
|
+
renderAxisTooltip(viz, target, content, event);
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
if (showing(viz)) viz._tooltipClass.data([]).render();
|
|
137
|
+
return false;
|
|
138
|
+
}
|