@zombie-mermaid/mermaid-parser 2.2.1
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/LICENSE +22 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +879 -0
- package/dist/index.d.ts +879 -0
- package/dist/index.js +994 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -0
- package/src/__tests__/box-color.test.ts +80 -0
- package/src/__tests__/sequence-activation-fix.test.ts +91 -0
- package/src/__tests__/xychart-colors.test.ts +149 -0
- package/src/class/format.ts +15 -0
- package/src/class/parser.ts +593 -0
- package/src/class/types.ts +166 -0
- package/src/er/parser.ts +286 -0
- package/src/er/types.ts +99 -0
- package/src/expanded-shapes.ts +376 -0
- package/src/index.ts +48 -0
- package/src/sequence/activation-check.ts +149 -0
- package/src/sequence/activation-fix.ts +112 -0
- package/src/sequence/box-color.ts +85 -0
- package/src/sequence/parser.ts +613 -0
- package/src/sequence/types.ts +242 -0
- package/src/xychart/colors.ts +177 -0
- package/src/xychart/parser.ts +246 -0
- package/src/xychart/types.ts +150 -0
|
@@ -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
|
+
}
|