@dschz/solid-uplot
Version:
SolidJS wrapper for uPlot — ultra-fast, tiny time-series & charting library
40 lines (37 loc) • 1.14 kB
JavaScript
// src/utils/getCursorData.ts
var getCursorData = (u) => {
const idx = u.cursor.idx;
const xValues = u.data[0];
const isValid = idx != null && xValues && idx < xValues.length;
return !isValid ? void 0 : {
plotId: u.root.id,
idx,
xValue: xValues[idx],
visible: Boolean(u.cursor.show),
position: { left: u.cursor.left || 0, top: u.cursor.top || 0 }
};
};
// src/utils/getSeriesData.ts
var getSeriesData = (u, options = {}) => {
const series = [];
for (let i = 1; i < u.series.length; i++) {
const s = u.series[i];
const stroke = typeof s.stroke === "function" ? s.stroke(u, i) : s.stroke;
const fill = typeof s.fill === "function" ? s.fill(u, i) : s.fill;
const label = options.labelTransform?.(s.label) || s.label?.toString() || `Series ${i}`;
series.push({
idx: i - 1,
seriesIdx: i,
label,
stroke: stroke ?? "#000",
fill: fill ?? "transparent",
width: s.width,
dash: s.dash,
scale: s.scale,
visible: Boolean(s.show)
});
}
return series;
};
// istanbul ignore next -- @preserve
export { getCursorData, getSeriesData };