Skip to content

Commit 26888bd

Browse files
committed
various fixes
1 parent effb40e commit 26888bd

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/filters/filters.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ const filters = {
6161
}),
6262
calibrate_linear:
6363
(mappingStr: `${number} -> ${number}`[]) =>
64-
({ ys }) => {
64+
({ ys, meta }) => {
6565
const mapping = mappingStr.map((str) => str.split("->").map(parseFloat));
66-
const mapper = linearRegressionLine(linearRegression(mapping));
66+
const regression = linearRegression(mapping);
67+
const mapper = linearRegressionLine(regression);
6768
return {
6869
ys: mapNumbers(ys, mapper),
70+
meta: { ...meta, regression },
6971
};
7072
},
7173
derivate:
@@ -141,7 +143,7 @@ const filters = {
141143
ys2.push(acc.y / acc.count);
142144
}
143145
}
144-
return { xs, ys, ...rest };
146+
return { xs: xs2, ys: ys2, ...rest };
145147
},
146148
median:
147149
({ window_size = 10, extended = false, centered = true } = {}) =>
@@ -192,7 +194,7 @@ const filters = {
192194
});
193195
},
194196
map_y: (fnStr: string) => {
195-
const fn = myEval(`(i, x, y, state, statistic) => ${fnStr}`);
197+
const fn = myEval(`(i, x, y, state, statistic, vars) => ${fnStr}`);
196198
return ({ xs, ys, states, statistics, vars }) => ({
197199
xs,
198200
ys: ys.map((_, i) => fn(i, xs[i], ys[i], states[i], statistics[i], vars)),

src/plotly-graph-card.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,11 @@ export class PlotlyGraph extends HTMLElement {
429429
try {
430430
for (const filter of trace.filters) {
431431
data = { ...data, ...filter(data) };
432+
vars = data.vars;
432433
}
433434
} catch (e) {
434-
throw new Error(`Error in filter `);
435+
console.error(e);
436+
throw new Error(`Error in filter: ${e}`);
435437
}
436438
}
437439
if (trace.lambda) {
@@ -453,6 +455,7 @@ export class PlotlyGraph extends HTMLElement {
453455
console.error(e);
454456
}
455457
}
458+
if (trace.internal) return;
456459
if (!this.isBrowsing) {
457460
// to ensure the y axis autoranges to the visible data
458461
removeOutOfRange(data, this.getAutoFetchRangeWithValueMargins());
@@ -492,8 +495,8 @@ export class PlotlyGraph extends HTMLElement {
492495
},
493496
trace
494497
);
495-
if (!trace.internal) real_traces.push(mergedTrace);
496-
if (!trace.internal && mergedTrace.show_value) {
498+
real_traces.push(mergedTrace);
499+
if (mergedTrace.show_value) {
497500
mergedTrace.legendgroup ??= "group" + traceIdx;
498501
show_value_traces.push({
499502
texttemplate: `%{y:.2~f}%{customdata.unit_of_measurement}`, // here so it can be overwritten

0 commit comments

Comments
 (0)