mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
fix(panel): adapt dense step splines and animate multi-model switches
- Add peak-preserving width-adaptive step spline downsampling (~2.1px/vertex, 128-256 points) with crisp 1.45px dense strokes so multi-thousand-step sessions remain readable while retaining exact summary stats, peaks, and anomaly ticks - Preserve the full union of source and target knots during cubic-Bezier morphing and align multi-series spline tension so curves >96 segments never skip peaks or jump on completion - Hand off morph state across single-model, pooled-all, and multi-model comparison modes and animate newly checked models rising smoothly from the baseline in both step line and LOESS fit charts
This commit is contained in:
+338
-34
@@ -14303,21 +14303,15 @@ function alignCubicChainsForMorph(fromSegs, toSegs) {
|
|||||||
const tSpan = tEnd - tStart;
|
const tSpan = tEnd - tStart;
|
||||||
|
|
||||||
const rawTau = [0, 1];
|
const rawTau = [0, 1];
|
||||||
const pushChainKnots = (segs, start, span, cap) => {
|
const pushChainKnots = (segs, start, span) => {
|
||||||
if (!(span > 1e-6)) return;
|
if (!(span > 1e-6)) return;
|
||||||
if (segs.length <= cap) {
|
for (let i = 0; i < segs.length; i++) {
|
||||||
for (let i = 0; i < segs.length; i++) {
|
rawTau.push(Math.max(0, Math.min(1, (segs[i].u0 - start) / span)));
|
||||||
rawTau.push(Math.max(0, Math.min(1, (segs[i].u3 - start) / span)));
|
rawTau.push(Math.max(0, Math.min(1, (segs[i].u3 - start) / span)));
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const stride = Math.ceil(segs.length / cap);
|
|
||||||
for (let i = 0; i < segs.length; i += stride) {
|
|
||||||
rawTau.push(Math.max(0, Math.min(1, (segs[i].u3 - start) / span)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
pushChainKnots(toSegs, tStart, tSpan, 96);
|
pushChainKnots(toSegs, tStart, tSpan);
|
||||||
pushChainKnots(fromSegs, fStart, fSpan, 48);
|
pushChainKnots(fromSegs, fStart, fSpan);
|
||||||
|
|
||||||
rawTau.sort((a, b) => a - b);
|
rawTau.sort((a, b) => a - b);
|
||||||
const tauKnots = [0];
|
const tauKnots = [0];
|
||||||
@@ -14402,6 +14396,20 @@ function createCubicCurveMorphController({ durationMs = CHART_CURVE_MORPH_MS } =
|
|||||||
hasRenderedOnce = false;
|
hasRenderedOnce = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCurrentSegs() {
|
||||||
|
const src = liveMorphSegs || committedSegs;
|
||||||
|
return hasRenderedOnce && src.length > 0 ? src.map((s) => ({ ...s })) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function seedSegs(segs) {
|
||||||
|
cancel();
|
||||||
|
if (Array.isArray(segs) && segs.length > 0) {
|
||||||
|
committedSegs = segs.map((s) => ({ ...s }));
|
||||||
|
liveMorphSegs = null;
|
||||||
|
hasRenderedOnce = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function morphTo({
|
function morphTo({
|
||||||
nextSegs,
|
nextSegs,
|
||||||
leftX,
|
leftX,
|
||||||
@@ -14459,6 +14467,17 @@ function createCubicCurveMorphController({ durationMs = CHART_CURVE_MORPH_MS } =
|
|||||||
|
|
||||||
const activeLive = alignedFrom.map((s) => ({ ...s }));
|
const activeLive = alignedFrom.map((s) => ({ ...s }));
|
||||||
liveMorphSegs = activeLive;
|
liveMorphSegs = activeLive;
|
||||||
|
const initialLineD = buildPathFromNormalizedSegs(activeLive, leftX, spanX);
|
||||||
|
patchAttr(linePath, 'd', initialLineD);
|
||||||
|
if (areaPath) {
|
||||||
|
if (finalAreaD) {
|
||||||
|
const firstX = (leftX + activeLive[0].u0 * spanX).toFixed(1);
|
||||||
|
const lastX = (leftX + activeLive[segCount - 1].u3 * spanX).toFixed(1);
|
||||||
|
patchAttr(areaPath, 'd', `${initialLineD} L ${lastX} ${bottomY} L ${firstX} ${bottomY} Z`);
|
||||||
|
} else {
|
||||||
|
patchAttr(areaPath, 'd', '');
|
||||||
|
}
|
||||||
|
}
|
||||||
const startTs = performance.now();
|
const startTs = performance.now();
|
||||||
|
|
||||||
const step = (nowTs) => {
|
const step = (nowTs) => {
|
||||||
@@ -14498,7 +14517,7 @@ function createCubicCurveMorphController({ durationMs = CHART_CURVE_MORPH_MS } =
|
|||||||
morphRafId = window.requestAnimationFrame(step);
|
morphRafId = window.requestAnimationFrame(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { morphTo, cancel, reset };
|
return { morphTo, cancel, reset, getCurrentSegs, seedSegs };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14507,6 +14526,7 @@ function createCubicCurveMorphController({ durationMs = CHART_CURVE_MORPH_MS } =
|
|||||||
*/
|
*/
|
||||||
function createMultiSeriesCurveMorphController({ durationMs = CHART_CURVE_MORPH_MS } = {}) {
|
function createMultiSeriesCurveMorphController({ durationMs = CHART_CURVE_MORPH_MS } = {}) {
|
||||||
let morphRafId = 0;
|
let morphRafId = 0;
|
||||||
|
let hasRenderedOnce = false;
|
||||||
const stateByKey = new Map();
|
const stateByKey = new Map();
|
||||||
|
|
||||||
function cancel() {
|
function cancel() {
|
||||||
@@ -14522,18 +14542,47 @@ function createMultiSeriesCurveMorphController({ durationMs = CHART_CURVE_MORPH_
|
|||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
cancel();
|
cancel();
|
||||||
|
hasRenderedOnce = false;
|
||||||
stateByKey.clear();
|
stateByKey.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSeriesSegs(key) {
|
||||||
|
const rec = stateByKey.get(key);
|
||||||
|
const src = rec ? rec.liveSegs || rec.committedSegs : null;
|
||||||
|
return src && src.length > 0 ? src.map((s) => ({ ...s })) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFirstSegs() {
|
||||||
|
for (const rec of stateByKey.values()) {
|
||||||
|
const src = rec.liveSegs || rec.committedSegs;
|
||||||
|
if (src && src.length > 0) return src.map((s) => ({ ...s }));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function seedSeries(key, segs) {
|
||||||
|
if (!key || !Array.isArray(segs) || segs.length === 0) return;
|
||||||
|
stateByKey.set(key, {
|
||||||
|
committedSegs: segs.map((s) => ({ ...s })),
|
||||||
|
liveSegs: null,
|
||||||
|
endX: NaN,
|
||||||
|
endY: NaN,
|
||||||
|
});
|
||||||
|
hasRenderedOnce = true;
|
||||||
|
}
|
||||||
|
|
||||||
function morphSeries({
|
function morphSeries({
|
||||||
items,
|
items,
|
||||||
leftX,
|
leftX,
|
||||||
spanX,
|
spanX,
|
||||||
bottomY,
|
bottomY,
|
||||||
skipMorph = false,
|
skipMorph = false,
|
||||||
|
allowBaselineEntry = false,
|
||||||
}) {
|
}) {
|
||||||
cancel();
|
cancel();
|
||||||
const canAnim = !skipMorph && canAnimateChartInBrowser();
|
const canAnim = !skipMorph && canAnimateChartInBrowser();
|
||||||
|
const wasRenderedBefore = hasRenderedOnce;
|
||||||
|
hasRenderedOnce = items.length > 0;
|
||||||
const activeSet = new Set();
|
const activeSet = new Set();
|
||||||
const jobs = [];
|
const jobs = [];
|
||||||
|
|
||||||
@@ -14541,7 +14590,26 @@ function createMultiSeriesCurveMorphController({ durationMs = CHART_CURVE_MORPH_
|
|||||||
const it = items[idx];
|
const it = items[idx];
|
||||||
activeSet.add(it.key);
|
activeSet.add(it.key);
|
||||||
const prevEntry = stateByKey.get(it.key);
|
const prevEntry = stateByKey.get(it.key);
|
||||||
const prevSegs = prevEntry ? prevEntry.liveSegs || prevEntry.committedSegs : null;
|
let prevSegs = prevEntry ? prevEntry.liveSegs || prevEntry.committedSegs : null;
|
||||||
|
if (
|
||||||
|
(!prevSegs || prevSegs.length === 0) &&
|
||||||
|
canAnim &&
|
||||||
|
allowBaselineEntry &&
|
||||||
|
wasRenderedBefore &&
|
||||||
|
it.nextSegs.length > 0 &&
|
||||||
|
Number.isFinite(bottomY)
|
||||||
|
) {
|
||||||
|
prevSegs = it.nextSegs.map((s) => ({
|
||||||
|
u0: s.u0,
|
||||||
|
y0: bottomY,
|
||||||
|
cu1: s.cu1,
|
||||||
|
cy1: bottomY,
|
||||||
|
cu2: s.cu2,
|
||||||
|
cy2: bottomY,
|
||||||
|
u3: s.u3,
|
||||||
|
y3: bottomY,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
if (!canAnim || !prevSegs || prevSegs.length === 0 || it.nextSegs.length === 0) {
|
if (!canAnim || !prevSegs || prevSegs.length === 0 || it.nextSegs.length === 0) {
|
||||||
stateByKey.set(it.key, {
|
stateByKey.set(it.key, {
|
||||||
@@ -14606,6 +14674,17 @@ function createMultiSeriesCurveMorphController({ durationMs = CHART_CURVE_MORPH_
|
|||||||
endY: fromEndY,
|
endY: fromEndY,
|
||||||
};
|
};
|
||||||
stateByKey.set(it.key, stateRec);
|
stateByKey.set(it.key, stateRec);
|
||||||
|
const initLineD = buildPathFromNormalizedSegs(activeLive, leftX, spanX);
|
||||||
|
patchAttr(it.lineEl, 'd', initLineD);
|
||||||
|
if (it.areaEl) {
|
||||||
|
if (it.finalAreaD) {
|
||||||
|
const firstX = (leftX + activeLive[0].u0 * spanX).toFixed(1);
|
||||||
|
const lastX = (leftX + activeLive[segCount - 1].u3 * spanX).toFixed(1);
|
||||||
|
patchAttr(it.areaEl, 'd', `${initLineD} L ${lastX} ${bottomY} L ${firstX} ${bottomY} Z`);
|
||||||
|
} else {
|
||||||
|
patchAttr(it.areaEl, 'd', '');
|
||||||
|
}
|
||||||
|
}
|
||||||
jobs.push({
|
jobs.push({
|
||||||
it,
|
it,
|
||||||
alignedFrom,
|
alignedFrom,
|
||||||
@@ -14684,7 +14763,7 @@ function createMultiSeriesCurveMorphController({ durationMs = CHART_CURVE_MORPH_
|
|||||||
morphRafId = window.requestAnimationFrame(step);
|
morphRafId = window.requestAnimationFrame(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { morphSeries, cancel, reset };
|
return { morphSeries, cancel, reset, getSeriesSegs, getFirstSegs, seedSeries };
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildGridFitPolylineD(grid) {
|
function buildGridFitPolylineD(grid) {
|
||||||
@@ -14708,12 +14787,41 @@ function buildGridCiBandD(grid) {
|
|||||||
return `${d} Z`;
|
return `${d} Z`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resampleFitGridToTargetXs(sourceGrid, targetGrid) {
|
||||||
|
if (!Array.isArray(sourceGrid) || sourceGrid.length === 0) return null;
|
||||||
|
const sLen = sourceGrid.length;
|
||||||
|
const sFirst = sourceGrid[0];
|
||||||
|
const sLast = sourceGrid[sLen - 1];
|
||||||
|
let j = 0;
|
||||||
|
return targetGrid.map((tg) => {
|
||||||
|
const x = tg.x;
|
||||||
|
if (sLen === 1 || x <= sFirst.x) {
|
||||||
|
return { x, fitY: sFirst.fitY, lowY: sFirst.lowY, highY: sFirst.highY };
|
||||||
|
}
|
||||||
|
if (x >= sLast.x) {
|
||||||
|
return { x, fitY: sLast.fitY, lowY: sLast.lowY, highY: sLast.highY };
|
||||||
|
}
|
||||||
|
while (j < sLen - 2 && sourceGrid[j + 1].x < x) j += 1;
|
||||||
|
const a = sourceGrid[j];
|
||||||
|
const b = sourceGrid[j + 1];
|
||||||
|
const span = b.x - a.x;
|
||||||
|
const r = span > 1e-6 ? Math.max(0, Math.min(1, (x - a.x) / span)) : 0;
|
||||||
|
return {
|
||||||
|
x,
|
||||||
|
fitY: a.fitY + (b.fitY - a.fitY) * r,
|
||||||
|
lowY: a.lowY + (b.lowY - a.lowY) * r,
|
||||||
|
highY: a.highY + (b.highY - a.highY) * r,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smoothly morphs LOESS fit polylines, `95% CI` confidence bands, and optional OLS lines
|
* Smoothly morphs LOESS fit polylines, `95% CI` confidence bands, and optional OLS lines
|
||||||
* across metric/model switches in `createModelFitChart`.
|
* across metric/model switches in `createModelFitChart`.
|
||||||
*/
|
*/
|
||||||
function createFitGridMorphController({ durationMs = CHART_CURVE_MORPH_MS } = {}) {
|
function createFitGridMorphController({ durationMs = CHART_CURVE_MORPH_MS } = {}) {
|
||||||
let morphRafId = 0;
|
let morphRafId = 0;
|
||||||
|
let hasRenderedOnce = false;
|
||||||
const stateByKey = new Map();
|
const stateByKey = new Map();
|
||||||
|
|
||||||
function cancel() {
|
function cancel() {
|
||||||
@@ -14729,12 +14837,39 @@ function createFitGridMorphController({ durationMs = CHART_CURVE_MORPH_MS } = {}
|
|||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
cancel();
|
cancel();
|
||||||
|
hasRenderedOnce = false;
|
||||||
stateByKey.clear();
|
stateByKey.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
function morphFits({ items, skipMorph = false }) {
|
function getGrid(key) {
|
||||||
|
const rec = stateByKey.get(key);
|
||||||
|
const src = rec ? rec.liveGrid || rec.committedGrid : null;
|
||||||
|
return src && src.length > 0 ? src.map((g) => ({ ...g })) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFirstGrid() {
|
||||||
|
for (const rec of stateByKey.values()) {
|
||||||
|
const src = rec.liveGrid || rec.committedGrid;
|
||||||
|
if (src && src.length > 0) return src.map((g) => ({ ...g }));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function seedGrid(key, gridPts) {
|
||||||
|
if (!key || !Array.isArray(gridPts) || gridPts.length === 0) return;
|
||||||
|
stateByKey.set(key, {
|
||||||
|
committedGrid: gridPts.map((g) => ({ ...g })),
|
||||||
|
liveGrid: null,
|
||||||
|
ols: null,
|
||||||
|
});
|
||||||
|
hasRenderedOnce = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function morphFits({ items, skipMorph = false, allowBaselineEntry = false, bottomY = NaN }) {
|
||||||
cancel();
|
cancel();
|
||||||
const canAnim = !skipMorph && canAnimateChartInBrowser();
|
const canAnim = !skipMorph && canAnimateChartInBrowser();
|
||||||
|
const wasRenderedBefore = hasRenderedOnce;
|
||||||
|
hasRenderedOnce = items.length > 0;
|
||||||
const activeSet = new Set();
|
const activeSet = new Set();
|
||||||
const jobs = [];
|
const jobs = [];
|
||||||
|
|
||||||
@@ -14742,7 +14877,32 @@ function createFitGridMorphController({ durationMs = CHART_CURVE_MORPH_MS } = {}
|
|||||||
const it = items[idx];
|
const it = items[idx];
|
||||||
activeSet.add(it.key);
|
activeSet.add(it.key);
|
||||||
const prevEntry = stateByKey.get(it.key);
|
const prevEntry = stateByKey.get(it.key);
|
||||||
const prevGrid = prevEntry ? prevEntry.liveGrid || prevEntry.committedGrid : null;
|
const rawPrevGrid = prevEntry ? prevEntry.liveGrid || prevEntry.committedGrid : null;
|
||||||
|
let prevGrid =
|
||||||
|
rawPrevGrid && rawPrevGrid.length > 0 && it.gridPts.length >= 2
|
||||||
|
? rawPrevGrid.length === it.gridPts.length &&
|
||||||
|
Math.abs(rawPrevGrid[0].x - it.gridPts[0].x) < 0.5 &&
|
||||||
|
Math.abs(
|
||||||
|
rawPrevGrid[rawPrevGrid.length - 1].x - it.gridPts[it.gridPts.length - 1].x
|
||||||
|
) < 0.5
|
||||||
|
? rawPrevGrid
|
||||||
|
: resampleFitGridToTargetXs(rawPrevGrid, it.gridPts)
|
||||||
|
: null;
|
||||||
|
if (
|
||||||
|
!prevGrid &&
|
||||||
|
canAnim &&
|
||||||
|
allowBaselineEntry &&
|
||||||
|
wasRenderedBefore &&
|
||||||
|
it.gridPts.length >= 2 &&
|
||||||
|
Number.isFinite(bottomY)
|
||||||
|
) {
|
||||||
|
prevGrid = it.gridPts.map((g) => ({
|
||||||
|
x: g.x,
|
||||||
|
fitY: bottomY,
|
||||||
|
lowY: bottomY,
|
||||||
|
highY: bottomY,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!canAnim ||
|
!canAnim ||
|
||||||
@@ -14803,6 +14963,16 @@ function createFitGridMorphController({ durationMs = CHART_CURVE_MORPH_MS } = {}
|
|||||||
ols: fromOls ? { ...fromOls } : null,
|
ols: fromOls ? { ...fromOls } : null,
|
||||||
};
|
};
|
||||||
stateByKey.set(it.key, stateRec);
|
stateByKey.set(it.key, stateRec);
|
||||||
|
patchAttr(it.curveEl, 'd', buildGridFitPolylineD(activeLive));
|
||||||
|
if (it.bandEl) {
|
||||||
|
patchAttr(it.bandEl, 'd', it.finalBandD ? buildGridCiBandD(activeLive) : '');
|
||||||
|
}
|
||||||
|
if (it.olsEl && fromOls) {
|
||||||
|
patchAttr(it.olsEl, 'x1', fromOls.x1.toFixed(1));
|
||||||
|
patchAttr(it.olsEl, 'y1', fromOls.y1.toFixed(1));
|
||||||
|
patchAttr(it.olsEl, 'x2', fromOls.x2.toFixed(1));
|
||||||
|
patchAttr(it.olsEl, 'y2', fromOls.y2.toFixed(1));
|
||||||
|
}
|
||||||
jobs.push({ it, fromGrid: prevGrid, activeLive, fromOls, stateRec });
|
jobs.push({ it, fromGrid: prevGrid, activeLive, fromOls, stateRec });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14869,7 +15039,7 @@ function createFitGridMorphController({ durationMs = CHART_CURVE_MORPH_MS } = {}
|
|||||||
morphRafId = window.requestAnimationFrame(step);
|
morphRafId = window.requestAnimationFrame(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { morphFits, cancel, reset };
|
return { morphFits, cancel, reset, getGrid, getFirstGrid, seedGrid };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16884,7 +17054,7 @@ return { HEATMAP_DAYS_THRESHOLD, createTrendAreaChart };
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
// --- src/components/charts/stepChartMath.js ---
|
// --- src/components/charts/stepChartMath.js ---
|
||||||
const { MODEL_COLOR_VARS, getStepModelGroupKey, toChronologicalSteps, clampValue, computeLinearFit, computePublicationFit, niceStepNumber, computeNiceYScale, computeNiceXStepTicks, formatYAxisTick, buildPolylinePath, buildSplinePath, computeStepTickIndices, formatStepAxisTag, formatChartMetricValue, formatChartMetricCompact } = (() => {
|
const { MODEL_COLOR_VARS, getStepModelGroupKey, toChronologicalSteps, clampValue, computeLinearFit, computePublicationFit, niceStepNumber, computeNiceYScale, computeNiceXStepTicks, formatYAxisTick, buildPolylinePath, buildSplinePath, computeStepTickIndices, formatStepAxisTag, formatChartMetricValue, formatChartMetricCompact, downsampleStepPointsForPlot } = (() => {
|
||||||
/**
|
/**
|
||||||
* @fileoverview Pure regression math (OLS + IRLS-LOESS), nice axis tick generators,
|
* @fileoverview Pure regression math (OLS + IRLS-LOESS), nice axis tick generators,
|
||||||
* SVG spline/polyline path builders, and step metric formatters extracted from SessionStepCharts.js.
|
* SVG spline/polyline path builders, and step metric formatters extracted from SessionStepCharts.js.
|
||||||
@@ -17540,7 +17710,54 @@ function formatChartMetricCompact(metric, val) {
|
|||||||
return String(val);
|
return String(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { MODEL_COLOR_VARS, getStepModelGroupKey, toChronologicalSteps, clampValue, computeLinearFit, computePublicationFit, niceStepNumber, computeNiceYScale, computeNiceXStepTicks, formatYAxisTick, buildPolylinePath, buildSplinePath, computeStepTickIndices, formatStepAxisTag, formatChartMetricValue, formatChartMetricCompact };
|
|
||||||
|
/**
|
||||||
|
* Downsamples dense chronological step series (`> maxPoints`, e.g. 1,500–5,000 steps) to an
|
||||||
|
* adaptive visual vertex budget (`~2.1px` per segment) so cubic splines never overplot into an
|
||||||
|
* opaque solid wall while strictly preserving the start step, end step, and exact global peak step.
|
||||||
|
*
|
||||||
|
* @template {{ value?: number }} T
|
||||||
|
* @param {T[]} points
|
||||||
|
* @param {number} [maxPoints=208]
|
||||||
|
* @returns {T[]}
|
||||||
|
*/
|
||||||
|
function downsampleStepPointsForPlot(points, maxPoints = 208) {
|
||||||
|
if (!Array.isArray(points) || points.length <= maxPoints || maxPoints < 8) {
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
const n = points.length;
|
||||||
|
let globalPeakIdx = -1;
|
||||||
|
let globalPeakVal = -Infinity;
|
||||||
|
for (let i = 0; i < n; i += 1) {
|
||||||
|
const v = Number(points[i]?.value);
|
||||||
|
if (Number.isFinite(v) && v >= globalPeakVal) {
|
||||||
|
globalPeakVal = v;
|
||||||
|
globalPeakIdx = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const out = [points[0]];
|
||||||
|
const bucketCount = maxPoints - 2;
|
||||||
|
const interiorLen = n - 2;
|
||||||
|
for (let b = 0; b < bucketCount; b += 1) {
|
||||||
|
const bStart = 1 + Math.floor((b * interiorLen) / bucketCount);
|
||||||
|
const bEnd = Math.max(bStart + 1, 1 + Math.floor(((b + 1) * interiorLen) / bucketCount));
|
||||||
|
const pickIdx =
|
||||||
|
globalPeakIdx >= bStart && globalPeakIdx < bEnd
|
||||||
|
? globalPeakIdx
|
||||||
|
: bStart + Math.floor((bEnd - bStart) / 2);
|
||||||
|
const picked = points[pickIdx];
|
||||||
|
if (picked && picked !== out[out.length - 1]) {
|
||||||
|
out.push(picked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const lastPt = points[n - 1];
|
||||||
|
if (lastPt && lastPt !== out[out.length - 1]) {
|
||||||
|
out.push(lastPt);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
return { MODEL_COLOR_VARS, getStepModelGroupKey, toChronologicalSteps, clampValue, computeLinearFit, computePublicationFit, niceStepNumber, computeNiceYScale, computeNiceXStepTicks, formatYAxisTick, buildPolylinePath, buildSplinePath, computeStepTickIndices, formatStepAxisTag, formatChartMetricValue, formatChartMetricCompact, downsampleStepPointsForPlot };
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// --- src/components/charts/SessionStepCharts.js ---
|
// --- src/components/charts/SessionStepCharts.js ---
|
||||||
@@ -17713,6 +17930,8 @@ function createSessionLineChart() {
|
|||||||
let lastSummaryBadge = '';
|
let lastSummaryBadge = '';
|
||||||
let lastUpdateParams = null;
|
let lastUpdateParams = null;
|
||||||
let cachedPlotSvgRect = null;
|
let cachedPlotSvgRect = null;
|
||||||
|
let lastLineMode = '';
|
||||||
|
let lastSingleLineKey = '';
|
||||||
const multiSeriesNodesByKey = new Map();
|
const multiSeriesNodesByKey = new Map();
|
||||||
|
|
||||||
const singleCurveMorphCtrl = createCubicCurveMorphController();
|
const singleCurveMorphCtrl = createCubicCurveMorphController();
|
||||||
@@ -17966,8 +18185,13 @@ function createSessionLineChart() {
|
|||||||
patchText(emptyHintEl, t('chart.step.empty'));
|
patchText(emptyHintEl, t('chart.step.empty'));
|
||||||
if (!matchedSteps.length) {
|
if (!matchedSteps.length) {
|
||||||
currentPoints = [];
|
currentPoints = [];
|
||||||
|
patchClasses(rootEl, { 'is-dense': false });
|
||||||
lastSig = 'empty';
|
lastSig = 'empty';
|
||||||
lastPreSig = '';
|
lastPreSig = '';
|
||||||
|
lastLineMode = '';
|
||||||
|
lastSingleLineKey = '';
|
||||||
|
singleCurveMorphCtrl.reset();
|
||||||
|
multiCurveMorphCtrl.reset();
|
||||||
lastSummaryBadge = t('chart.step.zeroSteps');
|
lastSummaryBadge = t('chart.step.zeroSteps');
|
||||||
invalidatePlotSvgRect();
|
invalidatePlotSvgRect();
|
||||||
patchAttr(areaPath, 'd', '');
|
patchAttr(areaPath, 'd', '');
|
||||||
@@ -18191,6 +18415,7 @@ function createSessionLineChart() {
|
|||||||
currentMaxVal = maxVal;
|
currentMaxVal = maxVal;
|
||||||
|
|
||||||
const { leftX, rightX, spanX } = resolvePlotBounds(viewW);
|
const { leftX, rightX, spanX } = resolvePlotBounds(viewW);
|
||||||
|
const maxPlotPoints = Math.max(128, Math.min(256, Math.floor(spanX / 2.1)));
|
||||||
const denom = maxVal > 0 ? maxVal : 1;
|
const denom = maxVal > 0 ? maxVal : 1;
|
||||||
const isSingle = rawItems.length === 1;
|
const isSingle = rawItems.length === 1;
|
||||||
const points = rawItems.map((item, i) => {
|
const points = rawItems.map((item, i) => {
|
||||||
@@ -18201,9 +18426,28 @@ function createSessionLineChart() {
|
|||||||
const y = item.valid ? BOTTOM_Y - ratio * SPAN_Y : BOTTOM_Y;
|
const y = item.valid ? BOTTOM_Y - ratio * SPAN_Y : BOTTOM_Y;
|
||||||
return { ...item, x, y };
|
return { ...item, x, y };
|
||||||
});
|
});
|
||||||
currentPoints = points;
|
|
||||||
|
|
||||||
const validPoints = points.filter((p) => p.valid);
|
const validPoints = points.filter((p) => p.valid);
|
||||||
|
let hoverPoints = points;
|
||||||
|
if (isMultiCompare) {
|
||||||
|
if (points.length > maxPlotPoints * targetKeys.length) {
|
||||||
|
const merged = [];
|
||||||
|
for (const gk of targetKeys) {
|
||||||
|
const rawSeries = points.filter((p) => p.modelGroupKey === gk && p.valid);
|
||||||
|
merged.push(...downsampleStepPointsForPlot(rawSeries, maxPlotPoints));
|
||||||
|
}
|
||||||
|
merged.sort((a, b) => a.idx - b.idx);
|
||||||
|
if (merged.length > 0) hoverPoints = merged;
|
||||||
|
}
|
||||||
|
} else if (validPoints.length > maxPlotPoints) {
|
||||||
|
hoverPoints = downsampleStepPointsForPlot(validPoints, maxPlotPoints);
|
||||||
|
}
|
||||||
|
currentPoints = hoverPoints;
|
||||||
|
patchClasses(rootEl, {
|
||||||
|
'is-dense': isMultiCompare
|
||||||
|
? hoverPoints.length > 120 * targetKeys.length
|
||||||
|
: hoverPoints.length > 120,
|
||||||
|
});
|
||||||
patchAttr(emptyHintEl, 'hidden', validPoints.length > 0);
|
patchAttr(emptyHintEl, 'hidden', validPoints.length > 0);
|
||||||
|
|
||||||
const colorSig = Array.from(modelColorMap.entries())
|
const colorSig = Array.from(modelColorMap.entries())
|
||||||
@@ -18224,7 +18468,21 @@ function createSessionLineChart() {
|
|||||||
while (anomalyDotsGroup.firstChild) anomalyDotsGroup.removeChild(anomalyDotsGroup.firstChild);
|
while (anomalyDotsGroup.firstChild) anomalyDotsGroup.removeChild(anomalyDotsGroup.firstChild);
|
||||||
|
|
||||||
if (isMultiCompare) {
|
if (isMultiCompare) {
|
||||||
|
if (lastLineMode === 'single') {
|
||||||
|
const prevSingleSegs = singleCurveMorphCtrl.getCurrentSegs();
|
||||||
|
if (prevSingleSegs.length > 0) {
|
||||||
|
if (lastSingleLineKey && lastSingleLineKey !== '__all__') {
|
||||||
|
multiCurveMorphCtrl.seedSeries(lastSingleLineKey, prevSingleSegs);
|
||||||
|
} else {
|
||||||
|
for (const gk of targetKeys) {
|
||||||
|
multiCurveMorphCtrl.seedSeries(gk, prevSingleSegs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
singleCurveMorphCtrl.reset();
|
singleCurveMorphCtrl.reset();
|
||||||
|
lastLineMode = 'multi';
|
||||||
|
lastSingleLineKey = '';
|
||||||
patchAttr(linePath, 'd', '');
|
patchAttr(linePath, 'd', '');
|
||||||
patchAttr(areaPath, 'd', '');
|
patchAttr(areaPath, 'd', '');
|
||||||
for (let ci = multiLineGroup.children.length - 1; ci >= 0; ci--) {
|
for (let ci = multiLineGroup.children.length - 1; ci >= 0; ci--) {
|
||||||
@@ -18239,7 +18497,8 @@ function createSessionLineChart() {
|
|||||||
|
|
||||||
for (const gk of targetKeys) {
|
for (const gk of targetKeys) {
|
||||||
const seriesColor = modelColorMap.get(gk) || accentColor;
|
const seriesColor = modelColorMap.get(gk) || accentColor;
|
||||||
const seriesPts = points.filter((p) => p.modelGroupKey === gk && p.valid);
|
const rawSeriesPts = points.filter((p) => p.modelGroupKey === gk && p.valid);
|
||||||
|
const seriesPts = downsampleStepPointsForPlot(rawSeriesPts, maxPlotPoints);
|
||||||
if (seriesPts.length === 0) continue;
|
if (seriesPts.length === 0) continue;
|
||||||
|
|
||||||
if (seriesPts.length === 1) {
|
if (seriesPts.length === 1) {
|
||||||
@@ -18277,7 +18536,6 @@ function createSessionLineChart() {
|
|||||||
nextSegs: pointsToNormalizedCubicSegs(seriesPts, BOTTOM_Y, {
|
nextSegs: pointsToNormalizedCubicSegs(seriesPts, BOTTOM_Y, {
|
||||||
leftX,
|
leftX,
|
||||||
spanX,
|
spanX,
|
||||||
tension: 0.42,
|
|
||||||
}),
|
}),
|
||||||
lineEl: nodes.mLine,
|
lineEl: nodes.mLine,
|
||||||
areaEl: nodes.mArea,
|
areaEl: nodes.mArea,
|
||||||
@@ -18303,19 +18561,32 @@ function createSessionLineChart() {
|
|||||||
spanX,
|
spanX,
|
||||||
bottomY: BOTTOM_Y,
|
bottomY: BOTTOM_Y,
|
||||||
skipMorph: _skipMorph,
|
skipMorph: _skipMorph,
|
||||||
|
allowBaselineEntry: true,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
const nextSingleKey = isPooledAll ? '__all__' : targetKeys[0] || '__all__';
|
||||||
|
if (lastLineMode === 'multi') {
|
||||||
|
const seedSegs =
|
||||||
|
multiCurveMorphCtrl.getSeriesSegs(nextSingleKey) ||
|
||||||
|
multiCurveMorphCtrl.getFirstSegs();
|
||||||
|
if (seedSegs && seedSegs.length > 0) {
|
||||||
|
singleCurveMorphCtrl.seedSegs(seedSegs);
|
||||||
|
}
|
||||||
|
}
|
||||||
multiCurveMorphCtrl.reset();
|
multiCurveMorphCtrl.reset();
|
||||||
|
lastLineMode = 'single';
|
||||||
|
lastSingleLineKey = nextSingleKey;
|
||||||
for (const nodes of multiSeriesNodesByKey.values()) {
|
for (const nodes of multiSeriesNodesByKey.values()) {
|
||||||
nodes.mArea.remove();
|
nodes.mArea.remove();
|
||||||
nodes.mLine.remove();
|
nodes.mLine.remove();
|
||||||
}
|
}
|
||||||
if (validPoints.length === 0) {
|
const plotValidPoints = downsampleStepPointsForPlot(validPoints, maxPlotPoints);
|
||||||
|
if (plotValidPoints.length === 0) {
|
||||||
singleCurveMorphCtrl.reset();
|
singleCurveMorphCtrl.reset();
|
||||||
patchAttr(linePath, 'd', '');
|
patchAttr(linePath, 'd', '');
|
||||||
patchAttr(areaPath, 'd', '');
|
patchAttr(areaPath, 'd', '');
|
||||||
} else if (validPoints.length === 1) {
|
} else if (plotValidPoints.length === 1) {
|
||||||
const yVal = validPoints[0].y;
|
const yVal = plotValidPoints[0].y;
|
||||||
const yStr = yVal.toFixed(1);
|
const yStr = yVal.toFixed(1);
|
||||||
const lineD = `M ${leftX.toFixed(1)} ${yStr} L ${rightX.toFixed(1)} ${yStr}`;
|
const lineD = `M ${leftX.toFixed(1)} ${yStr} L ${rightX.toFixed(1)} ${yStr}`;
|
||||||
const areaD = `${lineD} L ${rightX.toFixed(1)} ${BOTTOM_Y} L ${leftX.toFixed(1)} ${BOTTOM_Y} Z`;
|
const areaD = `${lineD} L ${rightX.toFixed(1)} ${BOTTOM_Y} L ${leftX.toFixed(1)} ${BOTTOM_Y} Z`;
|
||||||
@@ -18335,12 +18606,12 @@ function createSessionLineChart() {
|
|||||||
skipMorph: _skipMorph,
|
skipMorph: _skipMorph,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const lineD = buildSplinePath(validPoints);
|
const lineD = buildSplinePath(plotValidPoints);
|
||||||
const firstX = validPoints[0].x.toFixed(1);
|
const firstX = plotValidPoints[0].x.toFixed(1);
|
||||||
const lastX = validPoints[validPoints.length - 1].x.toFixed(1);
|
const lastX = plotValidPoints[plotValidPoints.length - 1].x.toFixed(1);
|
||||||
const areaD = `${lineD} L ${lastX} ${BOTTOM_Y} L ${firstX} ${BOTTOM_Y} Z`;
|
const areaD = `${lineD} L ${lastX} ${BOTTOM_Y} L ${firstX} ${BOTTOM_Y} Z`;
|
||||||
singleCurveMorphCtrl.morphTo({
|
singleCurveMorphCtrl.morphTo({
|
||||||
nextSegs: pointsToNormalizedCubicSegs(validPoints, BOTTOM_Y, { leftX, spanX }),
|
nextSegs: pointsToNormalizedCubicSegs(plotValidPoints, BOTTOM_Y, { leftX, spanX }),
|
||||||
leftX,
|
leftX,
|
||||||
spanX,
|
spanX,
|
||||||
bottomY: BOTTOM_Y,
|
bottomY: BOTTOM_Y,
|
||||||
@@ -18377,12 +18648,12 @@ function createSessionLineChart() {
|
|||||||
anomalyDotsGroup.appendChild(aTick);
|
anomalyDotsGroup.appendChild(aTick);
|
||||||
}
|
}
|
||||||
|
|
||||||
const tickIndices = computeStepTickIndices(points.length);
|
const tickIndices = computeStepTickIndices(currentPoints.length);
|
||||||
while (xAxisEl.firstChild) xAxisEl.removeChild(xAxisEl.firstChild);
|
while (xAxisEl.firstChild) xAxisEl.removeChild(xAxisEl.firstChild);
|
||||||
tickElsByIdx = new Map();
|
tickElsByIdx = new Map();
|
||||||
for (let i = 0; i < tickIndices.length; i++) {
|
for (let i = 0; i < tickIndices.length; i++) {
|
||||||
const tIdx = tickIndices[i];
|
const tIdx = tickIndices[i];
|
||||||
const pt = points[tIdx];
|
const pt = currentPoints[tIdx];
|
||||||
if (!pt) continue;
|
if (!pt) continue;
|
||||||
const isFirst = !isSingle && i === 0;
|
const isFirst = !isSingle && i === 0;
|
||||||
const isLast = !isSingle && i === tickIndices.length - 1;
|
const isLast = !isSingle && i === tickIndices.length - 1;
|
||||||
@@ -18467,7 +18738,7 @@ function createSessionLineChart() {
|
|||||||
patchAttr(peakPill, 'hidden', true);
|
patchAttr(peakPill, 'hidden', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hoveredIdx >= points.length) {
|
if (hoveredIdx >= currentPoints.length) {
|
||||||
clearHover();
|
clearHover();
|
||||||
} else if (hoveredIdx >= 0) {
|
} else if (hoveredIdx >= 0) {
|
||||||
showHoverAt(hoveredIdx, lastPointer, { forceRefresh: true });
|
showHoverAt(hoveredIdx, lastPointer, { forceRefresh: true });
|
||||||
@@ -18657,6 +18928,8 @@ function createModelFitChart() {
|
|||||||
const multiFitNodesByKey = new Map();
|
const multiFitNodesByKey = new Map();
|
||||||
|
|
||||||
const fitMorphCtrl = createFitGridMorphController();
|
const fitMorphCtrl = createFitGridMorphController();
|
||||||
|
let lastFitMode = '';
|
||||||
|
let lastSingleFitKey = '';
|
||||||
const fitTooltipCtrl = createFloatingChartTooltipController({
|
const fitTooltipCtrl = createFloatingChartTooltipController({
|
||||||
containerEl: rootEl,
|
containerEl: rootEl,
|
||||||
tooltipEl,
|
tooltipEl,
|
||||||
@@ -19091,6 +19364,8 @@ function createModelFitChart() {
|
|||||||
if (matchedItems.length === 0) {
|
if (matchedItems.length === 0) {
|
||||||
fitCache.clear();
|
fitCache.clear();
|
||||||
fitMorphCtrl.reset();
|
fitMorphCtrl.reset();
|
||||||
|
lastFitMode = '';
|
||||||
|
lastSingleFitKey = '';
|
||||||
currentSamples = [];
|
currentSamples = [];
|
||||||
lastSig = 'empty';
|
lastSig = 'empty';
|
||||||
patchAttr(ciBandPath, 'd', '');
|
patchAttr(ciBandPath, 'd', '');
|
||||||
@@ -19367,7 +19642,26 @@ function createModelFitChart() {
|
|||||||
nodes.curveEl.remove();
|
nodes.curveEl.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fitMorphCtrl.morphFits({ items: fitMorphItems, skipMorph: _skipMorph });
|
if (lastFitMode === 'single') {
|
||||||
|
const prevSingleGrid = fitMorphCtrl.getGrid('single');
|
||||||
|
if (prevSingleGrid && prevSingleGrid.length > 0) {
|
||||||
|
if (lastSingleFitKey && lastSingleFitKey !== '__all__') {
|
||||||
|
fitMorphCtrl.seedGrid(`multi:${lastSingleFitKey}`, prevSingleGrid);
|
||||||
|
} else {
|
||||||
|
for (const s of seriesList) {
|
||||||
|
fitMorphCtrl.seedGrid(`multi:${s.key}`, prevSingleGrid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastFitMode = 'multi';
|
||||||
|
lastSingleFitKey = '';
|
||||||
|
fitMorphCtrl.morphFits({
|
||||||
|
items: fitMorphItems,
|
||||||
|
skipMorph: _skipMorph,
|
||||||
|
allowBaselineEntry: true,
|
||||||
|
bottomY: BOTTOM_Y,
|
||||||
|
});
|
||||||
anomalyOverlayDots.sort((a, b) =>
|
anomalyOverlayDots.sort((a, b) =>
|
||||||
a.anomalySeverity === 'danger' ? 1 : b.anomalySeverity === 'danger' ? -1 : 0
|
a.anomalySeverity === 'danger' ? 1 : b.anomalySeverity === 'danger' ? -1 : 0
|
||||||
);
|
);
|
||||||
@@ -19431,6 +19725,16 @@ function createModelFitChart() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 分支 B:单模型或整体合并单曲线模式
|
// 分支 B:单模型或整体合并单曲线模式
|
||||||
|
const nextSingleFitKey = isPooledAll ? '__all__' : targetKeys[0] || '__all__';
|
||||||
|
if (lastFitMode === 'multi') {
|
||||||
|
const seedGrid =
|
||||||
|
fitMorphCtrl.getGrid(`multi:${nextSingleFitKey}`) || fitMorphCtrl.getFirstGrid();
|
||||||
|
if (seedGrid && seedGrid.length > 0) {
|
||||||
|
fitMorphCtrl.seedGrid('single', seedGrid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastFitMode = 'single';
|
||||||
|
lastSingleFitKey = nextSingleFitKey;
|
||||||
for (const nodes of multiFitNodesByKey.values()) {
|
for (const nodes of multiFitNodesByKey.values()) {
|
||||||
nodes.bandEl.remove();
|
nodes.bandEl.remove();
|
||||||
nodes.curveEl.remove();
|
nodes.curveEl.remove();
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>用量监控</title>
|
<title>用量监控</title>
|
||||||
<link rel="stylesheet" href="/styles.css?v=1795538353095">
|
<link rel="stylesheet" href="/styles.css?v=1795540221301">
|
||||||
<script src="/preload.js"></script>
|
<script src="/preload.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app-root"></div>
|
<div id="app-root"></div>
|
||||||
<script src="/app.js?v=1795538353095"></script>
|
<script src="/app.js?v=1795540221301"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import {
|
|||||||
computeNiceYScale,
|
computeNiceYScale,
|
||||||
computePublicationFit,
|
computePublicationFit,
|
||||||
computeStepTickIndices,
|
computeStepTickIndices,
|
||||||
|
downsampleStepPointsForPlot,
|
||||||
formatChartMetricCompact,
|
formatChartMetricCompact,
|
||||||
formatChartMetricValue,
|
formatChartMetricValue,
|
||||||
formatStepAxisTag,
|
formatStepAxisTag,
|
||||||
@@ -213,6 +214,8 @@ export function createSessionLineChart() {
|
|||||||
let lastSummaryBadge = '';
|
let lastSummaryBadge = '';
|
||||||
let lastUpdateParams = null;
|
let lastUpdateParams = null;
|
||||||
let cachedPlotSvgRect = null;
|
let cachedPlotSvgRect = null;
|
||||||
|
let lastLineMode = '';
|
||||||
|
let lastSingleLineKey = '';
|
||||||
const multiSeriesNodesByKey = new Map();
|
const multiSeriesNodesByKey = new Map();
|
||||||
|
|
||||||
const singleCurveMorphCtrl = createCubicCurveMorphController();
|
const singleCurveMorphCtrl = createCubicCurveMorphController();
|
||||||
@@ -466,8 +469,13 @@ export function createSessionLineChart() {
|
|||||||
patchText(emptyHintEl, t('chart.step.empty'));
|
patchText(emptyHintEl, t('chart.step.empty'));
|
||||||
if (!matchedSteps.length) {
|
if (!matchedSteps.length) {
|
||||||
currentPoints = [];
|
currentPoints = [];
|
||||||
|
patchClasses(rootEl, { 'is-dense': false });
|
||||||
lastSig = 'empty';
|
lastSig = 'empty';
|
||||||
lastPreSig = '';
|
lastPreSig = '';
|
||||||
|
lastLineMode = '';
|
||||||
|
lastSingleLineKey = '';
|
||||||
|
singleCurveMorphCtrl.reset();
|
||||||
|
multiCurveMorphCtrl.reset();
|
||||||
lastSummaryBadge = t('chart.step.zeroSteps');
|
lastSummaryBadge = t('chart.step.zeroSteps');
|
||||||
invalidatePlotSvgRect();
|
invalidatePlotSvgRect();
|
||||||
patchAttr(areaPath, 'd', '');
|
patchAttr(areaPath, 'd', '');
|
||||||
@@ -691,6 +699,7 @@ export function createSessionLineChart() {
|
|||||||
currentMaxVal = maxVal;
|
currentMaxVal = maxVal;
|
||||||
|
|
||||||
const { leftX, rightX, spanX } = resolvePlotBounds(viewW);
|
const { leftX, rightX, spanX } = resolvePlotBounds(viewW);
|
||||||
|
const maxPlotPoints = Math.max(128, Math.min(256, Math.floor(spanX / 2.1)));
|
||||||
const denom = maxVal > 0 ? maxVal : 1;
|
const denom = maxVal > 0 ? maxVal : 1;
|
||||||
const isSingle = rawItems.length === 1;
|
const isSingle = rawItems.length === 1;
|
||||||
const points = rawItems.map((item, i) => {
|
const points = rawItems.map((item, i) => {
|
||||||
@@ -701,9 +710,28 @@ export function createSessionLineChart() {
|
|||||||
const y = item.valid ? BOTTOM_Y - ratio * SPAN_Y : BOTTOM_Y;
|
const y = item.valid ? BOTTOM_Y - ratio * SPAN_Y : BOTTOM_Y;
|
||||||
return { ...item, x, y };
|
return { ...item, x, y };
|
||||||
});
|
});
|
||||||
currentPoints = points;
|
|
||||||
|
|
||||||
const validPoints = points.filter((p) => p.valid);
|
const validPoints = points.filter((p) => p.valid);
|
||||||
|
let hoverPoints = points;
|
||||||
|
if (isMultiCompare) {
|
||||||
|
if (points.length > maxPlotPoints * targetKeys.length) {
|
||||||
|
const merged = [];
|
||||||
|
for (const gk of targetKeys) {
|
||||||
|
const rawSeries = points.filter((p) => p.modelGroupKey === gk && p.valid);
|
||||||
|
merged.push(...downsampleStepPointsForPlot(rawSeries, maxPlotPoints));
|
||||||
|
}
|
||||||
|
merged.sort((a, b) => a.idx - b.idx);
|
||||||
|
if (merged.length > 0) hoverPoints = merged;
|
||||||
|
}
|
||||||
|
} else if (validPoints.length > maxPlotPoints) {
|
||||||
|
hoverPoints = downsampleStepPointsForPlot(validPoints, maxPlotPoints);
|
||||||
|
}
|
||||||
|
currentPoints = hoverPoints;
|
||||||
|
patchClasses(rootEl, {
|
||||||
|
'is-dense': isMultiCompare
|
||||||
|
? hoverPoints.length > 120 * targetKeys.length
|
||||||
|
: hoverPoints.length > 120,
|
||||||
|
});
|
||||||
patchAttr(emptyHintEl, 'hidden', validPoints.length > 0);
|
patchAttr(emptyHintEl, 'hidden', validPoints.length > 0);
|
||||||
|
|
||||||
const colorSig = Array.from(modelColorMap.entries())
|
const colorSig = Array.from(modelColorMap.entries())
|
||||||
@@ -724,7 +752,21 @@ export function createSessionLineChart() {
|
|||||||
while (anomalyDotsGroup.firstChild) anomalyDotsGroup.removeChild(anomalyDotsGroup.firstChild);
|
while (anomalyDotsGroup.firstChild) anomalyDotsGroup.removeChild(anomalyDotsGroup.firstChild);
|
||||||
|
|
||||||
if (isMultiCompare) {
|
if (isMultiCompare) {
|
||||||
|
if (lastLineMode === 'single') {
|
||||||
|
const prevSingleSegs = singleCurveMorphCtrl.getCurrentSegs();
|
||||||
|
if (prevSingleSegs.length > 0) {
|
||||||
|
if (lastSingleLineKey && lastSingleLineKey !== '__all__') {
|
||||||
|
multiCurveMorphCtrl.seedSeries(lastSingleLineKey, prevSingleSegs);
|
||||||
|
} else {
|
||||||
|
for (const gk of targetKeys) {
|
||||||
|
multiCurveMorphCtrl.seedSeries(gk, prevSingleSegs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
singleCurveMorphCtrl.reset();
|
singleCurveMorphCtrl.reset();
|
||||||
|
lastLineMode = 'multi';
|
||||||
|
lastSingleLineKey = '';
|
||||||
patchAttr(linePath, 'd', '');
|
patchAttr(linePath, 'd', '');
|
||||||
patchAttr(areaPath, 'd', '');
|
patchAttr(areaPath, 'd', '');
|
||||||
for (let ci = multiLineGroup.children.length - 1; ci >= 0; ci--) {
|
for (let ci = multiLineGroup.children.length - 1; ci >= 0; ci--) {
|
||||||
@@ -739,7 +781,8 @@ export function createSessionLineChart() {
|
|||||||
|
|
||||||
for (const gk of targetKeys) {
|
for (const gk of targetKeys) {
|
||||||
const seriesColor = modelColorMap.get(gk) || accentColor;
|
const seriesColor = modelColorMap.get(gk) || accentColor;
|
||||||
const seriesPts = points.filter((p) => p.modelGroupKey === gk && p.valid);
|
const rawSeriesPts = points.filter((p) => p.modelGroupKey === gk && p.valid);
|
||||||
|
const seriesPts = downsampleStepPointsForPlot(rawSeriesPts, maxPlotPoints);
|
||||||
if (seriesPts.length === 0) continue;
|
if (seriesPts.length === 0) continue;
|
||||||
|
|
||||||
if (seriesPts.length === 1) {
|
if (seriesPts.length === 1) {
|
||||||
@@ -777,7 +820,6 @@ export function createSessionLineChart() {
|
|||||||
nextSegs: pointsToNormalizedCubicSegs(seriesPts, BOTTOM_Y, {
|
nextSegs: pointsToNormalizedCubicSegs(seriesPts, BOTTOM_Y, {
|
||||||
leftX,
|
leftX,
|
||||||
spanX,
|
spanX,
|
||||||
tension: 0.42,
|
|
||||||
}),
|
}),
|
||||||
lineEl: nodes.mLine,
|
lineEl: nodes.mLine,
|
||||||
areaEl: nodes.mArea,
|
areaEl: nodes.mArea,
|
||||||
@@ -803,19 +845,32 @@ export function createSessionLineChart() {
|
|||||||
spanX,
|
spanX,
|
||||||
bottomY: BOTTOM_Y,
|
bottomY: BOTTOM_Y,
|
||||||
skipMorph: _skipMorph,
|
skipMorph: _skipMorph,
|
||||||
|
allowBaselineEntry: true,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
const nextSingleKey = isPooledAll ? '__all__' : targetKeys[0] || '__all__';
|
||||||
|
if (lastLineMode === 'multi') {
|
||||||
|
const seedSegs =
|
||||||
|
multiCurveMorphCtrl.getSeriesSegs(nextSingleKey) ||
|
||||||
|
multiCurveMorphCtrl.getFirstSegs();
|
||||||
|
if (seedSegs && seedSegs.length > 0) {
|
||||||
|
singleCurveMorphCtrl.seedSegs(seedSegs);
|
||||||
|
}
|
||||||
|
}
|
||||||
multiCurveMorphCtrl.reset();
|
multiCurveMorphCtrl.reset();
|
||||||
|
lastLineMode = 'single';
|
||||||
|
lastSingleLineKey = nextSingleKey;
|
||||||
for (const nodes of multiSeriesNodesByKey.values()) {
|
for (const nodes of multiSeriesNodesByKey.values()) {
|
||||||
nodes.mArea.remove();
|
nodes.mArea.remove();
|
||||||
nodes.mLine.remove();
|
nodes.mLine.remove();
|
||||||
}
|
}
|
||||||
if (validPoints.length === 0) {
|
const plotValidPoints = downsampleStepPointsForPlot(validPoints, maxPlotPoints);
|
||||||
|
if (plotValidPoints.length === 0) {
|
||||||
singleCurveMorphCtrl.reset();
|
singleCurveMorphCtrl.reset();
|
||||||
patchAttr(linePath, 'd', '');
|
patchAttr(linePath, 'd', '');
|
||||||
patchAttr(areaPath, 'd', '');
|
patchAttr(areaPath, 'd', '');
|
||||||
} else if (validPoints.length === 1) {
|
} else if (plotValidPoints.length === 1) {
|
||||||
const yVal = validPoints[0].y;
|
const yVal = plotValidPoints[0].y;
|
||||||
const yStr = yVal.toFixed(1);
|
const yStr = yVal.toFixed(1);
|
||||||
const lineD = `M ${leftX.toFixed(1)} ${yStr} L ${rightX.toFixed(1)} ${yStr}`;
|
const lineD = `M ${leftX.toFixed(1)} ${yStr} L ${rightX.toFixed(1)} ${yStr}`;
|
||||||
const areaD = `${lineD} L ${rightX.toFixed(1)} ${BOTTOM_Y} L ${leftX.toFixed(1)} ${BOTTOM_Y} Z`;
|
const areaD = `${lineD} L ${rightX.toFixed(1)} ${BOTTOM_Y} L ${leftX.toFixed(1)} ${BOTTOM_Y} Z`;
|
||||||
@@ -835,12 +890,12 @@ export function createSessionLineChart() {
|
|||||||
skipMorph: _skipMorph,
|
skipMorph: _skipMorph,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const lineD = buildSplinePath(validPoints);
|
const lineD = buildSplinePath(plotValidPoints);
|
||||||
const firstX = validPoints[0].x.toFixed(1);
|
const firstX = plotValidPoints[0].x.toFixed(1);
|
||||||
const lastX = validPoints[validPoints.length - 1].x.toFixed(1);
|
const lastX = plotValidPoints[plotValidPoints.length - 1].x.toFixed(1);
|
||||||
const areaD = `${lineD} L ${lastX} ${BOTTOM_Y} L ${firstX} ${BOTTOM_Y} Z`;
|
const areaD = `${lineD} L ${lastX} ${BOTTOM_Y} L ${firstX} ${BOTTOM_Y} Z`;
|
||||||
singleCurveMorphCtrl.morphTo({
|
singleCurveMorphCtrl.morphTo({
|
||||||
nextSegs: pointsToNormalizedCubicSegs(validPoints, BOTTOM_Y, { leftX, spanX }),
|
nextSegs: pointsToNormalizedCubicSegs(plotValidPoints, BOTTOM_Y, { leftX, spanX }),
|
||||||
leftX,
|
leftX,
|
||||||
spanX,
|
spanX,
|
||||||
bottomY: BOTTOM_Y,
|
bottomY: BOTTOM_Y,
|
||||||
@@ -877,12 +932,12 @@ export function createSessionLineChart() {
|
|||||||
anomalyDotsGroup.appendChild(aTick);
|
anomalyDotsGroup.appendChild(aTick);
|
||||||
}
|
}
|
||||||
|
|
||||||
const tickIndices = computeStepTickIndices(points.length);
|
const tickIndices = computeStepTickIndices(currentPoints.length);
|
||||||
while (xAxisEl.firstChild) xAxisEl.removeChild(xAxisEl.firstChild);
|
while (xAxisEl.firstChild) xAxisEl.removeChild(xAxisEl.firstChild);
|
||||||
tickElsByIdx = new Map();
|
tickElsByIdx = new Map();
|
||||||
for (let i = 0; i < tickIndices.length; i++) {
|
for (let i = 0; i < tickIndices.length; i++) {
|
||||||
const tIdx = tickIndices[i];
|
const tIdx = tickIndices[i];
|
||||||
const pt = points[tIdx];
|
const pt = currentPoints[tIdx];
|
||||||
if (!pt) continue;
|
if (!pt) continue;
|
||||||
const isFirst = !isSingle && i === 0;
|
const isFirst = !isSingle && i === 0;
|
||||||
const isLast = !isSingle && i === tickIndices.length - 1;
|
const isLast = !isSingle && i === tickIndices.length - 1;
|
||||||
@@ -967,7 +1022,7 @@ export function createSessionLineChart() {
|
|||||||
patchAttr(peakPill, 'hidden', true);
|
patchAttr(peakPill, 'hidden', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hoveredIdx >= points.length) {
|
if (hoveredIdx >= currentPoints.length) {
|
||||||
clearHover();
|
clearHover();
|
||||||
} else if (hoveredIdx >= 0) {
|
} else if (hoveredIdx >= 0) {
|
||||||
showHoverAt(hoveredIdx, lastPointer, { forceRefresh: true });
|
showHoverAt(hoveredIdx, lastPointer, { forceRefresh: true });
|
||||||
@@ -1157,6 +1212,8 @@ export function createModelFitChart() {
|
|||||||
const multiFitNodesByKey = new Map();
|
const multiFitNodesByKey = new Map();
|
||||||
|
|
||||||
const fitMorphCtrl = createFitGridMorphController();
|
const fitMorphCtrl = createFitGridMorphController();
|
||||||
|
let lastFitMode = '';
|
||||||
|
let lastSingleFitKey = '';
|
||||||
const fitTooltipCtrl = createFloatingChartTooltipController({
|
const fitTooltipCtrl = createFloatingChartTooltipController({
|
||||||
containerEl: rootEl,
|
containerEl: rootEl,
|
||||||
tooltipEl,
|
tooltipEl,
|
||||||
@@ -1591,6 +1648,8 @@ export function createModelFitChart() {
|
|||||||
if (matchedItems.length === 0) {
|
if (matchedItems.length === 0) {
|
||||||
fitCache.clear();
|
fitCache.clear();
|
||||||
fitMorphCtrl.reset();
|
fitMorphCtrl.reset();
|
||||||
|
lastFitMode = '';
|
||||||
|
lastSingleFitKey = '';
|
||||||
currentSamples = [];
|
currentSamples = [];
|
||||||
lastSig = 'empty';
|
lastSig = 'empty';
|
||||||
patchAttr(ciBandPath, 'd', '');
|
patchAttr(ciBandPath, 'd', '');
|
||||||
@@ -1867,7 +1926,26 @@ export function createModelFitChart() {
|
|||||||
nodes.curveEl.remove();
|
nodes.curveEl.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fitMorphCtrl.morphFits({ items: fitMorphItems, skipMorph: _skipMorph });
|
if (lastFitMode === 'single') {
|
||||||
|
const prevSingleGrid = fitMorphCtrl.getGrid('single');
|
||||||
|
if (prevSingleGrid && prevSingleGrid.length > 0) {
|
||||||
|
if (lastSingleFitKey && lastSingleFitKey !== '__all__') {
|
||||||
|
fitMorphCtrl.seedGrid(`multi:${lastSingleFitKey}`, prevSingleGrid);
|
||||||
|
} else {
|
||||||
|
for (const s of seriesList) {
|
||||||
|
fitMorphCtrl.seedGrid(`multi:${s.key}`, prevSingleGrid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastFitMode = 'multi';
|
||||||
|
lastSingleFitKey = '';
|
||||||
|
fitMorphCtrl.morphFits({
|
||||||
|
items: fitMorphItems,
|
||||||
|
skipMorph: _skipMorph,
|
||||||
|
allowBaselineEntry: true,
|
||||||
|
bottomY: BOTTOM_Y,
|
||||||
|
});
|
||||||
anomalyOverlayDots.sort((a, b) =>
|
anomalyOverlayDots.sort((a, b) =>
|
||||||
a.anomalySeverity === 'danger' ? 1 : b.anomalySeverity === 'danger' ? -1 : 0
|
a.anomalySeverity === 'danger' ? 1 : b.anomalySeverity === 'danger' ? -1 : 0
|
||||||
);
|
);
|
||||||
@@ -1931,6 +2009,16 @@ export function createModelFitChart() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 分支 B:单模型或整体合并单曲线模式
|
// 分支 B:单模型或整体合并单曲线模式
|
||||||
|
const nextSingleFitKey = isPooledAll ? '__all__' : targetKeys[0] || '__all__';
|
||||||
|
if (lastFitMode === 'multi') {
|
||||||
|
const seedGrid =
|
||||||
|
fitMorphCtrl.getGrid(`multi:${nextSingleFitKey}`) || fitMorphCtrl.getFirstGrid();
|
||||||
|
if (seedGrid && seedGrid.length > 0) {
|
||||||
|
fitMorphCtrl.seedGrid('single', seedGrid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastFitMode = 'single';
|
||||||
|
lastSingleFitKey = nextSingleFitKey;
|
||||||
for (const nodes of multiFitNodesByKey.values()) {
|
for (const nodes of multiFitNodesByKey.values()) {
|
||||||
nodes.bandEl.remove();
|
nodes.bandEl.remove();
|
||||||
nodes.curveEl.remove();
|
nodes.curveEl.remove();
|
||||||
|
|||||||
@@ -282,21 +282,15 @@ function alignCubicChainsForMorph(fromSegs, toSegs) {
|
|||||||
const tSpan = tEnd - tStart;
|
const tSpan = tEnd - tStart;
|
||||||
|
|
||||||
const rawTau = [0, 1];
|
const rawTau = [0, 1];
|
||||||
const pushChainKnots = (segs, start, span, cap) => {
|
const pushChainKnots = (segs, start, span) => {
|
||||||
if (!(span > 1e-6)) return;
|
if (!(span > 1e-6)) return;
|
||||||
if (segs.length <= cap) {
|
for (let i = 0; i < segs.length; i++) {
|
||||||
for (let i = 0; i < segs.length; i++) {
|
rawTau.push(Math.max(0, Math.min(1, (segs[i].u0 - start) / span)));
|
||||||
rawTau.push(Math.max(0, Math.min(1, (segs[i].u3 - start) / span)));
|
rawTau.push(Math.max(0, Math.min(1, (segs[i].u3 - start) / span)));
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const stride = Math.ceil(segs.length / cap);
|
|
||||||
for (let i = 0; i < segs.length; i += stride) {
|
|
||||||
rawTau.push(Math.max(0, Math.min(1, (segs[i].u3 - start) / span)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
pushChainKnots(toSegs, tStart, tSpan, 96);
|
pushChainKnots(toSegs, tStart, tSpan);
|
||||||
pushChainKnots(fromSegs, fStart, fSpan, 48);
|
pushChainKnots(fromSegs, fStart, fSpan);
|
||||||
|
|
||||||
rawTau.sort((a, b) => a - b);
|
rawTau.sort((a, b) => a - b);
|
||||||
const tauKnots = [0];
|
const tauKnots = [0];
|
||||||
@@ -381,6 +375,20 @@ export function createCubicCurveMorphController({ durationMs = CHART_CURVE_MORPH
|
|||||||
hasRenderedOnce = false;
|
hasRenderedOnce = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCurrentSegs() {
|
||||||
|
const src = liveMorphSegs || committedSegs;
|
||||||
|
return hasRenderedOnce && src.length > 0 ? src.map((s) => ({ ...s })) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function seedSegs(segs) {
|
||||||
|
cancel();
|
||||||
|
if (Array.isArray(segs) && segs.length > 0) {
|
||||||
|
committedSegs = segs.map((s) => ({ ...s }));
|
||||||
|
liveMorphSegs = null;
|
||||||
|
hasRenderedOnce = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function morphTo({
|
function morphTo({
|
||||||
nextSegs,
|
nextSegs,
|
||||||
leftX,
|
leftX,
|
||||||
@@ -438,6 +446,17 @@ export function createCubicCurveMorphController({ durationMs = CHART_CURVE_MORPH
|
|||||||
|
|
||||||
const activeLive = alignedFrom.map((s) => ({ ...s }));
|
const activeLive = alignedFrom.map((s) => ({ ...s }));
|
||||||
liveMorphSegs = activeLive;
|
liveMorphSegs = activeLive;
|
||||||
|
const initialLineD = buildPathFromNormalizedSegs(activeLive, leftX, spanX);
|
||||||
|
patchAttr(linePath, 'd', initialLineD);
|
||||||
|
if (areaPath) {
|
||||||
|
if (finalAreaD) {
|
||||||
|
const firstX = (leftX + activeLive[0].u0 * spanX).toFixed(1);
|
||||||
|
const lastX = (leftX + activeLive[segCount - 1].u3 * spanX).toFixed(1);
|
||||||
|
patchAttr(areaPath, 'd', `${initialLineD} L ${lastX} ${bottomY} L ${firstX} ${bottomY} Z`);
|
||||||
|
} else {
|
||||||
|
patchAttr(areaPath, 'd', '');
|
||||||
|
}
|
||||||
|
}
|
||||||
const startTs = performance.now();
|
const startTs = performance.now();
|
||||||
|
|
||||||
const step = (nowTs) => {
|
const step = (nowTs) => {
|
||||||
@@ -477,7 +496,7 @@ export function createCubicCurveMorphController({ durationMs = CHART_CURVE_MORPH
|
|||||||
morphRafId = window.requestAnimationFrame(step);
|
morphRafId = window.requestAnimationFrame(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { morphTo, cancel, reset };
|
return { morphTo, cancel, reset, getCurrentSegs, seedSegs };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -486,6 +505,7 @@ export function createCubicCurveMorphController({ durationMs = CHART_CURVE_MORPH
|
|||||||
*/
|
*/
|
||||||
export function createMultiSeriesCurveMorphController({ durationMs = CHART_CURVE_MORPH_MS } = {}) {
|
export function createMultiSeriesCurveMorphController({ durationMs = CHART_CURVE_MORPH_MS } = {}) {
|
||||||
let morphRafId = 0;
|
let morphRafId = 0;
|
||||||
|
let hasRenderedOnce = false;
|
||||||
const stateByKey = new Map();
|
const stateByKey = new Map();
|
||||||
|
|
||||||
function cancel() {
|
function cancel() {
|
||||||
@@ -501,18 +521,47 @@ export function createMultiSeriesCurveMorphController({ durationMs = CHART_CURVE
|
|||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
cancel();
|
cancel();
|
||||||
|
hasRenderedOnce = false;
|
||||||
stateByKey.clear();
|
stateByKey.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSeriesSegs(key) {
|
||||||
|
const rec = stateByKey.get(key);
|
||||||
|
const src = rec ? rec.liveSegs || rec.committedSegs : null;
|
||||||
|
return src && src.length > 0 ? src.map((s) => ({ ...s })) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFirstSegs() {
|
||||||
|
for (const rec of stateByKey.values()) {
|
||||||
|
const src = rec.liveSegs || rec.committedSegs;
|
||||||
|
if (src && src.length > 0) return src.map((s) => ({ ...s }));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function seedSeries(key, segs) {
|
||||||
|
if (!key || !Array.isArray(segs) || segs.length === 0) return;
|
||||||
|
stateByKey.set(key, {
|
||||||
|
committedSegs: segs.map((s) => ({ ...s })),
|
||||||
|
liveSegs: null,
|
||||||
|
endX: NaN,
|
||||||
|
endY: NaN,
|
||||||
|
});
|
||||||
|
hasRenderedOnce = true;
|
||||||
|
}
|
||||||
|
|
||||||
function morphSeries({
|
function morphSeries({
|
||||||
items,
|
items,
|
||||||
leftX,
|
leftX,
|
||||||
spanX,
|
spanX,
|
||||||
bottomY,
|
bottomY,
|
||||||
skipMorph = false,
|
skipMorph = false,
|
||||||
|
allowBaselineEntry = false,
|
||||||
}) {
|
}) {
|
||||||
cancel();
|
cancel();
|
||||||
const canAnim = !skipMorph && canAnimateChartInBrowser();
|
const canAnim = !skipMorph && canAnimateChartInBrowser();
|
||||||
|
const wasRenderedBefore = hasRenderedOnce;
|
||||||
|
hasRenderedOnce = items.length > 0;
|
||||||
const activeSet = new Set();
|
const activeSet = new Set();
|
||||||
const jobs = [];
|
const jobs = [];
|
||||||
|
|
||||||
@@ -520,7 +569,26 @@ export function createMultiSeriesCurveMorphController({ durationMs = CHART_CURVE
|
|||||||
const it = items[idx];
|
const it = items[idx];
|
||||||
activeSet.add(it.key);
|
activeSet.add(it.key);
|
||||||
const prevEntry = stateByKey.get(it.key);
|
const prevEntry = stateByKey.get(it.key);
|
||||||
const prevSegs = prevEntry ? prevEntry.liveSegs || prevEntry.committedSegs : null;
|
let prevSegs = prevEntry ? prevEntry.liveSegs || prevEntry.committedSegs : null;
|
||||||
|
if (
|
||||||
|
(!prevSegs || prevSegs.length === 0) &&
|
||||||
|
canAnim &&
|
||||||
|
allowBaselineEntry &&
|
||||||
|
wasRenderedBefore &&
|
||||||
|
it.nextSegs.length > 0 &&
|
||||||
|
Number.isFinite(bottomY)
|
||||||
|
) {
|
||||||
|
prevSegs = it.nextSegs.map((s) => ({
|
||||||
|
u0: s.u0,
|
||||||
|
y0: bottomY,
|
||||||
|
cu1: s.cu1,
|
||||||
|
cy1: bottomY,
|
||||||
|
cu2: s.cu2,
|
||||||
|
cy2: bottomY,
|
||||||
|
u3: s.u3,
|
||||||
|
y3: bottomY,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
if (!canAnim || !prevSegs || prevSegs.length === 0 || it.nextSegs.length === 0) {
|
if (!canAnim || !prevSegs || prevSegs.length === 0 || it.nextSegs.length === 0) {
|
||||||
stateByKey.set(it.key, {
|
stateByKey.set(it.key, {
|
||||||
@@ -585,6 +653,17 @@ export function createMultiSeriesCurveMorphController({ durationMs = CHART_CURVE
|
|||||||
endY: fromEndY,
|
endY: fromEndY,
|
||||||
};
|
};
|
||||||
stateByKey.set(it.key, stateRec);
|
stateByKey.set(it.key, stateRec);
|
||||||
|
const initLineD = buildPathFromNormalizedSegs(activeLive, leftX, spanX);
|
||||||
|
patchAttr(it.lineEl, 'd', initLineD);
|
||||||
|
if (it.areaEl) {
|
||||||
|
if (it.finalAreaD) {
|
||||||
|
const firstX = (leftX + activeLive[0].u0 * spanX).toFixed(1);
|
||||||
|
const lastX = (leftX + activeLive[segCount - 1].u3 * spanX).toFixed(1);
|
||||||
|
patchAttr(it.areaEl, 'd', `${initLineD} L ${lastX} ${bottomY} L ${firstX} ${bottomY} Z`);
|
||||||
|
} else {
|
||||||
|
patchAttr(it.areaEl, 'd', '');
|
||||||
|
}
|
||||||
|
}
|
||||||
jobs.push({
|
jobs.push({
|
||||||
it,
|
it,
|
||||||
alignedFrom,
|
alignedFrom,
|
||||||
@@ -663,7 +742,7 @@ export function createMultiSeriesCurveMorphController({ durationMs = CHART_CURVE
|
|||||||
morphRafId = window.requestAnimationFrame(step);
|
morphRafId = window.requestAnimationFrame(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { morphSeries, cancel, reset };
|
return { morphSeries, cancel, reset, getSeriesSegs, getFirstSegs, seedSeries };
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildGridFitPolylineD(grid) {
|
function buildGridFitPolylineD(grid) {
|
||||||
@@ -687,12 +766,41 @@ function buildGridCiBandD(grid) {
|
|||||||
return `${d} Z`;
|
return `${d} Z`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resampleFitGridToTargetXs(sourceGrid, targetGrid) {
|
||||||
|
if (!Array.isArray(sourceGrid) || sourceGrid.length === 0) return null;
|
||||||
|
const sLen = sourceGrid.length;
|
||||||
|
const sFirst = sourceGrid[0];
|
||||||
|
const sLast = sourceGrid[sLen - 1];
|
||||||
|
let j = 0;
|
||||||
|
return targetGrid.map((tg) => {
|
||||||
|
const x = tg.x;
|
||||||
|
if (sLen === 1 || x <= sFirst.x) {
|
||||||
|
return { x, fitY: sFirst.fitY, lowY: sFirst.lowY, highY: sFirst.highY };
|
||||||
|
}
|
||||||
|
if (x >= sLast.x) {
|
||||||
|
return { x, fitY: sLast.fitY, lowY: sLast.lowY, highY: sLast.highY };
|
||||||
|
}
|
||||||
|
while (j < sLen - 2 && sourceGrid[j + 1].x < x) j += 1;
|
||||||
|
const a = sourceGrid[j];
|
||||||
|
const b = sourceGrid[j + 1];
|
||||||
|
const span = b.x - a.x;
|
||||||
|
const r = span > 1e-6 ? Math.max(0, Math.min(1, (x - a.x) / span)) : 0;
|
||||||
|
return {
|
||||||
|
x,
|
||||||
|
fitY: a.fitY + (b.fitY - a.fitY) * r,
|
||||||
|
lowY: a.lowY + (b.lowY - a.lowY) * r,
|
||||||
|
highY: a.highY + (b.highY - a.highY) * r,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smoothly morphs LOESS fit polylines, `95% CI` confidence bands, and optional OLS lines
|
* Smoothly morphs LOESS fit polylines, `95% CI` confidence bands, and optional OLS lines
|
||||||
* across metric/model switches in `createModelFitChart`.
|
* across metric/model switches in `createModelFitChart`.
|
||||||
*/
|
*/
|
||||||
export function createFitGridMorphController({ durationMs = CHART_CURVE_MORPH_MS } = {}) {
|
export function createFitGridMorphController({ durationMs = CHART_CURVE_MORPH_MS } = {}) {
|
||||||
let morphRafId = 0;
|
let morphRafId = 0;
|
||||||
|
let hasRenderedOnce = false;
|
||||||
const stateByKey = new Map();
|
const stateByKey = new Map();
|
||||||
|
|
||||||
function cancel() {
|
function cancel() {
|
||||||
@@ -708,12 +816,39 @@ export function createFitGridMorphController({ durationMs = CHART_CURVE_MORPH_MS
|
|||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
cancel();
|
cancel();
|
||||||
|
hasRenderedOnce = false;
|
||||||
stateByKey.clear();
|
stateByKey.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
function morphFits({ items, skipMorph = false }) {
|
function getGrid(key) {
|
||||||
|
const rec = stateByKey.get(key);
|
||||||
|
const src = rec ? rec.liveGrid || rec.committedGrid : null;
|
||||||
|
return src && src.length > 0 ? src.map((g) => ({ ...g })) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFirstGrid() {
|
||||||
|
for (const rec of stateByKey.values()) {
|
||||||
|
const src = rec.liveGrid || rec.committedGrid;
|
||||||
|
if (src && src.length > 0) return src.map((g) => ({ ...g }));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function seedGrid(key, gridPts) {
|
||||||
|
if (!key || !Array.isArray(gridPts) || gridPts.length === 0) return;
|
||||||
|
stateByKey.set(key, {
|
||||||
|
committedGrid: gridPts.map((g) => ({ ...g })),
|
||||||
|
liveGrid: null,
|
||||||
|
ols: null,
|
||||||
|
});
|
||||||
|
hasRenderedOnce = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function morphFits({ items, skipMorph = false, allowBaselineEntry = false, bottomY = NaN }) {
|
||||||
cancel();
|
cancel();
|
||||||
const canAnim = !skipMorph && canAnimateChartInBrowser();
|
const canAnim = !skipMorph && canAnimateChartInBrowser();
|
||||||
|
const wasRenderedBefore = hasRenderedOnce;
|
||||||
|
hasRenderedOnce = items.length > 0;
|
||||||
const activeSet = new Set();
|
const activeSet = new Set();
|
||||||
const jobs = [];
|
const jobs = [];
|
||||||
|
|
||||||
@@ -721,7 +856,32 @@ export function createFitGridMorphController({ durationMs = CHART_CURVE_MORPH_MS
|
|||||||
const it = items[idx];
|
const it = items[idx];
|
||||||
activeSet.add(it.key);
|
activeSet.add(it.key);
|
||||||
const prevEntry = stateByKey.get(it.key);
|
const prevEntry = stateByKey.get(it.key);
|
||||||
const prevGrid = prevEntry ? prevEntry.liveGrid || prevEntry.committedGrid : null;
|
const rawPrevGrid = prevEntry ? prevEntry.liveGrid || prevEntry.committedGrid : null;
|
||||||
|
let prevGrid =
|
||||||
|
rawPrevGrid && rawPrevGrid.length > 0 && it.gridPts.length >= 2
|
||||||
|
? rawPrevGrid.length === it.gridPts.length &&
|
||||||
|
Math.abs(rawPrevGrid[0].x - it.gridPts[0].x) < 0.5 &&
|
||||||
|
Math.abs(
|
||||||
|
rawPrevGrid[rawPrevGrid.length - 1].x - it.gridPts[it.gridPts.length - 1].x
|
||||||
|
) < 0.5
|
||||||
|
? rawPrevGrid
|
||||||
|
: resampleFitGridToTargetXs(rawPrevGrid, it.gridPts)
|
||||||
|
: null;
|
||||||
|
if (
|
||||||
|
!prevGrid &&
|
||||||
|
canAnim &&
|
||||||
|
allowBaselineEntry &&
|
||||||
|
wasRenderedBefore &&
|
||||||
|
it.gridPts.length >= 2 &&
|
||||||
|
Number.isFinite(bottomY)
|
||||||
|
) {
|
||||||
|
prevGrid = it.gridPts.map((g) => ({
|
||||||
|
x: g.x,
|
||||||
|
fitY: bottomY,
|
||||||
|
lowY: bottomY,
|
||||||
|
highY: bottomY,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!canAnim ||
|
!canAnim ||
|
||||||
@@ -782,6 +942,16 @@ export function createFitGridMorphController({ durationMs = CHART_CURVE_MORPH_MS
|
|||||||
ols: fromOls ? { ...fromOls } : null,
|
ols: fromOls ? { ...fromOls } : null,
|
||||||
};
|
};
|
||||||
stateByKey.set(it.key, stateRec);
|
stateByKey.set(it.key, stateRec);
|
||||||
|
patchAttr(it.curveEl, 'd', buildGridFitPolylineD(activeLive));
|
||||||
|
if (it.bandEl) {
|
||||||
|
patchAttr(it.bandEl, 'd', it.finalBandD ? buildGridCiBandD(activeLive) : '');
|
||||||
|
}
|
||||||
|
if (it.olsEl && fromOls) {
|
||||||
|
patchAttr(it.olsEl, 'x1', fromOls.x1.toFixed(1));
|
||||||
|
patchAttr(it.olsEl, 'y1', fromOls.y1.toFixed(1));
|
||||||
|
patchAttr(it.olsEl, 'x2', fromOls.x2.toFixed(1));
|
||||||
|
patchAttr(it.olsEl, 'y2', fromOls.y2.toFixed(1));
|
||||||
|
}
|
||||||
jobs.push({ it, fromGrid: prevGrid, activeLive, fromOls, stateRec });
|
jobs.push({ it, fromGrid: prevGrid, activeLive, fromOls, stateRec });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -848,7 +1018,7 @@ export function createFitGridMorphController({ durationMs = CHART_CURVE_MORPH_MS
|
|||||||
morphRafId = window.requestAnimationFrame(step);
|
morphRafId = window.requestAnimationFrame(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { morphFits, cancel, reset };
|
return { morphFits, cancel, reset, getGrid, getFirstGrid, seedGrid };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -663,3 +663,50 @@ export function formatChartMetricCompact(metric, val) {
|
|||||||
return String(val);
|
return String(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downsamples dense chronological step series (`> maxPoints`, e.g. 1,500–5,000 steps) to an
|
||||||
|
* adaptive visual vertex budget (`~2.1px` per segment) so cubic splines never overplot into an
|
||||||
|
* opaque solid wall while strictly preserving the start step, end step, and exact global peak step.
|
||||||
|
*
|
||||||
|
* @template {{ value?: number }} T
|
||||||
|
* @param {T[]} points
|
||||||
|
* @param {number} [maxPoints=208]
|
||||||
|
* @returns {T[]}
|
||||||
|
*/
|
||||||
|
export function downsampleStepPointsForPlot(points, maxPoints = 208) {
|
||||||
|
if (!Array.isArray(points) || points.length <= maxPoints || maxPoints < 8) {
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
const n = points.length;
|
||||||
|
let globalPeakIdx = -1;
|
||||||
|
let globalPeakVal = -Infinity;
|
||||||
|
for (let i = 0; i < n; i += 1) {
|
||||||
|
const v = Number(points[i]?.value);
|
||||||
|
if (Number.isFinite(v) && v >= globalPeakVal) {
|
||||||
|
globalPeakVal = v;
|
||||||
|
globalPeakIdx = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const out = [points[0]];
|
||||||
|
const bucketCount = maxPoints - 2;
|
||||||
|
const interiorLen = n - 2;
|
||||||
|
for (let b = 0; b < bucketCount; b += 1) {
|
||||||
|
const bStart = 1 + Math.floor((b * interiorLen) / bucketCount);
|
||||||
|
const bEnd = Math.max(bStart + 1, 1 + Math.floor(((b + 1) * interiorLen) / bucketCount));
|
||||||
|
const pickIdx =
|
||||||
|
globalPeakIdx >= bStart && globalPeakIdx < bEnd
|
||||||
|
? globalPeakIdx
|
||||||
|
: bStart + Math.floor((bEnd - bStart) / 2);
|
||||||
|
const picked = points[pickIdx];
|
||||||
|
if (picked && picked !== out[out.length - 1]) {
|
||||||
|
out.push(picked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const lastPt = points[n - 1];
|
||||||
|
if (lastPt && lastPt !== out[out.length - 1]) {
|
||||||
|
out.push(lastPt);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|||||||
@@ -820,6 +820,11 @@
|
|||||||
stroke-width: 1.9;
|
stroke-width: 1.9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sstep-line-card .sstep-chart-wrap.is-dense .trend-line,
|
||||||
|
.sstep-line-card .sstep-chart-wrap.is-dense .sstep-fit-line {
|
||||||
|
stroke-width: 1.45;
|
||||||
|
}
|
||||||
|
|
||||||
.sstep-multi-area {
|
.sstep-multi-area {
|
||||||
fill: var(--sstep-series-color, var(--ctx-cached));
|
fill: var(--sstep-series-color, var(--ctx-cached));
|
||||||
fill-opacity: 0.08;
|
fill-opacity: 0.08;
|
||||||
|
|||||||
@@ -5135,6 +5135,11 @@ html[data-standalone="true"] .app-shell {
|
|||||||
stroke-width: 1.9;
|
stroke-width: 1.9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sstep-line-card .sstep-chart-wrap.is-dense .trend-line,
|
||||||
|
.sstep-line-card .sstep-chart-wrap.is-dense .sstep-fit-line {
|
||||||
|
stroke-width: 1.45;
|
||||||
|
}
|
||||||
|
|
||||||
.sstep-multi-area {
|
.sstep-multi-area {
|
||||||
fill: var(--sstep-series-color, var(--ctx-cached));
|
fill: var(--sstep-series-color, var(--ctx-cached));
|
||||||
fill-opacity: 0.08;
|
fill-opacity: 0.08;
|
||||||
|
|||||||
@@ -630,6 +630,109 @@ test('SegmentedControl variable-width glider snaps cleanly on reveal and glides
|
|||||||
queuedRaf?.();
|
queuedRaf?.();
|
||||||
assert.equal(stepTipEl.classList.contains('is-tracking'), true);
|
assert.equal(stepTipEl.classList.contains('is-tracking'), true);
|
||||||
assert.equal(stepHoverDot.classList.contains('is-tracking'), true);
|
assert.equal(stepHoverDot.classList.contains('is-tracking'), true);
|
||||||
|
|
||||||
|
// High-density 2606-step session downsamples spline cleanly without turning into a 2600-segment wall, while keeping exact peak
|
||||||
|
const denseSteps = Array.from({ length: 2606 }, (_, i) => ({
|
||||||
|
stepIndex: 5500 + i,
|
||||||
|
createdAtMs: 1000 + i * 100,
|
||||||
|
modelLabel: i % 2 === 0 ? 'neon-4-xhigh' : 'carbon-4-high',
|
||||||
|
modelShort: i % 2 === 0 ? 'neon-4-xhigh' : 'carbon-4-high',
|
||||||
|
tokPerSec: i === 1963 ? 151 : 25 + ((i * 17) % 90),
|
||||||
|
inputTokens: 1000,
|
||||||
|
cacheReadTokens: 2000,
|
||||||
|
outputTokens: 100,
|
||||||
|
}));
|
||||||
|
stepLineChart.update({
|
||||||
|
steps: denseSteps,
|
||||||
|
modelGroupKey: 'neon-4-xhigh',
|
||||||
|
modelGroupKeys: ['neon-4-xhigh'],
|
||||||
|
metric: 'tps',
|
||||||
|
});
|
||||||
|
// Flush any morph animation to final path
|
||||||
|
if (queuedRaf) queuedRaf(performance.now() + 400);
|
||||||
|
const denseLineD = stepLineChart.el.querySelector('.trend-line').getAttribute('d') || '';
|
||||||
|
const cubicSegCount = (denseLineD.match(/ C /g) || []).length;
|
||||||
|
assert.ok(
|
||||||
|
cubicSegCount >= 120 && cubicSegCount <= 256,
|
||||||
|
`Expected adaptive downsampled cubic segment count in [120..256], got ${cubicSegCount}`
|
||||||
|
);
|
||||||
|
stepLineChart.update({
|
||||||
|
steps: denseSteps,
|
||||||
|
modelGroupKey: '__all__',
|
||||||
|
modelGroupKeys: ['__all__'],
|
||||||
|
metric: 'tps',
|
||||||
|
});
|
||||||
|
if (queuedRaf) queuedRaf(performance.now() + 400);
|
||||||
|
assert.match(stepLineChart.el.querySelector('.trend-peak-pill').textContent, /#7463.*151/);
|
||||||
|
|
||||||
|
// Switching from 1 model -> 2 models animates newly added model smoothly from baseline instead of snapping
|
||||||
|
globalThis.window.getComputedStyle = () => ({});
|
||||||
|
stepLineChart.update({
|
||||||
|
steps: denseSteps,
|
||||||
|
modelGroupKey: 'neon-4-xhigh',
|
||||||
|
modelGroupKeys: ['neon-4-xhigh'],
|
||||||
|
metric: 'tps',
|
||||||
|
});
|
||||||
|
if (queuedRaf) queuedRaf(performance.now() + 400);
|
||||||
|
queuedRaf = null;
|
||||||
|
stepLineChart.update({
|
||||||
|
steps: denseSteps,
|
||||||
|
modelGroupKey: 'neon-4-xhigh',
|
||||||
|
modelGroupKeys: ['neon-4-xhigh', 'carbon-4-high'],
|
||||||
|
metric: 'tps',
|
||||||
|
});
|
||||||
|
assert.equal(
|
||||||
|
typeof queuedRaf,
|
||||||
|
'function',
|
||||||
|
'Checking a 2nd model in SessionLineChart schedules a 240ms morph animation'
|
||||||
|
);
|
||||||
|
const multiPaths = stepLineChart.el.querySelectorAll('.sstep-multi-line-group .sstep-fit-line');
|
||||||
|
assert.equal(multiPaths.length, 2);
|
||||||
|
const carbonStartD = multiPaths[1].getAttribute('d') || '';
|
||||||
|
queuedRaf(performance.now() + 400);
|
||||||
|
const carbonEndD = multiPaths[1].getAttribute('d') || '';
|
||||||
|
assert.notEqual(carbonStartD, carbonEndD, 'Newly checked 2nd model morphs from baseline to target curve');
|
||||||
|
|
||||||
|
// High-density (>96 segments at 460px width) morph must NOT skip knots during animation or pop peaks up at completion
|
||||||
|
stepStage.clientWidth = 460;
|
||||||
|
stepLineChart.update({
|
||||||
|
steps: denseSteps,
|
||||||
|
modelGroupKey: '__all__',
|
||||||
|
modelGroupKeys: ['__all__'],
|
||||||
|
metric: 'totalTokens',
|
||||||
|
});
|
||||||
|
if (queuedRaf) queuedRaf(performance.now() + 400);
|
||||||
|
queuedRaf = null;
|
||||||
|
const morphStartTs = performance.now();
|
||||||
|
stepLineChart.update({
|
||||||
|
steps: denseSteps,
|
||||||
|
modelGroupKey: '__all__',
|
||||||
|
modelGroupKeys: ['__all__'],
|
||||||
|
metric: 'tps',
|
||||||
|
});
|
||||||
|
assert.equal(typeof queuedRaf, 'function');
|
||||||
|
queuedRaf(morphStartTs + 239.95);
|
||||||
|
const nearEndD = stepLineChart.el.querySelector('.trend-line').getAttribute('d') || '';
|
||||||
|
queuedRaf(morphStartTs + 300);
|
||||||
|
const exactEndD = stepLineChart.el.querySelector('.trend-line').getAttribute('d') || '';
|
||||||
|
const nearSegCount = (nearEndD.match(/ C /g) || []).length;
|
||||||
|
const exactSegCount = (exactEndD.match(/ C /g) || []).length;
|
||||||
|
assert.ok(
|
||||||
|
exactSegCount > 96 && nearSegCount >= exactSegCount,
|
||||||
|
'460px plot preserves >=100% of target knots during >96-segment morph without stride-2 skipping'
|
||||||
|
);
|
||||||
|
const parseEndpoints = (d) =>
|
||||||
|
[...d.matchAll(/([\d.]+)\s+([\d.]+)(?=\s*C|$)/g)].map((m) => ({ x: +m[1], y: +m[2] }));
|
||||||
|
const nearPts = parseEndpoints(nearEndD);
|
||||||
|
const exactPts = parseEndpoints(exactEndD);
|
||||||
|
for (const ep of exactPts) {
|
||||||
|
const minDy = nearPts.reduce(
|
||||||
|
(best, np) => (Math.abs(np.x - ep.x) <= 0.2 ? Math.min(best, Math.abs(np.y - ep.y)) : best),
|
||||||
|
Infinity
|
||||||
|
);
|
||||||
|
assert.ok(minDy <= 0.2, `Target vertex (${ep.x}, ${ep.y}) must not pop at completion (dy=${minDy})`);
|
||||||
|
}
|
||||||
|
delete globalThis.window.getComputedStyle;
|
||||||
stepLineChart.destroy();
|
stepLineChart.destroy();
|
||||||
|
|
||||||
const fitChart = createModelFitChart();
|
const fitChart = createModelFitChart();
|
||||||
|
|||||||
Reference in New Issue
Block a user