@opendata-ai/openchart-engine 8.6.4 → 8.7.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/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7511,6 +7511,7 @@ function normalizeYouDrawIt(spec) {
|
|
|
7511
7511
|
return {
|
|
7512
7512
|
prompt: "Draw your guess",
|
|
7513
7513
|
revealLabel: "Show me",
|
|
7514
|
+
resetLabel: "Clear",
|
|
7514
7515
|
...spec.youDrawIt
|
|
7515
7516
|
};
|
|
7516
7517
|
}
|
|
@@ -13469,6 +13470,21 @@ function resolveYInvert(scaleY, area3) {
|
|
|
13469
13470
|
bottomData
|
|
13470
13471
|
};
|
|
13471
13472
|
}
|
|
13473
|
+
var AT_FROM_EPSILON = 1e-6;
|
|
13474
|
+
function resolveAnchor(points, fromX) {
|
|
13475
|
+
const sorted = [...points].sort((a, b) => a.x - b.x);
|
|
13476
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
13477
|
+
const p = sorted[i];
|
|
13478
|
+
if (Math.abs(p.x - fromX) <= AT_FROM_EPSILON) return { x: fromX, y: p.y };
|
|
13479
|
+
if (p.x > fromX) {
|
|
13480
|
+
if (i === 0) return void 0;
|
|
13481
|
+
const prev = sorted[i - 1];
|
|
13482
|
+
const t = (fromX - prev.x) / (p.x - prev.x);
|
|
13483
|
+
return { x: fromX, y: prev.y + t * (p.y - prev.y) };
|
|
13484
|
+
}
|
|
13485
|
+
}
|
|
13486
|
+
return void 0;
|
|
13487
|
+
}
|
|
13472
13488
|
function resolveYouDrawIt(config, marks, scales, chartArea, xField) {
|
|
13473
13489
|
if (!config || !scales.x) return void 0;
|
|
13474
13490
|
const targetLine = marks.find((m) => m.type === "line");
|
|
@@ -13479,7 +13495,7 @@ function resolveYouDrawIt(config, marks, scales, chartArea, xField) {
|
|
|
13479
13495
|
const samples = [];
|
|
13480
13496
|
if (targetLine.dataPoints?.length) {
|
|
13481
13497
|
for (const dp of targetLine.dataPoints) {
|
|
13482
|
-
if (dp.x
|
|
13498
|
+
if (dp.x <= fromX + AT_FROM_EPSILON) continue;
|
|
13483
13499
|
if (seen.has(dp.x)) continue;
|
|
13484
13500
|
seen.add(dp.x);
|
|
13485
13501
|
const raw = xField ? dp.datum[xField] : void 0;
|
|
@@ -13489,7 +13505,7 @@ function resolveYouDrawIt(config, marks, scales, chartArea, xField) {
|
|
|
13489
13505
|
}
|
|
13490
13506
|
if (samples.length === 0) {
|
|
13491
13507
|
for (const p of targetLine.points) {
|
|
13492
|
-
if (p.x
|
|
13508
|
+
if (p.x <= fromX + AT_FROM_EPSILON) continue;
|
|
13493
13509
|
if (seen.has(p.x)) continue;
|
|
13494
13510
|
seen.add(p.x);
|
|
13495
13511
|
samples.push({ px: p.x, xValue: p.x });
|
|
@@ -13511,15 +13527,18 @@ function resolveYouDrawIt(config, marks, scales, chartArea, xField) {
|
|
|
13511
13527
|
}
|
|
13512
13528
|
}
|
|
13513
13529
|
const yInvert = resolveYInvert(scales.y, chartArea);
|
|
13530
|
+
const anchor = resolveAnchor(targetLine.points, fromX);
|
|
13514
13531
|
return {
|
|
13515
13532
|
fromX,
|
|
13516
13533
|
area: chartArea,
|
|
13517
13534
|
samples,
|
|
13518
13535
|
prompt: config.prompt ?? "Draw your guess",
|
|
13519
13536
|
revealLabel: config.revealLabel ?? "Show me",
|
|
13537
|
+
resetLabel: config.resetLabel ?? "Clear",
|
|
13520
13538
|
lineColor: targetLine.stroke,
|
|
13521
13539
|
targetSeriesKey: targetLine.seriesKey,
|
|
13522
13540
|
...yInvert ? { yInvert } : {},
|
|
13541
|
+
...anchor ? { anchor } : {},
|
|
13523
13542
|
...comparisonPoints ? { comparisonPoints } : {}
|
|
13524
13543
|
};
|
|
13525
13544
|
}
|