@sckyzo/cosmos-charts 0.2.0 → 0.3.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/CHANGELOG.md +91 -0
- package/README.md +107 -22
- package/THIRD_PARTY_NOTICES.md +81 -0
- package/dist/BarChart.cjs +137 -0
- package/dist/BarChart.cjs.map +1 -0
- package/dist/BarChart.js +135 -0
- package/dist/BarChart.js.map +1 -0
- package/dist/BoxPlotChart.cjs +214 -0
- package/dist/BoxPlotChart.cjs.map +1 -0
- package/dist/BoxPlotChart.js +212 -0
- package/dist/BoxPlotChart.js.map +1 -0
- package/dist/BumpChart.cjs +328 -0
- package/dist/BumpChart.cjs.map +1 -0
- package/dist/BumpChart.js +326 -0
- package/dist/BumpChart.js.map +1 -0
- package/dist/CalendarChart.cjs +216 -0
- package/dist/CalendarChart.cjs.map +1 -0
- package/dist/CalendarChart.js +214 -0
- package/dist/CalendarChart.js.map +1 -0
- package/dist/DonutChart.cjs +122 -0
- package/dist/DonutChart.cjs.map +1 -0
- package/dist/DonutChart.js +120 -0
- package/dist/DonutChart.js.map +1 -0
- package/dist/FunnelChart.cjs +422 -0
- package/dist/FunnelChart.cjs.map +1 -0
- package/dist/FunnelChart.js +420 -0
- package/dist/FunnelChart.js.map +1 -0
- package/dist/GradientRadial.cjs +51 -0
- package/dist/GradientRadial.cjs.map +1 -0
- package/dist/GradientRadial.js +49 -0
- package/dist/GradientRadial.js.map +1 -0
- package/dist/HeatmapChart.cjs +146 -0
- package/dist/HeatmapChart.cjs.map +1 -0
- package/dist/HeatmapChart.js +144 -0
- package/dist/HeatmapChart.js.map +1 -0
- package/dist/LineAreaChart.cjs +98 -0
- package/dist/LineAreaChart.cjs.map +1 -0
- package/dist/LineAreaChart.js +96 -0
- package/dist/LineAreaChart.js.map +1 -0
- package/dist/MixedChart.cjs +195 -0
- package/dist/MixedChart.cjs.map +1 -0
- package/dist/MixedChart.js +193 -0
- package/dist/MixedChart.js.map +1 -0
- package/dist/RadarChart.cjs +109 -0
- package/dist/RadarChart.cjs.map +1 -0
- package/dist/RadarChart.js +107 -0
- package/dist/RadarChart.js.map +1 -0
- package/dist/RadialBarChart.cjs +99 -0
- package/dist/RadialBarChart.cjs.map +1 -0
- package/dist/RadialBarChart.js +97 -0
- package/dist/RadialBarChart.js.map +1 -0
- package/dist/RangeBarChart.cjs +218 -0
- package/dist/RangeBarChart.cjs.map +1 -0
- package/dist/RangeBarChart.js +216 -0
- package/dist/RangeBarChart.js.map +1 -0
- package/dist/RealtimeChart.cjs +173 -0
- package/dist/RealtimeChart.cjs.map +1 -0
- package/dist/RealtimeChart.js +171 -0
- package/dist/RealtimeChart.js.map +1 -0
- package/dist/ScatterChart.cjs +134 -0
- package/dist/ScatterChart.cjs.map +1 -0
- package/dist/ScatterChart.js +131 -0
- package/dist/ScatterChart.js.map +1 -0
- package/dist/SemiCircleGauge.cjs +142 -0
- package/dist/SemiCircleGauge.cjs.map +1 -0
- package/dist/SemiCircleGauge.js +140 -0
- package/dist/SemiCircleGauge.js.map +1 -0
- package/dist/Sparkline.cjs +117 -0
- package/dist/Sparkline.cjs.map +1 -0
- package/dist/Sparkline.js +115 -0
- package/dist/Sparkline.js.map +1 -0
- package/dist/StrokedGauge.cjs +94 -0
- package/dist/StrokedGauge.cjs.map +1 -0
- package/dist/StrokedGauge.js +92 -0
- package/dist/StrokedGauge.js.map +1 -0
- package/dist/TreemapChart.cjs +263 -0
- package/dist/TreemapChart.cjs.map +1 -0
- package/dist/TreemapChart.js +261 -0
- package/dist/TreemapChart.js.map +1 -0
- package/dist/WaterfallChart.cjs +235 -0
- package/dist/WaterfallChart.cjs.map +1 -0
- package/dist/WaterfallChart.js +233 -0
- package/dist/WaterfallChart.js.map +1 -0
- package/dist/WorldMap.cjs +2088 -0
- package/dist/WorldMap.cjs.map +1 -0
- package/dist/WorldMap.js +603 -0
- package/dist/WorldMap.js.map +1 -0
- package/dist/chunk-3N43QT36.js +60 -0
- package/dist/chunk-3N43QT36.js.map +1 -0
- package/dist/chunk-5C2RLJYZ.js +11 -0
- package/dist/chunk-5C2RLJYZ.js.map +1 -0
- package/dist/chunk-6ALKZLN2.js +127 -0
- package/dist/chunk-6ALKZLN2.js.map +1 -0
- package/dist/chunk-6BKLL7LZ.cjs +30 -0
- package/dist/chunk-6BKLL7LZ.cjs.map +1 -0
- package/dist/chunk-6NRRABPF.cjs +64 -0
- package/dist/chunk-6NRRABPF.cjs.map +1 -0
- package/dist/chunk-AAYHG7YK.cjs +30 -0
- package/dist/chunk-AAYHG7YK.cjs.map +1 -0
- package/dist/chunk-AOSO5QHL.js +19 -0
- package/dist/chunk-AOSO5QHL.js.map +1 -0
- package/dist/chunk-BFEDLXVW.js +12 -0
- package/dist/chunk-BFEDLXVW.js.map +1 -0
- package/dist/chunk-DBZQI4HM.cjs +14 -0
- package/dist/chunk-DBZQI4HM.cjs.map +1 -0
- package/dist/chunk-F2PMFYJ5.cjs +40 -0
- package/dist/chunk-F2PMFYJ5.cjs.map +1 -0
- package/dist/chunk-FUZW3H5X.js +38 -0
- package/dist/chunk-FUZW3H5X.js.map +1 -0
- package/dist/chunk-GDZLYYL2.js +27 -0
- package/dist/chunk-GDZLYYL2.js.map +1 -0
- package/dist/chunk-GVTMZYOM.cjs +30 -0
- package/dist/chunk-GVTMZYOM.cjs.map +1 -0
- package/dist/chunk-GZRMVE4X.cjs +131 -0
- package/dist/chunk-GZRMVE4X.cjs.map +1 -0
- package/dist/chunk-HMH6DI7U.js +27 -0
- package/dist/chunk-HMH6DI7U.js.map +1 -0
- package/dist/chunk-ICL5K2CW.js +280 -0
- package/dist/chunk-ICL5K2CW.js.map +1 -0
- package/dist/chunk-IW6EWB26.cjs +21 -0
- package/dist/chunk-IW6EWB26.cjs.map +1 -0
- package/dist/chunk-K3R7JGOW.cjs +18 -0
- package/dist/chunk-K3R7JGOW.cjs.map +1 -0
- package/dist/chunk-LT3UC65O.cjs +68 -0
- package/dist/chunk-LT3UC65O.cjs.map +1 -0
- package/dist/chunk-MN4CDVOS.cjs +63 -0
- package/dist/chunk-MN4CDVOS.cjs.map +1 -0
- package/dist/chunk-OCD6JIIX.js +23 -0
- package/dist/chunk-OCD6JIIX.js.map +1 -0
- package/dist/chunk-RILUG7JB.js +44 -0
- package/dist/chunk-RILUG7JB.js.map +1 -0
- package/dist/chunk-RLHGPHC7.cjs +51 -0
- package/dist/chunk-RLHGPHC7.cjs.map +1 -0
- package/dist/chunk-SGG7XKOY.js +58 -0
- package/dist/chunk-SGG7XKOY.js.map +1 -0
- package/dist/chunk-T3K6Q34U.cjs +82 -0
- package/dist/chunk-T3K6Q34U.cjs.map +1 -0
- package/dist/chunk-TPH5T3DA.cjs +282 -0
- package/dist/chunk-TPH5T3DA.cjs.map +1 -0
- package/dist/chunk-TYQWZR3S.cjs +13 -0
- package/dist/chunk-TYQWZR3S.cjs.map +1 -0
- package/dist/chunk-UATB2IRY.js +51 -0
- package/dist/chunk-UATB2IRY.js.map +1 -0
- package/dist/chunk-UJIV5PVI.js +13 -0
- package/dist/chunk-UJIV5PVI.js.map +1 -0
- package/dist/chunk-URNXLVSK.js +44 -0
- package/dist/chunk-URNXLVSK.js.map +1 -0
- package/dist/chunk-VIOSQN4Z.js +79 -0
- package/dist/chunk-VIOSQN4Z.js.map +1 -0
- package/dist/chunk-X3YZP5WF.cjs +46 -0
- package/dist/chunk-X3YZP5WF.cjs.map +1 -0
- package/dist/chunk-YWYF5CCJ.js +61 -0
- package/dist/chunk-YWYF5CCJ.js.map +1 -0
- package/dist/chunk-Z4LZFMDH.cjs +60 -0
- package/dist/chunk-Z4LZFMDH.cjs.map +1 -0
- package/dist/index.cjs +154 -1166
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +470 -80
- package/dist/index.d.ts +470 -80
- package/dist/index.js +23 -1144
- package/dist/index.js.map +1 -1
- package/dist/theme.cjs +88 -0
- package/dist/theme.cjs.map +1 -0
- package/dist/theme.js +84 -0
- package/dist/theme.js.map +1 -0
- package/package.json +23 -12
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var chunkGVTMZYOM_cjs = require('./chunk-GVTMZYOM.cjs');
|
|
5
|
+
var chunkTYQWZR3S_cjs = require('./chunk-TYQWZR3S.cjs');
|
|
6
|
+
var chunkT3K6Q34U_cjs = require('./chunk-T3K6Q34U.cjs');
|
|
7
|
+
var chunkK3R7JGOW_cjs = require('./chunk-K3R7JGOW.cjs');
|
|
8
|
+
var chunk6NRRABPF_cjs = require('./chunk-6NRRABPF.cjs');
|
|
9
|
+
var chunkLT3UC65O_cjs = require('./chunk-LT3UC65O.cjs');
|
|
10
|
+
var react = require('react');
|
|
11
|
+
var recharts = require('recharts');
|
|
12
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
13
|
+
|
|
14
|
+
var Sparkline = ({
|
|
15
|
+
data,
|
|
16
|
+
color = chunkLT3UC65O_cjs.SERIES[0],
|
|
17
|
+
variant = "area",
|
|
18
|
+
label = "value",
|
|
19
|
+
formatValue,
|
|
20
|
+
min,
|
|
21
|
+
max,
|
|
22
|
+
emptyMessage = "No data",
|
|
23
|
+
ariaLabel,
|
|
24
|
+
children,
|
|
25
|
+
height = 60,
|
|
26
|
+
width
|
|
27
|
+
}) => {
|
|
28
|
+
const uid = chunkK3R7JGOW_cjs.safeId(react.useId());
|
|
29
|
+
const name = ariaLabel ?? `Trend of ${label}`;
|
|
30
|
+
if (chunkK3R7JGOW_cjs.hasNoData([{ data }])) {
|
|
31
|
+
return /* @__PURE__ */ jsxRuntime.jsx(chunk6NRRABPF_cjs.ChartEmpty, { message: emptyMessage, ariaLabel: name, height, width });
|
|
32
|
+
}
|
|
33
|
+
if (variant === "bar") {
|
|
34
|
+
const fillFor = (value) => value < 0 ? chunkLT3UC65O_cjs.ERROR : void 0;
|
|
35
|
+
const hasNegative = data.some((value) => value < 0);
|
|
36
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
37
|
+
recharts.BarChart,
|
|
38
|
+
{
|
|
39
|
+
...chunk6NRRABPF_cjs.frameProps({ height, width, ariaLabel: name, keyboard: false }),
|
|
40
|
+
data: data.map((value, i) => ({ i, value })),
|
|
41
|
+
margin: { top: 6, right: 4, bottom: 4, left: 4 },
|
|
42
|
+
barCategoryGap: "20%",
|
|
43
|
+
children: [
|
|
44
|
+
/* @__PURE__ */ jsxRuntime.jsx(recharts.XAxis, { hide: true, dataKey: "i" }),
|
|
45
|
+
/* @__PURE__ */ jsxRuntime.jsx(recharts.YAxis, { hide: true, domain: [min ?? Math.min(0, ...data), max ?? Math.max(0, ...data)] }),
|
|
46
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
47
|
+
recharts.Tooltip,
|
|
48
|
+
{
|
|
49
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(chunkT3K6Q34U_cjs.ChartTooltip, { format: formatValue, hideTitle: true, colorOf: fillFor }),
|
|
50
|
+
cursor: { fill: chunkLT3UC65O_cjs.BORDER, fillOpacity: 0.35 },
|
|
51
|
+
offset: 12,
|
|
52
|
+
allowEscapeViewBox: { x: true, y: true },
|
|
53
|
+
animationDuration: 100
|
|
54
|
+
}
|
|
55
|
+
),
|
|
56
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
57
|
+
recharts.Bar,
|
|
58
|
+
{
|
|
59
|
+
name: label,
|
|
60
|
+
dataKey: "value",
|
|
61
|
+
fill: color,
|
|
62
|
+
maxBarSize: 14,
|
|
63
|
+
shape: chunkGVTMZYOM_cjs.roundedBarShape({ layout: "horizontal", radius: 2, dataKey: "value", fillFor }),
|
|
64
|
+
...chunkTYQWZR3S_cjs.ANIMATION
|
|
65
|
+
}
|
|
66
|
+
),
|
|
67
|
+
hasNegative && /* @__PURE__ */ jsxRuntime.jsx(recharts.ReferenceLine, { y: 0, stroke: chunkLT3UC65O_cjs.BORDER, strokeDasharray: "3 3", ifOverflow: "hidden" }),
|
|
68
|
+
children
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
74
|
+
recharts.AreaChart,
|
|
75
|
+
{
|
|
76
|
+
...chunk6NRRABPF_cjs.frameProps({ height, width, ariaLabel: name, keyboard: false }),
|
|
77
|
+
data: data.map((value, i) => ({ i, value })),
|
|
78
|
+
margin: { top: 6, right: 4, bottom: 4, left: 4 },
|
|
79
|
+
children: [
|
|
80
|
+
/* @__PURE__ */ jsxRuntime.jsx("defs", { children: /* @__PURE__ */ jsxRuntime.jsxs("linearGradient", { id: uid, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
81
|
+
/* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "0%", stopColor: color, stopOpacity: 0.32 }),
|
|
82
|
+
/* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "100%", stopColor: color, stopOpacity: 0 })
|
|
83
|
+
] }) }),
|
|
84
|
+
/* @__PURE__ */ jsxRuntime.jsx(recharts.YAxis, { hide: true, domain: [min ?? "dataMin", max ?? "dataMax"] }),
|
|
85
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
86
|
+
recharts.Tooltip,
|
|
87
|
+
{
|
|
88
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(chunkT3K6Q34U_cjs.ChartTooltip, { format: formatValue, hideTitle: true }),
|
|
89
|
+
cursor: false,
|
|
90
|
+
offset: 12,
|
|
91
|
+
allowEscapeViewBox: { x: true, y: true },
|
|
92
|
+
animationDuration: 100
|
|
93
|
+
}
|
|
94
|
+
),
|
|
95
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
96
|
+
recharts.Area,
|
|
97
|
+
{
|
|
98
|
+
name: label,
|
|
99
|
+
dataKey: "value",
|
|
100
|
+
type: "monotone",
|
|
101
|
+
stroke: color,
|
|
102
|
+
strokeWidth: 2,
|
|
103
|
+
fill: variant === "area" ? `url(#${uid})` : "none",
|
|
104
|
+
dot: false,
|
|
105
|
+
activeDot: { r: 4, fill: chunkLT3UC65O_cjs.PANEL, stroke: color, strokeWidth: 2 },
|
|
106
|
+
...chunkTYQWZR3S_cjs.ANIMATION
|
|
107
|
+
}
|
|
108
|
+
),
|
|
109
|
+
children
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
exports.Sparkline = Sparkline;
|
|
116
|
+
//# sourceMappingURL=Sparkline.cjs.map
|
|
117
|
+
//# sourceMappingURL=Sparkline.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Sparkline.tsx"],"names":["SERIES","safeId","useId","hasNoData","ChartEmpty","ERROR","jsxs","BarChart","frameProps","jsx","XAxis","YAxis","Tooltip","ChartTooltip","BORDER","Bar","roundedBarShape","ANIMATION","ReferenceLine","AreaChart","Area","PANEL"],"mappings":";;;;;;;;;;;;;AAmCO,IAAM,YAAY,CAAC;AAAA,EACxB,IAAA;AAAA,EACA,KAAA,GAAQA,yBAAO,CAAC,CAAA;AAAA,EAChB,OAAA,GAAU,MAAA;AAAA,EACV,KAAA,GAAQ,OAAA;AAAA,EACR,WAAA;AAAA,EACA,GAAA;AAAA,EACA,GAAA;AAAA,EACA,YAAA,GAAe,SAAA;AAAA,EACf,SAAA;AAAA,EACA,QAAA;AAAA,EACA,MAAA,GAAS,EAAA;AAAA,EACT;AACF,CAAA,KAAsB;AACpB,EAAA,MAAM,GAAA,GAAMC,wBAAA,CAAOC,WAAA,EAAO,CAAA;AAC1B,EAAA,MAAM,IAAA,GAAO,SAAA,IAAa,CAAA,SAAA,EAAY,KAAK,CAAA,CAAA;AAC3C,EAAA,IAAIC,4BAAU,CAAC,EAAE,IAAA,EAAM,CAAC,CAAA,EAAG;AACzB,IAAA,sCAAQC,4BAAA,EAAA,EAAW,OAAA,EAAS,cAAc,SAAA,EAAW,IAAA,EAAM,QAAgB,KAAA,EAAc,CAAA;AAAA,EAC3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AAA,EAAE;AAAA,YAC7D,GAAGJ;AAAA;AAAA,SACN;AAAA,QACC;AAAA;AAAA;AAAA,GACH;AAEJ","file":"Sparkline.cjs","sourcesContent":["import { useId } from 'react';\nimport { Area, AreaChart, Bar, BarChart, ReferenceLine, Tooltip, XAxis, YAxis } from 'recharts';\nimport { ANIMATION } from './core/animation';\nimport { ChartTooltip } from './core/ChartTooltip';\nimport { BORDER, ERROR, PANEL, SERIES } from './core/colors';\nimport { hasNoData, safeId } from './core/data';\nimport { ChartEmpty, frameProps } from './core/frame';\nimport { roundedBarShape } from './core/roundedBar';\nimport type { ChartEmptyProps, ChartProps } from './types';\n\nexport type SparklineProps = ChartProps &\n ChartEmptyProps & {\n data: number[];\n /** A CSS color. Default: the accent. */\n color?: string;\n /**\n * `area` (default), `line`, or `bar`: narrow columns in `color`, the ones below zero in the\n * danger color under a dashed zero line.\n */\n variant?: 'line' | 'area' | 'bar';\n /** Names the value in the tooltip. Default `value`. Drawn as plain text. */\n label?: string;\n /** Format the tooltip value (default `String`). */\n formatValue?: (value: number) => string;\n /**\n * Bottom of the scale. Default: the lowest value of `data`, so each sparkline fills its\n * height; for `bar`, the lower of 0 and the lowest value, since a bar scale that does not\n * start at zero exaggerates the differences. Set the same `min` and `max` on sparklines that\n * are read against each other.\n */\n min?: number;\n /** Top of the scale. Default: the highest value of `data` (for `bar`, at least 0). */\n max?: number;\n };\n\nexport const Sparkline = ({\n data,\n color = SERIES[0],\n variant = 'area',\n label = 'value',\n formatValue,\n min,\n max,\n emptyMessage = 'No data',\n ariaLabel,\n children,\n height = 60,\n width,\n}: SparklineProps) => {\n const uid = safeId(useId());\n const name = ariaLabel ?? `Trend of ${label}`;\n if (hasNoData([{ data }])) {\n return <ChartEmpty message={emptyMessage} ariaLabel={name} height={height} width={width} />;\n }\n if (variant === 'bar') {\n const fillFor = (value: number) => (value < 0 ? ERROR : undefined);\n const hasNegative = data.some((value) => value < 0);\n return (\n <BarChart\n {...frameProps({ height, width, ariaLabel: name, keyboard: false })}\n data={data.map((value, i) => ({ i, value }))}\n margin={{ top: 6, right: 4, bottom: 4, left: 4 }}\n barCategoryGap=\"20%\"\n >\n <XAxis hide dataKey=\"i\" />\n <YAxis hide domain={[min ?? Math.min(0, ...data), max ?? Math.max(0, ...data)]} />\n <Tooltip\n content={<ChartTooltip format={formatValue} hideTitle colorOf={fillFor} />}\n cursor={{ fill: BORDER, fillOpacity: 0.35 }}\n offset={12}\n allowEscapeViewBox={{ x: true, y: true }}\n animationDuration={100}\n />\n <Bar\n name={label}\n dataKey=\"value\"\n fill={color}\n maxBarSize={14}\n shape={roundedBarShape({ layout: 'horizontal', radius: 2, dataKey: 'value', fillFor })}\n {...ANIMATION}\n />\n {hasNegative && (\n <ReferenceLine y={0} stroke={BORDER} strokeDasharray=\"3 3\" ifOverflow=\"hidden\" />\n )}\n {children}\n </BarChart>\n );\n }\n return (\n <AreaChart\n // A sparkline is an image: the tooltip follows the pointer, and Tab skips it.\n {...frameProps({ height, width, ariaLabel: name, keyboard: false })}\n data={data.map((value, i) => ({ i, value }))}\n margin={{ top: 6, right: 4, bottom: 4, left: 4 }}\n >\n <defs>\n <linearGradient id={uid} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n <stop offset=\"0%\" stopColor={color} stopOpacity={0.32} />\n <stop offset=\"100%\" stopColor={color} stopOpacity={0} />\n </linearGradient>\n </defs>\n {/* The scale fits the data unless pinned. */}\n <YAxis hide domain={[min ?? 'dataMin', max ?? 'dataMax']} />\n <Tooltip\n content={<ChartTooltip format={formatValue} hideTitle />}\n cursor={false}\n offset={12}\n allowEscapeViewBox={{ x: true, y: true }}\n animationDuration={100}\n />\n <Area\n name={label}\n dataKey=\"value\"\n type=\"monotone\"\n stroke={color}\n strokeWidth={2}\n fill={variant === 'area' ? `url(#${uid})` : 'none'}\n dot={false}\n activeDot={{ r: 4, fill: PANEL, stroke: color, strokeWidth: 2 }}\n {...ANIMATION}\n />\n {children}\n </AreaChart>\n );\n};\n"]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { roundedBarShape } from './chunk-GDZLYYL2.js';
|
|
3
|
+
import { ANIMATION } from './chunk-5C2RLJYZ.js';
|
|
4
|
+
import { ChartTooltip } from './chunk-VIOSQN4Z.js';
|
|
5
|
+
import { safeId, hasNoData } from './chunk-UJIV5PVI.js';
|
|
6
|
+
import { ChartEmpty, frameProps } from './chunk-3N43QT36.js';
|
|
7
|
+
import { BORDER, ERROR, SERIES, PANEL } from './chunk-UATB2IRY.js';
|
|
8
|
+
import { useId } from 'react';
|
|
9
|
+
import { BarChart, XAxis, YAxis, Tooltip, Bar, ReferenceLine, AreaChart, Area } from 'recharts';
|
|
10
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
11
|
+
|
|
12
|
+
var Sparkline = ({
|
|
13
|
+
data,
|
|
14
|
+
color = SERIES[0],
|
|
15
|
+
variant = "area",
|
|
16
|
+
label = "value",
|
|
17
|
+
formatValue,
|
|
18
|
+
min,
|
|
19
|
+
max,
|
|
20
|
+
emptyMessage = "No data",
|
|
21
|
+
ariaLabel,
|
|
22
|
+
children,
|
|
23
|
+
height = 60,
|
|
24
|
+
width
|
|
25
|
+
}) => {
|
|
26
|
+
const uid = safeId(useId());
|
|
27
|
+
const name = ariaLabel ?? `Trend of ${label}`;
|
|
28
|
+
if (hasNoData([{ data }])) {
|
|
29
|
+
return /* @__PURE__ */ jsx(ChartEmpty, { message: emptyMessage, ariaLabel: name, height, width });
|
|
30
|
+
}
|
|
31
|
+
if (variant === "bar") {
|
|
32
|
+
const fillFor = (value) => value < 0 ? ERROR : void 0;
|
|
33
|
+
const hasNegative = data.some((value) => value < 0);
|
|
34
|
+
return /* @__PURE__ */ jsxs(
|
|
35
|
+
BarChart,
|
|
36
|
+
{
|
|
37
|
+
...frameProps({ height, width, ariaLabel: name, keyboard: false }),
|
|
38
|
+
data: data.map((value, i) => ({ i, value })),
|
|
39
|
+
margin: { top: 6, right: 4, bottom: 4, left: 4 },
|
|
40
|
+
barCategoryGap: "20%",
|
|
41
|
+
children: [
|
|
42
|
+
/* @__PURE__ */ jsx(XAxis, { hide: true, dataKey: "i" }),
|
|
43
|
+
/* @__PURE__ */ jsx(YAxis, { hide: true, domain: [min ?? Math.min(0, ...data), max ?? Math.max(0, ...data)] }),
|
|
44
|
+
/* @__PURE__ */ jsx(
|
|
45
|
+
Tooltip,
|
|
46
|
+
{
|
|
47
|
+
content: /* @__PURE__ */ jsx(ChartTooltip, { format: formatValue, hideTitle: true, colorOf: fillFor }),
|
|
48
|
+
cursor: { fill: BORDER, fillOpacity: 0.35 },
|
|
49
|
+
offset: 12,
|
|
50
|
+
allowEscapeViewBox: { x: true, y: true },
|
|
51
|
+
animationDuration: 100
|
|
52
|
+
}
|
|
53
|
+
),
|
|
54
|
+
/* @__PURE__ */ jsx(
|
|
55
|
+
Bar,
|
|
56
|
+
{
|
|
57
|
+
name: label,
|
|
58
|
+
dataKey: "value",
|
|
59
|
+
fill: color,
|
|
60
|
+
maxBarSize: 14,
|
|
61
|
+
shape: roundedBarShape({ layout: "horizontal", radius: 2, dataKey: "value", fillFor }),
|
|
62
|
+
...ANIMATION
|
|
63
|
+
}
|
|
64
|
+
),
|
|
65
|
+
hasNegative && /* @__PURE__ */ jsx(ReferenceLine, { y: 0, stroke: BORDER, strokeDasharray: "3 3", ifOverflow: "hidden" }),
|
|
66
|
+
children
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return /* @__PURE__ */ jsxs(
|
|
72
|
+
AreaChart,
|
|
73
|
+
{
|
|
74
|
+
...frameProps({ height, width, ariaLabel: name, keyboard: false }),
|
|
75
|
+
data: data.map((value, i) => ({ i, value })),
|
|
76
|
+
margin: { top: 6, right: 4, bottom: 4, left: 4 },
|
|
77
|
+
children: [
|
|
78
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", { id: uid, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
79
|
+
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: color, stopOpacity: 0.32 }),
|
|
80
|
+
/* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: color, stopOpacity: 0 })
|
|
81
|
+
] }) }),
|
|
82
|
+
/* @__PURE__ */ jsx(YAxis, { hide: true, domain: [min ?? "dataMin", max ?? "dataMax"] }),
|
|
83
|
+
/* @__PURE__ */ jsx(
|
|
84
|
+
Tooltip,
|
|
85
|
+
{
|
|
86
|
+
content: /* @__PURE__ */ jsx(ChartTooltip, { format: formatValue, hideTitle: true }),
|
|
87
|
+
cursor: false,
|
|
88
|
+
offset: 12,
|
|
89
|
+
allowEscapeViewBox: { x: true, y: true },
|
|
90
|
+
animationDuration: 100
|
|
91
|
+
}
|
|
92
|
+
),
|
|
93
|
+
/* @__PURE__ */ jsx(
|
|
94
|
+
Area,
|
|
95
|
+
{
|
|
96
|
+
name: label,
|
|
97
|
+
dataKey: "value",
|
|
98
|
+
type: "monotone",
|
|
99
|
+
stroke: color,
|
|
100
|
+
strokeWidth: 2,
|
|
101
|
+
fill: variant === "area" ? `url(#${uid})` : "none",
|
|
102
|
+
dot: false,
|
|
103
|
+
activeDot: { r: 4, fill: PANEL, stroke: color, strokeWidth: 2 },
|
|
104
|
+
...ANIMATION
|
|
105
|
+
}
|
|
106
|
+
),
|
|
107
|
+
children
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export { Sparkline };
|
|
114
|
+
//# sourceMappingURL=Sparkline.js.map
|
|
115
|
+
//# sourceMappingURL=Sparkline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Sparkline.tsx"],"names":[],"mappings":";;;;;;;;;;;AAmCO,IAAM,YAAY,CAAC;AAAA,EACxB,IAAA;AAAA,EACA,KAAA,GAAQ,OAAO,CAAC,CAAA;AAAA,EAChB,OAAA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AAA,EAAK;AAAA,YACvC,iBAAA,EAAmB;AAAA;AAAA,SACrB;AAAA,wBACA,GAAA;AAAA,UAAC,IAAA;AAAA,UAAA;AAAA,YACC,IAAA,EAAM,KAAA;AAAA,YACN,OAAA,EAAQ,OAAA;AAAA,YACR,IAAA,EAAK,UAAA;AAAA,YACL,MAAA,EAAQ,KAAA;AAAA,YACR,WAAA,EAAa,CAAA;AAAA,YACb,IAAA,EAAM,OAAA,KAAY,MAAA,GAAS,CAAA,KAAA,EAAQ,GAAG,CAAA,CAAA,CAAA,GAAM,MAAA;AAAA,YAC5C,GAAA,EAAK,KAAA;AAAA,YACL,SAAA,EAAW,EAAE,CAAA,EAAG,CAAA,EAAG,MAAM,KAAA,EAAO,MAAA,EAAQ,KAAA,EAAO,WAAA,EAAa,CAAA,EAAE;AAAA,YAC7D,GAAG;AAAA;AAAA,SACN;AAAA,QACC;AAAA;AAAA;AAAA,GACH;AAEJ","file":"Sparkline.js","sourcesContent":["import { useId } from 'react';\nimport { Area, AreaChart, Bar, BarChart, ReferenceLine, Tooltip, XAxis, YAxis } from 'recharts';\nimport { ANIMATION } from './core/animation';\nimport { ChartTooltip } from './core/ChartTooltip';\nimport { BORDER, ERROR, PANEL, SERIES } from './core/colors';\nimport { hasNoData, safeId } from './core/data';\nimport { ChartEmpty, frameProps } from './core/frame';\nimport { roundedBarShape } from './core/roundedBar';\nimport type { ChartEmptyProps, ChartProps } from './types';\n\nexport type SparklineProps = ChartProps &\n ChartEmptyProps & {\n data: number[];\n /** A CSS color. Default: the accent. */\n color?: string;\n /**\n * `area` (default), `line`, or `bar`: narrow columns in `color`, the ones below zero in the\n * danger color under a dashed zero line.\n */\n variant?: 'line' | 'area' | 'bar';\n /** Names the value in the tooltip. Default `value`. Drawn as plain text. */\n label?: string;\n /** Format the tooltip value (default `String`). */\n formatValue?: (value: number) => string;\n /**\n * Bottom of the scale. Default: the lowest value of `data`, so each sparkline fills its\n * height; for `bar`, the lower of 0 and the lowest value, since a bar scale that does not\n * start at zero exaggerates the differences. Set the same `min` and `max` on sparklines that\n * are read against each other.\n */\n min?: number;\n /** Top of the scale. Default: the highest value of `data` (for `bar`, at least 0). */\n max?: number;\n };\n\nexport const Sparkline = ({\n data,\n color = SERIES[0],\n variant = 'area',\n label = 'value',\n formatValue,\n min,\n max,\n emptyMessage = 'No data',\n ariaLabel,\n children,\n height = 60,\n width,\n}: SparklineProps) => {\n const uid = safeId(useId());\n const name = ariaLabel ?? `Trend of ${label}`;\n if (hasNoData([{ data }])) {\n return <ChartEmpty message={emptyMessage} ariaLabel={name} height={height} width={width} />;\n }\n if (variant === 'bar') {\n const fillFor = (value: number) => (value < 0 ? ERROR : undefined);\n const hasNegative = data.some((value) => value < 0);\n return (\n <BarChart\n {...frameProps({ height, width, ariaLabel: name, keyboard: false })}\n data={data.map((value, i) => ({ i, value }))}\n margin={{ top: 6, right: 4, bottom: 4, left: 4 }}\n barCategoryGap=\"20%\"\n >\n <XAxis hide dataKey=\"i\" />\n <YAxis hide domain={[min ?? Math.min(0, ...data), max ?? Math.max(0, ...data)]} />\n <Tooltip\n content={<ChartTooltip format={formatValue} hideTitle colorOf={fillFor} />}\n cursor={{ fill: BORDER, fillOpacity: 0.35 }}\n offset={12}\n allowEscapeViewBox={{ x: true, y: true }}\n animationDuration={100}\n />\n <Bar\n name={label}\n dataKey=\"value\"\n fill={color}\n maxBarSize={14}\n shape={roundedBarShape({ layout: 'horizontal', radius: 2, dataKey: 'value', fillFor })}\n {...ANIMATION}\n />\n {hasNegative && (\n <ReferenceLine y={0} stroke={BORDER} strokeDasharray=\"3 3\" ifOverflow=\"hidden\" />\n )}\n {children}\n </BarChart>\n );\n }\n return (\n <AreaChart\n // A sparkline is an image: the tooltip follows the pointer, and Tab skips it.\n {...frameProps({ height, width, ariaLabel: name, keyboard: false })}\n data={data.map((value, i) => ({ i, value }))}\n margin={{ top: 6, right: 4, bottom: 4, left: 4 }}\n >\n <defs>\n <linearGradient id={uid} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n <stop offset=\"0%\" stopColor={color} stopOpacity={0.32} />\n <stop offset=\"100%\" stopColor={color} stopOpacity={0} />\n </linearGradient>\n </defs>\n {/* The scale fits the data unless pinned. */}\n <YAxis hide domain={[min ?? 'dataMin', max ?? 'dataMax']} />\n <Tooltip\n content={<ChartTooltip format={formatValue} hideTitle />}\n cursor={false}\n offset={12}\n allowEscapeViewBox={{ x: true, y: true }}\n animationDuration={100}\n />\n <Area\n name={label}\n dataKey=\"value\"\n type=\"monotone\"\n stroke={color}\n strokeWidth={2}\n fill={variant === 'area' ? `url(#${uid})` : 'none'}\n dot={false}\n activeDot={{ r: 4, fill: PANEL, stroke: color, strokeWidth: 2 }}\n {...ANIMATION}\n />\n {children}\n </AreaChart>\n );\n};\n"]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var chunkMN4CDVOS_cjs = require('./chunk-MN4CDVOS.cjs');
|
|
5
|
+
var chunkAAYHG7YK_cjs = require('./chunk-AAYHG7YK.cjs');
|
|
6
|
+
require('./chunk-X3YZP5WF.cjs');
|
|
7
|
+
require('./chunk-TYQWZR3S.cjs');
|
|
8
|
+
require('./chunk-6NRRABPF.cjs');
|
|
9
|
+
var chunkLT3UC65O_cjs = require('./chunk-LT3UC65O.cjs');
|
|
10
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
11
|
+
|
|
12
|
+
var RADIAN = Math.PI / 180;
|
|
13
|
+
var arcPath = (cx, cy, r, from, to) => {
|
|
14
|
+
const at = (angle) => `${cx + r * Math.cos(-angle * RADIAN)} ${cy + r * Math.sin(-angle * RADIAN)}`;
|
|
15
|
+
const sweep = Math.abs(to - from);
|
|
16
|
+
if (sweep >= 359.99)
|
|
17
|
+
return `M${at(from)} A${r} ${r} 0 1 1 ${at(from - 180)} A${r} ${r} 0 1 1 ${at(from)}`;
|
|
18
|
+
return `M${at(from)} A${r} ${r} 0 ${sweep > 180 ? 1 : 0} 1 ${at(to)}`;
|
|
19
|
+
};
|
|
20
|
+
var dashes = (thickness, r) => {
|
|
21
|
+
const circumference = 2 * Math.PI * r;
|
|
22
|
+
const step = circumference / Math.max(1, Math.round(circumference / (thickness * 2)));
|
|
23
|
+
const dash = thickness * 0.4;
|
|
24
|
+
return `${dash} ${step - dash}`;
|
|
25
|
+
};
|
|
26
|
+
var dashedGauge = (color) => ({
|
|
27
|
+
cx = 0,
|
|
28
|
+
cy = 0,
|
|
29
|
+
innerRadius = 0,
|
|
30
|
+
outerRadius = 0,
|
|
31
|
+
startAngle = 0,
|
|
32
|
+
endAngle = 0
|
|
33
|
+
}) => {
|
|
34
|
+
const thickness = Number(outerRadius) - Number(innerRadius);
|
|
35
|
+
const r = (Number(outerRadius) + Number(innerRadius)) / 2;
|
|
36
|
+
const [x, y, from, to] = [cx, cy, startAngle, endAngle].map(Number);
|
|
37
|
+
const stroke = {
|
|
38
|
+
fill: "none",
|
|
39
|
+
strokeWidth: thickness,
|
|
40
|
+
strokeLinecap: "round",
|
|
41
|
+
strokeDasharray: dashes(thickness, r)
|
|
42
|
+
};
|
|
43
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
|
|
44
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
45
|
+
"path",
|
|
46
|
+
{
|
|
47
|
+
className: "recharts-radial-bar-background-sector",
|
|
48
|
+
d: arcPath(x, y, r, from, from - 360),
|
|
49
|
+
stroke: chunkLT3UC65O_cjs.TRACK,
|
|
50
|
+
...stroke
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
Math.abs(to - from) >= 0.01 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
54
|
+
"path",
|
|
55
|
+
{
|
|
56
|
+
className: "recharts-radial-bar-sector",
|
|
57
|
+
d: arcPath(x, y, r, from, to),
|
|
58
|
+
stroke: color,
|
|
59
|
+
...stroke
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
] });
|
|
63
|
+
};
|
|
64
|
+
var StrokedGauge = ({
|
|
65
|
+
value,
|
|
66
|
+
label = "",
|
|
67
|
+
color = chunkLT3UC65O_cjs.SERIES[0],
|
|
68
|
+
min = 0,
|
|
69
|
+
max = 100,
|
|
70
|
+
formatValue = chunkAAYHG7YK_cjs.percent,
|
|
71
|
+
ariaLabel,
|
|
72
|
+
children,
|
|
73
|
+
height = 280,
|
|
74
|
+
width
|
|
75
|
+
}) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
76
|
+
chunkMN4CDVOS_cjs.RadialGauge,
|
|
77
|
+
{
|
|
78
|
+
value,
|
|
79
|
+
label,
|
|
80
|
+
min,
|
|
81
|
+
max,
|
|
82
|
+
text: formatValue(value),
|
|
83
|
+
ariaLabel,
|
|
84
|
+
hollow: "88%",
|
|
85
|
+
shape: dashedGauge(color),
|
|
86
|
+
height,
|
|
87
|
+
width,
|
|
88
|
+
children
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
exports.StrokedGauge = StrokedGauge;
|
|
93
|
+
//# sourceMappingURL=StrokedGauge.cjs.map
|
|
94
|
+
//# sourceMappingURL=StrokedGauge.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/StrokedGauge.tsx"],"names":["jsx","TRACK","SERIES","percent","RadialGauge"],"mappings":";;;;;;;;;;;AAmBA,IAAM,MAAA,GAAS,KAAK,EAAA,GAAK,GAAA;AAKzB,IAAM,UAAU,CAAC,EAAA,EAAY,EAAA,EAAY,CAAA,EAAW,MAAc,EAAA,KAAe;AAC/E,EAAA,MAAM,EAAA,GAAK,CAAC,KAAA,KACV,CAAA,EAAG,KAAK,CAAA,GAAI,IAAA,CAAK,IAAI,CAAC,KAAA,GAAQ,MAAM,CAAC,CAAA,CAAA,EAAI,KAAK,CAAA,GAAI,IAAA,CAAK,IAAI,CAAC,KAAA,GAAQ,MAAM,CAAC,CAAA,CAAA;AAC7E,EAAA,MAAM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ACN,GAAA,GAAM,GAAA;AAAA,EACN,WAAA,GAAcC,yBAAA;AAAA,EACd,SAAA;AAAA,EACA,QAAA;AAAA,EACA,MAAA,GAAS,GAAA;AAAA,EACT;AACF,CAAA,qBACEH,cAAA;AAAA,EAACI,6BAAA;AAAA,EAAA;AAAA,IACC,KAAA;AAAA,IACA,KAAA;AAAA,IACA,GAAA;AAAA,IACA,GAAA;AAAA,IACA,IAAA,EAAM,YAAY,KAAK,CAAA;AAAA,IACvB,SAAA;AAAA,IACA,MAAA,EAAO,KAAA;AAAA,IACP,KAAA,EAAO,YAAY,KAAK,CAAA;AAAA,IACxB,MAAA;AAAA,IACA,KAAA;AAAA,IAEC;AAAA;AACH","file":"StrokedGauge.cjs","sourcesContent":["import type { SectorProps } from 'recharts';\nimport { SERIES, TRACK } from './core/colors';\nimport { percent } from './core/gauge';\nimport { RadialGauge } from './core/RadialGauge';\nimport type { ChartProps } from './types';\n\nexport type StrokedGaugeProps = ChartProps & {\n value: number;\n label?: string;\n /** Color of the arc. Default: the accent. */\n color?: string;\n /** Value at the start of the arc. Default 0. */\n min?: number;\n /** Value at the end of the arc, above `min`. Default 100. Out of range, the arc stops at an end. */\n max?: number;\n /** Format the center value, from `value` itself (not its share of the range). Default: `92%`. */\n formatValue?: (value: number) => string;\n};\n\nconst RADIAN = Math.PI / 180;\n\n// A Recharts sector is a filled shape, which cannot be dashed: the arc is\n// drawn as a stroke of the sector's thickness along its middle line. Recharts\n// angles run counter-clockwise from the right; the arc goes clockwise.\nconst arcPath = (cx: number, cy: number, r: number, from: number, to: number) => {\n const at = (angle: number) =>\n `${cx + r * Math.cos(-angle * RADIAN)} ${cy + r * Math.sin(-angle * RADIAN)}`;\n const sweep = Math.abs(to - from);\n // A single arc cannot close a circle: two halves.\n if (sweep >= 359.99)\n return `M${at(from)} A${r} ${r} 0 1 1 ${at(from - 180)} A${r} ${r} 0 1 1 ${at(from)}`;\n return `M${at(from)} A${r} ${r} 0 ${sweep > 180 ? 1 : 0} 1 ${at(to)}`;\n};\n\n// Round dashes a little longer than the ring is thick, spaced so a whole\n// number of them closes the circle: the arc and the track share the pattern\n// and the same start, so the arc lights the dashes of the track.\nconst dashes = (thickness: number, r: number) => {\n const circumference = 2 * Math.PI * r;\n const step = circumference / Math.max(1, Math.round(circumference / (thickness * 2)));\n const dash = thickness * 0.4;\n return `${dash} ${step - dash}`;\n};\n\n// The whole circle in the same dashes, from the same start, behind the arc: the\n// shape draws both from one set of sector props, so the arc lights the dashes\n// of the track. It is called for an empty arc too.\nconst dashedGauge =\n (color: string) =>\n ({\n cx = 0,\n cy = 0,\n innerRadius = 0,\n outerRadius = 0,\n startAngle = 0,\n endAngle = 0,\n }: SectorProps) => {\n const thickness = Number(outerRadius) - Number(innerRadius);\n const r = (Number(outerRadius) + Number(innerRadius)) / 2;\n const [x, y, from, to] = [cx, cy, startAngle, endAngle].map(Number);\n const stroke = {\n fill: 'none',\n strokeWidth: thickness,\n strokeLinecap: 'round' as const,\n strokeDasharray: dashes(thickness, r),\n };\n return (\n <g>\n <path\n className=\"recharts-radial-bar-background-sector\"\n d={arcPath(x, y, r, from, from - 360)}\n stroke={TRACK}\n {...stroke}\n />\n {/* A zero-length arc would still draw its round cap. */}\n {Math.abs(to - from) >= 0.01 && (\n <path\n className=\"recharts-radial-bar-sector\"\n d={arcPath(x, y, r, from, to)}\n stroke={color}\n {...stroke}\n />\n )}\n </g>\n );\n };\n\nexport const StrokedGauge = ({\n value,\n label = '',\n color = SERIES[0],\n min = 0,\n max = 100,\n formatValue = percent,\n ariaLabel,\n children,\n height = 280,\n width,\n}: StrokedGaugeProps) => (\n <RadialGauge\n value={value}\n label={label}\n min={min}\n max={max}\n text={formatValue(value)}\n ariaLabel={ariaLabel}\n hollow=\"88%\"\n shape={dashedGauge(color)}\n height={height}\n width={width}\n >\n {children}\n </RadialGauge>\n);\n"]}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { RadialGauge } from './chunk-YWYF5CCJ.js';
|
|
3
|
+
import { percent } from './chunk-OCD6JIIX.js';
|
|
4
|
+
import './chunk-URNXLVSK.js';
|
|
5
|
+
import './chunk-5C2RLJYZ.js';
|
|
6
|
+
import './chunk-3N43QT36.js';
|
|
7
|
+
import { SERIES, TRACK } from './chunk-UATB2IRY.js';
|
|
8
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
9
|
+
|
|
10
|
+
var RADIAN = Math.PI / 180;
|
|
11
|
+
var arcPath = (cx, cy, r, from, to) => {
|
|
12
|
+
const at = (angle) => `${cx + r * Math.cos(-angle * RADIAN)} ${cy + r * Math.sin(-angle * RADIAN)}`;
|
|
13
|
+
const sweep = Math.abs(to - from);
|
|
14
|
+
if (sweep >= 359.99)
|
|
15
|
+
return `M${at(from)} A${r} ${r} 0 1 1 ${at(from - 180)} A${r} ${r} 0 1 1 ${at(from)}`;
|
|
16
|
+
return `M${at(from)} A${r} ${r} 0 ${sweep > 180 ? 1 : 0} 1 ${at(to)}`;
|
|
17
|
+
};
|
|
18
|
+
var dashes = (thickness, r) => {
|
|
19
|
+
const circumference = 2 * Math.PI * r;
|
|
20
|
+
const step = circumference / Math.max(1, Math.round(circumference / (thickness * 2)));
|
|
21
|
+
const dash = thickness * 0.4;
|
|
22
|
+
return `${dash} ${step - dash}`;
|
|
23
|
+
};
|
|
24
|
+
var dashedGauge = (color) => ({
|
|
25
|
+
cx = 0,
|
|
26
|
+
cy = 0,
|
|
27
|
+
innerRadius = 0,
|
|
28
|
+
outerRadius = 0,
|
|
29
|
+
startAngle = 0,
|
|
30
|
+
endAngle = 0
|
|
31
|
+
}) => {
|
|
32
|
+
const thickness = Number(outerRadius) - Number(innerRadius);
|
|
33
|
+
const r = (Number(outerRadius) + Number(innerRadius)) / 2;
|
|
34
|
+
const [x, y, from, to] = [cx, cy, startAngle, endAngle].map(Number);
|
|
35
|
+
const stroke = {
|
|
36
|
+
fill: "none",
|
|
37
|
+
strokeWidth: thickness,
|
|
38
|
+
strokeLinecap: "round",
|
|
39
|
+
strokeDasharray: dashes(thickness, r)
|
|
40
|
+
};
|
|
41
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
42
|
+
/* @__PURE__ */ jsx(
|
|
43
|
+
"path",
|
|
44
|
+
{
|
|
45
|
+
className: "recharts-radial-bar-background-sector",
|
|
46
|
+
d: arcPath(x, y, r, from, from - 360),
|
|
47
|
+
stroke: TRACK,
|
|
48
|
+
...stroke
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
Math.abs(to - from) >= 0.01 && /* @__PURE__ */ jsx(
|
|
52
|
+
"path",
|
|
53
|
+
{
|
|
54
|
+
className: "recharts-radial-bar-sector",
|
|
55
|
+
d: arcPath(x, y, r, from, to),
|
|
56
|
+
stroke: color,
|
|
57
|
+
...stroke
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
] });
|
|
61
|
+
};
|
|
62
|
+
var StrokedGauge = ({
|
|
63
|
+
value,
|
|
64
|
+
label = "",
|
|
65
|
+
color = SERIES[0],
|
|
66
|
+
min = 0,
|
|
67
|
+
max = 100,
|
|
68
|
+
formatValue = percent,
|
|
69
|
+
ariaLabel,
|
|
70
|
+
children,
|
|
71
|
+
height = 280,
|
|
72
|
+
width
|
|
73
|
+
}) => /* @__PURE__ */ jsx(
|
|
74
|
+
RadialGauge,
|
|
75
|
+
{
|
|
76
|
+
value,
|
|
77
|
+
label,
|
|
78
|
+
min,
|
|
79
|
+
max,
|
|
80
|
+
text: formatValue(value),
|
|
81
|
+
ariaLabel,
|
|
82
|
+
hollow: "88%",
|
|
83
|
+
shape: dashedGauge(color),
|
|
84
|
+
height,
|
|
85
|
+
width,
|
|
86
|
+
children
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
export { StrokedGauge };
|
|
91
|
+
//# sourceMappingURL=StrokedGauge.js.map
|
|
92
|
+
//# sourceMappingURL=StrokedGauge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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AAK,IAAA,oBACtB,GAAA;AAAA,MAAC,MAAA;AAAA,MAAA;AAAA,QACC,SAAA,EAAU,4BAAA;AAAA,QACV,GAAG,OAAA,CAAQ,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,MAAM,EAAE,CAAA;AAAA,QAC5B,MAAA,EAAQ,KAAA;AAAA,QACP,GAAG;AAAA;AAAA;AACN,GAAA,EAEJ,CAAA;AAEJ,CAAA;AAEK,IAAM,eAAe,CAAC;AAAA,EAC3B,KAAA;AAAA,EACA,KAAA,GAAQ,EAAA;AAAA,EACR,KAAA,GAAQ,OAAO,CAAC,CAAA;AAAA,EAChB,GAAA,GAAM,CAAA;AAAA,EACN,GAAA,GAAM,GAAA;AAAA,EACN,WAAA,GAAc,OAAA;AAAA,EACd,SAAA;AAAA,EACA,QAAA;AAAA,EACA,MAAA,GAAS,GAAA;AAAA,EACT;AACF,CAAA,qBACE,GAAA;AAAA,EAAC,WAAA;AAAA,EAAA;AAAA,IACC,KAAA;AAAA,IACA,KAAA;AAAA,IACA,GAAA;AAAA,IACA,GAAA;AAAA,IACA,IAAA,EAAM,YAAY,KAAK,CAAA;AAAA,IACvB,SAAA;AAAA,IACA,MAAA,EAAO,KAAA;AAAA,IACP,KAAA,EAAO,YAAY,KAAK,CAAA;AAAA,IACxB,MAAA;AAAA,IACA,KAAA;AAAA,IAEC;AAAA;AACH","file":"StrokedGauge.js","sourcesContent":["import type { SectorProps } from 'recharts';\nimport { SERIES, TRACK } from './core/colors';\nimport { percent } from './core/gauge';\nimport { RadialGauge } from './core/RadialGauge';\nimport type { ChartProps } from './types';\n\nexport type StrokedGaugeProps = ChartProps & {\n value: number;\n label?: string;\n /** Color of the arc. Default: the accent. */\n color?: string;\n /** Value at the start of the arc. Default 0. */\n min?: number;\n /** Value at the end of the arc, above `min`. Default 100. Out of range, the arc stops at an end. */\n max?: number;\n /** Format the center value, from `value` itself (not its share of the range). Default: `92%`. */\n formatValue?: (value: number) => string;\n};\n\nconst RADIAN = Math.PI / 180;\n\n// A Recharts sector is a filled shape, which cannot be dashed: the arc is\n// drawn as a stroke of the sector's thickness along its middle line. Recharts\n// angles run counter-clockwise from the right; the arc goes clockwise.\nconst arcPath = (cx: number, cy: number, r: number, from: number, to: number) => {\n const at = (angle: number) =>\n `${cx + r * Math.cos(-angle * RADIAN)} ${cy + r * Math.sin(-angle * RADIAN)}`;\n const sweep = Math.abs(to - from);\n // A single arc cannot close a circle: two halves.\n if (sweep >= 359.99)\n return `M${at(from)} A${r} ${r} 0 1 1 ${at(from - 180)} A${r} ${r} 0 1 1 ${at(from)}`;\n return `M${at(from)} A${r} ${r} 0 ${sweep > 180 ? 1 : 0} 1 ${at(to)}`;\n};\n\n// Round dashes a little longer than the ring is thick, spaced so a whole\n// number of them closes the circle: the arc and the track share the pattern\n// and the same start, so the arc lights the dashes of the track.\nconst dashes = (thickness: number, r: number) => {\n const circumference = 2 * Math.PI * r;\n const step = circumference / Math.max(1, Math.round(circumference / (thickness * 2)));\n const dash = thickness * 0.4;\n return `${dash} ${step - dash}`;\n};\n\n// The whole circle in the same dashes, from the same start, behind the arc: the\n// shape draws both from one set of sector props, so the arc lights the dashes\n// of the track. It is called for an empty arc too.\nconst dashedGauge =\n (color: string) =>\n ({\n cx = 0,\n cy = 0,\n innerRadius = 0,\n outerRadius = 0,\n startAngle = 0,\n endAngle = 0,\n }: SectorProps) => {\n const thickness = Number(outerRadius) - Number(innerRadius);\n const r = (Number(outerRadius) + Number(innerRadius)) / 2;\n const [x, y, from, to] = [cx, cy, startAngle, endAngle].map(Number);\n const stroke = {\n fill: 'none',\n strokeWidth: thickness,\n strokeLinecap: 'round' as const,\n strokeDasharray: dashes(thickness, r),\n };\n return (\n <g>\n <path\n className=\"recharts-radial-bar-background-sector\"\n d={arcPath(x, y, r, from, from - 360)}\n stroke={TRACK}\n {...stroke}\n />\n {/* A zero-length arc would still draw its round cap. */}\n {Math.abs(to - from) >= 0.01 && (\n <path\n className=\"recharts-radial-bar-sector\"\n d={arcPath(x, y, r, from, to)}\n stroke={color}\n {...stroke}\n />\n )}\n </g>\n );\n };\n\nexport const StrokedGauge = ({\n value,\n label = '',\n color = SERIES[0],\n min = 0,\n max = 100,\n formatValue = percent,\n ariaLabel,\n children,\n height = 280,\n width,\n}: StrokedGaugeProps) => (\n <RadialGauge\n value={value}\n label={label}\n min={min}\n max={max}\n text={formatValue(value)}\n ariaLabel={ariaLabel}\n hollow=\"88%\"\n shape={dashedGauge(color)}\n height={height}\n width={width}\n >\n {children}\n </RadialGauge>\n);\n"]}
|