@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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** The fewest and most ticks a Timeline's brush selection may span. */ /** A `brushMin`/`brushMax` setting's value: a number, or a function returning one. */ const read = (value)=>typeof value === "function" ? value() : value;
|
|
2
|
+
/**
|
|
3
|
+
The fewest and most ticks a brush selection may span, from `brushMin` and
|
|
4
|
+
`brushMax` (each a number, or a function returning one). An unset or
|
|
5
|
+
non-finite `brushMax` is unlimited and a fractional one rounds down; one
|
|
6
|
+
below `brushMin` rises to it, so `brushMin` wins when they conflict.
|
|
7
|
+
*/ export function brushSpan(brushMin, brushMax) {
|
|
8
|
+
const lo = read(brushMin);
|
|
9
|
+
const min = typeof lo === "number" && Number.isFinite(lo) ? lo : 1;
|
|
10
|
+
const hi = read(brushMax);
|
|
11
|
+
const max = typeof hi === "number" && Number.isFinite(hi) ? Math.max(Math.floor(hi), Math.ceil(min), 1) : Infinity;
|
|
12
|
+
return {
|
|
13
|
+
min,
|
|
14
|
+
max
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
A selection's end tick indices (`lo` to `hi`, out of `count` ticks), moved
|
|
19
|
+
so it spans `span.min` to `span.max` ticks. Too short, it keeps its `fixed`
|
|
20
|
+
end and moves the other out, then the fixed end too where the ticks run
|
|
21
|
+
out. Too long, it keeps the `anchor` end (the one being dragged) and pulls
|
|
22
|
+
the other in.
|
|
23
|
+
*/ export function spanIndices(lo, hi, count, span, anchor = "hi", fixed = "lo") {
|
|
24
|
+
const fewest = span.min - 1;
|
|
25
|
+
if (Math.abs(hi - lo) < fewest) {
|
|
26
|
+
if (fixed === "lo") {
|
|
27
|
+
hi = Math.min(count - 1, lo + fewest);
|
|
28
|
+
lo = Math.max(0, hi - fewest);
|
|
29
|
+
} else {
|
|
30
|
+
lo = Math.max(0, hi - fewest);
|
|
31
|
+
hi = Math.min(count - 1, lo + fewest);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const most = span.max - 1;
|
|
35
|
+
if (hi - lo > most) {
|
|
36
|
+
if (anchor === "lo") hi = lo + most;
|
|
37
|
+
else lo = hi - most;
|
|
38
|
+
}
|
|
39
|
+
return [
|
|
40
|
+
lo,
|
|
41
|
+
hi
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
The end a selection keeps while it grows to `brushMin`: the end being
|
|
46
|
+
dragged (`anchor`), or its first when it is a single period (a click).
|
|
47
|
+
*/ export const growFrom = (lo, hi, anchor)=>lo === hi ? "lo" : anchor;
|
|
48
|
+
/**
|
|
49
|
+
A Timeline's brush span (see `brushSpan`); a single-period Timeline
|
|
50
|
+
(`brushing: false`) has no `brushMin` to meet.
|
|
51
|
+
*/ export function timelineBrushSpan(schema) {
|
|
52
|
+
const span = brushSpan(schema.brushMin, schema.brushMax);
|
|
53
|
+
return schema.brushing === false ? {
|
|
54
|
+
...span,
|
|
55
|
+
min: 1
|
|
56
|
+
} : span;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
A brushed selection fitted to `span`. `edges` are the period indices
|
|
60
|
+
(earliest first) under the brush's left and right edges, which a
|
|
61
|
+
reversed timeline holds latest first; `anchor` is the edge being dragged.
|
|
62
|
+
Pulled in, the dragged end stays put. Pushed out, the first period does,
|
|
63
|
+
or with `keepDragged` the dragged end (a click's period). Returns the
|
|
64
|
+
fitted indices, earliest first.
|
|
65
|
+
*/ export function fitBrush(edges, count, span, anchor, keepDragged = false) {
|
|
66
|
+
const lo = Math.min(...edges);
|
|
67
|
+
const hi = Math.max(...edges);
|
|
68
|
+
const dragged = edges[anchor === "lo" ? 0 : 1] === lo ? "lo" : "hi";
|
|
69
|
+
const fixed = keepDragged ? growFrom(lo, hi, dragged) : "lo";
|
|
70
|
+
return spanIndices(lo, hi, count, span, dragged, fixed);
|
|
71
|
+
}
|
|
72
|
+
/** The index of the value in `values` nearest `value`. */ export function nearestIndex(values, value) {
|
|
73
|
+
let best = -1;
|
|
74
|
+
values.forEach((v, i)=>{
|
|
75
|
+
if (best < 0 || Math.abs(v - value) < Math.abs(values[best] - value)) best = i;
|
|
76
|
+
});
|
|
77
|
+
return best;
|
|
78
|
+
}
|
|
@@ -2,6 +2,13 @@ import { colorContrast } from "@d3plus/color";
|
|
|
2
2
|
import { assign, backgroundColor } from "@d3plus/dom";
|
|
3
3
|
import TextBox from "../TextBox.js";
|
|
4
4
|
const colorMid = "#bbb";
|
|
5
|
+
/**
|
|
6
|
+
A copy of `values` (dates, years or pixel positions) in ascending order.
|
|
7
|
+
A `reverse` timeline lays its ticks out from latest to earliest, but its
|
|
8
|
+
selections, defaults and playback run from earliest to latest.
|
|
9
|
+
*/ export function byValue(values) {
|
|
10
|
+
return values.slice().sort((a, b)=>Number(a) - Number(b));
|
|
11
|
+
}
|
|
5
12
|
/**
|
|
6
13
|
Builds the play/pause TextBox. The button's visual is composed into the
|
|
7
14
|
scene in compute mode; its click is wired to `Timeline._togglePlay` via a
|
|
@@ -8,7 +8,10 @@ import { locale } from "@d3plus/locales";
|
|
|
8
8
|
import { SvgRenderer } from "@d3plus/render";
|
|
9
9
|
import { textWrap } from "@d3plus/text";
|
|
10
10
|
import { configPrep } from "../../utils/index.js";
|
|
11
|
+
import { applyClassName } from "../../utils/className.js";
|
|
11
12
|
import { parseTimeValues } from "../Axis/timeValues.js";
|
|
13
|
+
import { nearestIndex, spanIndices, timelineBrushSpan } from "./brushSpan.js";
|
|
14
|
+
import { byValue } from "./timelineConfig.js";
|
|
12
15
|
/**
|
|
13
16
|
Standalone paint for the Timeline's scene (axis ticks/domain line/labels
|
|
14
17
|
plus the play button's pixels). Inside a Viz the parent composes this via
|
|
@@ -47,6 +50,7 @@ import { parseTimeValues } from "../Axis/timeValues.js";
|
|
|
47
50
|
}, {
|
|
48
51
|
duration: 0
|
|
49
52
|
});
|
|
53
|
+
applyClassName(tl);
|
|
50
54
|
}
|
|
51
55
|
/** Coerces ticks/data to dates and resolves the tick format. */ export function prepareTicks(tl) {
|
|
52
56
|
if (tl.schema.ticks) tl.schema.ticks = parseTimeValues(tl.schema.ticks);
|
|
@@ -125,6 +129,33 @@ import { parseTimeValues } from "../Axis/timeValues.js";
|
|
|
125
129
|
}
|
|
126
130
|
return hiddenHandles;
|
|
127
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
Holds a starting `selection` to `brushMin` to `brushMax` periods, in
|
|
134
|
+
place, keeping its later end (or, at the first period, its earlier one),
|
|
135
|
+
and stores what remains as the Timeline's selection. `periods` are where
|
|
136
|
+
each period sits in `selection`'s terms (tick dates, or button positions)
|
|
137
|
+
and `dates` the periods themselves, both earliest first.
|
|
138
|
+
*/ export function clampSelection(tl, selection, periods, dates = periods) {
|
|
139
|
+
const span = timelineBrushSpan(tl.schema);
|
|
140
|
+
if (span.min <= 1 && span.max === Infinity || !periods.length) return;
|
|
141
|
+
const values = periods.map(Number);
|
|
142
|
+
const ends = [
|
|
143
|
+
selection[0],
|
|
144
|
+
selection[selection.length - 1]
|
|
145
|
+
].map((d)=>nearestIndex(values, Number(d)));
|
|
146
|
+
const first = Math.min(...ends);
|
|
147
|
+
const last = Math.max(...ends);
|
|
148
|
+
const [lo, hi] = spanIndices(first, last, values.length, span, "hi", "hi");
|
|
149
|
+
if (lo === first && hi === last) return;
|
|
150
|
+
[selection[0], selection[selection.length - 1]] = byValue([
|
|
151
|
+
periods[lo],
|
|
152
|
+
periods[hi]
|
|
153
|
+
]);
|
|
154
|
+
tl.schema.selection = [
|
|
155
|
+
dates[lo],
|
|
156
|
+
dates[hi]
|
|
157
|
+
].map((d)=>date(d));
|
|
158
|
+
}
|
|
128
159
|
/** Builds the d3-brush, computes the active selection, and mounts the brush group. */ export function setupBrush(tl, hiddenHandles, height, y) {
|
|
129
160
|
const offset = tl._outerBounds[y], range = tl._d3Scale.range();
|
|
130
161
|
// In "buttons" mode the scale positions ticks at each button's *midpoint*, so
|
|
@@ -149,20 +180,27 @@ import { parseTimeValues } from "../Axis/timeValues.js";
|
|
|
149
180
|
offset + tl._outerBounds[height]
|
|
150
181
|
]
|
|
151
182
|
]).filter(tl.schema.brushFilter).handleSize(hiddenHandles ? 0 : tl.schema.handleSize).on("start", tl._brushStart.bind(tl)).on("brush", tl._brushBrush.bind(tl)).on("end", tl._brushEnd.bind(tl));
|
|
152
|
-
//
|
|
153
|
-
|
|
183
|
+
// The ticks from earliest to latest, to pick the default from, and a
|
|
184
|
+
// button's position.
|
|
185
|
+
const ticks = byValue((tl._buttonBehaviorCurrent === "ticks" ? tl._availableTicks : tl.schema.ticks) || []);
|
|
186
|
+
const button = (d)=>{
|
|
187
|
+
const tick = ticks[ticks.map(Number).indexOf(+d)];
|
|
188
|
+
return tick === undefined ? undefined : tl._d3Scale(tick);
|
|
189
|
+
};
|
|
190
|
+
const defaultData = tl._buttonBehaviorCurrent === "ticks" ? ticks : ticks.map(button);
|
|
154
191
|
// the default selection, if needed
|
|
155
|
-
const defaultSelection = [
|
|
192
|
+
const defaultSelection = byValue([
|
|
156
193
|
tl.schema.brushMin() > defaultData.length ? defaultData[0] : defaultData[defaultData.length - tl.schema.brushMin()],
|
|
157
194
|
defaultData[defaultData.length - 1]
|
|
158
|
-
];
|
|
195
|
+
]);
|
|
159
196
|
// the current selection, considering user input, defaults, and data
|
|
160
|
-
const selection = tl.schema.selection === void 0 ? defaultSelection : tl.schema.selection instanceof Array ? tl._buttonBehaviorCurrent === "buttons" ? tl.schema.selection.map(date).map(
|
|
161
|
-
|
|
197
|
+
const selection = tl.schema.selection === void 0 ? defaultSelection : tl.schema.selection instanceof Array ? tl._buttonBehaviorCurrent === "buttons" ? byValue(tl.schema.selection.map(date).map(button)) : tl.schema.selection.map(date) : tl._buttonBehaviorCurrent === "buttons" ? [
|
|
198
|
+
button(date(tl.schema.selection))
|
|
162
199
|
] : [
|
|
163
200
|
tl.schema.selection
|
|
164
201
|
];
|
|
165
202
|
if (selection.length === 1) selection.push(selection[0]);
|
|
203
|
+
clampSelection(tl, selection, defaultData, ticks);
|
|
166
204
|
tl._updateBrushLimit(selection);
|
|
167
205
|
tl._brushGroup = elem("g.brushGroup", {
|
|
168
206
|
parent: tl._group
|
|
@@ -4,9 +4,11 @@ import { stylize } from "@d3plus/dom";
|
|
|
4
4
|
import { resetInjectedBoxes } from "@d3plus/render";
|
|
5
5
|
import { fontFamily, fontFamilyStringify } from "@d3plus/text";
|
|
6
6
|
import { accessor, BaseClass, constant } from "../utils/index.js";
|
|
7
|
+
import { setUserClasses } from "../utils/className.js";
|
|
7
8
|
import { installFluent, mergeConfigBag, resolvesReset } from "../fluent.js";
|
|
8
9
|
import { bindTooltips, buildTable, divElement, resolvePortal, TOOLTIP_SELECTORS } from "./tooltipDom.js";
|
|
9
|
-
/** Tooltip's fluent accessor schema. Config storage lives on `this.schema.<key>`. */ const
|
|
10
|
+
/** Tooltip's fluent accessor schema. Config storage lives on `this.schema.<key>`. */ /** Every tooltip element's fixed class; `className` adds classes beside it. */ const TOOLTIP_CLASS = "d3plus-tooltip";
|
|
11
|
+
const tooltipSchema = [
|
|
10
12
|
{
|
|
11
13
|
key: "arrow",
|
|
12
14
|
coerce: "const",
|
|
@@ -32,11 +34,6 @@ import { bindTooltips, buildTable, divElement, resolvePortal, TOOLTIP_SELECTORS
|
|
|
32
34
|
coerce: "const",
|
|
33
35
|
default: constant("4px")
|
|
34
36
|
},
|
|
35
|
-
{
|
|
36
|
-
key: "className",
|
|
37
|
-
coerce: "identity",
|
|
38
|
-
default: "d3plus-tooltip"
|
|
39
|
-
},
|
|
40
37
|
{
|
|
41
38
|
key: "footer",
|
|
42
39
|
coerce: "const",
|
|
@@ -195,11 +192,16 @@ import { bindTooltips, buildTable, divElement, resolvePortal, TOOLTIP_SELECTORS
|
|
|
195
192
|
const ownPrefix = `d3plus-tooltip-${this._uuid}-`;
|
|
196
193
|
const portal = resolvePortal(this);
|
|
197
194
|
resetInjectedBoxes(portal.node(), TOOLTIP_SELECTORS);
|
|
198
|
-
const tooltips = portal.selectAll(`.${
|
|
195
|
+
const tooltips = portal.selectAll(`.${TOOLTIP_CLASS}`).filter(function() {
|
|
199
196
|
return this.id.startsWith(ownPrefix);
|
|
200
197
|
}).data(this._data, this.schema.id);
|
|
201
|
-
const enter = tooltips.enter().append("div").attr("class",
|
|
198
|
+
const enter = tooltips.enter().append("div").attr("class", TOOLTIP_CLASS);
|
|
202
199
|
const update = tooltips.merge(enter);
|
|
200
|
+
update.each(function() {
|
|
201
|
+
if (this instanceof Element) setUserClasses(this, that.schema.className, [
|
|
202
|
+
TOOLTIP_CLASS
|
|
203
|
+
]);
|
|
204
|
+
});
|
|
203
205
|
stylize(update, this.schema.tooltipStyle);
|
|
204
206
|
/**
|
|
205
207
|
Fetches table contents given functions or values.
|
|
@@ -219,6 +221,9 @@ import { bindTooltips, buildTable, divElement, resolvePortal, TOOLTIP_SELECTORS
|
|
|
219
221
|
if (callback) setTimeout(callback, 100);
|
|
220
222
|
return this;
|
|
221
223
|
}
|
|
224
|
+
className(_) {
|
|
225
|
+
return arguments.length ? super.className(_) : super.className();
|
|
226
|
+
}
|
|
222
227
|
arrowStyle(_) {
|
|
223
228
|
return arguments.length ? (this.schema.arrowStyle = mergeConfigBag(this, "arrowStyle", _), this) : this.schema.arrowStyle;
|
|
224
229
|
}
|
package/es/src/shapes/Box.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { groups
|
|
1
|
+
import { groups } from "d3-array";
|
|
2
2
|
import { select } from "d3-selection";
|
|
3
3
|
import { merge } from "@d3plus/data";
|
|
4
4
|
import { elem } from "@d3plus/dom";
|
|
5
5
|
import { accessor, BaseClass, configPrep, constant } from "../utils/index.js";
|
|
6
6
|
import { installFluent, mergeConfigBag, resolvesReset } from "../fluent.js";
|
|
7
|
-
import Circle from "./Circle.js";
|
|
8
7
|
import Rect from "./Rect.js";
|
|
8
|
+
import { drawsOutlier, outlierShape } from "./boxOutlierShape.js";
|
|
9
|
+
import { boxStats, whiskerPair } from "./boxStats.js";
|
|
10
|
+
import { boxMedianConfig, boxOutlierConfig, boxRectConfig } from "./boxStyle.js";
|
|
11
|
+
import { computeSummaryBoxes, hasBoxStats, placeBox, toStatAccessor } from "./boxSummary.js";
|
|
9
12
|
import { stampOwners } from "./shapeOwners.js";
|
|
10
13
|
import { uniqueIds } from "./uniqueIds.js";
|
|
11
14
|
import Whisker from "./Whisker.js";
|
|
12
|
-
const shapes = {
|
|
13
|
-
Circle,
|
|
14
|
-
Rect
|
|
15
|
-
};
|
|
16
15
|
// Box's x/y setters wrap every non-function (including numbers) in
|
|
17
16
|
// `accessor(...)`, unlike the "accessor" coerce which would `constant(...)`
|
|
18
17
|
// a non-string — so a custom coerce preserves the exact behavior.
|
|
@@ -26,6 +25,34 @@ const toAccessor = (value)=>typeof value === "function" ? value : accessor(value
|
|
|
26
25
|
key: "backgroundImageFit",
|
|
27
26
|
coerce: "const"
|
|
28
27
|
},
|
|
28
|
+
{
|
|
29
|
+
key: "boxMax",
|
|
30
|
+
coerce: toStatAccessor
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "boxMedian",
|
|
34
|
+
coerce: toStatAccessor
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
key: "boxMin",
|
|
38
|
+
coerce: toStatAccessor
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
key: "boxOutliers",
|
|
42
|
+
coerce: toStatAccessor
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: "boxQ1",
|
|
46
|
+
coerce: toStatAccessor
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
key: "boxQ3",
|
|
50
|
+
coerce: toStatAccessor
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
key: "fill",
|
|
54
|
+
coerce: "const"
|
|
55
|
+
},
|
|
29
56
|
{
|
|
30
57
|
key: "id",
|
|
31
58
|
coerce: "accessor"
|
|
@@ -50,6 +77,10 @@ const toAccessor = (value)=>typeof value === "function" ? value : accessor(value
|
|
|
50
77
|
coerce: "identity",
|
|
51
78
|
default: "full"
|
|
52
79
|
},
|
|
80
|
+
{
|
|
81
|
+
key: "stroke",
|
|
82
|
+
coerce: "const"
|
|
83
|
+
},
|
|
53
84
|
{
|
|
54
85
|
key: "texture",
|
|
55
86
|
coerce: "const"
|
|
@@ -60,10 +91,7 @@ const toAccessor = (value)=>typeof value === "function" ? value : accessor(value
|
|
|
60
91
|
},
|
|
61
92
|
{
|
|
62
93
|
key: "whiskerMode",
|
|
63
|
-
coerce:
|
|
64
|
-
v,
|
|
65
|
-
v
|
|
66
|
-
],
|
|
94
|
+
coerce: whiskerPair,
|
|
67
95
|
default: [
|
|
68
96
|
"tukey",
|
|
69
97
|
"tukey"
|
|
@@ -80,54 +108,21 @@ const toAccessor = (value)=>typeof value === "function" ? value : accessor(value
|
|
|
80
108
|
default: accessor("y", 250)
|
|
81
109
|
}
|
|
82
110
|
];
|
|
83
|
-
/** The Box's own fill styling that its box Rect takes unless `rectConfig` sets it. */ const boxRectKeys = [
|
|
84
|
-
"backgroundImage",
|
|
85
|
-
"backgroundImageFit",
|
|
86
|
-
"texture",
|
|
87
|
-
"textureDefault"
|
|
88
|
-
];
|
|
89
|
-
/**
|
|
90
|
-
The box Rect's config: `rectConfig`, plus the Box's own `texture`,
|
|
91
|
-
`textureDefault`, `backgroundImage`, and `backgroundImageFit` where
|
|
92
|
-
`rectConfig` leaves them unset. Accessors resolve against the box's merged
|
|
93
|
-
datum, the same one `orient` and `rectWidth` see.
|
|
94
|
-
*/ export function boxRectConfig(schema, rectConfig) {
|
|
95
|
-
const config = {};
|
|
96
|
-
for (const key of boxRectKeys){
|
|
97
|
-
const value = schema[key];
|
|
98
|
-
if (value === undefined || key in rectConfig) continue;
|
|
99
|
-
config[key] = typeof value === "function" ? (d)=>value(d.data, d.i) : value;
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
...config,
|
|
103
|
-
...rectConfig
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
111
|
/**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
*/ function
|
|
110
|
-
if (mode[0] === "tukey") {
|
|
111
|
-
d.lowerLimit = d.first - (d.third - d.first) * 1.5;
|
|
112
|
-
if (d.lowerLimit < min(values)) d.lowerLimit = min(values);
|
|
113
|
-
} else if (mode[0] === "extent") d.lowerLimit = min(values);
|
|
114
|
-
else if (typeof mode[0] === "number") d.lowerLimit = quantile(values, mode[0]);
|
|
115
|
-
if (mode[1] === "tukey") {
|
|
116
|
-
d.upperLimit = d.third + (d.third - d.first) * 1.5;
|
|
117
|
-
if (d.upperLimit > max(values)) d.upperLimit = max(values);
|
|
118
|
-
} else if (mode[1] === "extent") d.upperLimit = max(values);
|
|
119
|
-
else if (typeof mode[1] === "number") d.upperLimit = quantile(values, mode[1]);
|
|
120
|
-
}
|
|
121
|
-
/** Appends an outlier DataPoint to `outlierData` for each value past a limit. */ function collectOutliers(box, d, outlierData) {
|
|
112
|
+
Appends an outlier DataPoint to `outlierData` for each value past a limit
|
|
113
|
+
whose `outlier` setting draws a point.
|
|
114
|
+
*/ function collectOutliers(box, d, outlierData) {
|
|
122
115
|
d.values.forEach((eachValue, index)=>{
|
|
123
116
|
const value = d.orient === "vertical" ? box.schema.y(eachValue, index) : box.schema.x(eachValue, index);
|
|
124
117
|
if (value < d.lowerLimit || value > d.upperLimit) {
|
|
118
|
+
const shape = box.schema.outlier(eachValue, index);
|
|
119
|
+
if (!drawsOutlier(shape)) return;
|
|
125
120
|
const dataObj = {};
|
|
126
121
|
dataObj.__d3plus__ = true;
|
|
127
122
|
dataObj.data = eachValue;
|
|
128
123
|
dataObj.i = index;
|
|
129
124
|
dataObj.id = `${d.id}-outlier-${index}`;
|
|
130
|
-
dataObj.outlier =
|
|
125
|
+
dataObj.outlier = shape;
|
|
131
126
|
if (d.orient === "vertical") {
|
|
132
127
|
dataObj.x = d.x;
|
|
133
128
|
dataObj.y = value;
|
|
@@ -155,27 +150,21 @@ const toAccessor = (value)=>typeof value === "function" ? value : accessor(value
|
|
|
155
150
|
d.orient = box.schema.orient(d.data, d.i);
|
|
156
151
|
const values = d.values.map(d.orient === "vertical" ? box.schema.y : box.schema.x);
|
|
157
152
|
values.sort((a, b)=>a - b);
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
// Compute values for horizontal orientation.
|
|
174
|
-
d.height = box.schema.rectWidth(d.data, d.i);
|
|
175
|
-
d.width = rectLength;
|
|
176
|
-
d.x = d.first + rectLength / 2;
|
|
177
|
-
d.y = key;
|
|
178
|
-
}
|
|
153
|
+
const { first, median, third, lowerLimit, upperLimit } = boxStats(values, box.schema.whiskerMode);
|
|
154
|
+
Object.assign(d, {
|
|
155
|
+
first,
|
|
156
|
+
median,
|
|
157
|
+
third
|
|
158
|
+
});
|
|
159
|
+
if (lowerLimit !== undefined) Object.assign(d, {
|
|
160
|
+
lowerLimit
|
|
161
|
+
});
|
|
162
|
+
if (upperLimit !== undefined) Object.assign(d, {
|
|
163
|
+
upperLimit
|
|
164
|
+
});
|
|
165
|
+
// The group key is this same accessor evaluated on each member; the
|
|
166
|
+
// merged datum can't be re-read because `merge` sums numeric fields.
|
|
167
|
+
placeBox(d, key, box.schema.rectWidth(d.data, d.i));
|
|
179
168
|
// Compute data for outliers.
|
|
180
169
|
collectOutliers(box, d, outlierData);
|
|
181
170
|
d.__d3plus__ = true;
|
|
@@ -282,9 +271,7 @@ const toAccessor = (value)=>typeof value === "function" ? value : accessor(value
|
|
|
282
271
|
*/ constructor(){
|
|
283
272
|
super();
|
|
284
273
|
installFluent(this, boxSchema);
|
|
285
|
-
this.schema.medianConfig = {
|
|
286
|
-
fill: constant("black")
|
|
287
|
-
};
|
|
274
|
+
this.schema.medianConfig = {};
|
|
288
275
|
this.schema.outlierConfig = {
|
|
289
276
|
Circle: {
|
|
290
277
|
r: accessor("r", 5)
|
|
@@ -295,8 +282,6 @@ const toAccessor = (value)=>typeof value === "function" ? value : accessor(value
|
|
|
295
282
|
}
|
|
296
283
|
};
|
|
297
284
|
this.schema.rectConfig = {
|
|
298
|
-
fill: constant("white"),
|
|
299
|
-
stroke: constant("black"),
|
|
300
285
|
strokeWidth: constant(1)
|
|
301
286
|
};
|
|
302
287
|
this.schema.whiskerConfig = {};
|
|
@@ -320,11 +305,12 @@ const toAccessor = (value)=>typeof value === "function" ? value : accessor(value
|
|
|
320
305
|
}).node();
|
|
321
306
|
};
|
|
322
307
|
const outlierData = [];
|
|
323
|
-
const filteredData = computeBoxes(this, outlierData);
|
|
308
|
+
const filteredData = hasBoxStats(this.schema) ? computeSummaryBoxes(this, outlierData) : computeBoxes(this, outlierData);
|
|
309
|
+
const rectConfig = boxRectConfig(this.schema, configPrep.bind(this)(this.schema.rectConfig, "shape"));
|
|
324
310
|
// Draw box.
|
|
325
|
-
this._box = new Rect().data(filteredData).id((d)=>`${d.id}-box`).x((d)=>d.x).y((d)=>d.y).renderMode(compute ? "compute" : "full").select(mountInner("g.d3plus-Box")).config(
|
|
311
|
+
this._box = new Rect().data(filteredData).id((d)=>`${d.id}-box`).x((d)=>d.x).y((d)=>d.y).renderMode(compute ? "compute" : "full").select(mountInner("g.d3plus-Box")).config(rectConfig).render();
|
|
326
312
|
// Draw median.
|
|
327
|
-
this._median = new Rect().data(filteredData).id((d)=>`${d.id}-median`).x((d)=>d.orient === "vertical" ? d.x : d.median).y((d)=>d.orient === "vertical" ? d.median : d.y).height((d)=>d.orient === "vertical" ? 1 : d.height).width((d)=>d.orient === "vertical" ? d.width : 1).renderMode(compute ? "compute" : "full").select(mountInner("g.d3plus-Box-Median")).config(configPrep.bind(this)(this.schema.medianConfig, "shape")).render();
|
|
313
|
+
this._median = new Rect().data(filteredData).id((d)=>`${d.id}-median`).x((d)=>d.orient === "vertical" ? d.x : d.median).y((d)=>d.orient === "vertical" ? d.median : d.y).height((d)=>d.orient === "vertical" ? 1 : d.height).width((d)=>d.orient === "vertical" ? d.width : 1).renderMode(compute ? "compute" : "full").select(mountInner("g.d3plus-Box-Median")).config(boxMedianConfig(rectConfig.fill, configPrep.bind(this)(this.schema.medianConfig, "shape"))).render();
|
|
328
314
|
// Draw 2 lines using Whisker class.
|
|
329
315
|
// Construct coordinates for whisker startpoints and push it to the whiskerData.
|
|
330
316
|
const whiskerData = buildWhiskerData(filteredData);
|
|
@@ -333,7 +319,8 @@ const toAccessor = (value)=>typeof value === "function" ? value : accessor(value
|
|
|
333
319
|
// Draw outliers.
|
|
334
320
|
this._whiskerEndpoint = [];
|
|
335
321
|
groups(outlierData, (d)=>d.outlier).forEach(([shapeName, values])=>{
|
|
336
|
-
|
|
322
|
+
const OutlierShape = outlierShape(shapeName);
|
|
323
|
+
this._whiskerEndpoint.push(new OutlierShape().data(values).renderMode(compute ? "compute" : "full").select(mountInner(`g.d3plus-Box-Outlier-${shapeName}`)).config(boxOutlierConfig(this.schema, configPrep.bind(this)(this.schema.outlierConfig, "shape", shapeName))).render());
|
|
337
324
|
});
|
|
338
325
|
return this;
|
|
339
326
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Circle from "./Circle.js";
|
|
2
|
+
import Rect from "./Rect.js";
|
|
3
|
+
/** The shapes a Box can draw its outliers with, by name. */ const outlierShapes = new Map([
|
|
4
|
+
[
|
|
5
|
+
"Circle",
|
|
6
|
+
Circle
|
|
7
|
+
],
|
|
8
|
+
[
|
|
9
|
+
"Rect",
|
|
10
|
+
Rect
|
|
11
|
+
]
|
|
12
|
+
]);
|
|
13
|
+
/**
|
|
14
|
+
The shape class a Box's `outlier` setting names: `"Circle"` or `"Rect"`.
|
|
15
|
+
Undefined for `false`, or any other value, which draws no point.
|
|
16
|
+
*/ export function outlierShape(value) {
|
|
17
|
+
return outlierShapes.get(value);
|
|
18
|
+
}
|
|
19
|
+
/** Whether a Box's `outlier` setting draws a point. */ export const drawsOutlier = (value)=>outlierShapes.has(value);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { max, min, quantile } from "d3-array";
|
|
2
|
+
/** A `whiskerMode` setting as a `[lower, upper]` pair. */ export function whiskerPair(mode) {
|
|
3
|
+
return Array.isArray(mode) ? mode : [
|
|
4
|
+
mode,
|
|
5
|
+
mode
|
|
6
|
+
];
|
|
7
|
+
}
|
|
8
|
+
/** One whisker end: `side` 0 is the lower, 1 the upper. */ function whiskerEnd(values, mode, side, first, third) {
|
|
9
|
+
const lo = min(values), hi = max(values);
|
|
10
|
+
if (mode === "tukey") {
|
|
11
|
+
const fence = side ? third + (third - first) * 1.5 : first - (third - first) * 1.5;
|
|
12
|
+
return side ? fence > hi ? hi : fence : fence < lo ? lo : fence;
|
|
13
|
+
}
|
|
14
|
+
if (mode === "extent") return side ? hi : lo;
|
|
15
|
+
if (typeof mode === "number") return quantile(values, mode);
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
The quartiles and whisker ends of ascending `values`. Each whisker end
|
|
20
|
+
follows its side of `mode`: `"tukey"` reaches 1.5 interquartile ranges
|
|
21
|
+
past its quartile, stopping at the extreme value; `"extent"` reaches the
|
|
22
|
+
extreme value; a number reaches that quantile.
|
|
23
|
+
*/ export function boxStats(values, mode) {
|
|
24
|
+
const first = quantile(values, 0.25);
|
|
25
|
+
const median = quantile(values, 0.5);
|
|
26
|
+
const third = quantile(values, 0.75);
|
|
27
|
+
const end = (side)=>whiskerEnd(values, mode[side], side, first, third);
|
|
28
|
+
return {
|
|
29
|
+
first,
|
|
30
|
+
median,
|
|
31
|
+
third,
|
|
32
|
+
lowerLimit: end(0),
|
|
33
|
+
upperLimit: end(1)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { color } from "d3-color";
|
|
2
|
+
import { colorContrast } from "@d3plus/color";
|
|
3
|
+
import { isSharedConfig, markSharedConfig } from "../utils/configWarnings.js";
|
|
4
|
+
/** The Box's own styling that its box Rect takes unless `rectConfig` sets it. */ const boxRectKeys = [
|
|
5
|
+
"fill",
|
|
6
|
+
"stroke",
|
|
7
|
+
"backgroundImage",
|
|
8
|
+
"backgroundImageFit",
|
|
9
|
+
"texture",
|
|
10
|
+
"textureDefault"
|
|
11
|
+
];
|
|
12
|
+
/** The box Rect's colors when neither the Box nor `rectConfig` sets them. */ const boxRectDefaults = {
|
|
13
|
+
fill: "white",
|
|
14
|
+
stroke: "black"
|
|
15
|
+
};
|
|
16
|
+
/** `config` with the Box's additions, still marked shared if `from` was. */ function extend(from, config) {
|
|
17
|
+
return isSharedConfig(from) ? markSharedConfig(config) : config;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
A Box-level value for one of its parts: an accessor is called with the
|
|
21
|
+
part's source datum and index (`d.data` and `d.i`), which is the box's
|
|
22
|
+
merged datum for the box Rect and the observation for an outlier.
|
|
23
|
+
*/ function fromBox(value) {
|
|
24
|
+
return typeof value === "function" ? (d)=>value(d.data, d.i) : value;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
The box Rect's config: `rectConfig`, plus the Box's own `fill`, `stroke`,
|
|
28
|
+
`texture`, `textureDefault`, `backgroundImage`, and `backgroundImageFit`
|
|
29
|
+
where `rectConfig` leaves them unset, and a white fill and black stroke
|
|
30
|
+
where neither sets them. Accessors resolve against the box's merged datum,
|
|
31
|
+
the same one `orient` and `rectWidth` see.
|
|
32
|
+
*/ export function boxRectConfig(schema, rectConfig) {
|
|
33
|
+
const config = {
|
|
34
|
+
...boxRectDefaults
|
|
35
|
+
};
|
|
36
|
+
for (const key of boxRectKeys){
|
|
37
|
+
const value = schema[key];
|
|
38
|
+
if (value !== undefined && !(key in rectConfig)) config[key] = fromBox(value);
|
|
39
|
+
}
|
|
40
|
+
return extend(rectConfig, {
|
|
41
|
+
...config,
|
|
42
|
+
...rectConfig
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
Black or white, whichever reads better over `fill`; black when `fill`
|
|
47
|
+
isn't an opaque color.
|
|
48
|
+
*/ export function boxMedianInk(fill) {
|
|
49
|
+
const c = typeof fill === "string" ? color(fill) : null;
|
|
50
|
+
if (!c || !c.opacity) return "black";
|
|
51
|
+
return colorContrast(c.formatRgb(), {
|
|
52
|
+
dark: "black",
|
|
53
|
+
light: "white"
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
The median Rect's config: `medianConfig`, with a fill that contrasts with
|
|
58
|
+
the box's `boxFill` (resolved on the same box datum) where `medianConfig`
|
|
59
|
+
leaves it unset.
|
|
60
|
+
*/ export function boxMedianConfig(boxFill, medianConfig) {
|
|
61
|
+
if ("fill" in medianConfig) return medianConfig;
|
|
62
|
+
const fill = typeof boxFill === "function" ? (d, i)=>boxMedianInk(boxFill(d, i)) : ()=>boxMedianInk(boxFill);
|
|
63
|
+
return extend(medianConfig, {
|
|
64
|
+
...medianConfig,
|
|
65
|
+
fill
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
An outlier shape's config: `outlierConfig`, plus the Box's own `fill`
|
|
70
|
+
resolved against each outlier's observation where `outlierConfig` leaves
|
|
71
|
+
it unset.
|
|
72
|
+
*/ export function boxOutlierConfig(schema, outlierConfig) {
|
|
73
|
+
if (schema.fill === undefined || "fill" in outlierConfig) return outlierConfig;
|
|
74
|
+
return extend(outlierConfig, {
|
|
75
|
+
...outlierConfig,
|
|
76
|
+
fill: fromBox(schema.fill)
|
|
77
|
+
});
|
|
78
|
+
}
|