@d3plus/core 4.9.0 → 4.10.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 +3 -1
- package/es/src/charts/BoxWhisker/index.js +73 -4
- package/es/src/charts/BoxWhisker/outliers.js +68 -0
- package/es/src/charts/BoxWhisker/summary.js +83 -0
- package/es/src/charts/BoxWhisker/tooltip.js +122 -0
- package/es/src/charts/Bullet/index.js +2 -1
- package/es/src/charts/BumpChart/index.js +5 -0
- package/es/src/charts/Calendar/index.js +2 -1
- package/es/src/charts/Candlestick/aggregate.js +11 -1
- package/es/src/charts/Candlestick/index.js +5 -5
- package/es/src/charts/Chord/index.js +3 -2
- package/es/src/charts/Funnel/index.js +2 -1
- package/es/src/charts/Gauge/index.js +2 -1
- package/es/src/charts/Geomap/index.js +9 -3
- package/es/src/charts/Histogram/index.js +5 -1
- package/es/src/charts/Matrix/index.js +3 -2
- package/es/src/charts/Network/index.js +9 -4
- package/es/src/charts/Pack/index.js +2 -1
- package/es/src/charts/Pie/index.js +2 -1
- package/es/src/charts/Plot/axisHover.js +180 -0
- package/es/src/charts/Plot/axisHoverAnchors.js +174 -0
- package/es/src/charts/Plot/axisHoverScene.js +202 -0
- package/es/src/charts/Plot/barHitArea.js +81 -0
- package/es/src/charts/Plot/barLabelFit.js +123 -0
- package/es/src/charts/Plot/barWidth.js +2 -2
- package/es/src/charts/Plot/confidenceConfig.js +2 -2
- package/es/src/charts/Plot/draw.js +6 -2
- package/es/src/charts/Plot/index.js +25 -6
- package/es/src/charts/Plot/labelPlacement.js +9 -1
- package/es/src/charts/Plot/openDomainEnds.js +2 -5
- package/es/src/charts/Plot/pipeline.js +5 -3
- package/es/src/charts/Plot/pipelineAxisLayout.js +38 -8
- package/es/src/charts/Plot/pipelineDomains.js +7 -3
- package/es/src/charts/Plot/pipelineLineLabels.js +1 -1
- package/es/src/charts/Plot/plotInit.js +15 -0
- package/es/src/charts/Plot/plotZoom.js +15 -6
- package/es/src/charts/Plot/shapeDefaults.js +4 -4
- package/es/src/charts/Plot/sharedHoverScene.js +50 -31
- package/es/src/charts/Plot/sharedTooltip.js +19 -7
- package/es/src/charts/Plot/stackHelpers.js +13 -1
- package/es/src/charts/Plot/stackShareTooltip.js +9 -4
- package/es/src/charts/Plot/stackThreshold.js +154 -0
- package/es/src/charts/PolarArea/index.js +3 -2
- package/es/src/charts/Priestley/index.js +3 -2
- package/es/src/charts/Pyramid/index.js +4 -2
- package/es/src/charts/Radar/index.js +3 -2
- package/es/src/charts/RadialBar/index.js +2 -1
- package/es/src/charts/RadialMatrix/index.js +3 -2
- package/es/src/charts/Rings/index.js +5 -3
- package/es/src/charts/Sankey/index.js +3 -2
- package/es/src/charts/Treemap/applyLayout.js +14 -1
- package/es/src/charts/Treemap/emit.js +8 -2
- package/es/src/charts/Treemap/emitGroupHeaders.js +104 -0
- package/es/src/charts/Treemap/groupHeaders.js +95 -0
- package/es/src/charts/Treemap/index.js +15 -2
- package/es/src/charts/Treemap/thresholdFunction.js +11 -9
- package/es/src/charts/Waffle/index.js +4 -2
- package/es/src/charts/Waffle/tooltip.js +6 -2
- package/es/src/charts/Waterfall/index.js +4 -2
- package/es/src/charts/definition/makeChart.js +12 -5
- package/es/src/charts/drawSteps/saveChart.js +176 -0
- package/es/src/charts/drawSteps/saveControl.js +148 -0
- package/es/src/charts/drawSteps/saveControlMarkup.js +104 -0
- package/es/src/charts/drawSteps/tableViewMarkup.js +1 -1
- package/es/src/charts/drawSteps/topLeftControls.js +3 -1
- package/es/src/charts/drawSteps/topLeftControlsMarkup.js +1 -1
- package/es/src/charts/events/click.shape.js +30 -1
- package/es/src/charts/events/mouseenter.js +9 -0
- package/es/src/charts/events/mousemove.legend.js +3 -0
- package/es/src/charts/events/mousemove.shape.js +7 -2
- package/es/src/charts/facet/facetConfig.js +2 -2
- package/es/src/charts/facet/facetData.js +2 -2
- package/es/src/charts/features/axes.js +7 -6
- package/es/src/charts/features/axesFinal.js +23 -3
- package/es/src/charts/features/axesMeasure.js +54 -2
- package/es/src/charts/features/colorScaleBucket.js +17 -0
- package/es/src/charts/features/colorScaleHover.js +69 -0
- package/es/src/charts/features/features.js +13 -1
- package/es/src/charts/features/featuresColorScale.js +44 -4
- package/es/src/charts/features/featuresLegend.js +6 -8
- package/es/src/charts/features/plotPaint.js +4 -4
- package/es/src/charts/features/shapeEmit.js +23 -2
- package/es/src/charts/features/shareKey.js +15 -0
- package/es/src/charts/features/thresholdMembers.js +71 -0
- package/es/src/charts/helpers/densityChart.js +3 -1
- package/es/src/charts/helpers/valueTitle.js +6 -3
- package/es/src/charts/partition/chartFields.js +4 -3
- package/es/src/charts/partition/hierarchy.js +2 -0
- package/es/src/charts/pipeline/preDrawData.js +31 -10
- package/es/src/charts/pipeline/vizDraw.js +40 -29
- package/es/src/charts/pipeline/vizPreDraw.js +24 -15
- package/es/src/charts/viz/Viz.js +43 -8
- package/es/src/charts/viz/VizBase.js +32 -12
- package/es/src/charts/viz/dataPoller.js +52 -0
- package/es/src/charts/viz/groupRow.js +35 -0
- package/es/src/charts/viz/interactionOpacity.js +19 -5
- package/es/src/charts/viz/missingFields.js +122 -0
- package/es/src/charts/viz/reportHandlerError.js +10 -0
- package/es/src/charts/viz/shapeClassTargets.js +18 -2
- package/es/src/charts/viz/simpleHover.js +2 -0
- package/es/src/charts/viz/vizClassName.js +31 -0
- package/es/src/charts/viz/vizDataPolling.js +167 -0
- package/es/src/charts/viz/vizDefaults.js +66 -0
- package/es/src/charts/viz/vizFields.js +18 -2
- package/es/src/charts/viz/vizRender.js +8 -2
- package/es/src/components/Axis/Axis.js +28 -0
- package/es/src/components/Axis/axisDefaults.js +3 -1
- package/es/src/components/Axis/axisLabelAngle.js +175 -0
- package/es/src/components/Axis/axisLabelThinning.js +13 -4
- package/es/src/components/Axis/axisLayout.js +86 -19
- package/es/src/components/Axis/axisLayoutLabels.js +66 -13
- package/es/src/components/Axis/axisLayoutScale.js +3 -0
- package/es/src/components/Axis/axisRender.js +38 -9
- package/es/src/components/Axis/axisRounding.js +15 -4
- package/es/src/components/Axis/axisSlantWrap.js +39 -0
- package/es/src/components/Axis/powTicks.js +73 -0
- package/es/src/components/ColorScale/ColorScale.js +28 -28
- package/es/src/components/ColorScale/bucketBounds.js +35 -0
- package/es/src/components/ColorScale/colorScaleHoverMark.js +327 -0
- package/es/src/components/ColorScale/colorScaleRender.js +25 -1
- package/es/src/components/ColorScale/colorScaleScale.js +15 -9
- package/es/src/components/ColorScale/colorScaleType.js +26 -0
- package/es/src/components/TextBox.js +2 -0
- package/es/src/components/Timeline/Timeline.js +43 -52
- package/es/src/components/Timeline/brushSpan.js +78 -0
- package/es/src/components/Timeline/timelineConfig.js +7 -0
- package/es/src/components/Timeline/timelineRender.js +44 -6
- package/es/src/components/Tooltip.js +13 -8
- package/es/src/shapes/Box.js +66 -79
- package/es/src/shapes/boxOutlierShape.js +19 -0
- package/es/src/shapes/boxStats.js +35 -0
- package/es/src/shapes/boxStyle.js +78 -0
- package/es/src/shapes/boxSummary.js +174 -0
- package/es/src/shapes/shapeStandalone.js +2 -0
- package/es/src/utils/BaseClass.js +19 -0
- package/es/src/utils/className.js +78 -0
- package/es/src/utils/configWarnings.js +25 -0
- package/es/src/utils/fieldAccessor.js +31 -0
- package/es/src/utils/paintComponentScene.js +2 -0
- package/package.json +10 -9
- package/types/index.d.ts +3 -1
- package/types/internal.d.ts +3 -1
- package/types/src/charts/BoxWhisker/index.d.ts +3 -1
- package/types/src/charts/BoxWhisker/outliers.d.ts +25 -0
- package/types/src/charts/BoxWhisker/summary.d.ts +39 -0
- package/types/src/charts/BoxWhisker/tooltip.d.ts +36 -0
- package/types/src/charts/Candlestick/aggregate.d.ts +6 -0
- package/types/src/charts/Plot/axisHover.d.ts +68 -0
- package/types/src/charts/Plot/axisHoverAnchors.d.ts +88 -0
- package/types/src/charts/Plot/axisHoverScene.d.ts +88 -0
- package/types/src/charts/Plot/barHitArea.d.ts +59 -0
- package/types/src/charts/Plot/barLabelFit.d.ts +81 -0
- package/types/src/charts/Plot/index.d.ts +13 -0
- package/types/src/charts/Plot/labelPlacement.d.ts +5 -0
- package/types/src/charts/Plot/plotInit.d.ts +9 -2
- package/types/src/charts/Plot/plotZoom.d.ts +2 -0
- package/types/src/charts/Plot/sharedHoverScene.d.ts +3 -3
- package/types/src/charts/Plot/sharedTooltip.d.ts +11 -4
- package/types/src/charts/Plot/stackHelpers.d.ts +5 -0
- package/types/src/charts/Plot/stackThreshold.d.ts +75 -0
- package/types/src/charts/Treemap/emit.d.ts +2 -1
- package/types/src/charts/Treemap/emitGroupHeaders.d.ts +16 -0
- package/types/src/charts/Treemap/groupHeaders.d.ts +91 -0
- package/types/src/charts/Treemap/index.d.ts +2 -0
- package/types/src/charts/Treemap/thresholdFunction.d.ts +5 -2
- package/types/src/charts/definition/ChartDefinition.d.ts +14 -2
- package/types/src/charts/definition/makeChart.d.ts +4 -3
- package/types/src/charts/drawSteps/saveChart.d.ts +47 -0
- package/types/src/charts/drawSteps/saveControl.d.ts +9 -0
- package/types/src/charts/drawSteps/saveControlMarkup.d.ts +44 -0
- package/types/src/charts/drawSteps/tableViewMarkup.d.ts +1 -0
- package/types/src/charts/drawSteps/topLeftControls.d.ts +1 -1
- package/types/src/charts/drawSteps/topLeftControlsMarkup.d.ts +1 -1
- package/types/src/charts/facet/facetData.d.ts +1 -1
- package/types/src/charts/features/axesMeasure.d.ts +9 -1
- package/types/src/charts/features/colorScaleBucket.d.ts +9 -0
- package/types/src/charts/features/colorScaleHover.d.ts +32 -0
- package/types/src/charts/features/features.d.ts +8 -0
- package/types/src/charts/features/plotPaint.d.ts +2 -0
- package/types/src/charts/features/shapeEmit.d.ts +2 -0
- package/types/src/charts/features/shareKey.d.ts +9 -0
- package/types/src/charts/features/thresholdMembers.d.ts +38 -0
- package/types/src/charts/helpers/valueTitle.d.ts +4 -2
- package/types/src/charts/pipeline/stages.d.ts +2 -0
- package/types/src/charts/pipeline/vizDraw.d.ts +8 -3
- package/types/src/charts/pipeline/vizPreDraw.d.ts +3 -2
- package/types/src/charts/viz/Viz.d.ts +28 -4
- package/types/src/charts/viz/VizBase.d.ts +12 -3
- package/types/src/charts/viz/dataPoller.d.ts +28 -0
- package/types/src/charts/viz/groupRow.d.ts +24 -0
- package/types/src/charts/viz/interactionOpacity.d.ts +3 -1
- package/types/src/charts/viz/missingFields.d.ts +57 -0
- package/types/src/charts/viz/reportHandlerError.d.ts +7 -0
- package/types/src/charts/viz/shapeClassTargets.d.ts +6 -0
- package/types/src/charts/viz/simpleHover.d.ts +2 -1
- package/types/src/charts/viz/vizClassName.d.ts +23 -0
- package/types/src/charts/viz/vizDataPolling.d.ts +48 -0
- package/types/src/charts/viz/vizDefaults.d.ts +49 -0
- package/types/src/charts/viz/vizFields.d.ts +15 -0
- package/types/src/charts/viz/vizTypes.d.ts +33 -1
- package/types/src/components/Axis/Axis.d.ts +36 -8
- package/types/src/components/Axis/axisLabelAngle.d.ts +110 -0
- package/types/src/components/Axis/axisLabelThinning.d.ts +3 -7
- package/types/src/components/Axis/axisLayout.d.ts +5 -0
- package/types/src/components/Axis/axisLayoutLabels.d.ts +13 -0
- package/types/src/components/Axis/axisRounding.d.ts +6 -3
- package/types/src/components/Axis/axisSlantWrap.d.ts +22 -0
- package/types/src/components/Axis/powTicks.d.ts +29 -0
- package/types/src/components/ColorScale/ColorScale.d.ts +13 -0
- package/types/src/components/ColorScale/bucketBounds.d.ts +14 -0
- package/types/src/components/ColorScale/colorScaleHoverMark.d.ts +86 -0
- package/types/src/components/ColorScale/colorScaleScale.d.ts +3 -0
- package/types/src/components/ColorScale/colorScaleType.d.ts +17 -0
- package/types/src/components/Timeline/brushSpan.d.ts +41 -0
- package/types/src/components/Timeline/timelineConfig.d.ts +6 -0
- package/types/src/components/Timeline/timelineRender.d.ts +8 -0
- package/types/src/components/Tooltip.d.ts +8 -0
- package/types/src/shapes/Box.d.ts +1 -8
- package/types/src/shapes/boxOutlierShape.d.ts +9 -0
- package/types/src/shapes/boxStats.d.ts +19 -0
- package/types/src/shapes/boxStyle.d.ts +25 -0
- package/types/src/shapes/boxSummary.d.ts +66 -0
- package/types/src/shapes/emitLabels.d.ts +1 -1
- package/types/src/shapes/shapeConfig.d.ts +42 -4
- package/types/src/utils/BaseClass.d.ts +23 -0
- package/types/src/utils/D3Scale.d.ts +3 -0
- package/types/src/utils/D3plusConfig.d.ts +261 -5
- package/types/src/utils/className.d.ts +64 -0
- package/types/src/utils/configWarnings.d.ts +21 -2
- package/types/src/utils/fieldAccessor.d.ts +24 -0
- package/types/src/utils/index.d.ts +1 -1
- package/types/src/utils/paintComponentScene.d.ts +3 -1
- package/umd/d3plus-core.full.js +6405 -1068
- package/umd/d3plus-core.full.min.js +2 -2
- package/umd/d3plus-core.js +5328 -1002
- package/umd/d3plus-core.min.js +2 -2
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
row's density curve.
|
|
7
7
|
*/ import { formatAbbreviate } from "@d3plus/format";
|
|
8
8
|
import constant from "../../utils/constant.js";
|
|
9
|
+
import { fieldAccessor } from "../../utils/fieldAccessor.js";
|
|
9
10
|
import { autoTitle, keyedAccessor, valueKeyOf } from "./valueTitle.js";
|
|
10
11
|
import { densityGroups, densityWidthScale, sortByMedian } from "./densityData.js";
|
|
11
12
|
/** The key each summary row keeps its distribution under. */ export const DENSITY = "__d3plusDensity";
|
|
@@ -41,6 +42,7 @@ import { densityGroups, densityWidthScale, sortByMedian } from "./densityData.js
|
|
|
41
42
|
*/ export function summarizeBeforePreDraw(viz) {
|
|
42
43
|
const state = viz.ctx.density;
|
|
43
44
|
if (viz._data !== state.rows) state.raw = viz._data;
|
|
45
|
+
viz._sourceData = state.raw;
|
|
44
46
|
const valueAxis = state.layout.valueAxis(viz);
|
|
45
47
|
const categoryAxis = valueAxis === "x" ? "y" : "x";
|
|
46
48
|
const groupBy = viz.schema.groupBy;
|
|
@@ -231,7 +233,7 @@ import { densityGroups, densityWidthScale, sortByMedian } from "./densityData.js
|
|
|
231
233
|
*/ {
|
|
232
234
|
key: "value",
|
|
233
235
|
default: keyedAccessor("value"),
|
|
234
|
-
coerce: (v)=>typeof v === "string" ?
|
|
236
|
+
coerce: (v)=>typeof v === "string" ? fieldAccessor(v) : typeof v === "function" ? v : constant(v)
|
|
235
237
|
}
|
|
236
238
|
];
|
|
237
239
|
}
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
accessor that remembers its key, so the value axis can be titled with it
|
|
4
4
|
until the user sets a title of their own.
|
|
5
5
|
*/ import accessor from "../../utils/accessor.js";
|
|
6
|
+
import { fieldNameOf } from "../../utils/fieldAccessor.js";
|
|
6
7
|
/** Data keys behind string `value` accessors. */ const valueKeys = new WeakMap();
|
|
7
8
|
/**
|
|
8
|
-
`accessor(key)` that remembers its key (see `valueKeyOf`)
|
|
9
|
+
`accessor(key)` that remembers its key (see `valueKeyOf`), for a default
|
|
10
|
+
`value`; a user's string `value` becomes a `fieldAccessor`.
|
|
9
11
|
@param key The data key to read.
|
|
10
12
|
*/ export function keyedAccessor(key) {
|
|
11
13
|
const fn = accessor(key);
|
|
@@ -13,10 +15,11 @@
|
|
|
13
15
|
return fn;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
|
-
The data key behind an accessor built by `keyedAccessor
|
|
18
|
+
The data key behind an accessor built by `keyedAccessor` or
|
|
19
|
+
`fieldAccessor`, if any.
|
|
17
20
|
@param fn The accessor.
|
|
18
21
|
*/ export function valueKeyOf(fn) {
|
|
19
|
-
return typeof fn === "function" ? valueKeys.get(fn) : undefined;
|
|
22
|
+
return typeof fn === "function" ? valueKeys.get(fn) ?? fieldNameOf(fn) : undefined;
|
|
20
23
|
}
|
|
21
24
|
/**
|
|
22
25
|
Sets an axis title to `next` unless the user has configured their own: one
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Treemap-style threshold bucketing, the default sibling order, the `sum`
|
|
4
4
|
accessor, the legend order, and the setup that installs the shared
|
|
5
5
|
interaction.
|
|
6
|
-
*/ import
|
|
6
|
+
*/ import { fieldAccessor } from "../../utils/fieldAccessor.js";
|
|
7
7
|
import { thresholdFunction } from "../Treemap/thresholdFunction.js";
|
|
8
8
|
import { partitionSort } from "./hierarchy.js";
|
|
9
9
|
import { partitionHandlers } from "./interaction.js";
|
|
@@ -13,7 +13,8 @@ import { partitionHandlers } from "./interaction.js";
|
|
|
13
13
|
drawDepth: viz._drawDepth,
|
|
14
14
|
groupBy: viz.schema.groupBy,
|
|
15
15
|
threshold: viz.schema.threshold,
|
|
16
|
-
thresholdKey: viz.schema.thresholdKey
|
|
16
|
+
thresholdKey: viz.schema.thresholdKey,
|
|
17
|
+
label: (d, i)=>viz._drawLabel(d, i)
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
20
|
/** The default `sort`: largest value first. */ export const partitionDefaultSort = (a, b)=>(b.value ?? 0) - (a.value ?? 0);
|
|
@@ -21,7 +22,7 @@ import { partitionHandlers } from "./interaction.js";
|
|
|
21
22
|
return partitionSort(base);
|
|
22
23
|
}
|
|
23
24
|
/** Coerces a `sum` key into an accessor. */ export function partitionSumCoerce(v) {
|
|
24
|
-
return typeof v === "function" ? v :
|
|
25
|
+
return typeof v === "function" ? v : fieldAccessor(v);
|
|
25
26
|
}
|
|
26
27
|
/** Thresholds bucket by the summed value. */ export function partitionSumOnSet(viz, v) {
|
|
27
28
|
viz.schema.thresholdKey = v;
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/ import { hierarchy, partition } from "d3-hierarchy";
|
|
7
7
|
import { merge } from "@d3plus/data";
|
|
8
8
|
import { SHARE_KEY } from "../features/shareKey.js";
|
|
9
|
+
import { MEMBERS_KEY } from "../features/thresholdMembers.js";
|
|
9
10
|
/**
|
|
10
11
|
Nests `rows` by `keys`, one level per key. A row whose key is missing at a
|
|
11
12
|
level ends at its parent (it adds to the parent's value without a child of
|
|
@@ -101,6 +102,7 @@ import { SHARE_KEY } from "../features/shareKey.js";
|
|
|
101
102
|
const merged = merge(rows.map(withoutStampedShare), aggs);
|
|
102
103
|
delete merged._isAggregation;
|
|
103
104
|
delete merged._threshold;
|
|
105
|
+
delete merged[MEMBERS_KEY];
|
|
104
106
|
return merged;
|
|
105
107
|
}
|
|
106
108
|
/**
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
The data half of `vizPreDraw`: the synthesized time filter and the
|
|
3
3
|
filter + rollup that produce a draw's `filteredData` and `legendData`.
|
|
4
4
|
Small multiples run the same steps over each panel's rows.
|
|
5
|
-
*/ import {
|
|
5
|
+
*/ import { rollup } from "d3-array";
|
|
6
6
|
import { merge } from "@d3plus/data";
|
|
7
7
|
import { date } from "@d3plus/dom";
|
|
8
|
+
import { brushSpan } from "../../components/Timeline/brushSpan.js";
|
|
8
9
|
import { discreteNestKeys } from "./stages.js";
|
|
9
10
|
/**
|
|
10
11
|
The `filter` the pipeline runs over `viz._data`: the configured `filter`,
|
|
@@ -14,6 +15,31 @@ import { discreteNestKeys } from "./stages.js";
|
|
|
14
15
|
const applied = viz._filterApplied;
|
|
15
16
|
return filter && applied ? (d, i)=>applied(d) || filter(d, i) : filter;
|
|
16
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
The span the chart's timeline holds its selection to (see `brushSpan`):
|
|
20
|
+
any span without a timeline, and at least one period when it selects a
|
|
21
|
+
single period (`brushing: false`).
|
|
22
|
+
*/ function timelineSpan(viz) {
|
|
23
|
+
if (!viz.schema.timeline) return {
|
|
24
|
+
min: 1,
|
|
25
|
+
max: Infinity
|
|
26
|
+
};
|
|
27
|
+
const config = viz.schema.timelineConfig || {};
|
|
28
|
+
const span = brushSpan(config.brushMin, config.brushMax);
|
|
29
|
+
return config.brushing === false ? {
|
|
30
|
+
...span,
|
|
31
|
+
min: 1
|
|
32
|
+
} : span;
|
|
33
|
+
}
|
|
34
|
+
/** A filter keeping the latest `count` of `dates`' periods, or every row. */ function latestPeriods(viz, dates, count) {
|
|
35
|
+
const periods = [
|
|
36
|
+
...new Set(dates.map(Number))
|
|
37
|
+
].sort((a, b)=>a - b);
|
|
38
|
+
if (periods.length <= count) return ()=>true;
|
|
39
|
+
const from = periods[periods.length - count];
|
|
40
|
+
const snapTime = viz.schema.time;
|
|
41
|
+
return (d, i)=>+date(snapTime(d, i)) >= from;
|
|
42
|
+
}
|
|
17
43
|
/**
|
|
18
44
|
Computes a NEW timeFilter when `time` is set but `timeFilter` isn't and
|
|
19
45
|
data exists; returns undefined otherwise.
|
|
@@ -23,16 +49,11 @@ import { discreteNestKeys } from "./stages.js";
|
|
|
23
49
|
const dates = viz._data.map(viz.schema.time).map((d)=>date(d));
|
|
24
50
|
const d = viz._data[0], i = 0;
|
|
25
51
|
if (viz.schema.discrete && `_${viz.schema.discrete}` in viz && viz[`_${viz.schema.discrete}`](d, i) === viz.schema.time(d, i)) {
|
|
26
|
-
|
|
52
|
+
// Every period, or the latest `brushMax` of them.
|
|
53
|
+
computedTimeFilter = latestPeriods(viz, dates, timelineSpan(viz).max);
|
|
27
54
|
} else {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// changing `.time(...)` after the filter is constructed would
|
|
31
|
-
// make the closure read the NEW accessor against the OLD
|
|
32
|
-
// latestTime — nonsense results. Matches the snapGroupBy /
|
|
33
|
-
// snapLabel pattern earlier in this file.
|
|
34
|
-
const snapTime = viz.schema.time;
|
|
35
|
-
computedTimeFilter = (dd, ii)=>+date(snapTime(dd, ii)) === latestTime;
|
|
55
|
+
// The latest period, or the latest `brushMin` of them.
|
|
56
|
+
computedTimeFilter = latestPeriods(viz, dates, Math.max(1, Math.ceil(timelineSpan(viz).min)));
|
|
36
57
|
}
|
|
37
58
|
}
|
|
38
59
|
return computedTimeFilter;
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
`vizDraw(viz)` — the chart-shell layout every draw runs: it lays out the
|
|
3
|
-
margin-claiming chrome
|
|
4
|
-
|
|
5
|
-
claims to `viz._margin`, and collects their panels on
|
|
3
|
+
margin-claiming chrome in two passes, adds their claims to
|
|
4
|
+
`viz._margin`, and collects their panels on
|
|
6
5
|
`viz._featurePanels`. Each FeatureModule.layout() still writes through to
|
|
7
6
|
`viz` (component mounts, intra-feature state); `vizUpdate` is the
|
|
8
7
|
cross-feature publishing channel.
|
|
9
8
|
|
|
9
|
+
The first pass lays out everything positioned top or bottom (title /
|
|
10
|
+
subtitle / total, timeline, the bottom-right corner panel, a top/bottom
|
|
11
|
+
legend or colorScale). The second lays out a left/right legend or
|
|
12
|
+
colorScale in the vertical band left between those claims, each starting
|
|
13
|
+
below the corner control panel on its side (see `sideControlsDrop`).
|
|
14
|
+
|
|
10
15
|
The post-layout consumers (axes, chartGeometry, plotPaint, ensureZoomDom,
|
|
11
16
|
attribution) read the final margin off `viz._margin`. Plot and other Viz
|
|
12
17
|
subclasses override `_draw` and reach this through `super._draw()`.
|
|
@@ -80,10 +85,9 @@ export function vizDraw(viz) {
|
|
|
80
85
|
bottom: viz._margin.bottom,
|
|
81
86
|
left: viz._margin.left
|
|
82
87
|
};
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
// title at y=0. "← Back" no longer claims margin here — it's a
|
|
88
|
+
// Everything positioned top or bottom lays out first, then the left/right
|
|
89
|
+
// legend and colorScale fit the vertical band left between them. "← Back"
|
|
90
|
+
// claims no margin here — it's a
|
|
87
91
|
// zero-margin contribution to the shared top-left controls panel
|
|
88
92
|
// (`topLeftControlsFeature`, registered post-draw in `runVizPipeline`),
|
|
89
93
|
// the same way zoom's buttons float rather than claim margin.
|
|
@@ -111,28 +115,11 @@ export function vizDraw(viz) {
|
|
|
111
115
|
width: viz.schema.width - running.left - running.right,
|
|
112
116
|
height: viz.schema.height - running.top - running.bottom
|
|
113
117
|
});
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
"left",
|
|
120
|
-
"right"
|
|
121
|
-
]);
|
|
122
|
-
}
|
|
123
|
-
if (colorScalePosition === "left" || colorScalePosition === "right" || colorScalePosition === false) {
|
|
124
|
-
claimSides(viz, colorScaleFeature, running, out.marginDelta, [
|
|
125
|
-
"left",
|
|
126
|
-
"right"
|
|
127
|
-
]);
|
|
128
|
-
}
|
|
129
|
-
// A right-side bottom-right panel (the size legend's default) shares the
|
|
130
|
-
// right column: widen the right margin to it, if the left/right claims
|
|
131
|
-
// above didn't already, before the bottom blocks lay out against it.
|
|
132
|
-
const rightShortfall = bottomRightControlsRightShortfall(viz, running.right);
|
|
133
|
-
out.marginDelta.right += rightShortfall;
|
|
134
|
-
running.right += rightShortfall;
|
|
135
|
-
// Top/bottom legend + colorScale.
|
|
118
|
+
// Top/bottom legend + colorScale, before the side ones so those fit the
|
|
119
|
+
// band between them. They lay out against the right column a right-side
|
|
120
|
+
// bottom-right panel will take, though that width is only claimed below.
|
|
121
|
+
const rightColumn = bottomRightControlsRightShortfall(viz, running.right);
|
|
122
|
+
running.right += rightColumn;
|
|
136
123
|
if (legendPosition === "top" || legendPosition === "bottom") {
|
|
137
124
|
claimSides(viz, legendFeature, running, out.marginDelta, [
|
|
138
125
|
"top",
|
|
@@ -145,11 +132,35 @@ export function vizDraw(viz) {
|
|
|
145
132
|
"bottom"
|
|
146
133
|
]);
|
|
147
134
|
}
|
|
135
|
+
running.right -= rightColumn;
|
|
148
136
|
// A bottom-side panel: the chart body must end above it, so if the bottom
|
|
149
137
|
// claims so far are shorter than it, top the bottom margin up.
|
|
150
138
|
const shortfall = bottomRightControlsShortfall(viz, running.bottom);
|
|
151
139
|
out.marginDelta.bottom += shortfall;
|
|
152
140
|
running.bottom += shortfall;
|
|
141
|
+
// Left/right legend + colorScale claims, within the band the top/bottom
|
|
142
|
+
// claims left (each also starts below the corner controls on its side).
|
|
143
|
+
// Includes `=== false` (mirrors colorScale below) so a previously-rendered
|
|
144
|
+
// left/right legend tears down its DOM when the user toggles off via
|
|
145
|
+
// `.legendPosition(false)`.
|
|
146
|
+
if (legendPosition === "left" || legendPosition === "right" || legendPosition === false) {
|
|
147
|
+
claimSides(viz, legendFeature, running, out.marginDelta, [
|
|
148
|
+
"left",
|
|
149
|
+
"right"
|
|
150
|
+
]);
|
|
151
|
+
}
|
|
152
|
+
if (colorScalePosition === "left" || colorScalePosition === "right" || colorScalePosition === false) {
|
|
153
|
+
claimSides(viz, colorScaleFeature, running, out.marginDelta, [
|
|
154
|
+
"left",
|
|
155
|
+
"right"
|
|
156
|
+
]);
|
|
157
|
+
}
|
|
158
|
+
// A right-side bottom-right panel (the size legend's default) shares the
|
|
159
|
+
// right column: widen the right margin to it, if the left/right claims
|
|
160
|
+
// above didn't already.
|
|
161
|
+
const rightShortfall = bottomRightControlsRightShortfall(viz, running.right);
|
|
162
|
+
out.marginDelta.right += rightShortfall;
|
|
163
|
+
running.right += rightShortfall;
|
|
153
164
|
// The corner controls (zoom, back/search) float at y:0 and claim no
|
|
154
165
|
// margin of their own; whatever sits above the chart body (title/
|
|
155
166
|
// subtitle/total, a top legend/colorScale) usually pushes it down clear
|
|
@@ -3,15 +3,18 @@
|
|
|
3
3
|
onto the viz:
|
|
4
4
|
1. `_drawDepth` and the `_id` / `_ids` / `_drawLabel` closures;
|
|
5
5
|
2. `_filteredData` (time filter, `filter`, rollup, hide/solo, then the
|
|
6
|
-
chart's `_thresholdFunction`) and `_legendData
|
|
6
|
+
chart's `_thresholdFunction`) and `_legendData` (through `_thresholdLegend`);
|
|
7
7
|
3. the hover/duration override past `dataCutoff`;
|
|
8
|
-
and mounts the no-data message when nothing is left to draw.
|
|
8
|
+
and mounts the no-data message when nothing is left to draw. It first
|
|
9
|
+
warns about config keys naming a field no row has (`missingFields.ts`).
|
|
9
10
|
|
|
10
11
|
`Viz._preDraw()` calls it, so subclass overrides run it through
|
|
11
12
|
`super._preDraw()`.
|
|
12
13
|
*/ import { group, min } from "d3-array";
|
|
13
14
|
import { formatAbbreviate } from "@d3plus/format";
|
|
14
15
|
import { computeFilteredData, computeTimeFilter } from "./preDrawData.js";
|
|
16
|
+
import { GROUP_LABEL_KEY, groupDepthOf } from "../viz/groupRow.js";
|
|
17
|
+
import { warnMissingFields } from "../viz/missingFields.js";
|
|
15
18
|
import { configureOrdinalColor } from "../viz/ordinalColor.js";
|
|
16
19
|
function listify(n) {
|
|
17
20
|
return n.reduce((str, item, i)=>{
|
|
@@ -65,12 +68,15 @@ function accessorFetch(acc, d, i) {
|
|
|
65
68
|
// subclass override) are reflected in label/aria output.
|
|
66
69
|
// `viz._drawDepth ?? drawDepth` mirrors the pre-snapshot behavior.
|
|
67
70
|
const liveLeaf = viz._drawDepth ?? drawDepth;
|
|
68
|
-
const effDepth = depth ?? liveLeaf;
|
|
69
71
|
if (!d) return "";
|
|
72
|
+
// A group row labels at its own level (see `groupRow.ts`).
|
|
73
|
+
const groupDepth = groupDepthOf(d);
|
|
74
|
+
const effDepth = depth ?? groupDepth ?? liveLeaf;
|
|
70
75
|
while(d.__d3plus__ && d.data){
|
|
71
76
|
d = d.data;
|
|
72
77
|
i = d.i;
|
|
73
78
|
}
|
|
79
|
+
if (effDepth === groupDepth && typeof d[GROUP_LABEL_KEY] === "string") return d[GROUP_LABEL_KEY];
|
|
74
80
|
// ColorScale range buckets carry their label in `id` and have no groupBy
|
|
75
81
|
// fields, so the groupBy resolution below would yield "undefined".
|
|
76
82
|
if (d._isColorScaleBucket) return `${d.id}`;
|
|
@@ -118,6 +124,7 @@ function accessorFetch(acc, d, i) {
|
|
|
118
124
|
return result;
|
|
119
125
|
}
|
|
120
126
|
export function vizPreDraw(viz) {
|
|
127
|
+
warnMissingFields(viz);
|
|
121
128
|
// Reads the live viz rather than a `resolveSpec(viz)` snapshot:
|
|
122
129
|
// `BaseClass.config()` reflects over every accessor and memoizes the
|
|
123
130
|
// defaults on first call, which would freeze them to whatever
|
|
@@ -127,17 +134,6 @@ export function vizPreDraw(viz) {
|
|
|
127
134
|
viz.schema.groupBy.length - 1
|
|
128
135
|
]) : viz.schema.groupBy.length - 1;
|
|
129
136
|
const { id, ids, drawLabel } = buildLabelClosures(viz, drawDepth);
|
|
130
|
-
// The synthesized time filter feeds this draw's rows but is never written
|
|
131
|
-
// onto `viz.schema.timeFilter`: it captures the latest time at synthesis,
|
|
132
|
-
// so pinning it would make a later render with newer data skip
|
|
133
|
-
// re-synthesis and filter the newer rows out.
|
|
134
|
-
const out = {};
|
|
135
|
-
computeFilteredData(viz, out, drawDepth, id, computeTimeFilter(viz));
|
|
136
|
-
viz._drawDepth = drawDepth;
|
|
137
|
-
viz._id = id;
|
|
138
|
-
viz._ids = ids;
|
|
139
|
-
viz._drawLabel = drawLabel;
|
|
140
|
-
if (out.legendData !== undefined) viz._legendData = out.legendData;
|
|
141
137
|
// A persistent trail only stays coherent with fixed axes (so committed
|
|
142
138
|
// segments don't drift as the domain shifts) and a single-period timeline (so
|
|
143
139
|
// the forward/backward step logic has one current time). Turn both on
|
|
@@ -149,11 +145,24 @@ export function vizPreDraw(viz) {
|
|
|
149
145
|
brushing: false
|
|
150
146
|
};
|
|
151
147
|
}
|
|
148
|
+
// The synthesized time filter feeds this draw's rows but is never written
|
|
149
|
+
// onto `viz.schema.timeFilter`: it captures the latest time at synthesis,
|
|
150
|
+
// so pinning it would make a later render with newer data skip
|
|
151
|
+
// re-synthesis and filter the newer rows out.
|
|
152
|
+
const out = {};
|
|
153
|
+
computeFilteredData(viz, out, drawDepth, id, computeTimeFilter(viz));
|
|
154
|
+
viz._drawDepth = drawDepth;
|
|
155
|
+
viz._id = id;
|
|
156
|
+
viz._ids = ids;
|
|
157
|
+
viz._drawLabel = drawLabel;
|
|
158
|
+
if (out.legendData !== undefined) viz._legendData = out.legendData;
|
|
159
|
+
viz._thresholdRows = out.legendData;
|
|
152
160
|
// The threshold reads `this.schema.aggs`/`_drawDepth`/`_groupBy` through
|
|
153
161
|
// the chart's instance method, so it runs after the writes above.
|
|
154
162
|
let filteredData = out.filteredData || [];
|
|
155
163
|
if (viz._data.length && out._thresholdTree) {
|
|
156
|
-
filteredData = viz._thresholdFunction(filteredData, out._thresholdTree);
|
|
164
|
+
filteredData = viz._thresholdFunction(filteredData, out._thresholdTree, viz._thresholdRows);
|
|
165
|
+
if (viz._thresholdLegend && out.legendData) viz._legendData = viz._thresholdLegend(out.legendData);
|
|
157
166
|
}
|
|
158
167
|
viz._filteredData = filteredData;
|
|
159
168
|
// Ordinal color mode: build the single-hue ramp scale from the distinct
|
package/es/src/charts/viz/Viz.js
CHANGED
|
@@ -9,11 +9,16 @@ import { initInsetDefaults, insetComponentScene } from "../features/insetState.j
|
|
|
9
9
|
import { applyZoomPointerEvents, bindCanvasZoom } from "../drawSteps/zoomControls.js";
|
|
10
10
|
import { initVizDefaults } from "./vizDefaults.js";
|
|
11
11
|
import { unregisterLink } from "./linkGroup.js";
|
|
12
|
+
import { stopDataPolling } from "./vizDataPolling.js";
|
|
12
13
|
import { facetPanelAt, withFacetPanel } from "../facet/facetPanel.js";
|
|
13
14
|
import { vizRender } from "./vizRender.js";
|
|
14
15
|
import { vizDraw } from "../pipeline/vizDraw.js";
|
|
15
16
|
import { vizPreDraw } from "../pipeline/vizPreDraw.js";
|
|
16
17
|
import { handlerDatum, shapeClassTargets } from "./shapeClassTargets.js";
|
|
18
|
+
import { reportHandlerError } from "./reportHandlerError.js";
|
|
19
|
+
import { vizClassNameTargets } from "./vizClassName.js";
|
|
20
|
+
import { applyClassName, withRootClasses } from "../../utils/className.js";
|
|
21
|
+
import { handleColorScaleHover } from "../features/colorScaleHover.js";
|
|
17
22
|
/**
|
|
18
23
|
Stamps `interactionGroup` onto a component's scene subtree so the pointer
|
|
19
24
|
bridge can route its nodes to component-scoped handlers (e.g. legend) on
|
|
@@ -195,14 +200,31 @@ import { handlerDatum, shapeClassTargets } from "./shapeClassTargets.js";
|
|
|
195
200
|
*/ _insetRegion() {
|
|
196
201
|
return null;
|
|
197
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
The shape a colorScale row draws as (see
|
|
205
|
+
`ChartDefinition.colorScaleShape`): the row's `shape`, unless the chart
|
|
206
|
+
draws it as something else.
|
|
207
|
+
@private
|
|
208
|
+
*/ _colorScaleShape(d, i) {
|
|
209
|
+
return this.schema.shape(d, i);
|
|
210
|
+
}
|
|
198
211
|
/**
|
|
199
212
|
* Applies the threshold algorithm according to the type of chart used.
|
|
200
213
|
* @param {Array} data The data to process.
|
|
214
|
+
* @param {Array} all Every row `data` was drawn from, legend-hidden ones included.
|
|
201
215
|
* @private
|
|
202
|
-
*/ _thresholdFunction(data, _tree) {
|
|
216
|
+
*/ _thresholdFunction(data, _tree, _all) {
|
|
203
217
|
return data;
|
|
204
218
|
}
|
|
205
219
|
/**
|
|
220
|
+
* The legend rows with the chart's threshold bucket folded in, so the
|
|
221
|
+
* legend shows the bucket rather than the items it holds.
|
|
222
|
+
* @param {Array} legendData Every legend row, legend-hidden ones included.
|
|
223
|
+
* @private
|
|
224
|
+
*/ _thresholdLegend(legendData) {
|
|
225
|
+
return legendData;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
206
228
|
* Detects width and height and sets SVG properties
|
|
207
229
|
* @private
|
|
208
230
|
*/ _setSVGSize(width, height) {
|
|
@@ -235,10 +257,12 @@ import { handlerDatum, shapeClassTargets } from "./shapeClassTargets.js";
|
|
|
235
257
|
Serializes the most recently rendered output to an SVG string. Returns
|
|
236
258
|
`""` if the chart has not been rendered yet. Both backends support this:
|
|
237
259
|
the SVG backend returns its live `<svg>`, the canvas backend re-renders the
|
|
238
|
-
retained scene through a throwaway SVG backend.
|
|
239
|
-
server-side rendering (see
|
|
260
|
+
retained scene through a throwaway SVG backend. Its root element carries
|
|
261
|
+
the chart's `className`. Primarily used for server-side rendering (see
|
|
262
|
+
`@d3plus/ssr`).
|
|
240
263
|
*/ toSVGString() {
|
|
241
|
-
|
|
264
|
+
const markup = this._sceneRenderer?.toSVGString?.() ?? "";
|
|
265
|
+
return withRootClasses(markup, this.schema.className);
|
|
242
266
|
}
|
|
243
267
|
/**
|
|
244
268
|
Returns the underlying canvas element of the most recent render when the
|
|
@@ -273,6 +297,7 @@ import { handlerDatum, shapeClassTargets } from "./shapeClassTargets.js";
|
|
|
273
297
|
const w = this.schema.width || 400;
|
|
274
298
|
const h = this.schema.height || 300;
|
|
275
299
|
this._ensureSceneRenderer(kind, mountTarget, w, h);
|
|
300
|
+
applyClassName(this);
|
|
276
301
|
// `durationOverride` defaults to the chart's `_duration` for normal
|
|
277
302
|
// re-renders. Interaction handlers (zoomed, hover, etc.) pass 0 to
|
|
278
303
|
// skip the transition machinery — animating every wheel/drag tick
|
|
@@ -384,6 +409,12 @@ import { handlerDatum, shapeClassTargets } from "./shapeClassTargets.js";
|
|
|
384
409
|
it to drive the shared multi-series tooltip and crosshair.
|
|
385
410
|
@private
|
|
386
411
|
*/ _sharedHover(_event) {}
|
|
412
|
+
/**
|
|
413
|
+
The element the chart draws on: its root svg, or its canvas.
|
|
414
|
+
@private
|
|
415
|
+
*/ _classNameTargets() {
|
|
416
|
+
return vizClassNameTargets(this._select?.node?.(), this._sceneRenderer, this._renderer === "canvas" ? "canvas" : "svg");
|
|
417
|
+
}
|
|
387
418
|
/**
|
|
388
419
|
The chart's small-multiple hooks (see `ChartDefinition.facet`). The base
|
|
389
420
|
chart has none: each panel draws the way the whole chart does.
|
|
@@ -468,6 +499,7 @@ import { handlerDatum, shapeClassTargets } from "./shapeClassTargets.js";
|
|
|
468
499
|
// across empty space (Plot's shared tooltip + crosshair) — and ahead of
|
|
469
500
|
// the transition guard below, so leaving mid-transition still clears it.
|
|
470
501
|
this._sharedHover(event);
|
|
502
|
+
handleColorScaleHover(this, event);
|
|
471
503
|
if (this._transitionEndsAt && Date.now() < this._transitionEndsAt) return;
|
|
472
504
|
const pick = event.pick;
|
|
473
505
|
// Dispatch helper shared by the live-pick path and the leave path.
|
|
@@ -476,9 +508,8 @@ import { handlerDatum, shapeClassTargets } from "./shapeClassTargets.js";
|
|
|
476
508
|
if (typeof fn === "function") {
|
|
477
509
|
try {
|
|
478
510
|
fn.call(this, d, i, x, event.nativeEvent);
|
|
479
|
-
} catch
|
|
480
|
-
|
|
481
|
-
// break subsequent events.
|
|
511
|
+
} catch (error) {
|
|
512
|
+
reportHandlerError(error);
|
|
482
513
|
}
|
|
483
514
|
}
|
|
484
515
|
};
|
|
@@ -518,6 +549,9 @@ import { handlerDatum, shapeClassTargets } from "./shapeClassTargets.js";
|
|
|
518
549
|
// its source row; Plot overrides `_interactionDatum` to report the point
|
|
519
550
|
// nearest the cursor for multi-point shapes (Line/Area).
|
|
520
551
|
const { d: sourceDatum, i: sourceIndex, x: rawDatum } = this._interactionDatum(pick, event);
|
|
552
|
+
// A node with no data (an inset legend's backdrop, gridlines) is not a
|
|
553
|
+
// chart shape.
|
|
554
|
+
if (sourceDatum === undefined) return;
|
|
521
555
|
// Shape-class-scoped handlers (`"click.Bar"`, `"mousemove.Circle"`): the
|
|
522
556
|
// node's own shape type, then any composite it is a part of (`"click.Box"`
|
|
523
557
|
// on a box's whisker). On the scene path this is the only place these fire
|
|
@@ -567,9 +601,10 @@ import { handlerDatum, shapeClassTargets } from "./shapeClassTargets.js";
|
|
|
567
601
|
});
|
|
568
602
|
}
|
|
569
603
|
/**
|
|
570
|
-
Tears down the visualization: disconnects the ResizeObserver, stops listening for web font loads, and removes DOM event listeners. Call this when unmounting to avoid memory leaks.
|
|
604
|
+
Tears down the visualization: disconnects the ResizeObserver, stops listening for web font loads and polling for data, and removes DOM event listeners. Call this when unmounting to avoid memory leaks.
|
|
571
605
|
*/ destroy() {
|
|
572
606
|
unregisterLink(this);
|
|
607
|
+
stopDataPolling(this);
|
|
573
608
|
this._resizeObserver?.disconnect();
|
|
574
609
|
this._fontsUnsubscribe?.();
|
|
575
610
|
this._fontsUnsubscribe = undefined;
|
|
@@ -2,10 +2,13 @@ import { select } from "d3-selection";
|
|
|
2
2
|
import { addToQueue, unique } from "@d3plus/data";
|
|
3
3
|
import { fontFamilyStringify } from "@d3plus/text";
|
|
4
4
|
import { date } from "@d3plus/dom";
|
|
5
|
-
import {
|
|
5
|
+
import { BaseClass, constant } from "../../utils/index.js";
|
|
6
|
+
import { fieldAccessor } from "../../utils/fieldAccessor.js";
|
|
6
7
|
import { coerceFacet } from "../facet/facetConfig.js";
|
|
8
|
+
import { groupDepthOf } from "./groupRow.js";
|
|
7
9
|
import { broadcastLink } from "./linkGroup.js";
|
|
8
10
|
import { shapeHoverEnabled } from "./shapeHover.js";
|
|
11
|
+
import { stopDataPolling } from "./vizDataPolling.js";
|
|
9
12
|
import { isPlainObject, mergeConfigBag, resolvesReset } from "../../fluent.js";
|
|
10
13
|
import validateShapeConfig from "../../shapes/validateShapeConfig.js";
|
|
11
14
|
/**
|
|
@@ -16,6 +19,7 @@ import validateShapeConfig from "../../shapes/validateShapeConfig.js";
|
|
|
16
19
|
/**
|
|
17
20
|
The active callback function for highlighting shapes.
|
|
18
21
|
*/ active(_) {
|
|
22
|
+
if (!arguments.length) return this._active;
|
|
19
23
|
this._active = _;
|
|
20
24
|
if (this.schema.shapeConfig.activeOpacity !== 1) {
|
|
21
25
|
if (this.schema.legend) this._legendClass.active(_);
|
|
@@ -29,12 +33,14 @@ import validateShapeConfig from "../../shapes/validateShapeConfig.js";
|
|
|
29
33
|
/**
|
|
30
34
|
The primary data array used to draw the visualization. The value passed should be an *Array* of objects or a *String* representing a filepath or URL to be loaded. The following filetypes are supported: `csv`, `tsv`, `txt`, and `json`.
|
|
31
35
|
|
|
32
|
-
If your data URL needs specific headers to be set, an Object with "url" and "headers"
|
|
36
|
+
If your data URL needs specific headers to be set, an Object with a "url" and "headers" (or any other `fetch` request option) may also be passed. An Object with any other key is a data row, not a request.
|
|
33
37
|
|
|
34
38
|
Additionally, a custom formatting function can be passed as a second argument to this method. This custom function will be passed the data that has been loaded, as long as there are no errors. This function should return the final array of obejcts to be used as the primary data array. For example, some JSON APIs return the headers split from the data values to save bandwidth. These would need be joined using a custom formatter.
|
|
35
39
|
|
|
36
40
|
If you would like to specify certain configuration options based on the yet-to-be-loaded data, you can also return a full `config` object from the data formatter (including the new `data` array as a key in the object).
|
|
37
41
|
|
|
42
|
+
To re-fetch a URL on an interval and redraw when its data changes, set `dataPollingInterval`; each poll runs the same formatter.
|
|
43
|
+
|
|
38
44
|
Defaults to an empty array (`[]`).
|
|
39
45
|
@param f The data array or a URL string to load data from.
|
|
40
46
|
*/ data(_, f) {
|
|
@@ -47,6 +53,9 @@ Defaults to an empty array (`[]`).
|
|
|
47
53
|
this._timelineSelection = false;
|
|
48
54
|
}
|
|
49
55
|
this._userData = _;
|
|
56
|
+
this._userDataFormat = f;
|
|
57
|
+
this._dataSignature = undefined;
|
|
58
|
+
stopDataPolling(this);
|
|
50
59
|
return this;
|
|
51
60
|
}
|
|
52
61
|
return this._data;
|
|
@@ -131,13 +140,12 @@ Defaults to an empty array (`[]`).
|
|
|
131
140
|
return v.length === 1 ? v[0] : v;
|
|
132
141
|
};
|
|
133
142
|
}
|
|
134
|
-
return
|
|
143
|
+
return fieldAccessor(k);
|
|
135
144
|
}
|
|
136
145
|
}), this;
|
|
137
146
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
*/ hover(_) {
|
|
147
|
+
hover(_) {
|
|
148
|
+
if (!arguments.length) return this._hover;
|
|
141
149
|
let hoverFunction = this._hover = _;
|
|
142
150
|
if (this.schema.shapeConfig.hoverOpacity !== 1 && _ !== undefined) {
|
|
143
151
|
if (typeof _ === "function") {
|
|
@@ -154,7 +162,13 @@ Defaults to an empty array (`[]`).
|
|
|
154
162
|
activeIds.add(JSON.stringify(ids.slice(0, x)));
|
|
155
163
|
}
|
|
156
164
|
});
|
|
157
|
-
|
|
165
|
+
// A group row (see `groupRow.ts`) matches by its ids down to its
|
|
166
|
+
// own level, so it stays bright while any row in its group does.
|
|
167
|
+
if (activeIds.size) hoverFunction = (d, i)=>{
|
|
168
|
+
const ids = this._ids(d, i);
|
|
169
|
+
const depth = groupDepthOf(d);
|
|
170
|
+
return activeIds.has(JSON.stringify(depth === undefined ? ids : ids.slice(0, depth + 1)));
|
|
171
|
+
};
|
|
158
172
|
}
|
|
159
173
|
if (this.schema.legend) this._legendClass.hover(hoverFunction);
|
|
160
174
|
}
|
|
@@ -196,7 +210,12 @@ Defaults to an empty array (`[]`).
|
|
|
196
210
|
return this;
|
|
197
211
|
}
|
|
198
212
|
/**
|
|
199
|
-
The threshold value for bucketing small data points together
|
|
213
|
+
The threshold value for bucketing small data points together, as a
|
|
214
|
+
share of the total. On a stacked Plot, the series whose summed value
|
|
215
|
+
across every position is under that share of the whole chart's total
|
|
216
|
+
merge into one series, stacked on top. A bucket needs at least two
|
|
217
|
+
items, and its tooltips list them. Off (`0`) by default on Plot
|
|
218
|
+
charts.
|
|
200
219
|
*/ threshold(_) {
|
|
201
220
|
if (arguments.length) {
|
|
202
221
|
if (typeof _ === "function") {
|
|
@@ -208,14 +227,15 @@ Defaults to an empty array (`[]`).
|
|
|
208
227
|
} else return this.schema.threshold;
|
|
209
228
|
}
|
|
210
229
|
/**
|
|
211
|
-
Accessor for the value used in the threshold algorithm.
|
|
230
|
+
Accessor for the value used in the threshold algorithm. A stacked Plot
|
|
231
|
+
defaults to its stacked value.
|
|
212
232
|
@param key The data key used to group values for thresholding.
|
|
213
233
|
*/ thresholdKey(key) {
|
|
214
234
|
if (arguments.length) {
|
|
215
235
|
if (typeof key === "function") {
|
|
216
236
|
this.schema.thresholdKey = key;
|
|
217
237
|
} else {
|
|
218
|
-
this.schema.thresholdKey =
|
|
238
|
+
this.schema.thresholdKey = fieldAccessor(key);
|
|
219
239
|
}
|
|
220
240
|
return this;
|
|
221
241
|
} else return this.schema.thresholdKey;
|
|
@@ -227,7 +247,7 @@ Defaults to an empty array (`[]`).
|
|
|
227
247
|
if (typeof _ === "function") {
|
|
228
248
|
this.schema.time = _;
|
|
229
249
|
} else if (_) {
|
|
230
|
-
this.schema.time =
|
|
250
|
+
this.schema.time = fieldAccessor(_);
|
|
231
251
|
if (!this.schema.aggs[_]) {
|
|
232
252
|
this.schema.aggs[_] = (a, c)=>{
|
|
233
253
|
const v = unique(a.map(c));
|
|
@@ -265,7 +285,7 @@ Defaults to an empty array (`[]`).
|
|
|
265
285
|
*/ total(_) {
|
|
266
286
|
if (arguments.length) {
|
|
267
287
|
if (typeof _ === "function") this.schema.total = _;
|
|
268
|
-
else if (_) this.schema.total =
|
|
288
|
+
else if (_) this.schema.total = fieldAccessor(_);
|
|
269
289
|
else this.schema.total = false;
|
|
270
290
|
return this;
|
|
271
291
|
} else return this.schema.total;
|