@c2n/chart 0.0.7
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 +21 -0
- package/README.md +81 -0
- package/dist/area-chart.js +29 -0
- package/dist/bar-chart.js +65 -0
- package/dist/chart-adapter.js +0 -0
- package/dist/chart-base-C4-1TyKq.js +666 -0
- package/dist/chart-base.js +2 -0
- package/dist/chart-data.js +286 -0
- package/dist/chart-series-BnpHO3lm.js +83 -0
- package/dist/chart-series.js +2 -0
- package/dist/chart-theme.js +151 -0
- package/dist/chart-types.js +8 -0
- package/dist/chart.js +13 -0
- package/dist/echarts-chart-base-LogCQN10.js +228 -0
- package/dist/echarts-chart-base.js +2 -0
- package/dist/line-chart.js +31 -0
- package/dist/pie-chart.js +100 -0
- package/dist/sparkline.js +79 -0
- package/dist/uplot-chart-base-BWr0zJE2.js +253 -0
- package/dist/uplot-chart-base.js +2 -0
- package/dist/uplot-paths-ChKohvIX.js +95 -0
- package/package.json +146 -0
- package/react.d.ts +34 -0
- package/react.js +3 -0
- package/types/src/area-chart.d.ts +36 -0
- package/types/src/area-chart.d.ts.map +1 -0
- package/types/src/bar-chart.d.ts +46 -0
- package/types/src/bar-chart.d.ts.map +1 -0
- package/types/src/chart-adapter.d.ts +67 -0
- package/types/src/chart-adapter.d.ts.map +1 -0
- package/types/src/chart-base.d.ts +265 -0
- package/types/src/chart-base.d.ts.map +1 -0
- package/types/src/chart-data.d.ts +43 -0
- package/types/src/chart-data.d.ts.map +1 -0
- package/types/src/chart-series.d.ts +51 -0
- package/types/src/chart-series.d.ts.map +1 -0
- package/types/src/chart-theme.d.ts +64 -0
- package/types/src/chart-theme.d.ts.map +1 -0
- package/types/src/chart-types.d.ts +162 -0
- package/types/src/chart-types.d.ts.map +1 -0
- package/types/src/chart.d.ts +27 -0
- package/types/src/chart.d.ts.map +1 -0
- package/types/src/echarts-chart-base.d.ts +28 -0
- package/types/src/echarts-chart-base.d.ts.map +1 -0
- package/types/src/engines/echarts-adapter.d.ts +17 -0
- package/types/src/engines/echarts-adapter.d.ts.map +1 -0
- package/types/src/engines/echarts-loader.d.ts +16 -0
- package/types/src/engines/echarts-loader.d.ts.map +1 -0
- package/types/src/engines/uplot-adapter.d.ts +4 -0
- package/types/src/engines/uplot-adapter.d.ts.map +1 -0
- package/types/src/engines/uplot-loader.d.ts +20 -0
- package/types/src/engines/uplot-loader.d.ts.map +1 -0
- package/types/src/engines/uplot-paths.d.ts +25 -0
- package/types/src/engines/uplot-paths.d.ts.map +1 -0
- package/types/src/line-chart.d.ts +40 -0
- package/types/src/line-chart.d.ts.map +1 -0
- package/types/src/pie-chart.d.ts +59 -0
- package/types/src/pie-chart.d.ts.map +1 -0
- package/types/src/sparkline.d.ts +56 -0
- package/types/src/sparkline.d.ts.map +1 -0
- package/types/src/uplot-chart-base.d.ts +50 -0
- package/types/src/uplot-chart-base.d.ts.map +1 -0
- package/vue.d.ts +134 -0
- package/vue.js +3 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { n as loadedUplot } from "./uplot-chart-base-BWr0zJE2.js";
|
|
2
|
+
//#region src/engines/uplot-paths.ts
|
|
3
|
+
var cache = /* @__PURE__ */ new Map();
|
|
4
|
+
/**
|
|
5
|
+
* The path builder for a curve, or `undefined` for `linear` — uPlot's default is already a straight line,
|
|
6
|
+
* and passing `undefined` keeps the fastest path.
|
|
7
|
+
*/
|
|
8
|
+
function linePaths(curve) {
|
|
9
|
+
if (curve === "linear") return void 0;
|
|
10
|
+
if (cache.has(curve)) return cache.get(curve);
|
|
11
|
+
const paths = loadedUplot()?.paths;
|
|
12
|
+
if (!paths) return void 0;
|
|
13
|
+
const builder = curve === "smooth" ? paths.spline?.() : paths.stepped?.({ align: 1 });
|
|
14
|
+
cache.set(curve, builder);
|
|
15
|
+
return builder;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Applies an alpha to a resolved colour, for the fill under an area series.
|
|
19
|
+
*
|
|
20
|
+
* The theme controller always hands back a computed `rgb(…)` or `rgba(…)`, so this only has to handle those
|
|
21
|
+
* two plus a hex literal a consumer may have set directly on a series.
|
|
22
|
+
*/
|
|
23
|
+
function withAlpha(color, alpha) {
|
|
24
|
+
const rgb = /^rgba?\(([^)]+)\)$/.exec(color.trim());
|
|
25
|
+
if (rgb) {
|
|
26
|
+
const [r, g, b] = rgb[1].split(/[,/]/).map((part) => part.trim());
|
|
27
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
28
|
+
}
|
|
29
|
+
const hex = /^#([0-9a-f]{6})$/i.exec(color.trim());
|
|
30
|
+
if (hex) {
|
|
31
|
+
const value = parseInt(hex[1], 16);
|
|
32
|
+
return `rgba(${value >> 16 & 255}, ${value >> 8 & 255}, ${value & 255}, ${alpha})`;
|
|
33
|
+
}
|
|
34
|
+
return color;
|
|
35
|
+
}
|
|
36
|
+
var barCache = /* @__PURE__ */ new Map();
|
|
37
|
+
/** uPlot's `BarsPathBuilderFacetUnit.ScaleValue`, which is a `const enum` and so cannot be imported here. */
|
|
38
|
+
var SCALE_VALUE = 1;
|
|
39
|
+
/**
|
|
40
|
+
* The bars path builder for one series of a chart: `width` is the share of the band the whole group takes
|
|
41
|
+
* and `gap` the share of each bar's slot given up to the gutter between grouped bars. Memoised on all four
|
|
42
|
+
* arguments, since uPlot wants one builder reused rather than a fresh one per option rebuild.
|
|
43
|
+
*
|
|
44
|
+
* uPlot draws every series' bars on the same x, so a second series would sit exactly on top of the first.
|
|
45
|
+
* Grouping is therefore ours to do: `disp` gives uPlot an explicit left edge and width per bar — in data
|
|
46
|
+
* units, which is what it reads when no `unit` is set — placing each series in its own slot of the band.
|
|
47
|
+
*/
|
|
48
|
+
function barPaths(width, gap, index, count) {
|
|
49
|
+
const key = `${width}:${gap}:${index}:${count}`;
|
|
50
|
+
if (barCache.has(key)) return barCache.get(key);
|
|
51
|
+
const paths = loadedUplot()?.paths;
|
|
52
|
+
if (!paths) return void 0;
|
|
53
|
+
const size = [
|
|
54
|
+
width,
|
|
55
|
+
Infinity,
|
|
56
|
+
1
|
|
57
|
+
];
|
|
58
|
+
const builder = count > 1 ? paths.bars?.({
|
|
59
|
+
size,
|
|
60
|
+
disp: {
|
|
61
|
+
x0: {
|
|
62
|
+
unit: SCALE_VALUE,
|
|
63
|
+
values: (self) => layout(self, width, gap, count).left(index)
|
|
64
|
+
},
|
|
65
|
+
size: {
|
|
66
|
+
unit: SCALE_VALUE,
|
|
67
|
+
values: (self) => [layout(self, width, gap, count).barWidth]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}) : paths.bars?.({ size });
|
|
71
|
+
barCache.set(key, builder);
|
|
72
|
+
return builder;
|
|
73
|
+
}
|
|
74
|
+
/** One group's geometry in data units, derived from the band width the x values themselves imply. */
|
|
75
|
+
function layout(self, width, gap, count) {
|
|
76
|
+
const xs = self.data[0];
|
|
77
|
+
const band = bandStep(xs) * width;
|
|
78
|
+
const slot = band / count;
|
|
79
|
+
return {
|
|
80
|
+
barWidth: slot * (1 - gap),
|
|
81
|
+
/** Left edge of series `index`'s bar at every x, centred on the band with the gutter split evenly. */
|
|
82
|
+
left: (index) => xs.map((x) => x - band / 2 + index * slot + slot * gap / 2)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Width of one band: the smallest gap between adjacent x values, which is how uPlot sizes bars itself. */
|
|
86
|
+
function bandStep(xs) {
|
|
87
|
+
let smallest = Infinity;
|
|
88
|
+
for (let index = 1; index < xs.length; index += 1) {
|
|
89
|
+
const delta = Math.abs(xs[index] - xs[index - 1]);
|
|
90
|
+
if (delta > 0 && delta < smallest) smallest = delta;
|
|
91
|
+
}
|
|
92
|
+
return Number.isFinite(smallest) ? smallest : 1;
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { linePaths as n, withAlpha as r, barPaths as t };
|
package/package.json
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@c2n/chart",
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/chart.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./types/src/chart.d.ts",
|
|
9
|
+
"default": "./dist/chart.js"
|
|
10
|
+
},
|
|
11
|
+
"./line-chart.js": {
|
|
12
|
+
"types": "./types/src/line-chart.d.ts",
|
|
13
|
+
"default": "./dist/line-chart.js"
|
|
14
|
+
},
|
|
15
|
+
"./area-chart.js": {
|
|
16
|
+
"types": "./types/src/area-chart.d.ts",
|
|
17
|
+
"default": "./dist/area-chart.js"
|
|
18
|
+
},
|
|
19
|
+
"./bar-chart.js": {
|
|
20
|
+
"types": "./types/src/bar-chart.d.ts",
|
|
21
|
+
"default": "./dist/bar-chart.js"
|
|
22
|
+
},
|
|
23
|
+
"./sparkline.js": {
|
|
24
|
+
"types": "./types/src/sparkline.d.ts",
|
|
25
|
+
"default": "./dist/sparkline.js"
|
|
26
|
+
},
|
|
27
|
+
"./pie-chart.js": {
|
|
28
|
+
"types": "./types/src/pie-chart.d.ts",
|
|
29
|
+
"default": "./dist/pie-chart.js"
|
|
30
|
+
},
|
|
31
|
+
"./chart-series.js": {
|
|
32
|
+
"types": "./types/src/chart-series.d.ts",
|
|
33
|
+
"default": "./dist/chart-series.js"
|
|
34
|
+
},
|
|
35
|
+
"./chart-base.js": {
|
|
36
|
+
"types": "./types/src/chart-base.d.ts",
|
|
37
|
+
"default": "./dist/chart-base.js"
|
|
38
|
+
},
|
|
39
|
+
"./uplot-chart-base.js": {
|
|
40
|
+
"types": "./types/src/uplot-chart-base.d.ts",
|
|
41
|
+
"default": "./dist/uplot-chart-base.js"
|
|
42
|
+
},
|
|
43
|
+
"./echarts-chart-base.js": {
|
|
44
|
+
"types": "./types/src/echarts-chart-base.d.ts",
|
|
45
|
+
"default": "./dist/echarts-chart-base.js"
|
|
46
|
+
},
|
|
47
|
+
"./chart-types.js": {
|
|
48
|
+
"types": "./types/src/chart-types.d.ts",
|
|
49
|
+
"default": "./dist/chart-types.js"
|
|
50
|
+
},
|
|
51
|
+
"./chart-adapter.js": {
|
|
52
|
+
"types": "./types/src/chart-adapter.d.ts",
|
|
53
|
+
"default": "./dist/chart-adapter.js"
|
|
54
|
+
},
|
|
55
|
+
"./chart-theme.js": {
|
|
56
|
+
"types": "./types/src/chart-theme.d.ts",
|
|
57
|
+
"default": "./dist/chart-theme.js"
|
|
58
|
+
},
|
|
59
|
+
"./chart-data.js": {
|
|
60
|
+
"types": "./types/src/chart-data.d.ts",
|
|
61
|
+
"default": "./dist/chart-data.js"
|
|
62
|
+
},
|
|
63
|
+
"./react": {
|
|
64
|
+
"types": "./react.d.ts",
|
|
65
|
+
"default": "./react.js"
|
|
66
|
+
},
|
|
67
|
+
"./vue": {
|
|
68
|
+
"types": "./vue.d.ts",
|
|
69
|
+
"default": "./vue.js"
|
|
70
|
+
},
|
|
71
|
+
"./custom-elements.json": "./custom-elements.json"
|
|
72
|
+
},
|
|
73
|
+
"files": [
|
|
74
|
+
"dist",
|
|
75
|
+
"types",
|
|
76
|
+
"react.d.ts",
|
|
77
|
+
"react.js",
|
|
78
|
+
"vue.d.ts",
|
|
79
|
+
"vue.js"
|
|
80
|
+
],
|
|
81
|
+
"keywords": [
|
|
82
|
+
"chart",
|
|
83
|
+
"charts",
|
|
84
|
+
"graph",
|
|
85
|
+
"data visualization",
|
|
86
|
+
"line chart",
|
|
87
|
+
"sparkline",
|
|
88
|
+
"uplot",
|
|
89
|
+
"echarts",
|
|
90
|
+
"web component",
|
|
91
|
+
"lit"
|
|
92
|
+
],
|
|
93
|
+
"license": "MIT",
|
|
94
|
+
"author": "code2nguyen@gmail.com",
|
|
95
|
+
"publishConfig": {
|
|
96
|
+
"registry": "https://registry.npmjs.org",
|
|
97
|
+
"access": "public"
|
|
98
|
+
},
|
|
99
|
+
"repository": {
|
|
100
|
+
"type": "git",
|
|
101
|
+
"url": "https://github.com/code2nguyen/web-components.git"
|
|
102
|
+
},
|
|
103
|
+
"scripts": {
|
|
104
|
+
"dev": "vite",
|
|
105
|
+
"build": "wireit",
|
|
106
|
+
"build:only": "vite build",
|
|
107
|
+
"type-check": "wireit"
|
|
108
|
+
},
|
|
109
|
+
"wireit": {
|
|
110
|
+
"type-check": {
|
|
111
|
+
"dependencies": [
|
|
112
|
+
"../../core:build"
|
|
113
|
+
],
|
|
114
|
+
"command": "tsc -p tsconfig.lib.json --composite false"
|
|
115
|
+
},
|
|
116
|
+
"build": {
|
|
117
|
+
"dependencies": [
|
|
118
|
+
"type-check"
|
|
119
|
+
],
|
|
120
|
+
"command": "vite build"
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"dependencies": {
|
|
124
|
+
"@c2n/core": "0.0.7",
|
|
125
|
+
"lit": "3.3.3"
|
|
126
|
+
},
|
|
127
|
+
"devDependencies": {
|
|
128
|
+
"@c2n/config": "*",
|
|
129
|
+
"echarts": "^6.1.0",
|
|
130
|
+
"uplot": "^1.6.32"
|
|
131
|
+
},
|
|
132
|
+
"customElements": "custom-elements.json",
|
|
133
|
+
"peerDependencies": {
|
|
134
|
+
"echarts": "^5.5.0 || ^6.0.0",
|
|
135
|
+
"uplot": "^1.6.31"
|
|
136
|
+
},
|
|
137
|
+
"peerDependenciesMeta": {
|
|
138
|
+
"echarts": {
|
|
139
|
+
"optional": true
|
|
140
|
+
},
|
|
141
|
+
"uplot": {
|
|
142
|
+
"optional": true
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
"gitHead": "c8db398a27f7cd417d665fdf5da455fee2d4e910"
|
|
146
|
+
}
|
package/react.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// GENERATED by @c2n/framework-types. Do not edit by hand.
|
|
2
|
+
//
|
|
3
|
+
// JSX types for the custom elements of @c2n/chart. Import once, anywhere in the program:
|
|
4
|
+
//
|
|
5
|
+
// import '@c2n/chart/react'
|
|
6
|
+
//
|
|
7
|
+
// Register the elements at module scope before React renders, or React writes an object prop as an
|
|
8
|
+
// attribute and it stringifies.
|
|
9
|
+
|
|
10
|
+
import type { DetailedHTMLProps, HTMLAttributes } from 'react'
|
|
11
|
+
import type { AreaChart } from '@c2n/chart/area-chart.js'
|
|
12
|
+
import type { BarChart } from '@c2n/chart/bar-chart.js'
|
|
13
|
+
import type { ChartSeries } from '@c2n/chart/chart-series.js'
|
|
14
|
+
import type { LineChart } from '@c2n/chart/line-chart.js'
|
|
15
|
+
import type { PieChart } from '@c2n/chart/pie-chart.js'
|
|
16
|
+
import type { Sparkline } from '@c2n/chart/sparkline.js'
|
|
17
|
+
|
|
18
|
+
/** Standard React host-element attributes plus the element's own public properties. */
|
|
19
|
+
type C2Props<T> = DetailedHTMLProps<HTMLAttributes<T>, T> & Partial<Omit<T, keyof HTMLElement>>
|
|
20
|
+
|
|
21
|
+
declare module 'react' {
|
|
22
|
+
namespace JSX {
|
|
23
|
+
interface IntrinsicElements {
|
|
24
|
+
'c2-area-chart': C2Props<AreaChart>
|
|
25
|
+
'c2-bar-chart': C2Props<BarChart>
|
|
26
|
+
'c2-chart-series': C2Props<ChartSeries>
|
|
27
|
+
'c2-line-chart': C2Props<LineChart>
|
|
28
|
+
'c2-pie-chart': C2Props<PieChart>
|
|
29
|
+
'c2-sparkline': C2Props<Sparkline>
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export {}
|
package/react.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { TypedAddEventListener, TypedRemoveEventListener } from '@c2n/core/event-helper.js';
|
|
2
|
+
import { LineChart } from './line-chart.js';
|
|
3
|
+
import type { UplotSeriesStyle } from './uplot-chart-base.js';
|
|
4
|
+
import type { ChartEventMap } from './chart-base.js';
|
|
5
|
+
import type { ChartBuildContext } from './chart-adapter.js';
|
|
6
|
+
import type { ChartSeriesConfig } from './chart-types.js';
|
|
7
|
+
export interface AreaChart {
|
|
8
|
+
addEventListener: TypedAddEventListener<AreaChart, ChartEventMap>;
|
|
9
|
+
removeEventListener: TypedRemoveEventListener<AreaChart, ChartEventMap>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A line chart with the region under each line filled — an area chart *is* a line chart plus a fill, so it
|
|
13
|
+
* extends `c2-line-chart` and every one of its attributes (`curve`, `points`, `zoom`, the axis bounds)
|
|
14
|
+
* means the same thing here.
|
|
15
|
+
*
|
|
16
|
+
* ```html
|
|
17
|
+
* <c2-area-chart x-type="time" x-field="t" fill-opacity="0.2" data="[]">
|
|
18
|
+
* <c2-chart-series field="sessions" label="Sessions"></c2-chart-series>
|
|
19
|
+
* </c2-area-chart>
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @tag c2-area-chart
|
|
23
|
+
*/
|
|
24
|
+
export declare class AreaChart extends LineChart {
|
|
25
|
+
/** Opacity of the fill under each line. Falls back to `--c2-chart__area--opacity`. */
|
|
26
|
+
fillOpacity?: number;
|
|
27
|
+
protected seriesStyle(series: ChartSeriesConfig, index: number, context: ChartBuildContext): UplotSeriesStyle;
|
|
28
|
+
/** Reads `--c2-chart__area--opacity` off the host, falling back to uPlot-friendly 0.15. */
|
|
29
|
+
private areaOpacity;
|
|
30
|
+
}
|
|
31
|
+
declare global {
|
|
32
|
+
interface HTMLElementTagNameMap {
|
|
33
|
+
'c2-area-chart': AreaChart;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=area-chart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"area-chart.d.ts","sourceRoot":"","sources":["../../src/area-chart.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAE3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEzD,MAAM,WAAW,SAAS;IACxB,gBAAgB,EAAE,qBAAqB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;IACjE,mBAAmB,EAAE,wBAAwB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;CACxE;AAED;;;;;;;;;;;;GAYG;AACH,qBACa,SAAU,SAAQ,SAAS;IACtC,sFAAsF;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAA;cAExD,WAAW,CAAC,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,gBAAgB;IAOtH,2FAA2F;IAC3F,OAAO,CAAC,WAAW;CAIpB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,eAAe,EAAE,SAAS,CAAA;KAC3B;CACF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { TypedAddEventListener, TypedRemoveEventListener } from '@c2n/core/event-helper.js';
|
|
2
|
+
import type { Options } from 'uplot';
|
|
3
|
+
import { UplotChartBase, type UplotSeriesStyle } from './uplot-chart-base.js';
|
|
4
|
+
import type { ChartEventMap } from './chart-base.js';
|
|
5
|
+
import type { ChartBuildContext } from './chart-adapter.js';
|
|
6
|
+
import type { ChartSeriesConfig } from './chart-types.js';
|
|
7
|
+
import './chart-series.js';
|
|
8
|
+
export interface BarChart {
|
|
9
|
+
addEventListener: TypedAddEventListener<BarChart, ChartEventMap>;
|
|
10
|
+
removeEventListener: TypedRemoveEventListener<BarChart, ChartEventMap>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A bar chart drawn by uPlot's bars path builder, for categorical or time-bucketed values. Several series
|
|
14
|
+
* are drawn side by side within each band.
|
|
15
|
+
*
|
|
16
|
+
* ```html
|
|
17
|
+
* <c2-bar-chart label-field="team" legend="bottom" data='[{ "team": "Core", "shipped": 18 }]'>
|
|
18
|
+
* <c2-chart-series field="shipped" label="Shipped"></c2-chart-series>
|
|
19
|
+
* </c2-bar-chart>
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @tag c2-bar-chart
|
|
23
|
+
*/
|
|
24
|
+
export declare class BarChart extends UplotChartBase {
|
|
25
|
+
/** Share of each band a bar group occupies, from 0 to 1. */
|
|
26
|
+
barWidth: number;
|
|
27
|
+
/** Share of the group taken by the gaps between grouped bars, from 0 to 1. */
|
|
28
|
+
barGap: number;
|
|
29
|
+
protected seriesStyle(series: ChartSeriesConfig, index: number, context: ChartBuildContext): UplotSeriesStyle;
|
|
30
|
+
/** A band chart reads its x as discrete slots, so the scale is padded by half a band at each end. */
|
|
31
|
+
protected decorateOptions(options: Options, _context: ChartBuildContext): Options;
|
|
32
|
+
/**
|
|
33
|
+
* Bars sit on category labels when there are any, so the tick shows the label rather than the index.
|
|
34
|
+
*
|
|
35
|
+
* uPlot picks its own split values, and on a handful of bands those land on halves — which would round
|
|
36
|
+
* to the same label twice and then off the end of the list. A band has no label between its slots, so
|
|
37
|
+
* those ticks are blank.
|
|
38
|
+
*/
|
|
39
|
+
protected formatAxisX(value: number): string;
|
|
40
|
+
}
|
|
41
|
+
declare global {
|
|
42
|
+
interface HTMLElementTagNameMap {
|
|
43
|
+
'c2-bar-chart': BarChart;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=bar-chart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bar-chart.d.ts","sourceRoot":"","sources":["../../src/bar-chart.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AAChG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACpC,OAAO,EAAE,cAAc,EAAE,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAE7E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,mBAAmB,CAAA;AAE1B,MAAM,WAAW,QAAQ;IACvB,gBAAgB,EAAE,qBAAqB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAA;IAChE,mBAAmB,EAAE,wBAAwB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAA;CACvE;AAED;;;;;;;;;;;GAWG;AACH,qBACa,QAAS,SAAQ,cAAc;IAC1C,4DAA4D;IACR,QAAQ,SAAM;IAElE,8EAA8E;IAC5B,MAAM,SAAM;cAE3C,WAAW,CAAC,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,gBAAgB;IAatH,qGAAqG;cAClF,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,iBAAiB,GAAG,OAAO;IAS1F;;;;;;OAMG;cACgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAKtD;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,cAAc,EAAE,QAAQ,CAAA;KACzB;CACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract between a chart element and a drawing engine.
|
|
3
|
+
*
|
|
4
|
+
* The split between {@link ChartAdapter.setData} and {@link ChartAdapter.setOptions} is the whole reason
|
|
5
|
+
* this interface exists: a realtime tick must reach the engine through `setData` and nothing else, because
|
|
6
|
+
* `setOptions` is allowed to be expensive (under uPlot it destroys and rebuilds the instance).
|
|
7
|
+
*/
|
|
8
|
+
import type { ChartSeriesConfig } from './chart-types.js';
|
|
9
|
+
import type { ChartTheme } from './chart-theme.js';
|
|
10
|
+
/** Everything an element hands its engine layer to build options. Presentation only — never raw data. */
|
|
11
|
+
export interface ChartBuildContext {
|
|
12
|
+
theme: ChartTheme;
|
|
13
|
+
/** The resolved series, in draw order. */
|
|
14
|
+
series: ChartSeriesConfig[];
|
|
15
|
+
/** Indices currently hidden by the legend. */
|
|
16
|
+
hidden: ReadonlySet<number>;
|
|
17
|
+
/** Category labels, when the chart is categorical. */
|
|
18
|
+
labels?: string[];
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
}
|
|
22
|
+
/** Engine callbacks, normalised so the element never sees a uPlot hook or an ECharts action. */
|
|
23
|
+
export interface ChartAdapterEvents {
|
|
24
|
+
/** A point is hovered, or `null` when the pointer leaves the plot. */
|
|
25
|
+
hover(detail: {
|
|
26
|
+
index: number;
|
|
27
|
+
seriesIndex: number;
|
|
28
|
+
px: number;
|
|
29
|
+
py: number;
|
|
30
|
+
} | null): void;
|
|
31
|
+
click(detail: {
|
|
32
|
+
index: number;
|
|
33
|
+
seriesIndex: number;
|
|
34
|
+
}): void;
|
|
35
|
+
rangeChange(detail: {
|
|
36
|
+
min: number;
|
|
37
|
+
max: number;
|
|
38
|
+
}): void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* One drawing engine, wrapped. Only {@link create} is asynchronous — by the time it resolves the engine
|
|
42
|
+
* module has loaded and the instance exists, so every later call is synchronous and cheap to reason about.
|
|
43
|
+
*/
|
|
44
|
+
export interface ChartAdapter<TOptions = unknown, TData = unknown> {
|
|
45
|
+
readonly engine: 'uplot' | 'echarts';
|
|
46
|
+
/** Builds the instance. Options and data are applied together so nothing flashes on first paint. */
|
|
47
|
+
create(container: HTMLElement, options: TOptions, data: TData, events: ChartAdapterEvents): Promise<void>;
|
|
48
|
+
/** The hot path. Data only: must not rebuild options, re-measure, or recreate the instance. */
|
|
49
|
+
setData(data: TData): void;
|
|
50
|
+
/**
|
|
51
|
+
* Streaming append, when the engine has a cheaper path than a full `setData`. Optional: the element
|
|
52
|
+
* falls back to `setData` when it is absent.
|
|
53
|
+
*/
|
|
54
|
+
appendData?(data: TData, appended: number): void;
|
|
55
|
+
/** Presentation changed. Allowed to be expensive. `replace` is required when the series set shrinks. */
|
|
56
|
+
setOptions(options: TOptions, mode: 'merge' | 'replace'): void;
|
|
57
|
+
/** Shows or hides one series without rebuilding anything. */
|
|
58
|
+
setSeriesVisibility(index: number, visible: boolean): void;
|
|
59
|
+
/**
|
|
60
|
+
* Shows or hides one datum by name, for a chart whose legend is its data rather than its series — a pie has
|
|
61
|
+
* one series and many slices. Only the engines that can do it implement it.
|
|
62
|
+
*/
|
|
63
|
+
setDatumVisibility?(name: string, visible: boolean): void;
|
|
64
|
+
resize(width: number, height: number): void;
|
|
65
|
+
destroy(): void;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=chart-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-adapter.d.ts","sourceRoot":"","sources":["../../src/chart-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,yGAAyG;AACzG,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,UAAU,CAAA;IACjB,0CAA0C;IAC1C,MAAM,EAAE,iBAAiB,EAAE,CAAA;IAC3B,8CAA8C;IAC9C,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAC3B,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,gGAAgG;AAChG,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,KAAK,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,GAAG,IAAI,CAAA;IAC1F,KAAK,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;IAC3D,WAAW,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;CACxD;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY,CAAC,QAAQ,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO;IAC/D,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAA;IAEpC,oGAAoG;IACpG,MAAM,CAAC,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEzG,+FAA+F;IAC/F,OAAO,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,CAAA;IAE1B;;;OAGG;IACH,UAAU,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IAEhD,wGAAwG;IACxG,UAAU,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAAA;IAE9D,6DAA6D;IAC7D,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;IAE1D;;;OAGG;IACH,kBAAkB,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;IAEzD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAE3C,OAAO,IAAI,IAAI,CAAA;CAChB"}
|