-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchart.zod.ts
More file actions
194 lines (158 loc) · 5.12 KB
/
chart.zod.ts
File metadata and controls
194 lines (158 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { z } from 'zod';
import { I18nLabelSchema, AriaPropsSchema } from './i18n.zod';
/**
* Unified Chart Type Taxonomy
*
* Shared by Dashboard and Report widgets.
* Provides a comprehensive set of chart types for data visualization.
*/
/**
* Chart Type Enum
* Categorized by visualization purpose
*/
export const ChartTypeSchema = z.enum([
// Comparison
'bar',
'horizontal-bar',
'column',
'grouped-bar',
'stacked-bar',
'bi-polar-bar',
// Trend
'line',
'area',
'stacked-area',
'step-line',
'spline',
// Distribution
'pie',
'donut',
'funnel',
'pyramid',
// Relationship
'scatter',
'bubble',
// Composition
'treemap',
'sunburst',
'sankey',
'word-cloud',
// Performance
'gauge',
'solid-gauge',
'metric',
'kpi',
'bullet',
// Geo
'choropleth',
'bubble-map',
'gl-map',
// Advanced
'heatmap',
'radar',
'waterfall',
'box-plot',
'violin',
'candlestick',
'stock',
// Tabular
'table',
'pivot',
]);
export type ChartType = z.infer<typeof ChartTypeSchema>;
/**
* Chart Axis Schema
* Definition for X and Y axes
*/
export const ChartAxisSchema = z.object({
/** Data field to map to this axis */
field: z.string().describe('Data field key'),
/** Axis title */
title: I18nLabelSchema.optional().describe('Axis display title'),
/** Value formatting (d3-format or similar) */
format: z.string().optional().describe('Value format string (e.g., "$0,0.00")'),
/** Axis scale settings */
min: z.number().optional().describe('Minimum value'),
max: z.number().optional().describe('Maximum value'),
stepSize: z.number().optional().describe('Step size for ticks'),
/** Appearance */
showGridLines: z.boolean().default(true),
position: z.enum(['left', 'right', 'top', 'bottom']).optional().describe('Axis position'),
/** Logarithmic scale */
logarithmic: z.boolean().default(false),
});
/**
* Chart Series Schema
* Defines a single data series in the chart
*/
export const ChartSeriesSchema = z.object({
/** Field name for values */
name: z.string().describe('Field name or series identifier'),
/** Display label */
label: I18nLabelSchema.optional().describe('Series display label'),
/** Series type override (combo charts) */
type: ChartTypeSchema.optional().describe('Override chart type for this series'),
/** Specific color */
color: z.string().optional().describe('Series color (hex/rgb/token)'),
/** Stacking group */
stack: z.string().optional().describe('Stack identifier to group series'),
/** Axis binding */
yAxis: z.enum(['left', 'right']).default('left').describe('Bind to specific Y-Axis'),
});
/**
* Chart Annotation Schema
* Static lines or regions to highlight data
*/
export const ChartAnnotationSchema = z.object({
type: z.enum(['line', 'region']).default('line'),
axis: z.enum(['x', 'y']).default('y'),
value: z.union([z.number(), z.string()]).describe('Start value'),
endValue: z.union([z.number(), z.string()]).optional().describe('End value for regions'),
color: z.string().optional(),
label: I18nLabelSchema.optional(),
style: z.enum(['solid', 'dashed', 'dotted']).default('dashed'),
});
/**
* Chart Interaction Schema
*/
export const ChartInteractionSchema = z.object({
tooltips: z.boolean().default(true),
zoom: z.boolean().default(false),
brush: z.boolean().default(false),
clickAction: z.string().optional().describe('Action ID to trigger on click'),
});
/**
* Chart Configuration Base
* Common configuration for all chart types
*/
export const ChartConfigSchema = z.object({
/** Chart Type */
type: ChartTypeSchema,
/** Titles */
title: I18nLabelSchema.optional().describe('Chart title'),
subtitle: I18nLabelSchema.optional().describe('Chart subtitle'),
description: I18nLabelSchema.optional().describe('Accessibility description'),
/** Axes Mapping */
xAxis: ChartAxisSchema.optional().describe('X-Axis configuration'),
yAxis: z.array(ChartAxisSchema).optional().describe('Y-Axis configuration (support dual axis)'),
/** Series Configuration */
series: z.array(ChartSeriesSchema).optional().describe('Defined series configuration'),
/** Appearance */
colors: z.array(z.string()).optional().describe('Color palette'),
height: z.number().optional().describe('Fixed height in pixels'),
/** Components */
showLegend: z.boolean().default(true).describe('Display legend'),
showDataLabels: z.boolean().default(false).describe('Display data labels'),
/** Annotations & Reference Lines */
annotations: z.array(ChartAnnotationSchema).optional(),
/** Interactions */
interaction: ChartInteractionSchema.optional(),
/** ARIA accessibility attributes */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
export type ChartConfig = z.infer<typeof ChartConfigSchema>;
export type ChartAxis = z.infer<typeof ChartAxisSchema>;
export type ChartSeries = z.infer<typeof ChartSeriesSchema>;
export type ChartAnnotation = z.infer<typeof ChartAnnotationSchema>;
export type ChartInteraction = z.infer<typeof ChartInteractionSchema>;