@qfo/qfchart 0.8.4 → 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,39 +1,39 @@
1
- import { SeriesRenderer, RenderContext } from './SeriesRenderer';
2
-
3
- export class StepRenderer implements SeriesRenderer {
4
- render(context: RenderContext): any {
5
- const { seriesName, xAxisIndex, yAxisIndex, dataArray, colorArray, plotOptions } = context;
6
- const defaultColor = '#2962ff';
7
-
8
- return {
9
- name: seriesName,
10
- type: 'custom',
11
- xAxisIndex: xAxisIndex,
12
- yAxisIndex: yAxisIndex,
13
- renderItem: (params: any, api: any) => {
14
- const x = api.value(0);
15
- const y = api.value(1);
16
- if (isNaN(y) || y === null) return;
17
-
18
- const coords = api.coord([x, y]);
19
- const width = api.size([1, 0])[0];
20
-
21
- return {
22
- type: 'line',
23
- shape: {
24
- x1: coords[0] - width / 2,
25
- y1: coords[1],
26
- x2: coords[0] + width / 2,
27
- y2: coords[1],
28
- },
29
- style: {
30
- stroke: colorArray[params.dataIndex] || plotOptions.color || defaultColor,
31
- lineWidth: plotOptions.linewidth || 1,
32
- },
33
- silent: true,
34
- };
35
- },
36
- data: dataArray.map((val, i) => [i, val]),
37
- };
38
- }
39
- }
1
+ import { SeriesRenderer, RenderContext } from './SeriesRenderer';
2
+
3
+ export class StepRenderer implements SeriesRenderer {
4
+ render(context: RenderContext): any {
5
+ const { seriesName, xAxisIndex, yAxisIndex, dataArray, colorArray, plotOptions } = context;
6
+ const defaultColor = '#2962ff';
7
+
8
+ return {
9
+ name: seriesName,
10
+ type: 'custom',
11
+ xAxisIndex: xAxisIndex,
12
+ yAxisIndex: yAxisIndex,
13
+ renderItem: (params: any, api: any) => {
14
+ const x = api.value(0);
15
+ const y = api.value(1);
16
+ if (isNaN(y) || y === null) return;
17
+
18
+ const coords = api.coord([x, y]);
19
+ const width = api.size([1, 0])[0];
20
+
21
+ return {
22
+ type: 'line',
23
+ shape: {
24
+ x1: coords[0] - width / 2,
25
+ y1: coords[1],
26
+ x2: coords[0] + width / 2,
27
+ y2: coords[1],
28
+ },
29
+ style: {
30
+ stroke: colorArray[params.dataIndex] || plotOptions.color || defaultColor,
31
+ lineWidth: plotOptions.linewidth || 1,
32
+ },
33
+ silent: true,
34
+ };
35
+ },
36
+ data: dataArray.map((val, i) => [i, val]),
37
+ };
38
+ }
39
+ }
@@ -36,10 +36,11 @@ export class ColorUtils {
36
36
  };
37
37
  }
38
38
 
39
- // For 6-digit hex or named colors, default opacity to 0.3 for fill areas
39
+ // For 6-digit hex or named colors, return full opacity.
40
+ // Individual renderers (fill, gradient) apply their own opacity as needed.
40
41
  return {
41
42
  color: colorStr,
42
- opacity: 0.3,
43
+ opacity: 1.0,
43
44
  };
44
45
  }
45
46
 
@@ -74,4 +75,35 @@ export class ColorUtils {
74
75
  // Fallback: return color as-is
75
76
  return color;
76
77
  }
78
+
79
+ /**
80
+ * Parse a color string into {r, g, b} components.
81
+ */
82
+ private static toRGB(color: string): { r: number; g: number; b: number } {
83
+ const rgbMatch = color.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
84
+ if (rgbMatch) return { r: +rgbMatch[1], g: +rgbMatch[2], b: +rgbMatch[3] };
85
+
86
+ const hexMatch = color.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/);
87
+ if (hexMatch) return { r: parseInt(hexMatch[1], 16), g: parseInt(hexMatch[2], 16), b: parseInt(hexMatch[3], 16) };
88
+
89
+ return { r: 128, g: 128, b: 128 };
90
+ }
91
+
92
+ /**
93
+ * Linearly interpolate between two colors at a given t (0 = colorA, 1 = colorB).
94
+ * Returns an rgba() string.
95
+ */
96
+ public static interpolateColor(
97
+ colorA: string, opacityA: number,
98
+ colorB: string, opacityB: number,
99
+ t: number,
100
+ ): string {
101
+ const a = this.toRGB(colorA);
102
+ const b = this.toRGB(colorB);
103
+ const r = Math.round(a.r + (b.r - a.r) * t);
104
+ const g = Math.round(a.g + (b.g - a.g) * t);
105
+ const bl = Math.round(a.b + (b.b - a.b) * t);
106
+ const op = opacityA + (opacityB - opacityA) * t;
107
+ return `rgba(${r},${g},${bl},${op})`;
108
+ }
77
109
  }
@@ -47,6 +47,11 @@ export class ShapeUtils {
47
47
  case 'shape_label_up':
48
48
  return 'path://M12 1l2 3h8a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-20a1 1 0 0 1-1-1v-14a1 1 0 0 1 1-1h8z';
49
49
 
50
+ case 'labelcenter':
51
+ case 'shape_label_center':
52
+ // Rounded rectangle with no pointer — centered at anchor
53
+ return 'path://M1 1h22a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-22a1 1 0 0 1-1-1v-16a1 1 0 0 1 1-1z';
54
+
50
55
  case 'square':
51
56
  case 'shape_square':
52
57
  return 'rect';