@faintshadow/flarecharts 26.3.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 +40 -0
- package/README.md +103 -0
- package/dist/charts/AreaChart.svelte +150 -0
- package/dist/charts/AreaChart.svelte.d.ts +60 -0
- package/dist/charts/BarChart.svelte +142 -0
- package/dist/charts/BarChart.svelte.d.ts +58 -0
- package/dist/charts/BoxPlotChart.svelte +138 -0
- package/dist/charts/BoxPlotChart.svelte.d.ts +56 -0
- package/dist/charts/DonutChart.svelte +129 -0
- package/dist/charts/DonutChart.svelte.d.ts +73 -0
- package/dist/charts/LineChart.svelte +149 -0
- package/dist/charts/LineChart.svelte.d.ts +63 -0
- package/dist/charts/Sparkline.svelte +87 -0
- package/dist/charts/Sparkline.svelte.d.ts +40 -0
- package/dist/charts/StackChart.svelte +157 -0
- package/dist/charts/StackChart.svelte.d.ts +69 -0
- package/dist/components/Arc.svelte +202 -0
- package/dist/components/Arc.svelte.d.ts +50 -0
- package/dist/components/Area.svelte +264 -0
- package/dist/components/Area.svelte.d.ts +54 -0
- package/dist/components/Axis.svelte +139 -0
- package/dist/components/Axis.svelte.d.ts +26 -0
- package/dist/components/Bars.svelte +192 -0
- package/dist/components/Bars.svelte.d.ts +55 -0
- package/dist/components/Box.svelte +287 -0
- package/dist/components/Box.svelte.d.ts +48 -0
- package/dist/components/Chart.svelte +207 -0
- package/dist/components/Chart.svelte.d.ts +23 -0
- package/dist/components/Crosshair.svelte +67 -0
- package/dist/components/Crosshair.svelte.d.ts +14 -0
- package/dist/components/Grid.svelte +38 -0
- package/dist/components/Grid.svelte.d.ts +14 -0
- package/dist/components/Labels.svelte +61 -0
- package/dist/components/Labels.svelte.d.ts +35 -0
- package/dist/components/Legend.svelte +81 -0
- package/dist/components/Legend.svelte.d.ts +12 -0
- package/dist/components/Line.svelte +192 -0
- package/dist/components/Line.svelte.d.ts +47 -0
- package/dist/components/PlotBand.svelte +68 -0
- package/dist/components/PlotBand.svelte.d.ts +14 -0
- package/dist/components/PlotLine.svelte +54 -0
- package/dist/components/PlotLine.svelte.d.ts +16 -0
- package/dist/components/Points.svelte +179 -0
- package/dist/components/Points.svelte.d.ts +53 -0
- package/dist/components/Svg.svelte +36 -0
- package/dist/components/Svg.svelte.d.ts +8 -0
- package/dist/components/Tooltip.svelte +211 -0
- package/dist/components/Tooltip.svelte.d.ts +44 -0
- package/dist/core/bisect.d.ts +5 -0
- package/dist/core/bisect.js +23 -0
- package/dist/core/context.svelte.d.ts +140 -0
- package/dist/core/context.svelte.js +294 -0
- package/dist/core/curves.d.ts +4 -0
- package/dist/core/curves.js +13 -0
- package/dist/core/hit.d.ts +34 -0
- package/dist/core/hit.js +43 -0
- package/dist/core/keynav.d.ts +20 -0
- package/dist/core/keynav.js +41 -0
- package/dist/core/labels.d.ts +39 -0
- package/dist/core/labels.js +27 -0
- package/dist/core/merge.d.ts +17 -0
- package/dist/core/merge.js +46 -0
- package/dist/core/motion.svelte.d.ts +31 -0
- package/dist/core/motion.svelte.js +129 -0
- package/dist/core/normalize.d.ts +35 -0
- package/dist/core/normalize.js +97 -0
- package/dist/core/options.d.ts +113 -0
- package/dist/core/options.js +36 -0
- package/dist/core/palette.d.ts +8 -0
- package/dist/core/palette.js +24 -0
- package/dist/core/responsive.d.ts +6 -0
- package/dist/core/responsive.js +19 -0
- package/dist/core/scales.d.ts +31 -0
- package/dist/core/scales.js +89 -0
- package/dist/core/stack.d.ts +19 -0
- package/dist/core/stack.js +133 -0
- package/dist/core/stats.d.ts +45 -0
- package/dist/core/stats.js +114 -0
- package/dist/core/symbols.d.ts +8 -0
- package/dist/core/symbols.js +31 -0
- package/dist/core/types.d.ts +28 -0
- package/dist/core/types.js +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +42 -0
- package/package.json +81 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { BandSpec, LegendSpec, PlotLineSpec, PlotOptions, SeriesOptions, SimpleAxisOptions, TooltipSpec } from '../core/options.js';
|
|
2
|
+
import type { ResponsiveRule } from '../core/responsive.js';
|
|
3
|
+
import type { Padding } from '../core/types.js';
|
|
4
|
+
declare function $$render<T>(): {
|
|
5
|
+
props: {
|
|
6
|
+
series: SeriesOptions<T>[];
|
|
7
|
+
xAxis?: SimpleAxisOptions;
|
|
8
|
+
yAxis?: SimpleAxisOptions;
|
|
9
|
+
bands?: BandSpec[];
|
|
10
|
+
lines?: PlotLineSpec[];
|
|
11
|
+
grid?: boolean;
|
|
12
|
+
tooltip?: boolean | TooltipSpec;
|
|
13
|
+
legend?: boolean | LegendSpec;
|
|
14
|
+
plotOptions?: PlotOptions<T>;
|
|
15
|
+
padding?: Padding;
|
|
16
|
+
label?: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
} & {
|
|
19
|
+
responsive?: ResponsiveRule<{
|
|
20
|
+
series: SeriesOptions<T>[];
|
|
21
|
+
xAxis?: SimpleAxisOptions;
|
|
22
|
+
yAxis?: SimpleAxisOptions;
|
|
23
|
+
bands?: BandSpec[];
|
|
24
|
+
lines?: PlotLineSpec[];
|
|
25
|
+
grid?: boolean;
|
|
26
|
+
tooltip?: boolean | TooltipSpec;
|
|
27
|
+
legend?: boolean | LegendSpec;
|
|
28
|
+
plotOptions?: PlotOptions<T>;
|
|
29
|
+
padding?: Padding;
|
|
30
|
+
label?: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
}>[];
|
|
33
|
+
class?: string;
|
|
34
|
+
};
|
|
35
|
+
exports: {};
|
|
36
|
+
bindings: "";
|
|
37
|
+
slots: {};
|
|
38
|
+
events: {};
|
|
39
|
+
};
|
|
40
|
+
declare class __sveltets_Render<T> {
|
|
41
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
42
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
43
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
44
|
+
bindings(): "";
|
|
45
|
+
exports(): {};
|
|
46
|
+
}
|
|
47
|
+
interface $$IsomorphicComponent {
|
|
48
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
49
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
50
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
51
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
52
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
53
|
+
}
|
|
54
|
+
declare const BoxPlotChart: $$IsomorphicComponent;
|
|
55
|
+
type BoxPlotChart<T> = InstanceType<typeof BoxPlotChart<T>>;
|
|
56
|
+
export default BoxPlotChart;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
<script lang="ts" generics="T">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import Chart from '../components/Chart.svelte';
|
|
4
|
+
import Svg from '../components/Svg.svelte';
|
|
5
|
+
import Arc from '../components/Arc.svelte';
|
|
6
|
+
import { applyResponsive } from '../core/responsive.js';
|
|
7
|
+
import type { ResponsiveRule } from '../core/responsive.js';
|
|
8
|
+
|
|
9
|
+
const formatTotalDefault = (total: number) => total.toLocaleString();
|
|
10
|
+
|
|
11
|
+
interface BaseProps {
|
|
12
|
+
/** number[] | { value, label? }[] | T[] with accessors. */
|
|
13
|
+
data: readonly T[];
|
|
14
|
+
value?: (datum: T, index: number) => number | null | undefined;
|
|
15
|
+
sliceLabel?: (datum: T, index: number) => string;
|
|
16
|
+
innerRadius?: number;
|
|
17
|
+
radius?: number;
|
|
18
|
+
padAngle?: number;
|
|
19
|
+
cornerRadius?: number;
|
|
20
|
+
colors?: readonly string[];
|
|
21
|
+
labels?: 'inside' | 'outside' | 'none';
|
|
22
|
+
/** Caption under the default center total. */
|
|
23
|
+
centerCaption?: string;
|
|
24
|
+
/** Show the built-in center total (donuts only). */
|
|
25
|
+
showTotal?: boolean;
|
|
26
|
+
formatTotal?: (total: number) => string;
|
|
27
|
+
label?: string;
|
|
28
|
+
/** Accessible chart description. */
|
|
29
|
+
description?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Props extends BaseProps {
|
|
33
|
+
/** Replaces the built-in center entirely. */
|
|
34
|
+
center?: Snippet<[{ total: number; radius: number; innerRadius: number }]>;
|
|
35
|
+
responsive?: ResponsiveRule<BaseProps>[];
|
|
36
|
+
class?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let {
|
|
40
|
+
data,
|
|
41
|
+
value,
|
|
42
|
+
sliceLabel,
|
|
43
|
+
innerRadius = 0.62,
|
|
44
|
+
radius = 0.8,
|
|
45
|
+
padAngle = 1,
|
|
46
|
+
cornerRadius = 2,
|
|
47
|
+
colors,
|
|
48
|
+
labels = 'outside',
|
|
49
|
+
centerCaption,
|
|
50
|
+
showTotal = true,
|
|
51
|
+
formatTotal = formatTotalDefault,
|
|
52
|
+
label = 'Donut chart',
|
|
53
|
+
description,
|
|
54
|
+
center,
|
|
55
|
+
responsive,
|
|
56
|
+
class: klass = ''
|
|
57
|
+
}: Props = $props();
|
|
58
|
+
|
|
59
|
+
let width = $state(0);
|
|
60
|
+
|
|
61
|
+
const eff = $derived(
|
|
62
|
+
applyResponsive(
|
|
63
|
+
{
|
|
64
|
+
data,
|
|
65
|
+
value,
|
|
66
|
+
sliceLabel,
|
|
67
|
+
innerRadius,
|
|
68
|
+
radius,
|
|
69
|
+
padAngle,
|
|
70
|
+
cornerRadius,
|
|
71
|
+
colors,
|
|
72
|
+
labels,
|
|
73
|
+
centerCaption,
|
|
74
|
+
showTotal,
|
|
75
|
+
formatTotal,
|
|
76
|
+
label,
|
|
77
|
+
description
|
|
78
|
+
},
|
|
79
|
+
responsive,
|
|
80
|
+
width
|
|
81
|
+
)
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const centerOn = $derived(eff.showTotal && (eff.innerRadius ?? 0) > 0);
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
{#snippet defaultCenter({ total }: { total: number; radius: number; innerRadius: number })}
|
|
88
|
+
<text class="fc-donut-total" text-anchor="middle" dy={eff.centerCaption ? '-0.05em' : '0.35em'}>
|
|
89
|
+
{(eff.formatTotal ?? formatTotalDefault)(total)}
|
|
90
|
+
</text>
|
|
91
|
+
{#if eff.centerCaption}
|
|
92
|
+
<text class="fc-donut-caption" text-anchor="middle" dy="1.5em">{eff.centerCaption}</text>
|
|
93
|
+
{/if}
|
|
94
|
+
{/snippet}
|
|
95
|
+
|
|
96
|
+
<div class="fc-simple fc-donut-chart {klass}" bind:clientWidth={width}>
|
|
97
|
+
<Chart label={eff.label} description={eff.description}>
|
|
98
|
+
<Svg>
|
|
99
|
+
<Arc
|
|
100
|
+
data={eff.data}
|
|
101
|
+
value={eff.value}
|
|
102
|
+
label={eff.sliceLabel}
|
|
103
|
+
innerRadius={eff.innerRadius}
|
|
104
|
+
radius={eff.radius}
|
|
105
|
+
padAngle={eff.padAngle}
|
|
106
|
+
cornerRadius={eff.cornerRadius}
|
|
107
|
+
colors={eff.colors}
|
|
108
|
+
labelPosition={eff.labels}
|
|
109
|
+
center={center ?? (centerOn ? defaultCenter : undefined)}
|
|
110
|
+
/>
|
|
111
|
+
</Svg>
|
|
112
|
+
</Chart>
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
<style>
|
|
116
|
+
.fc-simple {
|
|
117
|
+
width: 100%;
|
|
118
|
+
height: 100%;
|
|
119
|
+
}
|
|
120
|
+
.fc-donut-chart :global(.fc-donut-total) {
|
|
121
|
+
font-size: 24px;
|
|
122
|
+
font-weight: 700;
|
|
123
|
+
fill: var(--fc-donut-total, currentColor);
|
|
124
|
+
}
|
|
125
|
+
.fc-donut-chart :global(.fc-donut-caption) {
|
|
126
|
+
font-size: 12px;
|
|
127
|
+
fill: var(--fc-axis-label, #64748b);
|
|
128
|
+
}
|
|
129
|
+
</style>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { ResponsiveRule } from '../core/responsive.js';
|
|
3
|
+
declare function $$render<T>(): {
|
|
4
|
+
props: {
|
|
5
|
+
/** number[] | { value, label? }[] | T[] with accessors. */
|
|
6
|
+
data: readonly T[];
|
|
7
|
+
value?: (datum: T, index: number) => number | null | undefined;
|
|
8
|
+
sliceLabel?: (datum: T, index: number) => string;
|
|
9
|
+
innerRadius?: number;
|
|
10
|
+
radius?: number;
|
|
11
|
+
padAngle?: number;
|
|
12
|
+
cornerRadius?: number;
|
|
13
|
+
colors?: readonly string[];
|
|
14
|
+
labels?: "inside" | "outside" | "none";
|
|
15
|
+
/** Caption under the default center total. */
|
|
16
|
+
centerCaption?: string;
|
|
17
|
+
/** Show the built-in center total (donuts only). */
|
|
18
|
+
showTotal?: boolean;
|
|
19
|
+
formatTotal?: (total: number) => string;
|
|
20
|
+
label?: string;
|
|
21
|
+
/** Accessible chart description. */
|
|
22
|
+
description?: string;
|
|
23
|
+
} & {
|
|
24
|
+
/** Replaces the built-in center entirely. */
|
|
25
|
+
center?: Snippet<[{
|
|
26
|
+
total: number;
|
|
27
|
+
radius: number;
|
|
28
|
+
innerRadius: number;
|
|
29
|
+
}]>;
|
|
30
|
+
responsive?: ResponsiveRule<{
|
|
31
|
+
/** number[] | { value, label? }[] | T[] with accessors. */
|
|
32
|
+
data: readonly T[];
|
|
33
|
+
value?: (datum: T, index: number) => number | null | undefined;
|
|
34
|
+
sliceLabel?: (datum: T, index: number) => string;
|
|
35
|
+
innerRadius?: number;
|
|
36
|
+
radius?: number;
|
|
37
|
+
padAngle?: number;
|
|
38
|
+
cornerRadius?: number;
|
|
39
|
+
colors?: readonly string[];
|
|
40
|
+
labels?: "inside" | "outside" | "none";
|
|
41
|
+
/** Caption under the default center total. */
|
|
42
|
+
centerCaption?: string;
|
|
43
|
+
/** Show the built-in center total (donuts only). */
|
|
44
|
+
showTotal?: boolean;
|
|
45
|
+
formatTotal?: (total: number) => string;
|
|
46
|
+
label?: string;
|
|
47
|
+
/** Accessible chart description. */
|
|
48
|
+
description?: string;
|
|
49
|
+
}>[];
|
|
50
|
+
class?: string;
|
|
51
|
+
};
|
|
52
|
+
exports: {};
|
|
53
|
+
bindings: "";
|
|
54
|
+
slots: {};
|
|
55
|
+
events: {};
|
|
56
|
+
};
|
|
57
|
+
declare class __sveltets_Render<T> {
|
|
58
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
59
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
60
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
61
|
+
bindings(): "";
|
|
62
|
+
exports(): {};
|
|
63
|
+
}
|
|
64
|
+
interface $$IsomorphicComponent {
|
|
65
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
66
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
67
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
68
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
69
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
70
|
+
}
|
|
71
|
+
declare const DonutChart: $$IsomorphicComponent;
|
|
72
|
+
type DonutChart<T> = InstanceType<typeof DonutChart<T>>;
|
|
73
|
+
export default DonutChart;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
<script lang="ts" generics="T">
|
|
2
|
+
import Chart from '../components/Chart.svelte';
|
|
3
|
+
import Svg from '../components/Svg.svelte';
|
|
4
|
+
import Axis from '../components/Axis.svelte';
|
|
5
|
+
import Grid from '../components/Grid.svelte';
|
|
6
|
+
import Line from '../components/Line.svelte';
|
|
7
|
+
|
|
8
|
+
import Labels from '../components/Labels.svelte';
|
|
9
|
+
import PlotBand from '../components/PlotBand.svelte';
|
|
10
|
+
import PlotLine from '../components/PlotLine.svelte';
|
|
11
|
+
import Tooltip from '../components/Tooltip.svelte';
|
|
12
|
+
import Crosshair from '../components/Crosshair.svelte';
|
|
13
|
+
import Legend from '../components/Legend.svelte';
|
|
14
|
+
import { resolveSeries, splitAxisOptions } from '../core/options.js';
|
|
15
|
+
import type {
|
|
16
|
+
BandSpec,
|
|
17
|
+
LegendSpec,
|
|
18
|
+
PlotLineSpec,
|
|
19
|
+
PlotOptions,
|
|
20
|
+
SeriesOptions,
|
|
21
|
+
SimpleAxisOptions,
|
|
22
|
+
TooltipSpec
|
|
23
|
+
} from '../core/options.js';
|
|
24
|
+
import { applyResponsive } from '../core/responsive.js';
|
|
25
|
+
import type { ResponsiveRule } from '../core/responsive.js';
|
|
26
|
+
import type { Padding } from '../core/types.js';
|
|
27
|
+
|
|
28
|
+
interface BaseProps {
|
|
29
|
+
series: SeriesOptions<T>[];
|
|
30
|
+
xAxis?: SimpleAxisOptions;
|
|
31
|
+
yAxis?: SimpleAxisOptions;
|
|
32
|
+
bands?: BandSpec[];
|
|
33
|
+
lines?: PlotLineSpec[];
|
|
34
|
+
grid?: boolean;
|
|
35
|
+
crosshair?: boolean;
|
|
36
|
+
tooltip?: boolean | TooltipSpec;
|
|
37
|
+
/** Defaults to on when there is more than one series. */
|
|
38
|
+
legend?: boolean | LegendSpec;
|
|
39
|
+
plotOptions?: PlotOptions<T>;
|
|
40
|
+
padding?: Padding;
|
|
41
|
+
label?: string;
|
|
42
|
+
/** Accessible chart description. */
|
|
43
|
+
description?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface Props extends BaseProps {
|
|
47
|
+
/** `{ maxWidth?/minWidth?, options }` rules merged over the props (precedence utility). */
|
|
48
|
+
responsive?: ResponsiveRule<BaseProps>[];
|
|
49
|
+
class?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let {
|
|
53
|
+
series,
|
|
54
|
+
xAxis,
|
|
55
|
+
yAxis,
|
|
56
|
+
bands,
|
|
57
|
+
lines,
|
|
58
|
+
grid = true,
|
|
59
|
+
crosshair = false,
|
|
60
|
+
tooltip = true,
|
|
61
|
+
legend,
|
|
62
|
+
plotOptions,
|
|
63
|
+
padding,
|
|
64
|
+
label = 'Line chart',
|
|
65
|
+
description,
|
|
66
|
+
responsive,
|
|
67
|
+
class: klass = ''
|
|
68
|
+
}: Props = $props();
|
|
69
|
+
|
|
70
|
+
let width = $state(0);
|
|
71
|
+
|
|
72
|
+
const eff = $derived(
|
|
73
|
+
applyResponsive(
|
|
74
|
+
{ series, xAxis, yAxis, bands, lines, grid, crosshair, tooltip, legend, plotOptions, padding, label, description },
|
|
75
|
+
responsive,
|
|
76
|
+
width
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const resolved = $derived(eff.series.map((s) => resolveSeries(eff.plotOptions, s)));
|
|
81
|
+
const xa = $derived(splitAxisOptions(eff.xAxis));
|
|
82
|
+
const ya = $derived(splitAxisOptions(eff.yAxis));
|
|
83
|
+
|
|
84
|
+
const legendOn = $derived(
|
|
85
|
+
eff.legend === undefined ? eff.series.length > 1 : eff.legend !== false
|
|
86
|
+
);
|
|
87
|
+
const legendPos = $derived(
|
|
88
|
+
typeof eff.legend === 'object' && eff.legend ? (eff.legend.position ?? 'bottom') : 'bottom'
|
|
89
|
+
);
|
|
90
|
+
const tooltipOn = $derived(eff.tooltip !== false);
|
|
91
|
+
const tip = $derived(typeof eff.tooltip === 'object' && eff.tooltip ? eff.tooltip : {});
|
|
92
|
+
const pad = $derived({
|
|
93
|
+
...(legendOn ? (legendPos === 'top' ? { top: 48 } : { bottom: 56 }) : {}),
|
|
94
|
+
...eff.padding
|
|
95
|
+
});
|
|
96
|
+
</script>
|
|
97
|
+
|
|
98
|
+
<div class="fc-simple fc-line-chart {klass}" bind:clientWidth={width}>
|
|
99
|
+
<Chart x={xa.scale} y={ya.scale} padding={pad} label={eff.label} description={eff.description}>
|
|
100
|
+
<Svg>
|
|
101
|
+
{#if eff.grid}<Grid y />{/if}
|
|
102
|
+
{#each eff.bands ?? [] as band, i (i)}
|
|
103
|
+
<PlotBand axis={band.axis} from={band.from} to={band.to} color={band.color} label={band.label} />
|
|
104
|
+
{/each}
|
|
105
|
+
{#each eff.lines ?? [] as pl, i (i)}
|
|
106
|
+
<PlotLine axis={pl.axis} value={pl.value} color={pl.color} dash={pl.dash} label={pl.label} />
|
|
107
|
+
{/each}
|
|
108
|
+
{#if eff.crosshair}<Crosshair />{/if}
|
|
109
|
+
{#each resolved as s, i (i)}
|
|
110
|
+
<Line
|
|
111
|
+
data={s.data}
|
|
112
|
+
x={s.x}
|
|
113
|
+
y={s.y}
|
|
114
|
+
color={s.color}
|
|
115
|
+
name={s.name}
|
|
116
|
+
description={s.description}
|
|
117
|
+
curve={s.curve}
|
|
118
|
+
strokeWidth={s.strokeWidth}
|
|
119
|
+
index={i}
|
|
120
|
+
markers={s.markers}
|
|
121
|
+
symbol={s.symbol}
|
|
122
|
+
symbolSize={s.symbolSize}
|
|
123
|
+
/>
|
|
124
|
+
{/each}
|
|
125
|
+
{#each resolved as s, i (i)}
|
|
126
|
+
{#if s.labels}
|
|
127
|
+
<Labels data={s.data} x={s.x} y={s.y} />
|
|
128
|
+
{/if}
|
|
129
|
+
{/each}
|
|
130
|
+
{#if xa.visible}
|
|
131
|
+
<Axis placement="bottom" title={xa.display.title} ticks={xa.display.ticks} format={xa.display.format} rotate={xa.display.rotate} />
|
|
132
|
+
{/if}
|
|
133
|
+
{#if ya.visible}
|
|
134
|
+
<Axis placement="left" title={ya.display.title} ticks={ya.display.ticks} format={ya.display.format} rotate={ya.display.rotate} />
|
|
135
|
+
{/if}
|
|
136
|
+
</Svg>
|
|
137
|
+
{#if tooltipOn}
|
|
138
|
+
<Tooltip mode={tip.mode ?? 'bisect-x'} shared={tip.shared ?? true} formatX={tip.formatX} formatY={tip.formatY} />
|
|
139
|
+
{/if}
|
|
140
|
+
{#if legendOn}<Legend position={legendPos} />{/if}
|
|
141
|
+
</Chart>
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
<style>
|
|
145
|
+
.fc-simple {
|
|
146
|
+
width: 100%;
|
|
147
|
+
height: 100%;
|
|
148
|
+
}
|
|
149
|
+
</style>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { BandSpec, LegendSpec, PlotLineSpec, PlotOptions, SeriesOptions, SimpleAxisOptions, TooltipSpec } from '../core/options.js';
|
|
2
|
+
import type { ResponsiveRule } from '../core/responsive.js';
|
|
3
|
+
import type { Padding } from '../core/types.js';
|
|
4
|
+
declare function $$render<T>(): {
|
|
5
|
+
props: {
|
|
6
|
+
series: SeriesOptions<T>[];
|
|
7
|
+
xAxis?: SimpleAxisOptions;
|
|
8
|
+
yAxis?: SimpleAxisOptions;
|
|
9
|
+
bands?: BandSpec[];
|
|
10
|
+
lines?: PlotLineSpec[];
|
|
11
|
+
grid?: boolean;
|
|
12
|
+
crosshair?: boolean;
|
|
13
|
+
tooltip?: boolean | TooltipSpec;
|
|
14
|
+
/** Defaults to on when there is more than one series. */
|
|
15
|
+
legend?: boolean | LegendSpec;
|
|
16
|
+
plotOptions?: PlotOptions<T>;
|
|
17
|
+
padding?: Padding;
|
|
18
|
+
label?: string;
|
|
19
|
+
/** Accessible chart description. */
|
|
20
|
+
description?: string;
|
|
21
|
+
} & {
|
|
22
|
+
/** `{ maxWidth?/minWidth?, options }` rules merged over the props (precedence utility). */
|
|
23
|
+
responsive?: ResponsiveRule<{
|
|
24
|
+
series: SeriesOptions<T>[];
|
|
25
|
+
xAxis?: SimpleAxisOptions;
|
|
26
|
+
yAxis?: SimpleAxisOptions;
|
|
27
|
+
bands?: BandSpec[];
|
|
28
|
+
lines?: PlotLineSpec[];
|
|
29
|
+
grid?: boolean;
|
|
30
|
+
crosshair?: boolean;
|
|
31
|
+
tooltip?: boolean | TooltipSpec;
|
|
32
|
+
/** Defaults to on when there is more than one series. */
|
|
33
|
+
legend?: boolean | LegendSpec;
|
|
34
|
+
plotOptions?: PlotOptions<T>;
|
|
35
|
+
padding?: Padding;
|
|
36
|
+
label?: string;
|
|
37
|
+
/** Accessible chart description. */
|
|
38
|
+
description?: string;
|
|
39
|
+
}>[];
|
|
40
|
+
class?: string;
|
|
41
|
+
};
|
|
42
|
+
exports: {};
|
|
43
|
+
bindings: "";
|
|
44
|
+
slots: {};
|
|
45
|
+
events: {};
|
|
46
|
+
};
|
|
47
|
+
declare class __sveltets_Render<T> {
|
|
48
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
49
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
50
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
51
|
+
bindings(): "";
|
|
52
|
+
exports(): {};
|
|
53
|
+
}
|
|
54
|
+
interface $$IsomorphicComponent {
|
|
55
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
56
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
57
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
58
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
59
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
60
|
+
}
|
|
61
|
+
declare const LineChart: $$IsomorphicComponent;
|
|
62
|
+
type LineChart<T> = InstanceType<typeof LineChart<T>>;
|
|
63
|
+
export default LineChart;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<script lang="ts" generics="T">
|
|
2
|
+
import Chart from '../components/Chart.svelte';
|
|
3
|
+
import Svg from '../components/Svg.svelte';
|
|
4
|
+
import Line from '../components/Line.svelte';
|
|
5
|
+
import Area from '../components/Area.svelte';
|
|
6
|
+
import Bars from '../components/Bars.svelte';
|
|
7
|
+
import Points from '../components/Points.svelte';
|
|
8
|
+
import { normalizePoints } from '../core/normalize.js';
|
|
9
|
+
import type { XValue } from '../core/normalize.js';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
data: readonly T[];
|
|
13
|
+
x?: (datum: T, index: number) => XValue;
|
|
14
|
+
y?: (datum: T, index: number) => number | null | undefined;
|
|
15
|
+
type?: 'line' | 'area' | 'bars';
|
|
16
|
+
color?: string;
|
|
17
|
+
strokeWidth?: number;
|
|
18
|
+
/** Mark the last (non-gap) point. */
|
|
19
|
+
dot?: boolean;
|
|
20
|
+
/** Number = px. Defaults size a table cell: 120 × 32. */
|
|
21
|
+
width?: number | string;
|
|
22
|
+
height?: number | string;
|
|
23
|
+
/** Accessible name (role="img"). */
|
|
24
|
+
label?: string;
|
|
25
|
+
class?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let {
|
|
29
|
+
data,
|
|
30
|
+
x,
|
|
31
|
+
y,
|
|
32
|
+
type = 'line',
|
|
33
|
+
color,
|
|
34
|
+
strokeWidth = 1.5,
|
|
35
|
+
dot = false,
|
|
36
|
+
width = 120,
|
|
37
|
+
height = 32,
|
|
38
|
+
label = 'Sparkline',
|
|
39
|
+
class: klass = ''
|
|
40
|
+
}: Props = $props();
|
|
41
|
+
|
|
42
|
+
const css = (v: number | string) => (typeof v === 'number' ? `${v}px` : v);
|
|
43
|
+
|
|
44
|
+
// Last non-gap point as an [x, y] tuple — position survives any accessor/data shape.
|
|
45
|
+
const lastPoint = $derived.by((): [XValue, number] | null => {
|
|
46
|
+
const points = normalizePoints(data, { x, y });
|
|
47
|
+
for (let i = points.length - 1; i >= 0; i--) {
|
|
48
|
+
const p = points[i];
|
|
49
|
+
if (p.y != null) return [p.x, p.y];
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
});
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<span class="fc-sparkline {klass}" style="width: {css(width)}; height: {css(height)};">
|
|
56
|
+
<!-- keyboard/dataTable off: a cell-sized trend glyph; the label carries the meaning. -->
|
|
57
|
+
<Chart
|
|
58
|
+
{label}
|
|
59
|
+
x={{ nice: false }}
|
|
60
|
+
y={{ nice: false }}
|
|
61
|
+
padding={{ top: 2, right: 2, bottom: 2, left: 2 }}
|
|
62
|
+
keyboard={false}
|
|
63
|
+
dataTable={false}
|
|
64
|
+
>
|
|
65
|
+
<Svg>
|
|
66
|
+
{#if type === 'bars'}
|
|
67
|
+
<Bars {data} {x} {y} {color} barPadding={0.15} />
|
|
68
|
+
{:else if type === 'area'}
|
|
69
|
+
<Area {data} {x} {y} {color} {strokeWidth} fillOpacity={0.15} />
|
|
70
|
+
{:else}
|
|
71
|
+
<Line {data} {x} {y} {color} {strokeWidth} />
|
|
72
|
+
{/if}
|
|
73
|
+
{#if dot && lastPoint}
|
|
74
|
+
<Points data={[lastPoint]} {color} index={0} r={2.5} />
|
|
75
|
+
{/if}
|
|
76
|
+
</Svg>
|
|
77
|
+
</Chart>
|
|
78
|
+
</span>
|
|
79
|
+
|
|
80
|
+
<style>
|
|
81
|
+
.fc-sparkline {
|
|
82
|
+
display: inline-block;
|
|
83
|
+
vertical-align: middle;
|
|
84
|
+
line-height: 0;
|
|
85
|
+
overflow: hidden;
|
|
86
|
+
}
|
|
87
|
+
</style>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { XValue } from '../core/normalize.js';
|
|
2
|
+
declare function $$render<T>(): {
|
|
3
|
+
props: {
|
|
4
|
+
data: readonly T[];
|
|
5
|
+
x?: (datum: T, index: number) => XValue;
|
|
6
|
+
y?: (datum: T, index: number) => number | null | undefined;
|
|
7
|
+
type?: "line" | "area" | "bars";
|
|
8
|
+
color?: string;
|
|
9
|
+
strokeWidth?: number;
|
|
10
|
+
/** Mark the last (non-gap) point. */
|
|
11
|
+
dot?: boolean;
|
|
12
|
+
/** Number = px. Defaults size a table cell: 120 × 32. */
|
|
13
|
+
width?: number | string;
|
|
14
|
+
height?: number | string;
|
|
15
|
+
/** Accessible name (role="img"). */
|
|
16
|
+
label?: string;
|
|
17
|
+
class?: string;
|
|
18
|
+
};
|
|
19
|
+
exports: {};
|
|
20
|
+
bindings: "";
|
|
21
|
+
slots: {};
|
|
22
|
+
events: {};
|
|
23
|
+
};
|
|
24
|
+
declare class __sveltets_Render<T> {
|
|
25
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
26
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
27
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
28
|
+
bindings(): "";
|
|
29
|
+
exports(): {};
|
|
30
|
+
}
|
|
31
|
+
interface $$IsomorphicComponent {
|
|
32
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
33
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
34
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
35
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
36
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
37
|
+
}
|
|
38
|
+
declare const Sparkline: $$IsomorphicComponent;
|
|
39
|
+
type Sparkline<T> = InstanceType<typeof Sparkline<T>>;
|
|
40
|
+
export default Sparkline;
|