@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
|
@@ -13,6 +13,7 @@ import { applyAxisBreaks, breakTickValues } from "./axisBreak.js";
|
|
|
13
13
|
import { axisDateCategories, axisShownDates, axisTimeDomain, axisTimeReference, isCategoryAxis, isValidDate, parseTimeValues } from "./timeValues.js";
|
|
14
14
|
import { axisIsYearLike, formatYear } from "./yearValues.js";
|
|
15
15
|
import { floorPow, isNegative, roundedDomain } from "./axisRounding.js";
|
|
16
|
+
import { powExponent } from "./powTicks.js";
|
|
16
17
|
/**
|
|
17
18
|
Builds the tick label formatter (user-supplied or scale-derived). With a
|
|
18
19
|
`rotatedTickFormat`, the formatter reads `axis._labelRotation` on every
|
|
@@ -233,10 +234,12 @@ import { floorPow, isNegative, roundedDomain } from "./axisRounding.js";
|
|
|
233
234
|
const scale = `scale${axis.schema.scale.charAt(0).toUpperCase()}${axis.schema.scale.slice(1)}`;
|
|
234
235
|
const initialDomain = axis.schema.domain.slice();
|
|
235
236
|
axis._d3Scale = scales[scale]().domain(axis.schema.scale === "time" ? axisTimeDomain(axis) : initialDomain).range(range);
|
|
237
|
+
if (axis.schema.scale === "pow" && axis._d3Scale.exponent) axis._d3Scale.exponent(powExponent(axis.schema.exponent));
|
|
236
238
|
if (axis.schema.rounding !== "none") {
|
|
237
239
|
const rounded = roundedDomain(initialDomain, axis.schema.rounding, axis.schema.scale);
|
|
238
240
|
if (rounded) axis._d3Scale.domain(rounded);
|
|
239
241
|
}
|
|
242
|
+
if (axis.schema.reverse) axis._d3Scale.domain(axis._d3Scale.domain().slice().reverse());
|
|
240
243
|
if (axis._d3Scale.padding) axis._d3Scale.padding(axis.schema.scalePadding);
|
|
241
244
|
if (axis._d3Scale.align) axis._d3Scale.align(axis.schema.scaleAlign);
|
|
242
245
|
if (axis._d3Scale.paddingInner) axis._d3Scale.paddingInner(axis.schema.paddingInner);
|
|
@@ -4,9 +4,12 @@ import { elem } from "@d3plus/dom";
|
|
|
4
4
|
import * as shapes from "../../shapes/index.js";
|
|
5
5
|
import { addDomainEnds, crowdsEndLabel } from "./axisEndLabels.js";
|
|
6
6
|
import { configPrep } from "../../utils/index.js";
|
|
7
|
+
import { wholeWordSplit } from "../../utils/wholeWords.js";
|
|
7
8
|
import { brokenScaleTicks, isBrokenScale } from "./axisBreak.js";
|
|
8
9
|
import { ceilPow, fixFloat, floorPow, isNegative } from "./axisRounding.js";
|
|
10
|
+
import { powTicks } from "./powTicks.js";
|
|
9
11
|
import { timeDataInDomain } from "./timeValues.js";
|
|
12
|
+
import { slantedLabelBox } from "./axisLabelAngle.js";
|
|
10
13
|
const maxTimezoneOffset = 1000 * 60 * 60 * 26;
|
|
11
14
|
/**
|
|
12
15
|
* Calculates ticks from a given scale (negative and/or positive)
|
|
@@ -76,6 +79,9 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
|
|
|
76
79
|
ticks = powMod <= 1 && powers[0] === powers[1] || invertedRound !== inverted ? scaleClone.ticks(step).filter((d)=>+`${d}`.replace("0.", "") % 2 === 0) : d3Range(powers[0], powers[1], powers[1] < powers[0] ? -1 : 1).concat([
|
|
77
80
|
powers[1]
|
|
78
81
|
]).filter((d)=>Math.abs(d) % powMod === 0).map((d)=>+`${(isNegative(d) ? -1 : 1) * (d ? Math.pow(10, Math.abs(d)) : Math.sign(1 / d) > 0 ? 1 : -1)}`.replace(/9+/g, "1"));
|
|
82
|
+
} else if (scaleClone.exponent && scaleClone.exponent() !== 1) {
|
|
83
|
+
// Labels take every other step, as the linear filter below does.
|
|
84
|
+
ticks = powTicks(domain, scaleClone.exponent(), Math.max(1, step / 2), minorTicks);
|
|
79
85
|
} else {
|
|
80
86
|
ticks = scaleClone.ticks(step);
|
|
81
87
|
if (!minorTicks && ![
|
|
@@ -103,6 +109,28 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
|
|
|
103
109
|
}
|
|
104
110
|
return addDomainEnds(this, ticks, domain, scaleClone, !minorTicks);
|
|
105
111
|
}
|
|
112
|
+
/** A slanted label's box, relative to its tick (see `slantedLabelBox`). */ function slantedBounds(axis, data, gap) {
|
|
113
|
+
const { x, y, width, height } = slantedLabelBox(axis.schema.orient, data.angle, data.width, data.height - data.fP, data.height, gap);
|
|
114
|
+
return {
|
|
115
|
+
x,
|
|
116
|
+
y,
|
|
117
|
+
width,
|
|
118
|
+
height
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
An upright (±90 degree) label's box, relative to its tick: centered on
|
|
123
|
+
it, reaching out from the axis by the label's length.
|
|
124
|
+
*/ function uprightBounds(axis, data, size) {
|
|
125
|
+
const { fP, fS, lineHeight, lines, width } = data;
|
|
126
|
+
const text = lineHeight * lines.length;
|
|
127
|
+
return {
|
|
128
|
+
x: -width / 2 + ((data.angle ?? -90) > 0 ? -1 : 1) * (fS / 4),
|
|
129
|
+
y: axis.schema.orient === "bottom" ? size + (width - text) / 2 + fP : size - (width + text) / 2 - 2 * fP,
|
|
130
|
+
width,
|
|
131
|
+
height: data.height
|
|
132
|
+
};
|
|
133
|
+
}
|
|
106
134
|
/**
|
|
107
135
|
Builds the per-tick config array consumed by the tick Shape. Extracted from
|
|
108
136
|
`Axis.render` so the render method stays under the per-function line budget;
|
|
@@ -124,8 +152,6 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
|
|
|
124
152
|
const data = textData.find((td)=>td.d === d);
|
|
125
153
|
const xPos = axis._getPosition(d);
|
|
126
154
|
const space = data ? data.space : 0;
|
|
127
|
-
const lines = data ? data.lines.length : 1;
|
|
128
|
-
const lineHeight = data ? data.lineHeight : 1;
|
|
129
155
|
const fP = data ? data.fP : 0;
|
|
130
156
|
const labelOffset = data && axis.schema.labelOffset ? data.offset ?? 0 : 0;
|
|
131
157
|
const fitWidth = horizontal ? space : bounds.width - margin[axis._position.opposite] - hBuff - margin[axis.schema.orient] + p;
|
|
@@ -135,18 +161,14 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
|
|
|
135
161
|
const offset = margin[opposite], size = (hBuff + labelOffset) * (flip ? -1 : 1), yPos = flip ? bounds[y] + bounds[height] - offset : bounds[y] + offset;
|
|
136
162
|
const tickConfig = {
|
|
137
163
|
id: d,
|
|
138
|
-
labelBounds: rotated && data ? {
|
|
139
|
-
x: -data.width / 2 + data.fS / 4,
|
|
140
|
-
y: axis.schema.orient === "bottom" ? size + (data.width - lineHeight * lines) / 2 + fP : size - (data.width + lineHeight * lines) / 2 - 2 * fP,
|
|
141
|
-
width: data.width,
|
|
142
|
-
height: data.height
|
|
143
|
-
} : {
|
|
164
|
+
labelBounds: data?.slant ? slantedBounds(axis, data, Math.abs(size) + (horizontal ? fP : p)) : rotated && data ? uprightBounds(axis, data, size) : {
|
|
144
165
|
x: horizontal ? -space / 2 : axis.schema.orient === "left" ? -labelWidth - p + size : size + p,
|
|
145
166
|
y: horizontal ? axis.schema.orient === "bottom" ? size + fP : size - labelHeight - fP : -space / 2,
|
|
146
167
|
width: horizontal ? space : labelWidth,
|
|
147
168
|
height: horizontal ? labelHeight : space
|
|
148
169
|
},
|
|
149
170
|
rotate: data ? data.rotate : false,
|
|
171
|
+
angle: data ? data.angle : 0,
|
|
150
172
|
size: labels.includes(d) || axis.schema.scale === "log" && Math.log10(Math.abs(d)) % 1 === 0 ? size : ticks.includes(d) ? Math.ceil(size / 2) : axis._scaleData.find((t)=>+t === d) ? Math.ceil(size / 4) : 0,
|
|
151
173
|
text: !data?.truncated && labels.includes(d) ? tickFormat(d) : false,
|
|
152
174
|
tick: ticks.includes(d),
|
|
@@ -177,10 +199,17 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
|
|
|
177
199
|
// would silently leak one <div> per tick render.
|
|
178
200
|
.renderMode("compute").select(null).data(tickData).duration(axis.schema.duration).labelConfig({
|
|
179
201
|
ellipsis: (d)=>d && d.length ? `${d}...` : "",
|
|
202
|
+
// Slanted labels wrap between words, as they were measured.
|
|
203
|
+
...axis._labelRotation && axis._labelSlant ? {
|
|
204
|
+
split: wholeWordSplit
|
|
205
|
+
} : {},
|
|
180
206
|
// The label TextBox invokes this with the laid-out label record, whose
|
|
181
207
|
// tick datum (carrying `rotate`) sits on `.data`; fall back to the raw
|
|
182
208
|
// datum for any path that passes it directly.
|
|
183
|
-
rotate: (d)=>
|
|
209
|
+
rotate: (d)=>{
|
|
210
|
+
const datum = d.rotate !== undefined ? d : d.data;
|
|
211
|
+
return datum?.rotate ? Number(datum.angle ?? -90) : 0;
|
|
212
|
+
}
|
|
184
213
|
});
|
|
185
214
|
// v4 scene-only: tick shape stays compute-mode; toScene() composes ticks.
|
|
186
215
|
// No `g.ticks` DOM wrapper needed in the detached compute.
|
|
@@ -46,12 +46,23 @@
|
|
|
46
46
|
}
|
|
47
47
|
return newDomain.map(fixFloat);
|
|
48
48
|
}
|
|
49
|
+
/** The axis scales whose domains round to nice values (see `roundedDomain`). */ export const roundingScales = [
|
|
50
|
+
"linear",
|
|
51
|
+
"log",
|
|
52
|
+
"pow",
|
|
53
|
+
"sqrt"
|
|
54
|
+
];
|
|
49
55
|
/**
|
|
50
|
-
A linear or
|
|
51
|
-
("outside" or "inside") rounds it, or undefined when the axis
|
|
52
|
-
domain as given (another scale, or nothing to round).
|
|
56
|
+
A linear, log or power axis domain rounded the way an Axis with this
|
|
57
|
+
`rounding` ("outside" or "inside") rounds it, or undefined when the axis
|
|
58
|
+
leaves the domain as given (another scale, or nothing to round). A power
|
|
59
|
+
scale's domain rounds as a linear one does.
|
|
53
60
|
*/ export function roundedDomain(initialDomain, rounding, scale) {
|
|
54
|
-
if (
|
|
61
|
+
if ([
|
|
62
|
+
"linear",
|
|
63
|
+
"pow",
|
|
64
|
+
"sqrt"
|
|
65
|
+
].includes(scale)) {
|
|
55
66
|
return roundLinear(initialDomain, rounding, scale);
|
|
56
67
|
} else if (scale === "log") {
|
|
57
68
|
const powDomain = [];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Wrapping for slanted axis labels (see `labelRotation`). Long labels wrap
|
|
3
|
+
onto two or three lines, as many as fit between neighbouring labels,
|
|
4
|
+
breaking only between words, so
|
|
5
|
+
a slanted label reaches less far from the axis than it would on one long
|
|
6
|
+
line. Every label wraps at one shared width: the narrowest at which the
|
|
7
|
+
longest label fits those lines, so the shorter ones stay whole on fewer.
|
|
8
|
+
*/ import { textWidth } from "@d3plus/dom";
|
|
9
|
+
import { textWrap } from "@d3plus/text";
|
|
10
|
+
import { wholeWordSplit } from "../../utils/wholeWords.js";
|
|
11
|
+
/** The most lines a slanted label wraps onto. */ export const SLANTED_MAX_LINES = 3;
|
|
12
|
+
/** How many lines of `lineHeight` fit in a slanted label `thickness` thick: 1 to 3. */ export const slantedLines = (thickness, lineHeight)=>Math.max(1, Math.min(SLANTED_MAX_LINES, Math.floor(thickness / lineHeight + 1e-9)));
|
|
13
|
+
/**
|
|
14
|
+
The narrowest width, from `min` up to `max` in steps of `step` times the
|
|
15
|
+
last, at which text wraps onto at most `lines` lines, as `lineCount`
|
|
16
|
+
counts them at a width; `max` when none does.
|
|
17
|
+
*/ export function narrowestWidth(lineCount, lines, min, max, step = 1.08) {
|
|
18
|
+
for(let width = Math.max(1, min); width < max; width *= step)if (lineCount(width) <= lines) return Math.ceil(width);
|
|
19
|
+
return max;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
The width slanted labels wrap at to fit on `lines` lines, at most `max`:
|
|
23
|
+
the widest any one of them needs, and never narrower than a word.
|
|
24
|
+
*/ export function slantedLineWidth(labels, lines, max) {
|
|
25
|
+
if (lines < 2) return max;
|
|
26
|
+
const widths = labels.map(({ text, fontFamily, fontSize, lineHeight })=>{
|
|
27
|
+
const font = {
|
|
28
|
+
"font-family": fontFamily,
|
|
29
|
+
"font-size": fontSize
|
|
30
|
+
};
|
|
31
|
+
const whole = textWidth(`${text}`, font);
|
|
32
|
+
const words = `${text}`.split(/\s+/).filter(Boolean);
|
|
33
|
+
const word = Math.max(0, ...words.map((w)=>textWidth(w, font)));
|
|
34
|
+
const wrap = textWrap().fontFamily(fontFamily).fontSize(fontSize).lineHeight(lineHeight).split(wholeWordSplit).height(lineHeight * (lines + 1));
|
|
35
|
+
const count = (width)=>wrap.width(width)(`${text}`).lines.filter((l)=>l !== "").length;
|
|
36
|
+
return narrowestWidth(count, lines, Math.max(word + 1, whole / lines), max);
|
|
37
|
+
});
|
|
38
|
+
return Math.min(max, Math.max(0, ...widths));
|
|
39
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Tick values for a power scale whose exponent isn't 1. Value-spaced ticks
|
|
3
|
+
bunch up where the exponent compresses the axis and leave long gaps
|
|
4
|
+
where it stretches it, so these are spaced evenly along the axis instead,
|
|
5
|
+
each rounded to a round number at the precision its neighbors allow.
|
|
6
|
+
*/ /**
|
|
7
|
+
The exponent a `"pow"` axis uses: `exponent` when it is a positive
|
|
8
|
+
number, else 1.
|
|
9
|
+
*/ export const powExponent = (exponent)=>typeof exponent === "number" && Number.isFinite(exponent) && exponent > 0 ? exponent : 1;
|
|
10
|
+
/** `value` raised to `exponent`, keeping its sign (as d3's `scalePow` does). */ const raise = (value, exponent)=>value < 0 ? -Math.pow(-value, exponent) : Math.pow(value, exponent);
|
|
11
|
+
/**
|
|
12
|
+
`value` rounded to the roundest number within `tolerance` of it: the
|
|
13
|
+
nearest multiple of the largest step (1, 2 or 5 times a power of ten)
|
|
14
|
+
that lands that close.
|
|
15
|
+
*/ export function roundWithin(value, tolerance) {
|
|
16
|
+
if (!(tolerance > 0) || !Number.isFinite(tolerance)) return value;
|
|
17
|
+
let power = Math.floor(Math.log10(Math.max(Math.abs(value), tolerance))) + 1;
|
|
18
|
+
for(; power > -30; power--){
|
|
19
|
+
for (const m of [
|
|
20
|
+
5,
|
|
21
|
+
2,
|
|
22
|
+
1
|
|
23
|
+
]){
|
|
24
|
+
const step = m * Math.pow(10, power);
|
|
25
|
+
const rounded = Math.round(value / step) * step;
|
|
26
|
+
if (Math.abs(rounded - value) <= tolerance) return +rounded.toPrecision(12);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
Each value rounded to within a third of the distance to its nearest
|
|
33
|
+
neighbor in `neighbors`, so neighbors stay apart.
|
|
34
|
+
*/ function roundEach(values, neighbors) {
|
|
35
|
+
return values.map((value)=>{
|
|
36
|
+
const spacing = Math.min(...neighbors.map((n)=>Math.abs(n - value)).filter((d)=>d > 0));
|
|
37
|
+
return roundWithin(value, spacing / 3);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
Tick values for a power scale: `count` equal steps along the axis (in the
|
|
42
|
+
scale's transformed space), each rounded to a round number. With
|
|
43
|
+
`minor`, the midpoints between those steps are added, so the major
|
|
44
|
+
ticks are always a subset of the minor ones. Returns ascending values
|
|
45
|
+
inside the domain, or the domain's own order when it runs high to low.
|
|
46
|
+
@param domain The scale's domain.
|
|
47
|
+
@param exponent The scale's exponent.
|
|
48
|
+
@param count How many steps to divide the axis into.
|
|
49
|
+
@param minor Whether to add a tick between each pair of steps.
|
|
50
|
+
*/ export function powTicks(domain, exponent, count, minor = false) {
|
|
51
|
+
const [d0, d1] = domain.map(Number);
|
|
52
|
+
const lo = Math.min(d0, d1);
|
|
53
|
+
const hi = Math.max(d0, d1);
|
|
54
|
+
if (!Number.isFinite(lo) || !Number.isFinite(hi) || lo === hi || !exponent) return lo === hi && Number.isFinite(lo) ? [
|
|
55
|
+
lo
|
|
56
|
+
] : [];
|
|
57
|
+
const steps = Math.max(1, Math.round(count));
|
|
58
|
+
const t0 = raise(lo, exponent);
|
|
59
|
+
const t1 = raise(hi, exponent);
|
|
60
|
+
const sample = (n)=>Array.from({
|
|
61
|
+
length: n + 1
|
|
62
|
+
}, (_, i)=>raise(t0 + (t1 - t0) * i / n, 1 / exponent));
|
|
63
|
+
const majorRaw = sample(steps);
|
|
64
|
+
const major = roundEach(majorRaw, majorRaw);
|
|
65
|
+
let ticks = major;
|
|
66
|
+
if (minor) {
|
|
67
|
+
const all = sample(steps * 2);
|
|
68
|
+
const mids = all.filter((_, i)=>i % 2);
|
|
69
|
+
ticks = major.concat(roundEach(mids, all));
|
|
70
|
+
}
|
|
71
|
+
const values = Array.from(new Set(ticks)).filter((d)=>d >= lo && d <= hi).sort((a, b)=>a - b);
|
|
72
|
+
return d1 < d0 ? values.reverse() : values;
|
|
73
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { max
|
|
1
|
+
import { max } from "d3-array";
|
|
2
2
|
import { select } from "d3-selection";
|
|
3
3
|
import { transition } from "d3-transition";
|
|
4
4
|
import { colorContrast } from "@d3plus/color";
|
|
@@ -10,8 +10,11 @@ import { accessor, BaseClass, paintComponentScene } from "../../utils/index.js";
|
|
|
10
10
|
import { installFluent, mergeConfigBag, resolvesReset } from "../../fluent.js";
|
|
11
11
|
import Legend from "../Legend/Legend.js";
|
|
12
12
|
import { formatYear, isYearLike } from "../Axis/yearValues.js";
|
|
13
|
+
import { bucketBounds } from "./bucketBounds.js";
|
|
13
14
|
import { computeColorScale } from "./colorScaleScale.js";
|
|
14
15
|
import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
|
|
16
|
+
import { isBucketScale } from "./colorScaleType.js";
|
|
17
|
+
import { addHoverMark, hoverMarkDefaults } from "./colorScaleHoverMark.js";
|
|
15
18
|
/** ColorScale's fluent accessor schema. Config storage lives on `this.schema.<key>`. */ const colorScaleSchema = [
|
|
16
19
|
{
|
|
17
20
|
key: "align",
|
|
@@ -78,6 +81,16 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
|
|
|
78
81
|
coerce: "identity",
|
|
79
82
|
default: 200
|
|
80
83
|
},
|
|
84
|
+
{
|
|
85
|
+
key: "hoverMark",
|
|
86
|
+
coerce: "identity",
|
|
87
|
+
default: true
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
key: "hoverMarkConfig",
|
|
91
|
+
merge: true,
|
|
92
|
+
factory: hoverMarkDefaults
|
|
93
|
+
},
|
|
81
94
|
{
|
|
82
95
|
key: "midpoint",
|
|
83
96
|
coerce: "identity",
|
|
@@ -134,6 +147,9 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
|
|
|
134
147
|
_legendClass;
|
|
135
148
|
_outerBounds;
|
|
136
149
|
_rectClass;
|
|
150
|
+
/** The scale the last render built, with a `scale` function resolved. */ _scaleType = "linear";
|
|
151
|
+
/** Where the color bar sits, set when the bar variant renders (see colorScaleHoverMark). */ _barGeometry;
|
|
152
|
+
/** The value marked on the scale, set with `hover()`. */ _hoverValue;
|
|
137
153
|
/** Smooth-gradient fill token (`gradient:<json>`), set by renderGradientStops. */ _gradientFill;
|
|
138
154
|
// Standalone scene renderer (used when rendered on its own, not inside a
|
|
139
155
|
// Viz). Reused across re-renders by paintComponentScene().
|
|
@@ -151,26 +167,13 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
|
|
|
151
167
|
this._axisTest = new Axis();
|
|
152
168
|
this.schema.bucketFormat = (tick, i, ticks, allValues)=>{
|
|
153
169
|
const format = this.schema.axisConfig.tickFormat ? this.schema.axisConfig.tickFormat : isYearLike(allValues) ? (v)=>formatYear(v, this.schema.locale) : formatAbbreviate;
|
|
154
|
-
const next = ticks[i + 1];
|
|
155
|
-
const prev = i ? ticks[i - 1] : false;
|
|
156
170
|
const last = i === ticks.length - 1;
|
|
157
|
-
if (tick ===
|
|
171
|
+
if (tick === ticks[i + 1] || last) {
|
|
158
172
|
const suffix = last && tick < max(allValues) ? "+" : "";
|
|
159
173
|
return `${format(tick)}${suffix}`;
|
|
160
|
-
} else {
|
|
161
|
-
const mod = next ? next / 100 : tick / 100;
|
|
162
|
-
const pow = mod >= 1 || mod <= -1 ? Math.round(mod).toString().length - 1 : mod.toString().split(".")[1].replace(/([1-9])[1-9].*$/, "$1").length * -1;
|
|
163
|
-
const ten = Math.pow(10, pow);
|
|
164
|
-
const prevValue = prev === tick && i === 1 ? format(min([
|
|
165
|
-
tick + ten,
|
|
166
|
-
allValues.find((d)=>d > tick && d < next)
|
|
167
|
-
])) : format(tick);
|
|
168
|
-
const nextValue = tick && i === 1 ? format(next) : format(max([
|
|
169
|
-
next - ten,
|
|
170
|
-
allValues.reverse().find((d)=>d > tick && d < next)
|
|
171
|
-
]));
|
|
172
|
-
return this.schema.bucketJoiner(prevValue, nextValue);
|
|
173
174
|
}
|
|
175
|
+
const [lower, upper] = bucketBounds(tick, i, ticks, allValues, format);
|
|
176
|
+
return this.schema.bucketJoiner(format(lower), format(upper));
|
|
174
177
|
};
|
|
175
178
|
this._data = [];
|
|
176
179
|
this._labelClass = new TextBox();
|
|
@@ -214,11 +217,7 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
|
|
|
214
217
|
parent: this._select
|
|
215
218
|
});
|
|
216
219
|
const compute = computeColorScale(this);
|
|
217
|
-
const gradient = this.schema.bucketAxis || !
|
|
218
|
-
"buckets",
|
|
219
|
-
"jenks",
|
|
220
|
-
"quantile"
|
|
221
|
-
].includes(this.schema.scale);
|
|
220
|
+
const gradient = this.schema.bucketAxis || !isBucketScale(compute.scale);
|
|
222
221
|
const t = transition().duration(this.schema.duration);
|
|
223
222
|
const groupParams = {
|
|
224
223
|
enter: {
|
|
@@ -272,11 +271,7 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
|
|
|
272
271
|
and the discrete variant use concrete per-bucket fills.
|
|
273
272
|
*/ toScene() {
|
|
274
273
|
const children = [];
|
|
275
|
-
const gradient = this.schema.bucketAxis || !
|
|
276
|
-
"buckets",
|
|
277
|
-
"jenks",
|
|
278
|
-
"quantile"
|
|
279
|
-
].includes(this.schema.scale);
|
|
274
|
+
const gradient = this.schema.bucketAxis || !isBucketScale(this._scaleType);
|
|
280
275
|
const pushScene = (cls)=>{
|
|
281
276
|
if (cls && typeof cls.toScene === "function") {
|
|
282
277
|
const s = cls.toScene();
|
|
@@ -304,7 +299,7 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
|
|
|
304
299
|
};
|
|
305
300
|
}
|
|
306
301
|
}
|
|
307
|
-
|
|
302
|
+
const group = {
|
|
308
303
|
type: "group",
|
|
309
304
|
key: `ColorScale-${this._uuid.slice(0, 8)}`,
|
|
310
305
|
...transform ? {
|
|
@@ -312,6 +307,8 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
|
|
|
312
307
|
} : {},
|
|
313
308
|
children
|
|
314
309
|
};
|
|
310
|
+
addHoverMark(this, group);
|
|
311
|
+
return group;
|
|
315
312
|
}
|
|
316
313
|
axisConfig(_) {
|
|
317
314
|
return arguments.length ? (this.schema.axisConfig = mergeConfigBag(this, "axisConfig", _), this) : this.schema.axisConfig;
|
|
@@ -319,6 +316,9 @@ import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
|
|
|
319
316
|
data(_) {
|
|
320
317
|
return arguments.length ? (this._data = _, this) : this._data;
|
|
321
318
|
}
|
|
319
|
+
hover(_) {
|
|
320
|
+
return arguments.length ? (this._hoverValue = _, this) : this._hoverValue;
|
|
321
|
+
}
|
|
322
322
|
labelConfig(_) {
|
|
323
323
|
return arguments.length ? (this.schema.labelConfig = mergeConfigBag(this, "labelConfig", _), this) : this.schema.labelConfig;
|
|
324
324
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { max } from "d3-array";
|
|
2
|
+
/**
|
|
3
|
+
The number of decimal places `value` is written with, read at 15
|
|
4
|
+
significant digits so float noise (`0.1 + 0.2`) doesn't count.
|
|
5
|
+
*/ export function decimalPlaces(value) {
|
|
6
|
+
const [mantissa, exponent] = value.toExponential(14).split("e");
|
|
7
|
+
const decimals = mantissa.split(".")[1].replace(/0+$/, "");
|
|
8
|
+
return Math.max(0, decimals.length - Number(exponent));
|
|
9
|
+
}
|
|
10
|
+
/** `value` counted in steps of `10^-places`, with float noise rounded off. */ const toSteps = (value, places)=>+(value * 10 ** places).toPrecision(15);
|
|
11
|
+
/** The value of `steps` steps of `10^-places`. */ const fromSteps = (steps, places)=>+(steps / 10 ** places).toPrecision(15);
|
|
12
|
+
/**
|
|
13
|
+
The `[lower, upper]` values a ColorScale label shows for the bucket
|
|
14
|
+
`[ticks[i], ticks[i + 1])`: the first and last values the data's own
|
|
15
|
+
precision can write inside it, so integer data reads "1 - 2", "3 - 4".
|
|
16
|
+
When `format` prints the upper bound the same as the next bucket's lower
|
|
17
|
+
one (an abbreviation like "1.5k"), the upper bound drops a decimal place
|
|
18
|
+
at a time until it reads differently ("1.49k").
|
|
19
|
+
*/ export function bucketBounds(tick, i, ticks, allValues, format) {
|
|
20
|
+
const next = ticks[i + 1];
|
|
21
|
+
const places = max(allValues.filter(Number.isFinite).map(decimalPlaces)) ?? 0;
|
|
22
|
+
const tickSteps = toSteps(tick, places);
|
|
23
|
+
// A repeated first tick labels its own value, so the bucket after it
|
|
24
|
+
// starts one step above.
|
|
25
|
+
const lower = fromSteps(i === 1 && ticks[0] === tick ? Math.floor(tickSteps) + 1 : Math.ceil(tickSteps), places);
|
|
26
|
+
const below = (p)=>fromSteps(Math.ceil(toSteps(next, p)) - 1, p);
|
|
27
|
+
const nextLabel = format(fromSteps(Math.ceil(toSteps(next, places)), places));
|
|
28
|
+
let p = places;
|
|
29
|
+
let upper = below(p);
|
|
30
|
+
while(format(upper) === nextLabel && below(p - 1) >= lower)upper = below(--p);
|
|
31
|
+
return [
|
|
32
|
+
lower,
|
|
33
|
+
upper
|
|
34
|
+
];
|
|
35
|
+
}
|