@opendata-ai/openchart-engine 7.2.0 → 7.2.1
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/dist/index.js +32 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/compile-chart.test.ts +27 -0
- package/src/__tests__/scales.test.ts +34 -0
- package/src/charts/line/index.ts +53 -3
- package/src/layout/scales.ts +5 -1
package/dist/index.js
CHANGED
|
@@ -3932,6 +3932,7 @@ function computeLineLabels(marks, strategy, density = "auto", labelOffsets, spec
|
|
|
3932
3932
|
}
|
|
3933
3933
|
|
|
3934
3934
|
// src/charts/line/index.ts
|
|
3935
|
+
var AREA_POINT_RADIUS = 3;
|
|
3935
3936
|
var lineRenderer = (spec, scales, chartArea, strategy, _theme) => {
|
|
3936
3937
|
const marks = computeLineMarks(spec, scales, chartArea, strategy);
|
|
3937
3938
|
const lineMarks = marks.filter((m) => m.type === "line");
|
|
@@ -3957,7 +3958,8 @@ var areaRenderer = (spec, scales, chartArea, strategy, theme) => {
|
|
|
3957
3958
|
const encoding = spec.encoding;
|
|
3958
3959
|
const hasColor = !!(encoding.color && "field" in encoding.color);
|
|
3959
3960
|
const lines = hasColor ? linesFromAreas(areas) : computeLineMarks(spec, scales, chartArea, strategy);
|
|
3960
|
-
|
|
3961
|
+
const points = hasColor && spec.markDef.point ? pointsFromAreas(areas, spec.markDef.point) : [];
|
|
3962
|
+
return [...areas, ...lines, ...points];
|
|
3961
3963
|
};
|
|
3962
3964
|
function linesFromAreas(areas) {
|
|
3963
3965
|
return areas.map((a) => ({
|
|
@@ -3972,6 +3974,34 @@ function linesFromAreas(areas) {
|
|
|
3972
3974
|
aria: { label: `${a.seriesKey ?? "Series"}: line with ${a.topPoints.length} data points` }
|
|
3973
3975
|
}));
|
|
3974
3976
|
}
|
|
3977
|
+
function pointsFromAreas(areas, pointMode) {
|
|
3978
|
+
const isTransparent = pointMode === "transparent";
|
|
3979
|
+
const isEndpoints = pointMode === "endpoints";
|
|
3980
|
+
const points = [];
|
|
3981
|
+
for (const a of areas) {
|
|
3982
|
+
const stroke = getRepresentativeColor6(a.fill);
|
|
3983
|
+
const lastIdx = a.topPoints.length - 1;
|
|
3984
|
+
for (let i = 0; i < a.topPoints.length; i++) {
|
|
3985
|
+
const pt = a.topPoints[i];
|
|
3986
|
+
const isEndpoint = i === 0 || i === lastIdx;
|
|
3987
|
+
const visible = !isTransparent && (!isEndpoints || isEndpoint);
|
|
3988
|
+
const hollow = isEndpoints && visible;
|
|
3989
|
+
points.push({
|
|
3990
|
+
type: "point",
|
|
3991
|
+
cx: pt.x,
|
|
3992
|
+
cy: pt.y,
|
|
3993
|
+
r: visible ? AREA_POINT_RADIUS : 0,
|
|
3994
|
+
fill: hollow ? "transparent" : stroke,
|
|
3995
|
+
stroke: hollow ? stroke : visible ? "#ffffff" : "transparent",
|
|
3996
|
+
strokeWidth: visible ? 1.5 : 0,
|
|
3997
|
+
fillOpacity: isTransparent ? 0 : 1,
|
|
3998
|
+
data: a.data[i] ?? {},
|
|
3999
|
+
aria: { decorative: true }
|
|
4000
|
+
});
|
|
4001
|
+
}
|
|
4002
|
+
}
|
|
4003
|
+
return points;
|
|
4004
|
+
}
|
|
3975
4005
|
|
|
3976
4006
|
// src/charts/pie/compute.ts
|
|
3977
4007
|
import { isConditionalDef, isGradientDef as isGradientDef4 } from "@opendata-ai/openchart-core";
|
|
@@ -10978,7 +11008,7 @@ function buildBandScale(channel, data, rangeStart, rangeEnd) {
|
|
|
10978
11008
|
}
|
|
10979
11009
|
function buildPointScale(channel, data, rangeStart, rangeEnd) {
|
|
10980
11010
|
const values = channel.scale?.domain ? channel.scale.domain : applyCategoricalSort(uniqueStrings(fieldValues(data, channel.field)), channel.sort);
|
|
10981
|
-
const padding = channel.scale?.padding ?? 0.5;
|
|
11011
|
+
const padding = channel.scale?.padding ?? channel.scale?.paddingOuter ?? 0.5;
|
|
10982
11012
|
const scale = point4().domain(values).range([rangeStart, rangeEnd]).padding(padding);
|
|
10983
11013
|
if (channel.scale?.reverse) {
|
|
10984
11014
|
const [r0, r1] = scale.range();
|