mirror of
https://github.com/samsonjs/spirit-tracker.git
synced 2026-04-27 15:07:43 +00:00
UX Improvements
This commit is contained in:
parent
a2c91eb6c7
commit
4db1d33f8a
3 changed files with 52 additions and 10 deletions
|
|
@ -668,20 +668,24 @@ export async function renderItem($app, skuInput) {
|
||||||
const colorMap = buildStoreColorMap(series.map((s) => s.label));
|
const colorMap = buildStoreColorMap(series.map((s) => s.label));
|
||||||
|
|
||||||
const datasets = series.map((s) => {
|
const datasets = series.map((s) => {
|
||||||
const c = storeColor(s.label, colorMap);
|
const base = storeColor(s.label, colorMap);
|
||||||
|
const stroke = lighten(base, 0.25);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
label: s.label,
|
label: s.label,
|
||||||
data: labels.map((d) => (s.points.has(d) ? s.points.get(d) : null)),
|
data: labels.map((d) => (s.points.has(d) ? s.points.get(d) : null)),
|
||||||
spanGaps: false,
|
spanGaps: false,
|
||||||
tension: 0.15,
|
tension: 0.15,
|
||||||
|
|
||||||
borderColor: c,
|
backgroundColor: base,
|
||||||
backgroundColor: c,
|
borderColor: stroke,
|
||||||
pointBackgroundColor: c,
|
pointBackgroundColor: base,
|
||||||
pointBorderColor: c,
|
pointBorderColor: stroke,
|
||||||
|
borderWidth: datasetStrokeWidth(base),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const ctx = $canvas.getContext("2d");
|
const ctx = $canvas.getContext("2d");
|
||||||
CHART = new Chart(ctx, {
|
CHART = new Chart(ctx, {
|
||||||
type: "line",
|
type: "line",
|
||||||
|
|
|
||||||
|
|
@ -695,17 +695,20 @@ export async function renderStats($app) {
|
||||||
const colorMap = buildStoreColorMap(stores);
|
const colorMap = buildStoreColorMap(stores);
|
||||||
|
|
||||||
const datasets = stores.map((s) => {
|
const datasets = stores.map((s) => {
|
||||||
const c = storeColor(s, colorMap);
|
const base = storeColor(s, colorMap);
|
||||||
|
const stroke = lighten(base, 0.25);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
label: displayStoreName(s),
|
label: displayStoreName(s),
|
||||||
data: Array.isArray(seriesByStore[s]) ? seriesByStore[s] : labels.map(() => null),
|
data: Array.isArray(seriesByStore[s]) ? seriesByStore[s] : labels.map(() => null),
|
||||||
spanGaps: false,
|
spanGaps: false,
|
||||||
tension: 0.15,
|
tension: 0.15,
|
||||||
|
|
||||||
borderColor: c,
|
backgroundColor: base,
|
||||||
backgroundColor: c,
|
borderColor: stroke,
|
||||||
pointBackgroundColor: c,
|
pointBackgroundColor: base,
|
||||||
pointBorderColor: c,
|
pointBorderColor: stroke,
|
||||||
|
borderWidth: datasetStrokeWidth(base),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,4 +127,39 @@ function normalizeId(s) {
|
||||||
export function datasetPointRadius(color) {
|
export function datasetPointRadius(color) {
|
||||||
return isWhiteHex(color) ? 2.8 : 2.2;
|
return isWhiteHex(color) ? 2.8 : 2.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clamp(v, lo, hi) {
|
||||||
|
return Math.max(lo, Math.min(hi, v));
|
||||||
|
}
|
||||||
|
|
||||||
|
function hexToRgb(hex) {
|
||||||
|
const m = String(hex).replace("#", "");
|
||||||
|
if (m.length !== 6) return null;
|
||||||
|
const n = parseInt(m, 16);
|
||||||
|
return {
|
||||||
|
r: (n >> 16) & 255,
|
||||||
|
g: (n >> 8) & 255,
|
||||||
|
b: n & 255,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function rgbToHex({ r, g, b }) {
|
||||||
|
const h = (x) => clamp(Math.round(x), 0, 255).toString(16).padStart(2, "0");
|
||||||
|
return `#${h(r)}${h(g)}${h(b)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// lighten by mixing with white (amount 0–1)
|
||||||
|
export function lighten(hex, amount = 0.25) {
|
||||||
|
const rgb = hexToRgb(hex);
|
||||||
|
if (!rgb) return hex;
|
||||||
|
return rgbToHex({
|
||||||
|
r: rgb.r + (255 - rgb.r) * amount,
|
||||||
|
g: rgb.g + (255 - rgb.g) * amount,
|
||||||
|
b: rgb.b + (255 - rgb.b) * amount,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function datasetStrokeWidth(color) {
|
||||||
|
return String(color).toUpperCase() === "#FFFFFF" ? 2.5 : 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in a new issue