- An array of line objects to display on the chart.
+ An array of line objects to display on the chart. Each line has
+ label, data and optional color.
+
+
+ lines[].color
+
+
+ ChartLineColor.Red / ChartLineColor.LightGrey,
+ or any CSS color string ('#3F88FF', 'rgb(...)').
+ Omit it and the line stays red.
+
+
+
red, light-grey — built-in palette
+
any CSS color: '#3F88FF', '#00C853'
+
+
+
detalization
- Controls how timestamps are formatted on the X-axis legend and tooltip.
- Does not affect data aggregation — only the display format.
+ Grain of the X-axis and tooltip timestamps. Preview data follows the selected step.
-
'days' — shows day and month (e.g., "19 dec")
-
'hours' — shows day, month, and time (e.g., "19 dec, 14:00")
-
'minutes' — shows day, month, and time (e.g., "19 dec, 14:30")
+
'days' — 30 daily points, labels like "19 dec"
+
'hours' — 24 hourly points, labels like "19 dec, 14:00"
+
'minutes' — 60 minute points, labels like "14:30"
Try it:
@@ -39,6 +54,23 @@
/>
+
+
+
+ legend
+
+
+ Static series legend under the chart: color dot + label for each line.
+ Off by default so existing layouts stay the same.
+
+
+ Try it:
+
+
+
@@ -49,6 +81,7 @@
@@ -61,6 +94,23 @@
+
+
+
+
+ Many Series
+
+
+ Extra series via hex strings. Legend below, tooltip grows down from the axis.
+
+
+
+
@@ -69,7 +119,7 @@
diff --git a/@codexteam/ui/package.json b/@codexteam/ui/package.json
index 2550ce0f..d54b572f 100644
--- a/@codexteam/ui/package.json
+++ b/@codexteam/ui/package.json
@@ -1,6 +1,6 @@
{
"name": "@codexteam/ui",
- "version": "0.2.5",
+ "version": "0.2.6",
"type": "module",
"sideEffects": [
"*.css",
diff --git a/@codexteam/ui/src/vue/components/chart/Chart.colors.ts b/@codexteam/ui/src/vue/components/chart/Chart.colors.ts
index 3dd1a96e..d498217a 100644
--- a/@codexteam/ui/src/vue/components/chart/Chart.colors.ts
+++ b/@codexteam/ui/src/vue/components/chart/Chart.colors.ts
@@ -1,5 +1,5 @@
import { ChartLineColor } from './Chart.types';
-import type { ChartLineColors } from './Chart.types';
+import type { ChartLineColorToken, ChartLineColors } from './Chart.types';
/**
* Colors for dark color scheme.
@@ -44,3 +44,95 @@ export const chartColorsLight: ChartLineColors[] = [
pointerColor: '#FF4A68',
},
];
+
+/**
+ * Clamp a color channel to 0–255
+ *
+ * @param value - parsed channel
+ */
+function clampChannel(value: number): number {
+ if (!Number.isFinite(value)) {
+ return 0;
+ }
+
+ return Math.max(0, Math.min(255, Math.round(value)));
+}
+
+/**
+ * Parse #RGB or #RRGGBB only. Anything else is rejected — never pass raw CSS through.
+ *
+ * @param color - CSS color string
+ */
+function parseHexColor(color: string): { r: number; g: number; b: number } | null {
+ const value = color.trim();
+ const shortHex = /^#([0-9a-fA-F]{3})$/.exec(value);
+
+ if (shortHex) {
+ const [r, g, b] = shortHex[1].split('');
+
+ return {
+ r: parseInt(r + r, 16),
+ g: parseInt(g + g, 16),
+ b: parseInt(b + b, 16),
+ };
+ }
+
+ const longHex = /^#([0-9a-fA-F]{6})$/.exec(value);
+
+ if (longHex) {
+ return {
+ r: parseInt(longHex[1].slice(0, 2), 16),
+ g: parseInt(longHex[1].slice(2, 4), 16),
+ b: parseInt(longHex[1].slice(4, 6), 16),
+ };
+ }
+
+ return null;
+}
+
+/**
+ * Build a gradient set from a hex color. Returns null if the string is not a hex.
+ *
+ * @param color - CSS color string
+ */
+export function createChartLineColorsFromCss(color: string): ChartLineColors | null {
+ const parsed = parseHexColor(color);
+
+ if (!parsed) {
+ return null;
+ }
+
+ const r = clampChannel(parsed.r);
+ const g = clampChannel(parsed.g);
+ const b = clampChannel(parsed.b);
+
+ return {
+ name: `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`,
+ strokeStart: `rgb(${r}, ${g}, ${b})`,
+ strokeEnd: `rgba(${r}, ${g}, ${b}, 0.22)`,
+ fillStart: `rgba(${r}, ${g}, ${b}, 0.26)`,
+ fillEnd: `rgba(${r}, ${g}, ${b}, 0)`,
+ pointerColor: `rgb(${r}, ${g}, ${b})`,
+ };
+}
+
+/**
+ * Resolve a line color: palette token or hex. Invalid values fall back to red.
+ *
+ * @param color - palette token or hex
+ * @param palette - dark/light chart palette
+ */
+export function resolveChartLineColor(
+ color: ChartLineColorToken | undefined,
+ palette: ChartLineColors[]
+): ChartLineColors {
+ const fallback = palette.find(c => c.name === ChartLineColor.Red) ?? palette[0];
+ const colorName = color ?? ChartLineColor.Red;
+ const fromPalette = palette.find(c => c.name === colorName);
+
+ if (fromPalette) {
+ return fromPalette;
+ }
+
+ return createChartLineColorsFromCss(String(colorName)) ?? fallback;
+}
diff --git a/@codexteam/ui/src/vue/components/chart/Chart.types.ts b/@codexteam/ui/src/vue/components/chart/Chart.types.ts
index d29562e1..7ab3b964 100644
--- a/@codexteam/ui/src/vue/components/chart/Chart.types.ts
+++ b/@codexteam/ui/src/vue/components/chart/Chart.types.ts
@@ -13,6 +13,11 @@ export enum ChartLineColor {
LightGrey = 'light-grey'
}
+/**
+ * Palette token (`red` / `light-grey`) or a CSS hex/rgb color string.
+ */
+export type ChartLineColorToken = ChartLineColor | (string & {});
+
/**
* Chart element in common case
*/
@@ -43,9 +48,10 @@ export interface ChartLine {
data: ChartItem[];
/**
- * Name of the color for the line stroke and fill.
+ * Line color: a ChartLineColor token, or any CSS color string.
+ * Defaults to red when omitted.
*/
- color?: ChartLineColor;
+ color?: ChartLineColorToken;
}
/**
@@ -53,9 +59,9 @@ export interface ChartLine {
*/
export interface ChartLineColors {
/**
- * Name of the color
+ * Name of the color (palette token or the original CSS color)
*/
- name: ChartLineColor;
+ name: string;
/**
* Starting color for stroke gradient (top)
*/
diff --git a/@codexteam/ui/src/vue/components/chart/Chart.vue b/@codexteam/ui/src/vue/components/chart/Chart.vue
index fe592be8..5275c0a2 100644
--- a/@codexteam/ui/src/vue/components/chart/Chart.vue
+++ b/@codexteam/ui/src/vue/components/chart/Chart.vue
@@ -1,87 +1,101 @@
-