@g9tm/lynxcontrols-charts 0.0.0-stage → 2.1.0
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/README.md +13 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/charts.css +181 -0
- package/dist/charts.css.map +1 -0
- package/dist/charts.d.ts +158 -0
- package/dist/charts.d.ts.map +1 -0
- package/dist/charts.jsx +424 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.jsx +2 -0
- package/dist/svg/builders.d.ts +124 -0
- package/dist/svg/builders.d.ts.map +1 -0
- package/dist/svg/builders.jsx +354 -0
- package/dist/svg/index.d.ts +3 -0
- package/dist/svg/index.d.ts.map +1 -0
- package/dist/svg/index.jsx +2 -0
- package/dist/svg/scale.d.ts +44 -0
- package/dist/svg/scale.d.ts.map +1 -0
- package/dist/svg/scale.jsx +82 -0
- package/package.json +34 -4
package/dist/charts.jsx
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import "./charts.css";
|
|
2
|
+
import { g9IdProps } from "@g9tm/lynxcontrols/base";
|
|
3
|
+
import { useG9Culture, useG9Direction, useG9Theme } from "@g9tm/lynxcontrols/provider";
|
|
4
|
+
import { chartPalette, formatNumber, interpolateStops } from "@g9tm/lynxcontrols-foundation";
|
|
5
|
+
import { memo, useMemo, useState } from "@lynx-js/react";
|
|
6
|
+
import { barChart, candleChart, donut, fanChart, gauge, heatmap, lineChart, radar, sparkline, stackedBarChart } from "./svg/builders.jsx";
|
|
7
|
+
import { nearestIndex } from "./svg/scale.jsx";
|
|
8
|
+
function useChartColors(n = 8) {
|
|
9
|
+
const { palette } = useG9Theme();
|
|
10
|
+
return useMemo(()=>chartPalette(palette.Primary, palette.Surface, n), [
|
|
11
|
+
palette.Primary,
|
|
12
|
+
palette.Surface,
|
|
13
|
+
n
|
|
14
|
+
]);
|
|
15
|
+
}
|
|
16
|
+
function useMeasuredWidth(fixed) {
|
|
17
|
+
const [w, setW] = useState(null != fixed ? fixed : 0);
|
|
18
|
+
return [
|
|
19
|
+
null != fixed ? fixed : w,
|
|
20
|
+
(e)=>{
|
|
21
|
+
const next = Math.round(e.detail.width);
|
|
22
|
+
if (!fixed && Math.abs(next - w) >= 1) setW(next);
|
|
23
|
+
}
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
const cls = (base, extra)=>extra ? `${base} ${extra}` : base;
|
|
27
|
+
const G9Sparkline = memo(function(props) {
|
|
28
|
+
var _props_height;
|
|
29
|
+
const { palette } = useG9Theme();
|
|
30
|
+
const [w, onLayout] = useMeasuredWidth(props.width);
|
|
31
|
+
const h = null != (_props_height = props.height) ? _props_height : 30;
|
|
32
|
+
const svg1 = useMemo(()=>{
|
|
33
|
+
var _props_color;
|
|
34
|
+
return w > 0 ? sparkline(w, h, props.values, null != (_props_color = props.color) ? _props_color : palette.Primary, {
|
|
35
|
+
...props.kind ? {
|
|
36
|
+
kind: props.kind
|
|
37
|
+
} : {},
|
|
38
|
+
dim: palette.OutlineVariant
|
|
39
|
+
}) : '';
|
|
40
|
+
}, [
|
|
41
|
+
w,
|
|
42
|
+
h,
|
|
43
|
+
props.values,
|
|
44
|
+
props.color,
|
|
45
|
+
palette.Primary,
|
|
46
|
+
palette.OutlineVariant,
|
|
47
|
+
props.kind
|
|
48
|
+
]);
|
|
49
|
+
return <view className={cls('g9-spark', props.className)} {...g9IdProps(props.id)} style={{
|
|
50
|
+
height: `${h}px`,
|
|
51
|
+
...props.style
|
|
52
|
+
}} bindlayoutchange={onLayout} accessibility-element={Boolean(props.accessibilityLabel)} {...props.accessibilityLabel ? {
|
|
53
|
+
'accessibility-label': props.accessibilityLabel
|
|
54
|
+
} : {}}>
|
|
55
|
+
{svg1 ? <svg content={svg1} style={{
|
|
56
|
+
width: `${w}px`,
|
|
57
|
+
height: `${h}px`
|
|
58
|
+
}}/> : null}
|
|
59
|
+
</view>;
|
|
60
|
+
});
|
|
61
|
+
const AXIS_W = 44;
|
|
62
|
+
const AXIS_H = 20;
|
|
63
|
+
function G9ChartBox(props) {
|
|
64
|
+
var _props_height, _props_yFormat, _props_everyX, _props_style, _props_accessibilityLabel, _built_xs_active, _built_xs_active1;
|
|
65
|
+
const { palette } = useG9Theme();
|
|
66
|
+
const culture = useG9Culture();
|
|
67
|
+
const dir = useG9Direction();
|
|
68
|
+
const [w, onLayout] = useMeasuredWidth(props.width);
|
|
69
|
+
const h = null != (_props_height = props.height) ? _props_height : 180;
|
|
70
|
+
const plotW = Math.max(0, w - AXIS_W);
|
|
71
|
+
const built = useMemo(()=>plotW > 0 ? props.build(plotW, h, palette) : null, [
|
|
72
|
+
plotW,
|
|
73
|
+
h,
|
|
74
|
+
palette,
|
|
75
|
+
...props.deps
|
|
76
|
+
]);
|
|
77
|
+
const [active, setActive] = useState(null);
|
|
78
|
+
const fmt = null != (_props_yFormat = props.yFormat) ? _props_yFormat : (v)=>formatNumber(v, {
|
|
79
|
+
numberingSystem: culture.numberingSystem,
|
|
80
|
+
maximumFractionDigits: 1,
|
|
81
|
+
useGrouping: true
|
|
82
|
+
});
|
|
83
|
+
const rtl = 'rtl' === dir;
|
|
84
|
+
const touch = (x)=>{
|
|
85
|
+
if (!built || !props.tooltip) return;
|
|
86
|
+
const local = rtl ? x : x - AXIS_W;
|
|
87
|
+
setActive(nearestIndex(built.xs, local));
|
|
88
|
+
};
|
|
89
|
+
const every = null != (_props_everyX = props.everyX) ? _props_everyX : 1;
|
|
90
|
+
return <view className={cls('g9-chart', props.className)} {...g9IdProps(props.id)} style={null != (_props_style = props.style) ? _props_style : {}} bindlayoutchange={onLayout} accessibility-element={true} accessibility-label={null != (_props_accessibilityLabel = props.accessibilityLabel) ? _props_accessibilityLabel : ''}>
|
|
91
|
+
<view className="g9-chart__row" style={{
|
|
92
|
+
flexDirection: rtl ? 'row' : 'row-reverse',
|
|
93
|
+
direction: 'ltr',
|
|
94
|
+
height: `${h}px`
|
|
95
|
+
}}>
|
|
96
|
+
<view className="g9-chart__plot" style={{
|
|
97
|
+
width: `${plotW}px`,
|
|
98
|
+
height: `${h}px`
|
|
99
|
+
}} {...props.tooltip ? {
|
|
100
|
+
bindtouchstart: (e)=>touch(e.detail.x),
|
|
101
|
+
bindtouchmove: (e)=>touch(e.detail.x),
|
|
102
|
+
bindtouchend: ()=>setActive(null),
|
|
103
|
+
bindtouchcancel: ()=>setActive(null)
|
|
104
|
+
} : {}}>
|
|
105
|
+
{built ? <svg content={built.svg} style={{
|
|
106
|
+
width: `${plotW}px`,
|
|
107
|
+
height: `${h}px`
|
|
108
|
+
}}/> : null}
|
|
109
|
+
{built && null !== active && props.tooltip ? <view className="g9-chart__cursor" style={{
|
|
110
|
+
left: `${null != (_built_xs_active = built.xs[active]) ? _built_xs_active : 0}px`
|
|
111
|
+
}}>
|
|
112
|
+
<view className="g9-chart__tip" style={{
|
|
113
|
+
[(null != (_built_xs_active1 = built.xs[active]) ? _built_xs_active1 : 0) > plotW / 2 ? 'right' : 'left']: '6px'
|
|
114
|
+
}}>
|
|
115
|
+
<text className="g9-chart__tip-text">{props.tooltip(active)}</text>
|
|
116
|
+
</view>
|
|
117
|
+
</view> : null}
|
|
118
|
+
</view>
|
|
119
|
+
<view className="g9-chart__axis" style={{
|
|
120
|
+
width: `${AXIS_W}px`,
|
|
121
|
+
height: `${h}px`
|
|
122
|
+
}}>
|
|
123
|
+
{null == built ? void 0 : built.ticks.map((t)=><text key={t.value} className="g9-chart__y" style={{
|
|
124
|
+
top: `${t.y - 7}px`,
|
|
125
|
+
textAlign: rtl ? 'left' : 'right'
|
|
126
|
+
}}>
|
|
127
|
+
{fmt(t.value)}
|
|
128
|
+
</text>)}
|
|
129
|
+
</view>
|
|
130
|
+
</view>
|
|
131
|
+
{props.xLabels && built ? <view className="g9-chart__x-row" style={{
|
|
132
|
+
height: `${AXIS_H}px`,
|
|
133
|
+
[rtl ? 'marginRight' : 'marginLeft']: `${AXIS_W}px`,
|
|
134
|
+
width: `${plotW}px`
|
|
135
|
+
}}>
|
|
136
|
+
{props.xLabels.map((l, i)=>{
|
|
137
|
+
var _built_xs_i;
|
|
138
|
+
return i % every === 0 ? <text key={i} className="g9-chart__x" style={{
|
|
139
|
+
left: `${(null != (_built_xs_i = built.xs[i]) ? _built_xs_i : 0) - 24}px`
|
|
140
|
+
}}>
|
|
141
|
+
{l}
|
|
142
|
+
</text> : null;
|
|
143
|
+
})}
|
|
144
|
+
</view> : null}
|
|
145
|
+
{props.legend ? <view className="g9-chart__legend" style={{
|
|
146
|
+
flexDirection: rtl ? 'row-reverse' : 'row'
|
|
147
|
+
}}>
|
|
148
|
+
{props.legend.map((l)=><view key={l.label} className="g9-chart__legend-item" style={{
|
|
149
|
+
flexDirection: rtl ? 'row-reverse' : 'row'
|
|
150
|
+
}}>
|
|
151
|
+
<view className="g9-chart__swatch" style={{
|
|
152
|
+
backgroundColor: l.color
|
|
153
|
+
}}/>
|
|
154
|
+
<text className="g9-chart__legend-text">{l.label}</text>
|
|
155
|
+
</view>)}
|
|
156
|
+
</view> : null}
|
|
157
|
+
</view>;
|
|
158
|
+
}
|
|
159
|
+
function G9LineChart(props) {
|
|
160
|
+
const colors = useChartColors(Math.max(1, props.series.length));
|
|
161
|
+
const series = props.series.map((s, i)=>{
|
|
162
|
+
var _s_color;
|
|
163
|
+
return {
|
|
164
|
+
...s,
|
|
165
|
+
color: null != (_s_color = s.color) ? _s_color : colors[i]
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
const { series: _s, legend, min, max, ...box } = props;
|
|
169
|
+
return <G9ChartBox {...box} deps={[
|
|
170
|
+
series,
|
|
171
|
+
min,
|
|
172
|
+
max
|
|
173
|
+
]} {...false !== legend && series.length > 1 ? {
|
|
174
|
+
legend: series.map((s)=>({
|
|
175
|
+
label: s.label,
|
|
176
|
+
color: s.color
|
|
177
|
+
}))
|
|
178
|
+
} : {}} build={(w, h, p)=>lineChart(w, h, series, {
|
|
179
|
+
grid: p.OutlineVariant,
|
|
180
|
+
...void 0 !== min ? {
|
|
181
|
+
min
|
|
182
|
+
} : {},
|
|
183
|
+
...void 0 !== max ? {
|
|
184
|
+
max
|
|
185
|
+
} : {}
|
|
186
|
+
})}/>;
|
|
187
|
+
}
|
|
188
|
+
function G9BarChart(props) {
|
|
189
|
+
const { values, color, highlightIndex, ...box } = props;
|
|
190
|
+
return <G9ChartBox {...box} deps={[
|
|
191
|
+
values,
|
|
192
|
+
color,
|
|
193
|
+
highlightIndex
|
|
194
|
+
]} build={(w, h, p)=>barChart(w, h, values, {
|
|
195
|
+
color: null != color ? color : p.PrimaryBorder,
|
|
196
|
+
grid: p.OutlineVariant,
|
|
197
|
+
...void 0 !== highlightIndex ? {
|
|
198
|
+
highlightIndex,
|
|
199
|
+
highlight: p.Primary
|
|
200
|
+
} : {}
|
|
201
|
+
})}/>;
|
|
202
|
+
}
|
|
203
|
+
function G9StackedBarChart(props) {
|
|
204
|
+
var _props_colors;
|
|
205
|
+
const auto = useChartColors(props.parts.length);
|
|
206
|
+
const colors = null != (_props_colors = props.colors) ? _props_colors : auto;
|
|
207
|
+
const { stacks, parts, colors: _c, ...box } = props;
|
|
208
|
+
return <G9ChartBox {...box} deps={[
|
|
209
|
+
stacks,
|
|
210
|
+
colors
|
|
211
|
+
]} legend={parts.map((l, i)=>({
|
|
212
|
+
label: l,
|
|
213
|
+
color: colors[i % colors.length]
|
|
214
|
+
}))} build={(w, h, p)=>stackedBarChart(w, h, stacks, colors, {
|
|
215
|
+
grid: p.OutlineVariant
|
|
216
|
+
})}/>;
|
|
217
|
+
}
|
|
218
|
+
function G9FanChart(props) {
|
|
219
|
+
const { points, color, ...box } = props;
|
|
220
|
+
return <G9ChartBox {...box} deps={[
|
|
221
|
+
points,
|
|
222
|
+
color
|
|
223
|
+
]} build={(w, h, p)=>fanChart(w, h, points, null != color ? color : p.Primary, p.OutlineVariant)}/>;
|
|
224
|
+
}
|
|
225
|
+
function G9CandleChart(props) {
|
|
226
|
+
const { candles, ...box } = props;
|
|
227
|
+
return <G9ChartBox {...box} deps={[
|
|
228
|
+
candles
|
|
229
|
+
]} build={(w, h, p)=>candleChart(w, h, candles, {
|
|
230
|
+
up: p.Success,
|
|
231
|
+
down: p.Error,
|
|
232
|
+
grid: p.OutlineVariant,
|
|
233
|
+
lastLine: p.TextTertiary
|
|
234
|
+
})}/>;
|
|
235
|
+
}
|
|
236
|
+
function G9Donut(props) {
|
|
237
|
+
var _props_size, _props_style, _props_accessibilityLabel;
|
|
238
|
+
const { palette } = useG9Theme();
|
|
239
|
+
const rtl = 'rtl' === useG9Direction();
|
|
240
|
+
const culture = useG9Culture();
|
|
241
|
+
const colors = useChartColors(Math.max(1, props.slices.length));
|
|
242
|
+
const size = null != (_props_size = props.size) ? _props_size : 160;
|
|
243
|
+
const slices = props.slices.map((s, i)=>{
|
|
244
|
+
var _s_color;
|
|
245
|
+
return {
|
|
246
|
+
...s,
|
|
247
|
+
color: null != (_s_color = s.color) ? _s_color : colors[i]
|
|
248
|
+
};
|
|
249
|
+
});
|
|
250
|
+
const built = useMemo(()=>{
|
|
251
|
+
var _props_thickness;
|
|
252
|
+
return donut(size, null != (_props_thickness = props.thickness) ? _props_thickness : 18, slices, {
|
|
253
|
+
track: palette.SurfaceContainerHigh
|
|
254
|
+
});
|
|
255
|
+
}, [
|
|
256
|
+
size,
|
|
257
|
+
props.thickness,
|
|
258
|
+
slices.map((s)=>`${s.value}${s.color}`).join(),
|
|
259
|
+
palette.SurfaceContainerHigh
|
|
260
|
+
]);
|
|
261
|
+
return <view className={cls('g9-donut', props.className)} {...g9IdProps(props.id)} style={null != (_props_style = props.style) ? _props_style : {}} accessibility-element={true} accessibility-label={null != (_props_accessibilityLabel = props.accessibilityLabel) ? _props_accessibilityLabel : slices.map((s, i)=>{
|
|
262
|
+
var _built_shares_i;
|
|
263
|
+
return `${s.label} ${Math.round((null != (_built_shares_i = built.shares[i]) ? _built_shares_i : 0) * 100)}%`;
|
|
264
|
+
}).join(', ')}>
|
|
265
|
+
<view className="g9-donut__ring" style={{
|
|
266
|
+
width: `${size}px`,
|
|
267
|
+
height: `${size}px`
|
|
268
|
+
}}>
|
|
269
|
+
<svg content={built.svg} style={{
|
|
270
|
+
width: `${size}px`,
|
|
271
|
+
height: `${size}px`
|
|
272
|
+
}}/>
|
|
273
|
+
{props.children ? <view className="g9-donut__hole">{props.children}</view> : null}
|
|
274
|
+
</view>
|
|
275
|
+
{false !== props.legend ? <view className="g9-donut__legend">
|
|
276
|
+
{slices.map((s, i)=>{
|
|
277
|
+
var _s_text, _built_shares_i;
|
|
278
|
+
return <view key={s.label} className="g9-donut__legend-row" style={{
|
|
279
|
+
flexDirection: rtl ? 'row-reverse' : 'row',
|
|
280
|
+
direction: 'ltr'
|
|
281
|
+
}}>
|
|
282
|
+
<view className="g9-chart__swatch" style={{
|
|
283
|
+
backgroundColor: s.color
|
|
284
|
+
}}/>
|
|
285
|
+
<text className="g9-chart__legend-text">{s.label}</text>
|
|
286
|
+
<text className={`g9-donut__share g9-donut__share--${rtl ? 'rtl' : 'ltr'}`}>
|
|
287
|
+
{null != (_s_text = s.text) ? _s_text : `${formatNumber(Math.round((null != (_built_shares_i = built.shares[i]) ? _built_shares_i : 0) * 100), {
|
|
288
|
+
numberingSystem: culture.numberingSystem
|
|
289
|
+
})}%`}
|
|
290
|
+
</text>
|
|
291
|
+
</view>;
|
|
292
|
+
})}
|
|
293
|
+
</view> : null}
|
|
294
|
+
</view>;
|
|
295
|
+
}
|
|
296
|
+
function G9Gauge(props) {
|
|
297
|
+
var _props_size, _props_stops, _props_accessibilityLabel;
|
|
298
|
+
const { palette } = useG9Theme();
|
|
299
|
+
const size = null != (_props_size = props.size) ? _props_size : 200;
|
|
300
|
+
const stops = null != (_props_stops = props.stops) ? _props_stops : [
|
|
301
|
+
palette.Success,
|
|
302
|
+
palette.Warning,
|
|
303
|
+
palette.Error
|
|
304
|
+
];
|
|
305
|
+
const svg1 = useMemo(()=>{
|
|
306
|
+
var _props_thickness;
|
|
307
|
+
return gauge(size, null != (_props_thickness = props.thickness) ? _props_thickness : 14, props.value, {
|
|
308
|
+
track: palette.SurfaceContainerHigh,
|
|
309
|
+
colorAt: (t)=>interpolateStops(stops, t)
|
|
310
|
+
});
|
|
311
|
+
}, [
|
|
312
|
+
size,
|
|
313
|
+
props.thickness,
|
|
314
|
+
props.value,
|
|
315
|
+
stops.join(),
|
|
316
|
+
palette.SurfaceContainerHigh
|
|
317
|
+
]);
|
|
318
|
+
return <view className={cls('g9-gauge', props.className)} {...g9IdProps(props.id)} style={{
|
|
319
|
+
width: `${size}px`,
|
|
320
|
+
height: `${size}px`,
|
|
321
|
+
...props.style
|
|
322
|
+
}} accessibility-element={true} accessibility-label={null != (_props_accessibilityLabel = props.accessibilityLabel) ? _props_accessibilityLabel : `${Math.round(100 * props.value)}%`}>
|
|
323
|
+
<svg content={svg1} style={{
|
|
324
|
+
width: `${size}px`,
|
|
325
|
+
height: `${size}px`
|
|
326
|
+
}}/>
|
|
327
|
+
{props.children ? <view className="g9-donut__hole">{props.children}</view> : null}
|
|
328
|
+
</view>;
|
|
329
|
+
}
|
|
330
|
+
function G9Radar(props) {
|
|
331
|
+
var _props_size, _props_accessibilityLabel;
|
|
332
|
+
const { palette } = useG9Theme();
|
|
333
|
+
const size = null != (_props_size = props.size) ? _props_size : 280;
|
|
334
|
+
const built = useMemo(()=>{
|
|
335
|
+
var _props_color;
|
|
336
|
+
return radar(size, props.values, null != (_props_color = props.color) ? _props_color : palette.Primary, palette.OutlineVariant);
|
|
337
|
+
}, [
|
|
338
|
+
size,
|
|
339
|
+
props.values,
|
|
340
|
+
props.color,
|
|
341
|
+
palette.Primary,
|
|
342
|
+
palette.OutlineVariant
|
|
343
|
+
]);
|
|
344
|
+
return <view className={cls('g9-radar', props.className)} {...g9IdProps(props.id)} style={{
|
|
345
|
+
width: `${size}px`,
|
|
346
|
+
height: `${size}px`,
|
|
347
|
+
...props.style
|
|
348
|
+
}} accessibility-element={true} accessibility-label={null != (_props_accessibilityLabel = props.accessibilityLabel) ? _props_accessibilityLabel : props.labels.map((l, i)=>{
|
|
349
|
+
var _props_values_i;
|
|
350
|
+
return `${l} ${Math.round((null != (_props_values_i = props.values[i]) ? _props_values_i : 0) * 100)}%`;
|
|
351
|
+
}).join(', ')}>
|
|
352
|
+
<svg content={built.svg} style={{
|
|
353
|
+
width: `${size}px`,
|
|
354
|
+
height: `${size}px`
|
|
355
|
+
}}/>
|
|
356
|
+
{built.axes.map(([x, y], i)=>{
|
|
357
|
+
var _props_labels_i;
|
|
358
|
+
return <text key={i} className="g9-radar__label" style={{
|
|
359
|
+
left: `${x - 40}px`,
|
|
360
|
+
top: `${y - 8}px`
|
|
361
|
+
}}>
|
|
362
|
+
{null != (_props_labels_i = props.labels[i]) ? _props_labels_i : ''}
|
|
363
|
+
</text>;
|
|
364
|
+
})}
|
|
365
|
+
</view>;
|
|
366
|
+
}
|
|
367
|
+
function G9Heatmap(props) {
|
|
368
|
+
var _props_height, _props_style, _props_accessibilityLabel;
|
|
369
|
+
const { palette } = useG9Theme();
|
|
370
|
+
const dir = useG9Direction();
|
|
371
|
+
const [w, onLayout] = useMeasuredWidth(props.width);
|
|
372
|
+
const h = null != (_props_height = props.height) ? _props_height : 160;
|
|
373
|
+
const labelW = props.rowLabels ? 36 : 0;
|
|
374
|
+
const plotW = Math.max(0, w - labelW);
|
|
375
|
+
const built = useMemo(()=>{
|
|
376
|
+
var _props_color;
|
|
377
|
+
return plotW > 0 ? heatmap(plotW, h, props.grid, null != (_props_color = props.color) ? _props_color : palette.Primary, palette.SurfaceContainerHigh) : null;
|
|
378
|
+
}, [
|
|
379
|
+
plotW,
|
|
380
|
+
h,
|
|
381
|
+
props.grid,
|
|
382
|
+
props.color,
|
|
383
|
+
palette.Primary,
|
|
384
|
+
palette.SurfaceContainerHigh
|
|
385
|
+
]);
|
|
386
|
+
const rows = props.grid.length;
|
|
387
|
+
const cols = Math.max(0, ...props.grid.map((r)=>r.length));
|
|
388
|
+
return <view className={cls('g9-heatmap', props.className)} {...g9IdProps(props.id)} style={null != (_props_style = props.style) ? _props_style : {}} bindlayoutchange={onLayout} accessibility-element={true} accessibility-label={null != (_props_accessibilityLabel = props.accessibilityLabel) ? _props_accessibilityLabel : ''}>
|
|
389
|
+
<view className="g9-heatmap__row" style={{
|
|
390
|
+
flexDirection: 'rtl' === dir ? 'row-reverse' : 'row',
|
|
391
|
+
direction: 'ltr',
|
|
392
|
+
height: `${h}px`
|
|
393
|
+
}}>
|
|
394
|
+
{props.rowLabels ? <view className="g9-heatmap__rows" style={{
|
|
395
|
+
width: `${labelW}px`
|
|
396
|
+
}}>
|
|
397
|
+
{props.rowLabels.map((l, i)=><text key={i} className="g9-heatmap__label" style={{
|
|
398
|
+
top: `${h / Math.max(1, rows) * (i + 0.5) - 7}px`
|
|
399
|
+
}}>
|
|
400
|
+
{l}
|
|
401
|
+
</text>)}
|
|
402
|
+
</view> : null}
|
|
403
|
+
{built ? <svg content={built.svg} style={{
|
|
404
|
+
width: `${plotW}px`,
|
|
405
|
+
height: `${h}px`
|
|
406
|
+
}}/> : null}
|
|
407
|
+
</view>
|
|
408
|
+
{props.colLabels ? <view className="g9-chart__x-row" style={{
|
|
409
|
+
height: '18px',
|
|
410
|
+
width: `${plotW}px`,
|
|
411
|
+
['rtl' === dir ? 'marginRight' : 'marginLeft']: `${labelW}px`
|
|
412
|
+
}}>
|
|
413
|
+
{props.colLabels.map((l, i)=>{
|
|
414
|
+
var _props_everyCol;
|
|
415
|
+
return i % (null != (_props_everyCol = props.everyCol) ? _props_everyCol : 3) === 0 ? <text key={i} className="g9-chart__x" style={{
|
|
416
|
+
left: `${plotW / Math.max(1, cols) * (i + 0.5) - 24}px`
|
|
417
|
+
}}>
|
|
418
|
+
{l}
|
|
419
|
+
</text> : null;
|
|
420
|
+
})}
|
|
421
|
+
</view> : null}
|
|
422
|
+
</view>;
|
|
423
|
+
}
|
|
424
|
+
export { G9BarChart, G9CandleChart, G9ChartBox, G9Donut, G9FanChart, G9Gauge, G9Heatmap, G9LineChart, G9Radar, G9Sparkline, G9StackedBarChart, useChartColors };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { G9BarChart, type G9BarChartProps, G9CandleChart, type G9CandleChartProps, G9ChartBox, type G9ChartBoxProps, G9Donut, type G9DonutProps, G9FanChart, type G9FanChartProps, G9Gauge, type G9GaugeProps, G9Heatmap, type G9HeatmapProps, G9LineChart, type G9LineChartProps, type G9LineChartSeries, G9Radar, type G9RadarProps, G9Sparkline, type G9SparklineProps, G9StackedBarChart, type G9StackedBarChartProps, useChartColors, } from './charts.js';
|
|
2
|
+
export * from './svg/index.js';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,eAAe,EACpB,aAAa,EACb,KAAK,kBAAkB,EACvB,UAAU,EACV,KAAK,eAAe,EACpB,OAAO,EACP,KAAK,YAAY,EACjB,UAAU,EACV,KAAK,eAAe,EACpB,OAAO,EACP,KAAK,YAAY,EACjB,SAAS,EACT,KAAK,cAAc,EACnB,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,OAAO,EACP,KAAK,YAAY,EACjB,WAAW,EACX,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,KAAK,sBAAsB,EAC3B,cAAc,GACf,MAAM,UAAU,CAAC;AAClB,cAAc,aAAa,CAAC"}
|
package/dist/index.jsx
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { type G9ChartInsets, type G9Tick } from './scale.js';
|
|
2
|
+
/** A built chart: the SVG, its y ticks, the x of every slot. */
|
|
3
|
+
export interface G9BuiltChart {
|
|
4
|
+
readonly svg: string;
|
|
5
|
+
readonly ticks: readonly G9Tick[];
|
|
6
|
+
readonly xs: readonly number[];
|
|
7
|
+
readonly width: number;
|
|
8
|
+
readonly height: number;
|
|
9
|
+
/** y of `value` in this chart. */
|
|
10
|
+
readonly y: (value: number) => number;
|
|
11
|
+
}
|
|
12
|
+
/** One line of {@link lineChart}: its values (`null` breaks the line), colour, width, area fill and dash. */
|
|
13
|
+
export interface G9LineSeries {
|
|
14
|
+
readonly values: readonly (number | null)[];
|
|
15
|
+
readonly color: string;
|
|
16
|
+
readonly width?: number;
|
|
17
|
+
readonly dashed?: boolean;
|
|
18
|
+
/** Fill under the line with this opacity (0 none). */
|
|
19
|
+
readonly area?: number;
|
|
20
|
+
/** Dots: none, the last point, or every point. */
|
|
21
|
+
readonly dots?: 'none' | 'last' | 'all';
|
|
22
|
+
}
|
|
23
|
+
/** What every gridded chart takes: the grid line colour, insets, tick count and the y range (`min`, `max`, `zero`). */
|
|
24
|
+
export interface G9GridOptions {
|
|
25
|
+
readonly grid?: string;
|
|
26
|
+
readonly insets?: Partial<G9ChartInsets>;
|
|
27
|
+
readonly ticks?: number;
|
|
28
|
+
readonly min?: number;
|
|
29
|
+
readonly max?: number;
|
|
30
|
+
/** Keep zero in range. Default true. */
|
|
31
|
+
readonly zero?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** Lines (and areas) over shared slots. Null values break the line. */
|
|
34
|
+
export declare function lineChart(w: number, h: number, series: readonly G9LineSeries[], o?: G9GridOptions): G9BuiltChart;
|
|
35
|
+
/** Options of the bar builders: the grid options plus the bar colours and their share of a slot. */
|
|
36
|
+
export interface G9BarOptions extends G9GridOptions {
|
|
37
|
+
/** One colour, or one per bar. */
|
|
38
|
+
readonly color: string | readonly string[];
|
|
39
|
+
/** Bar share of its slot, 0..1. Default 0.62. */
|
|
40
|
+
readonly band?: number;
|
|
41
|
+
readonly radius?: number;
|
|
42
|
+
/** Bars whose index is in this set use `highlight`. */
|
|
43
|
+
readonly highlightIndex?: number;
|
|
44
|
+
readonly highlight?: string;
|
|
45
|
+
}
|
|
46
|
+
/** Vertical bars (SAC barChart, G9Hub admin BarChart, ShopManager Bars). Negative values hang below zero. */
|
|
47
|
+
export declare function barChart(w: number, h: number, values: readonly number[], o: G9BarOptions): G9BuiltChart;
|
|
48
|
+
/** Stacked bars (SAC stackedChart): `stacks[i]` is the parts of bar i, coloured by `colors[j]`. */
|
|
49
|
+
export declare function stackedBarChart(w: number, h: number, stacks: readonly (readonly number[])[], colors: readonly string[], o?: G9GridOptions & {
|
|
50
|
+
readonly band?: number;
|
|
51
|
+
}): G9BuiltChart;
|
|
52
|
+
/** A sparkline (SAC sparkline, Riskara sparkline, ShopManager Sparkline): a line with a soft area, or bars. */
|
|
53
|
+
export declare function sparkline(w: number, h: number, values: readonly number[], color: string, o?: {
|
|
54
|
+
readonly kind?: 'line' | 'bars';
|
|
55
|
+
readonly area?: number;
|
|
56
|
+
readonly mark?: number;
|
|
57
|
+
readonly dim?: string;
|
|
58
|
+
}): string;
|
|
59
|
+
/** A donut slice. */
|
|
60
|
+
export interface G9Slice {
|
|
61
|
+
readonly value: number;
|
|
62
|
+
readonly color: string;
|
|
63
|
+
}
|
|
64
|
+
/** A donut (SAC donut, Riskara donutSegments): slices with a gap; returns each slice's share and mid angle. */
|
|
65
|
+
export declare function donut(size: number, thickness: number, slices: readonly G9Slice[], o?: {
|
|
66
|
+
readonly track?: string;
|
|
67
|
+
readonly gapDeg?: number;
|
|
68
|
+
}): {
|
|
69
|
+
readonly svg: string;
|
|
70
|
+
readonly shares: readonly number[];
|
|
71
|
+
readonly mids: readonly number[];
|
|
72
|
+
};
|
|
73
|
+
/** A heatmap (SAC hour × weekday): `grid[row][col]`, intensity by opacity of `color`. */
|
|
74
|
+
export declare function heatmap(w: number, h: number, grid: readonly (readonly number[])[], color: string, empty: string, gap?: number): {
|
|
75
|
+
readonly svg: string;
|
|
76
|
+
readonly max: number;
|
|
77
|
+
};
|
|
78
|
+
/** A gauge arc (Riskara spectrum gauge): 240° sweep from `from` to `to`, `value` 0..1, coloured by `colorAt(t)`. */
|
|
79
|
+
export declare function gauge(size: number, thickness: number, value: number, o: {
|
|
80
|
+
readonly track: string;
|
|
81
|
+
readonly colorAt: (t: number) => string;
|
|
82
|
+
readonly segments?: number;
|
|
83
|
+
readonly needle?: string;
|
|
84
|
+
}): string;
|
|
85
|
+
/** A radar (Riskara): `values` 0..1 on `values.length` axes; returns the label anchor points. */
|
|
86
|
+
export declare function radar(size: number, values: readonly number[], color: string, grid: string, pad?: number): {
|
|
87
|
+
readonly svg: string;
|
|
88
|
+
readonly axes: readonly [number, number][];
|
|
89
|
+
};
|
|
90
|
+
/** A fan chart (Riskara): median line in a p10–p90 band. */
|
|
91
|
+
export declare function fanChart(w: number, h: number, points: readonly {
|
|
92
|
+
readonly p10: number;
|
|
93
|
+
readonly p50: number;
|
|
94
|
+
readonly p90: number;
|
|
95
|
+
}[], color: string, grid?: string): G9BuiltChart;
|
|
96
|
+
/** One candle. */
|
|
97
|
+
export interface G9Candle {
|
|
98
|
+
readonly open: number;
|
|
99
|
+
readonly high: number;
|
|
100
|
+
readonly low: number;
|
|
101
|
+
readonly close: number;
|
|
102
|
+
}
|
|
103
|
+
/** Candlesticks (Riskara symbol page): up and down colours, the last close as a tag line. */
|
|
104
|
+
export declare function candleChart(w: number, h: number, candles: readonly G9Candle[], o: {
|
|
105
|
+
readonly up: string;
|
|
106
|
+
readonly down: string;
|
|
107
|
+
readonly grid?: string;
|
|
108
|
+
readonly lastLine?: string;
|
|
109
|
+
}): G9BuiltChart & {
|
|
110
|
+
readonly last: number | null;
|
|
111
|
+
};
|
|
112
|
+
/** Points in quadrants (SAC menu engineering matrix): popularity on x, margin on y, split at the medians given. */
|
|
113
|
+
export declare function matrixChart(w: number, h: number, points: readonly {
|
|
114
|
+
readonly x: number;
|
|
115
|
+
readonly y: number;
|
|
116
|
+
readonly color: string;
|
|
117
|
+
readonly label?: string;
|
|
118
|
+
}[], o: {
|
|
119
|
+
readonly xLine: number;
|
|
120
|
+
readonly yLine: number;
|
|
121
|
+
readonly line: string;
|
|
122
|
+
readonly radius?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