@oh-my-pi/pi-utils 16.0.7 → 16.0.8
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.
- package/CHANGELOG.md +10 -0
- package/dist/types/mermaid-ascii.d.ts +1 -1
- package/dist/types/vendor/mermaid-ascii/ascii/ansi.d.ts +41 -0
- package/dist/types/vendor/mermaid-ascii/ascii/canvas.d.ts +89 -0
- package/dist/types/vendor/mermaid-ascii/ascii/class-diagram.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/converter.d.ts +12 -0
- package/dist/types/vendor/mermaid-ascii/ascii/draw.d.ts +66 -0
- package/dist/types/vendor/mermaid-ascii/ascii/edge-bundling.d.ts +48 -0
- package/dist/types/vendor/mermaid-ascii/ascii/edge-routing.d.ts +43 -0
- package/dist/types/vendor/mermaid-ascii/ascii/er-diagram.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/grid.d.ts +56 -0
- package/dist/types/vendor/mermaid-ascii/ascii/index.d.ts +65 -0
- package/dist/types/vendor/mermaid-ascii/ascii/multiline-utils.d.ts +27 -0
- package/dist/types/vendor/mermaid-ascii/ascii/pathfinder.d.ts +17 -0
- package/dist/types/vendor/mermaid-ascii/ascii/sequence.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/circle.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/corners.d.ts +34 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/diamond.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/hexagon.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/index.d.ts +26 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/rectangle.d.ts +31 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/rounded.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/special.d.ts +59 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/stadium.d.ts +17 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/state.d.ts +30 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/types.d.ts +55 -0
- package/dist/types/vendor/mermaid-ascii/ascii/types.d.ts +206 -0
- package/dist/types/vendor/mermaid-ascii/ascii/validate.d.ts +51 -0
- package/dist/types/vendor/mermaid-ascii/ascii/xychart.d.ts +2 -0
- package/dist/types/vendor/mermaid-ascii/class/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/class/types.d.ts +102 -0
- package/dist/types/vendor/mermaid-ascii/er/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/er/types.d.ts +76 -0
- package/dist/types/vendor/mermaid-ascii/index.d.ts +1 -0
- package/dist/types/vendor/mermaid-ascii/multiline-utils.d.ts +9 -0
- package/dist/types/vendor/mermaid-ascii/parser.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/sequence/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/sequence/types.d.ts +130 -0
- package/dist/types/vendor/mermaid-ascii/text-metrics.d.ts +21 -0
- package/dist/types/vendor/mermaid-ascii/types.d.ts +114 -0
- package/dist/types/vendor/mermaid-ascii/xychart/colors.d.ts +25 -0
- package/dist/types/vendor/mermaid-ascii/xychart/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/xychart/types.d.ts +145 -0
- package/package.json +2 -3
- package/src/mermaid-ascii.ts +1 -1
- package/src/vendor/mermaid-ascii/NOTICE +33 -0
- package/src/vendor/mermaid-ascii/ascii/ansi.ts +409 -0
- package/src/vendor/mermaid-ascii/ascii/canvas.ts +476 -0
- package/src/vendor/mermaid-ascii/ascii/class-diagram.ts +699 -0
- package/src/vendor/mermaid-ascii/ascii/converter.ts +271 -0
- package/src/vendor/mermaid-ascii/ascii/draw.ts +1382 -0
- package/src/vendor/mermaid-ascii/ascii/edge-bundling.ts +328 -0
- package/src/vendor/mermaid-ascii/ascii/edge-routing.ts +297 -0
- package/src/vendor/mermaid-ascii/ascii/er-diagram.ts +441 -0
- package/src/vendor/mermaid-ascii/ascii/grid.ts +578 -0
- package/src/vendor/mermaid-ascii/ascii/index.ts +187 -0
- package/src/vendor/mermaid-ascii/ascii/multiline-utils.ts +78 -0
- package/src/vendor/mermaid-ascii/ascii/pathfinder.ts +215 -0
- package/src/vendor/mermaid-ascii/ascii/sequence.ts +460 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/circle.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/corners.ts +127 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/diamond.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/hexagon.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/index.ts +101 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/rectangle.ts +175 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/rounded.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/special.ts +296 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/stadium.ts +114 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/state.ts +192 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/types.ts +73 -0
- package/src/vendor/mermaid-ascii/ascii/types.ts +273 -0
- package/src/vendor/mermaid-ascii/ascii/validate.ts +120 -0
- package/src/vendor/mermaid-ascii/ascii/xychart.ts +875 -0
- package/src/vendor/mermaid-ascii/class/parser.ts +290 -0
- package/src/vendor/mermaid-ascii/class/types.ts +121 -0
- package/src/vendor/mermaid-ascii/er/parser.ts +181 -0
- package/src/vendor/mermaid-ascii/er/types.ts +91 -0
- package/src/vendor/mermaid-ascii/index.ts +14 -0
- package/src/vendor/mermaid-ascii/multiline-utils.ts +30 -0
- package/src/vendor/mermaid-ascii/parser.ts +645 -0
- package/src/vendor/mermaid-ascii/sequence/parser.ts +207 -0
- package/src/vendor/mermaid-ascii/sequence/types.ts +146 -0
- package/src/vendor/mermaid-ascii/text-metrics.ts +71 -0
- package/src/vendor/mermaid-ascii/types.ts +164 -0
- package/src/vendor/mermaid-ascii/xychart/colors.ts +140 -0
- package/src/vendor/mermaid-ascii/xychart/parser.ts +115 -0
- package/src/vendor/mermaid-ascii/xychart/types.ts +150 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// XY Chart — shared color palette
|
|
3
|
+
//
|
|
4
|
+
// Generates monochromatic shades from the theme accent color.
|
|
5
|
+
// Series 0 = accent (or blue fallback). Series 1+ are darker/lighter
|
|
6
|
+
// shades of the same hue with subtle hue drift to stay in the same
|
|
7
|
+
// color family (like navy ↔ cyan from blue).
|
|
8
|
+
//
|
|
9
|
+
// Used by both the SVG and ASCII renderers.
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
/** Default accent for charts when the theme doesn't provide one. */
|
|
13
|
+
export const CHART_ACCENT_FALLBACK = '#3b82f6' // blue-500
|
|
14
|
+
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// HSL ↔ Hex conversion
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
function hexToHsl(hex: string): [number, number, number] {
|
|
20
|
+
const h = hex.replace('#', '')
|
|
21
|
+
const ri = parseInt(h.substring(0, 2), 16) / 255
|
|
22
|
+
const gi = parseInt(h.substring(2, 4), 16) / 255
|
|
23
|
+
const bi = parseInt(h.substring(4, 6), 16) / 255
|
|
24
|
+
|
|
25
|
+
const max = Math.max(ri, gi, bi)
|
|
26
|
+
const min = Math.min(ri, gi, bi)
|
|
27
|
+
const l = (max + min) / 2
|
|
28
|
+
|
|
29
|
+
if (max === min) return [0, 0, l * 100]
|
|
30
|
+
|
|
31
|
+
const d = max - min
|
|
32
|
+
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min)
|
|
33
|
+
|
|
34
|
+
let hue: number
|
|
35
|
+
if (max === ri) hue = ((gi - bi) / d + (gi < bi ? 6 : 0)) / 6
|
|
36
|
+
else if (max === gi) hue = ((bi - ri) / d + 2) / 6
|
|
37
|
+
else hue = ((ri - gi) / d + 4) / 6
|
|
38
|
+
|
|
39
|
+
return [hue * 360, s * 100, l * 100]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function hslToHex(h: number, s: number, l: number): string {
|
|
43
|
+
const si = s / 100
|
|
44
|
+
const li = l / 100
|
|
45
|
+
|
|
46
|
+
const c = (1 - Math.abs(2 * li - 1)) * si
|
|
47
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1))
|
|
48
|
+
const m = li - c / 2
|
|
49
|
+
|
|
50
|
+
let r: number, g: number, b: number
|
|
51
|
+
if (h < 60) { r = c; g = x; b = 0 }
|
|
52
|
+
else if (h < 120) { r = x; g = c; b = 0 }
|
|
53
|
+
else if (h < 180) { r = 0; g = c; b = x }
|
|
54
|
+
else if (h < 240) { r = 0; g = x; b = c }
|
|
55
|
+
else if (h < 300) { r = x; g = 0; b = c }
|
|
56
|
+
else { r = c; g = 0; b = x }
|
|
57
|
+
|
|
58
|
+
const toHex = (v: number) => Math.round((v + m) * 255).toString(16).padStart(2, '0')
|
|
59
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
// Hex ↔ RGB conversion
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
|
|
66
|
+
function hexToRgb(hex: string): [number, number, number] {
|
|
67
|
+
const h = hex.replace('#', '')
|
|
68
|
+
return [
|
|
69
|
+
parseInt(h.substring(0, 2), 16),
|
|
70
|
+
parseInt(h.substring(2, 4), 16),
|
|
71
|
+
parseInt(h.substring(4, 6), 16),
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function rgbToHex(r: number, g: number, b: number): string {
|
|
76
|
+
const toHex = (v: number) => Math.round(Math.max(0, Math.min(255, v))).toString(16).padStart(2, '0')
|
|
77
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
// Public API
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
|
|
84
|
+
/** Check whether a string is a valid 6-digit hex color (e.g. "#3b82f6"). */
|
|
85
|
+
export function isValidHex(color: string): boolean {
|
|
86
|
+
return /^#[0-9a-fA-F]{6}$/.test(color)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Detect whether a background color is dark (lightness < 50%).
|
|
91
|
+
*/
|
|
92
|
+
export function isDarkBackground(bgHex: string): boolean {
|
|
93
|
+
return hexToHsl(bgHex)[2] < 50
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Mix two hex colors in RGB space.
|
|
98
|
+
* `ratio` controls how much of `fgHex` shows: 0 = pure bg, 1 = pure fg.
|
|
99
|
+
* Equivalent to alpha-compositing fg over bg at the given opacity.
|
|
100
|
+
*/
|
|
101
|
+
export function mixHexColors(bgHex: string, fgHex: string, ratio: number): string {
|
|
102
|
+
const [br, bg, bb] = hexToRgb(bgHex)
|
|
103
|
+
const [fr, fg, fb] = hexToRgb(fgHex)
|
|
104
|
+
const inv = 1 - ratio
|
|
105
|
+
return rgbToHex(br * inv + fr * ratio, bg * inv + fg * ratio, bb * inv + fb * ratio)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get the hex color for a series index.
|
|
110
|
+
* Index 0 returns the accent color as-is.
|
|
111
|
+
* Index 1+ alternate between darker and lighter shades of the same hue
|
|
112
|
+
* with subtle hue drift (±8-12° per tier) to stay in the same family.
|
|
113
|
+
*
|
|
114
|
+
* When `bgColor` is provided, shade direction adapts to the background:
|
|
115
|
+
* - Light bg: odd = darker, even = lighter (default)
|
|
116
|
+
* - Dark bg: odd = lighter, even = darker (so shades stay visible)
|
|
117
|
+
*/
|
|
118
|
+
export function getSeriesColor(index: number, accentColor: string, bgColor?: string): string {
|
|
119
|
+
if (index === 0) return accentColor
|
|
120
|
+
// Fall back to defaults when inputs aren't valid hex (e.g. CSS variable refs like "var(--accent)")
|
|
121
|
+
const safeAccent = isValidHex(accentColor) ? accentColor : CHART_ACCENT_FALLBACK
|
|
122
|
+
const safeBg = bgColor && isValidHex(bgColor) ? bgColor : undefined
|
|
123
|
+
const [h, s] = hexToHsl(safeAccent)
|
|
124
|
+
const chartS = Math.max(55, Math.min(85, s))
|
|
125
|
+
|
|
126
|
+
const tier = Math.ceil(index / 2)
|
|
127
|
+
const oddIndex = index % 2 === 1
|
|
128
|
+
|
|
129
|
+
// On dark backgrounds, flip: odd = lighter, even = darker
|
|
130
|
+
const dark = safeBg && isDarkBackground(safeBg) ? !oddIndex : oddIndex
|
|
131
|
+
const l = dark
|
|
132
|
+
? Math.max(25, 48 - tier * 13)
|
|
133
|
+
: Math.min(78, 55 + tier * 11)
|
|
134
|
+
|
|
135
|
+
// Subtle hue drift: darker shades shift slightly negative, lighter shift positive
|
|
136
|
+
const hShift = (dark ? -8 : 12) * tier
|
|
137
|
+
const newH = ((h + hShift) % 360 + 360) % 360
|
|
138
|
+
|
|
139
|
+
return hslToHex(newH, chartS, l)
|
|
140
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { XYChart, XYAxis, XYChartSeries } from './types'
|
|
2
|
+
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// XY Chart parser
|
|
5
|
+
//
|
|
6
|
+
// Parses Mermaid xychart-beta syntax into a typed XYChart structure.
|
|
7
|
+
//
|
|
8
|
+
// Supported directives:
|
|
9
|
+
// xychart-beta [horizontal]
|
|
10
|
+
// title "Chart Title"
|
|
11
|
+
// x-axis [label1, label2, ...] — categorical
|
|
12
|
+
// x-axis min --> max — numeric range
|
|
13
|
+
// x-axis "Axis Title" [label1, ...] — with title
|
|
14
|
+
// x-axis "Axis Title" min --> max — with title
|
|
15
|
+
// y-axis (same patterns)
|
|
16
|
+
// bar [val1, val2, ...]
|
|
17
|
+
// line [val1, val2, ...]
|
|
18
|
+
// ============================================================================
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Parse a Mermaid xychart-beta diagram from preprocessed lines.
|
|
22
|
+
* Lines should already be trimmed and comment-stripped.
|
|
23
|
+
*/
|
|
24
|
+
export function parseXYChart(lines: string[]): XYChart {
|
|
25
|
+
const xAxis: XYAxis = {}
|
|
26
|
+
const yAxis: XYAxis = {}
|
|
27
|
+
const series: XYChartSeries[] = []
|
|
28
|
+
let title: string | undefined
|
|
29
|
+
let horizontal = false
|
|
30
|
+
|
|
31
|
+
for (const line of lines) {
|
|
32
|
+
// Header line — detect horizontal
|
|
33
|
+
if (/^xychart(-beta)?\b/i.test(line)) {
|
|
34
|
+
if (/\bhorizontal\b/i.test(line)) horizontal = true
|
|
35
|
+
continue
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Title
|
|
39
|
+
const titleMatch = line.match(/^title\s+"([^"]+)"/)
|
|
40
|
+
if (titleMatch) {
|
|
41
|
+
title = titleMatch[1]
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// x-axis with categories: x-axis "Title" [a, b, c] or x-axis [a, b, c]
|
|
46
|
+
const xCatMatch = line.match(/^x-axis\s+(?:"([^"]*)"\s*)?\[([^\]]+)\]/)
|
|
47
|
+
if (xCatMatch) {
|
|
48
|
+
if (xCatMatch[1]) xAxis.title = xCatMatch[1]
|
|
49
|
+
xAxis.categories = xCatMatch[2]!.split(',').map(s => s.trim())
|
|
50
|
+
continue
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// x-axis with range: x-axis "Title" min --> max or x-axis min --> max
|
|
54
|
+
const xRangeMatch = line.match(/^x-axis\s+(?:"([^"]*)"\s+)?(-?\d+(?:\.\d+)?)\s*-->\s*(-?\d+(?:\.\d+)?)/)
|
|
55
|
+
if (xRangeMatch) {
|
|
56
|
+
if (xRangeMatch[1]) xAxis.title = xRangeMatch[1]
|
|
57
|
+
xAxis.range = { min: parseFloat(xRangeMatch[2]!), max: parseFloat(xRangeMatch[3]!) }
|
|
58
|
+
continue
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// y-axis with range: y-axis "Title" min --> max or y-axis min --> max
|
|
62
|
+
const yRangeMatch = line.match(/^y-axis\s+(?:"([^"]*)"\s+)?(-?\d+(?:\.\d+)?)\s*-->\s*(-?\d+(?:\.\d+)?)/)
|
|
63
|
+
if (yRangeMatch) {
|
|
64
|
+
if (yRangeMatch[1]) yAxis.title = yRangeMatch[1]
|
|
65
|
+
yAxis.range = { min: parseFloat(yRangeMatch[2]!), max: parseFloat(yRangeMatch[3]!) }
|
|
66
|
+
continue
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// y-axis with just title (no range)
|
|
70
|
+
const yTitleOnly = line.match(/^y-axis\s+"([^"]+)"\s*$/)
|
|
71
|
+
if (yTitleOnly) {
|
|
72
|
+
yAxis.title = yTitleOnly[1]
|
|
73
|
+
continue
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// bar [...]
|
|
77
|
+
const barMatch = line.match(/^bar\s+\[([^\]]+)\]/)
|
|
78
|
+
if (barMatch) {
|
|
79
|
+
series.push({ type: 'bar', data: parseNumericArray(barMatch[1]!) })
|
|
80
|
+
continue
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// line [...]
|
|
84
|
+
const lineMatch = line.match(/^line\s+\[([^\]]+)\]/)
|
|
85
|
+
if (lineMatch) {
|
|
86
|
+
series.push({ type: 'line', data: parseNumericArray(lineMatch[1]!) })
|
|
87
|
+
continue
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Auto-derive y-axis range from data if not specified
|
|
92
|
+
if (!yAxis.range && series.length > 0) {
|
|
93
|
+
const allValues = series.flatMap(s => s.data)
|
|
94
|
+
let min = Math.min(...allValues)
|
|
95
|
+
let max = Math.max(...allValues)
|
|
96
|
+
const span = max - min || 1
|
|
97
|
+
// Add 10% padding
|
|
98
|
+
min = min - span * 0.1
|
|
99
|
+
max = max + span * 0.1
|
|
100
|
+
// Floor to 0 if all values are positive and min is close to 0
|
|
101
|
+
if (min > 0 && min < span * 0.5) min = 0
|
|
102
|
+
yAxis.range = { min, max }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Fallback y-axis range
|
|
106
|
+
if (!yAxis.range) {
|
|
107
|
+
yAxis.range = { min: 0, max: 100 }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return { title, horizontal, xAxis, yAxis, series }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function parseNumericArray(str: string): number[] {
|
|
114
|
+
return str.split(',').map(s => parseFloat(s.trim()))
|
|
115
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// XY Chart types
|
|
3
|
+
//
|
|
4
|
+
// Models the parsed and positioned representations of a Mermaid xychart-beta
|
|
5
|
+
// diagram. Supports bar charts, line charts, and combinations with categorical
|
|
6
|
+
// or numeric x-axes.
|
|
7
|
+
// ============================================================================
|
|
8
|
+
|
|
9
|
+
/** Parsed XY chart — logical structure from mermaid text */
|
|
10
|
+
export interface XYChart {
|
|
11
|
+
/** Optional chart title */
|
|
12
|
+
title?: string
|
|
13
|
+
/** Chart orientation: vertical (default) or horizontal */
|
|
14
|
+
horizontal: boolean
|
|
15
|
+
/** X-axis configuration */
|
|
16
|
+
xAxis: XYAxis
|
|
17
|
+
/** Y-axis configuration */
|
|
18
|
+
yAxis: XYAxis
|
|
19
|
+
/** Data series (bar and/or line) */
|
|
20
|
+
series: XYChartSeries[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Axis configuration — categorical (labels) or numeric (range) */
|
|
24
|
+
export interface XYAxis {
|
|
25
|
+
/** Optional axis title/label */
|
|
26
|
+
title?: string
|
|
27
|
+
/** Categorical labels (e.g., ["jan", "feb", "mar"]) — mutually exclusive with range */
|
|
28
|
+
categories?: string[]
|
|
29
|
+
/** Numeric range — mutually exclusive with categories */
|
|
30
|
+
range?: { min: number; max: number }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A single data series (bar or line) */
|
|
34
|
+
export interface XYChartSeries {
|
|
35
|
+
/** Series type */
|
|
36
|
+
type: 'bar' | 'line'
|
|
37
|
+
/** Data values — one per category, or evenly spaced across numeric range */
|
|
38
|
+
data: number[]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ============================================================================
|
|
42
|
+
// Positioned XY chart — ready for SVG rendering
|
|
43
|
+
// ============================================================================
|
|
44
|
+
|
|
45
|
+
export interface PositionedXYChart {
|
|
46
|
+
width: number
|
|
47
|
+
height: number
|
|
48
|
+
/** Whether this is a horizontal (rotated) chart */
|
|
49
|
+
horizontal?: boolean
|
|
50
|
+
/** Title text and position (if present) */
|
|
51
|
+
title?: PositionedTitle
|
|
52
|
+
/** Positioned x-axis with tick marks and labels */
|
|
53
|
+
xAxis: PositionedAxis
|
|
54
|
+
/** Positioned y-axis with tick marks and labels */
|
|
55
|
+
yAxis: PositionedAxis
|
|
56
|
+
/** The plot area bounds (inside axes) */
|
|
57
|
+
plotArea: PlotArea
|
|
58
|
+
/** Positioned bar groups */
|
|
59
|
+
bars: PositionedBar[]
|
|
60
|
+
/** Positioned line polylines */
|
|
61
|
+
lines: PositionedLine[]
|
|
62
|
+
/** Horizontal grid lines for readability */
|
|
63
|
+
gridLines: GridLine[]
|
|
64
|
+
/** Legend items (shown when multiple series) */
|
|
65
|
+
legend: LegendItem[]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface LegendItem {
|
|
69
|
+
/** Display label */
|
|
70
|
+
label: string
|
|
71
|
+
/** Position of the swatch/icon */
|
|
72
|
+
x: number
|
|
73
|
+
y: number
|
|
74
|
+
/** Series type determines swatch shape (rect for bar, line+dot for line) */
|
|
75
|
+
type: 'bar' | 'line'
|
|
76
|
+
/** Series index within its type (for layout grouping) */
|
|
77
|
+
seriesIndex: number
|
|
78
|
+
/** Global color index across all series (for unified color assignment) */
|
|
79
|
+
colorIndex: number
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface PositionedTitle {
|
|
83
|
+
text: string
|
|
84
|
+
x: number
|
|
85
|
+
y: number
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface PositionedAxis {
|
|
89
|
+
/** Optional axis title text and position */
|
|
90
|
+
title?: { text: string; x: number; y: number; rotate?: number }
|
|
91
|
+
/** Tick positions along the axis */
|
|
92
|
+
ticks: AxisTick[]
|
|
93
|
+
/** Axis line: start and end coordinates */
|
|
94
|
+
line: { x1: number; y1: number; x2: number; y2: number }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface AxisTick {
|
|
98
|
+
/** Label text for this tick */
|
|
99
|
+
label: string
|
|
100
|
+
/** Position of the tick mark on the axis */
|
|
101
|
+
x: number
|
|
102
|
+
y: number
|
|
103
|
+
/** End of the tick mark (short perpendicular line) */
|
|
104
|
+
tx: number
|
|
105
|
+
ty: number
|
|
106
|
+
/** Label anchor position */
|
|
107
|
+
labelX: number
|
|
108
|
+
labelY: number
|
|
109
|
+
/** Text anchor for label */
|
|
110
|
+
textAnchor: 'start' | 'middle' | 'end'
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface PlotArea {
|
|
114
|
+
x: number
|
|
115
|
+
y: number
|
|
116
|
+
width: number
|
|
117
|
+
height: number
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface PositionedBar {
|
|
121
|
+
/** Bar rectangle in SVG coordinates */
|
|
122
|
+
x: number
|
|
123
|
+
y: number
|
|
124
|
+
width: number
|
|
125
|
+
height: number
|
|
126
|
+
/** Original data value */
|
|
127
|
+
value: number
|
|
128
|
+
/** Category label for this bar (e.g. "Jan") */
|
|
129
|
+
label?: string
|
|
130
|
+
/** Series index within bar type (for layout grouping) */
|
|
131
|
+
seriesIndex: number
|
|
132
|
+
/** Global color index across all series */
|
|
133
|
+
colorIndex: number
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface PositionedLine {
|
|
137
|
+
/** Polyline points */
|
|
138
|
+
points: Array<{ x: number; y: number; value: number; label?: string }>
|
|
139
|
+
/** Series index within line type (for layout grouping) */
|
|
140
|
+
seriesIndex: number
|
|
141
|
+
/** Global color index across all series */
|
|
142
|
+
colorIndex: number
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface GridLine {
|
|
146
|
+
x1: number
|
|
147
|
+
y1: number
|
|
148
|
+
x2: number
|
|
149
|
+
y2: number
|
|
150
|
+
}
|