@xplortech/apollo-data 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -91
- package/dist/apollo-data/apollo-data.esm.js +1 -1
- package/dist/apollo-data/p-25841a73.entry.js +1 -0
- package/dist/apollo-data/p-2nuV5Vny.js +1 -0
- package/dist/apollo-data/p-839050b7.entry.js +1 -0
- package/dist/apollo-data/p-C2k3WBpi.js +11 -0
- package/dist/apollo-data/p-D64asVrg.js +2 -0
- package/dist/apollo-data/p-e2c3a317.entry.js +1 -0
- package/dist/cjs/apollo-data-bar-chart.cjs.entry.js +315 -0
- package/dist/{esm/apollo-data-bar-chart_2.entry.js → cjs/apollo-data-base-COGMOEqL.js} +9 -724
- package/dist/cjs/apollo-data-donut-chart.cjs.entry.js +408 -0
- package/dist/cjs/apollo-data-heat-map_4.cjs.entry.js +883 -0
- package/dist/cjs/apollo-data.cjs.js +3 -3
- package/dist/cjs/constants-B3weDEpc.js +5 -0
- package/dist/cjs/{index-Cl7HgRm0.js → index-Bd5risOy.js} +116 -63
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/collection/apollo-data-base.js +4 -8
- package/dist/collection/collection-manifest.json +7 -2
- package/dist/collection/components/apollo-data-bar/apollo-data-bar.js +8 -7
- package/dist/collection/components/apollo-data-bar/apollo-data-bar.stories.js +122 -0
- package/dist/collection/components/apollo-data-donut/apollo-data-donut.js +1 -1
- package/dist/collection/components/apollo-data-donut/apollo-data-donut.stories.js +132 -0
- package/dist/collection/components/apollo-data-heat-map/apollo-data-heat-map.js +208 -0
- package/dist/collection/components/apollo-data-heat-map/apollo-data-heat-map.stories.js +137 -0
- package/dist/collection/components/apollo-data-line/apollo-data-line.js +348 -0
- package/dist/collection/components/apollo-data-line/apollo-data-line.stories.js +122 -0
- package/dist/collection/components/apollo-data-scatter/apollo-data-scatter.js +329 -0
- package/dist/collection/components/apollo-data-scatter/apollo-data-scatter.stories.js +147 -0
- package/dist/collection/components/apollo-data-world-map/apollo-data-world-map.js +294 -0
- package/dist/collection/components/apollo-data-world-map/apollo-data-world-map.stories.js +126 -0
- package/dist/collection/examples/apollo-data-heat-map.examples.js +131 -0
- package/dist/collection/examples/apollo-data-line.examples.js +91 -0
- package/dist/collection/examples/apollo-data-scatter.examples.js +94 -0
- package/dist/collection/examples/apollo-data-world-map.examples.js +45 -0
- package/dist/collection/examples/index.js +3 -0
- package/dist/collection/utils/code-generator.js +1 -1
- package/dist/components/apollo-data-bar-chart.js +1 -1
- package/dist/components/apollo-data-donut-chart.js +1 -1
- package/dist/components/apollo-data-heat-map.d.ts +11 -0
- package/dist/components/apollo-data-heat-map.js +1 -0
- package/dist/components/apollo-data-line-chart.d.ts +11 -0
- package/dist/components/apollo-data-line-chart.js +1 -0
- package/dist/components/apollo-data-scatter-chart.d.ts +11 -0
- package/dist/components/apollo-data-scatter-chart.js +1 -0
- package/dist/components/apollo-data-world-map-chart.d.ts +11 -0
- package/dist/components/apollo-data-world-map-chart.js +1 -0
- package/dist/components/index.js +1 -1
- package/dist/components/p-2nuV5Vny.js +1 -0
- package/dist/components/p-CfbMSXKd.js +11 -0
- package/dist/components/p-gcjU8DVr.js +1 -0
- package/dist/esm/apollo-data-bar-chart.entry.js +313 -0
- package/dist/{cjs/apollo-data-bar-chart_2.cjs.entry.js → esm/apollo-data-base-C2k3WBpi.js} +8 -728
- package/dist/esm/apollo-data-donut-chart.entry.js +406 -0
- package/dist/esm/apollo-data-heat-map_4.entry.js +878 -0
- package/dist/esm/apollo-data.js +4 -4
- package/dist/esm/constants-2nuV5Vny.js +3 -0
- package/dist/esm/{index-Bb2nY-Tf.js → index-D64asVrg.js} +116 -63
- package/dist/esm/loader.js +3 -3
- package/dist/types/apollo-data-base.d.ts +2 -2
- package/dist/types/components/apollo-data-bar/apollo-data-bar.stories.d.ts +5 -0
- package/dist/types/components/apollo-data-donut/apollo-data-donut.stories.d.ts +5 -0
- package/dist/types/components/apollo-data-heat-map/apollo-data-heat-map.d.ts +140 -0
- package/dist/types/components/apollo-data-heat-map/apollo-data-heat-map.stories.d.ts +5 -0
- package/dist/types/components/apollo-data-line/apollo-data-line.d.ts +244 -0
- package/dist/types/components/apollo-data-line/apollo-data-line.stories.d.ts +5 -0
- package/dist/types/components/apollo-data-scatter/apollo-data-scatter.d.ts +327 -0
- package/dist/types/components/apollo-data-scatter/apollo-data-scatter.stories.d.ts +5 -0
- package/dist/types/components/apollo-data-world-map/apollo-data-world-map.d.ts +281 -0
- package/dist/types/components/apollo-data-world-map/apollo-data-world-map.stories.d.ts +5 -0
- package/dist/types/components.d.ts +210 -4
- package/dist/types/examples/apollo-data-heat-map.examples.d.ts +11 -0
- package/dist/types/examples/apollo-data-line.examples.d.ts +12 -0
- package/dist/types/examples/apollo-data-scatter.examples.d.ts +11 -0
- package/dist/types/examples/apollo-data-world-map.examples.d.ts +11 -0
- package/dist/types/examples/index.d.ts +3 -0
- package/dist/types/stencil-public-runtime.d.ts +23 -2
- package/dist/types/utils/code-generator.d.ts +1 -3
- package/package.json +8 -8
- package/src/examples/apollo-data-bar.examples.ts +157 -157
- package/src/examples/apollo-data-heat-map.examples.ts +147 -0
- package/src/examples/apollo-data-line.examples.ts +103 -0
- package/src/examples/apollo-data-scatter.examples.ts +109 -0
- package/src/examples/apollo-data-world-map.examples.ts +57 -0
- package/src/examples/index.ts +4 -1
- package/dist/apollo-data/p-Bb2nY-Tf.js +0 -2
- package/dist/apollo-data/p-e6584598.entry.js +0 -11
- package/dist/components/p-7XF5Cax8.js +0 -11
- package/dist/components/p-Dws5s-Xe.js +0 -1
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { h, Host } from "@stencil/core";
|
|
2
|
+
import { ApolloBase } from "../../apollo-data-base";
|
|
3
|
+
export class ApolloDataHeatMap extends ApolloBase {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
}
|
|
7
|
+
el = null;
|
|
8
|
+
/**
|
|
9
|
+
* Data for the heat map. Each item defines a cell by xLabel, yLabel, and value.
|
|
10
|
+
* @property {string} xLabel - Label for the X-axis (horizontal).
|
|
11
|
+
* @property {string} yLabel - Label for the Y-axis (vertical).
|
|
12
|
+
* @property {number} value - Numeric value encoded as color.
|
|
13
|
+
*/
|
|
14
|
+
adData = [];
|
|
15
|
+
/**
|
|
16
|
+
* Optional specification for axis titles, color range, and tooltip behavior.
|
|
17
|
+
* @property {string} [xAxisTitle] - Label for the X-axis.
|
|
18
|
+
* @property {string} [yAxisTitle] - Label for the Y-axis.
|
|
19
|
+
* @property {string[]} [colorRange] - Two or more colors for the value scale (Vega interpolates between them).
|
|
20
|
+
* @property {'auto' | 'none'} [tooltip] - Tooltip behavior.
|
|
21
|
+
*/
|
|
22
|
+
adSpec = {};
|
|
23
|
+
async componentDidRender() {
|
|
24
|
+
await this.renderChart();
|
|
25
|
+
}
|
|
26
|
+
DEFAULT_COLOR_RANGE = ['#e8f4f8', '#0066a1'];
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
async getViewData(data, spec) {
|
|
29
|
+
const rawRange = spec?.colorRange;
|
|
30
|
+
const colorRange = Array.isArray(rawRange) && rawRange.length >= 2 ? rawRange : this.DEFAULT_COLOR_RANGE;
|
|
31
|
+
const tooltip = spec?.tooltip !== 'none';
|
|
32
|
+
const valid = data.filter(d => d != null && typeof d.xLabel === 'string' && typeof d.yLabel === 'string' && d.xLabel !== '' && d.yLabel !== '' && typeof d.value === 'number');
|
|
33
|
+
const xLabels = [...new Set(valid.map(d => d.xLabel))];
|
|
34
|
+
const yLabels = [...new Set(valid.map(d => d.yLabel))];
|
|
35
|
+
return {
|
|
36
|
+
$schema: 'https://vega.github.io/schema/vega/v6.json',
|
|
37
|
+
description: 'A heat map with xLabel and yLabel categories and value encoded as color.',
|
|
38
|
+
width: 450,
|
|
39
|
+
height: 350,
|
|
40
|
+
padding: { left: 5, top: 5, bottom: 5, right: 70 },
|
|
41
|
+
autosize: { type: 'fit', resize: true },
|
|
42
|
+
data: [
|
|
43
|
+
{
|
|
44
|
+
name: 'source',
|
|
45
|
+
values: valid,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
scales: [
|
|
49
|
+
{
|
|
50
|
+
name: 'xscale',
|
|
51
|
+
type: 'band',
|
|
52
|
+
range: [0, { signal: 'width' }],
|
|
53
|
+
domain: xLabels,
|
|
54
|
+
padding: 0.05,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'yscale',
|
|
58
|
+
type: 'band',
|
|
59
|
+
range: [{ signal: 'height' }, 0],
|
|
60
|
+
domain: yLabels,
|
|
61
|
+
padding: 0.05,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'color',
|
|
65
|
+
type: 'sequential',
|
|
66
|
+
range: colorRange,
|
|
67
|
+
domain: { data: 'source', field: 'value' },
|
|
68
|
+
zero: true,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
axes: [
|
|
72
|
+
{
|
|
73
|
+
orient: 'bottom',
|
|
74
|
+
scale: 'xscale',
|
|
75
|
+
title: spec?.xAxisTitle ?? 'X',
|
|
76
|
+
labelAngle: -90,
|
|
77
|
+
labelAlign: 'right',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
orient: 'left',
|
|
81
|
+
scale: 'yscale',
|
|
82
|
+
title: spec?.yAxisTitle ?? 'Y',
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
legends: [
|
|
86
|
+
{
|
|
87
|
+
type: 'gradient',
|
|
88
|
+
fill: 'color',
|
|
89
|
+
orient: 'right',
|
|
90
|
+
direction: 'vertical',
|
|
91
|
+
title: 'Value',
|
|
92
|
+
titleLimit: 120,
|
|
93
|
+
tickCount: 5,
|
|
94
|
+
format: 's',
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
marks: [
|
|
98
|
+
{
|
|
99
|
+
type: 'rect',
|
|
100
|
+
from: { data: 'source' },
|
|
101
|
+
encode: {
|
|
102
|
+
...(tooltip && {
|
|
103
|
+
enter: {
|
|
104
|
+
tooltip: {
|
|
105
|
+
signal: "datum.xLabel + ' | ' + datum.yLabel + ' | ' + format(datum.value, ',.2f')",
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
update: {
|
|
110
|
+
x: { scale: 'xscale', field: 'xLabel' },
|
|
111
|
+
y: { scale: 'yscale', field: 'yLabel' },
|
|
112
|
+
width: { scale: 'xscale', band: 1 },
|
|
113
|
+
height: { scale: 'yscale', band: 1 },
|
|
114
|
+
fill: { scale: 'color', field: 'value' },
|
|
115
|
+
},
|
|
116
|
+
hover: {
|
|
117
|
+
fill: { value: 'firebrick' },
|
|
118
|
+
opacity: { value: 0.8 },
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
render() {
|
|
126
|
+
return (h(Host, { key: 'd15b44f268f153498e61dc7829fe0d45f315a992' }, h("div", { key: '7783444f4675c885980f1cd571737d506e00fdbc', id: "container", style: { width: '100%', height: '100%' } })));
|
|
127
|
+
}
|
|
128
|
+
static get is() { return "apollo-data-heat-map"; }
|
|
129
|
+
static get encapsulation() { return "shadow"; }
|
|
130
|
+
static get properties() {
|
|
131
|
+
return {
|
|
132
|
+
"adData": {
|
|
133
|
+
"type": "string",
|
|
134
|
+
"mutable": false,
|
|
135
|
+
"complexType": {
|
|
136
|
+
"original": "string | HeatMapDataItem[]",
|
|
137
|
+
"resolved": "HeatMapDataItem[] | string",
|
|
138
|
+
"references": {
|
|
139
|
+
"HeatMapDataItem": {
|
|
140
|
+
"location": "local",
|
|
141
|
+
"path": "/home/runner/work/apollo/apollo/packages/apollo-data/src/components/apollo-data-heat-map/apollo-data-heat-map.tsx",
|
|
142
|
+
"id": "src/components/apollo-data-heat-map/apollo-data-heat-map.tsx::HeatMapDataItem"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
"required": false,
|
|
147
|
+
"optional": false,
|
|
148
|
+
"docs": {
|
|
149
|
+
"tags": [{
|
|
150
|
+
"name": "property",
|
|
151
|
+
"text": "{string} xLabel - Label for the X-axis (horizontal)."
|
|
152
|
+
}, {
|
|
153
|
+
"name": "property",
|
|
154
|
+
"text": "{string} yLabel - Label for the Y-axis (vertical)."
|
|
155
|
+
}, {
|
|
156
|
+
"name": "property",
|
|
157
|
+
"text": "{number} value - Numeric value encoded as color."
|
|
158
|
+
}],
|
|
159
|
+
"text": "Data for the heat map. Each item defines a cell by xLabel, yLabel, and value."
|
|
160
|
+
},
|
|
161
|
+
"getter": false,
|
|
162
|
+
"setter": false,
|
|
163
|
+
"reflect": false,
|
|
164
|
+
"attribute": "ad-data",
|
|
165
|
+
"defaultValue": "[]"
|
|
166
|
+
},
|
|
167
|
+
"adSpec": {
|
|
168
|
+
"type": "string",
|
|
169
|
+
"mutable": false,
|
|
170
|
+
"complexType": {
|
|
171
|
+
"original": "string | HeatMapSpec",
|
|
172
|
+
"resolved": "HeatMapSpec | string",
|
|
173
|
+
"references": {
|
|
174
|
+
"HeatMapSpec": {
|
|
175
|
+
"location": "local",
|
|
176
|
+
"path": "/home/runner/work/apollo/apollo/packages/apollo-data/src/components/apollo-data-heat-map/apollo-data-heat-map.tsx",
|
|
177
|
+
"id": "src/components/apollo-data-heat-map/apollo-data-heat-map.tsx::HeatMapSpec"
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
"required": false,
|
|
182
|
+
"optional": false,
|
|
183
|
+
"docs": {
|
|
184
|
+
"tags": [{
|
|
185
|
+
"name": "property",
|
|
186
|
+
"text": "{string} [xAxisTitle] - Label for the X-axis."
|
|
187
|
+
}, {
|
|
188
|
+
"name": "property",
|
|
189
|
+
"text": "{string} [yAxisTitle] - Label for the Y-axis."
|
|
190
|
+
}, {
|
|
191
|
+
"name": "property",
|
|
192
|
+
"text": "{string[]} [colorRange] - Two or more colors for the value scale (Vega interpolates between them)."
|
|
193
|
+
}, {
|
|
194
|
+
"name": "property",
|
|
195
|
+
"text": "{'auto' | 'none'} [tooltip] - Tooltip behavior."
|
|
196
|
+
}],
|
|
197
|
+
"text": "Optional specification for axis titles, color range, and tooltip behavior."
|
|
198
|
+
},
|
|
199
|
+
"getter": false,
|
|
200
|
+
"setter": false,
|
|
201
|
+
"reflect": false,
|
|
202
|
+
"attribute": "ad-spec",
|
|
203
|
+
"defaultValue": "{}"
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
static get elementRef() { return "el"; }
|
|
208
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { html } from "lit-html";
|
|
2
|
+
import { generateReactCode, generateVueCode, generateWebComponentCode, generateInstallationDocs } from "../../utils/code-generator";
|
|
3
|
+
import { heatMapExamples } from "../../examples/apollo-data-heat-map.examples";
|
|
4
|
+
function getCodeForFramework(props, framework) {
|
|
5
|
+
switch (framework) {
|
|
6
|
+
case 'vue':
|
|
7
|
+
return generateVueCode('apollo-data-heat-map', props);
|
|
8
|
+
case 'webcomponent':
|
|
9
|
+
return generateWebComponentCode('apollo-data-heat-map', props);
|
|
10
|
+
case 'react':
|
|
11
|
+
default:
|
|
12
|
+
return generateReactCode('apollo-data-heat-map', props);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const meta = {
|
|
16
|
+
title: 'Apollo Data/Heat Map',
|
|
17
|
+
tags: ['autodocs'],
|
|
18
|
+
argTypes: {
|
|
19
|
+
adData: {
|
|
20
|
+
control: 'object',
|
|
21
|
+
description: 'Array of data items. Each item defines a cell by xLabel, yLabel, and value (value is encoded as color).',
|
|
22
|
+
table: {
|
|
23
|
+
type: {
|
|
24
|
+
summary: 'HeatMapDataItem[]',
|
|
25
|
+
detail: 'interface HeatMapDataItem {\n xLabel: string;\n yLabel: string;\n value: number;\n}',
|
|
26
|
+
},
|
|
27
|
+
defaultValue: { summary: '[]' },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
adSpec: {
|
|
31
|
+
control: 'object',
|
|
32
|
+
description: 'Optional specification for axis titles, color range, and tooltip behavior.',
|
|
33
|
+
table: {
|
|
34
|
+
type: {
|
|
35
|
+
summary: 'HeatMapSpec',
|
|
36
|
+
detail: `interface HeatMapSpec {
|
|
37
|
+
xAxisTitle?: string;
|
|
38
|
+
yAxisTitle?: string;
|
|
39
|
+
colorRange?: string[];
|
|
40
|
+
tooltip?: 'auto' | 'none';
|
|
41
|
+
}`,
|
|
42
|
+
},
|
|
43
|
+
defaultValue: { summary: '{}' },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
decorators: [
|
|
48
|
+
(story, context) => {
|
|
49
|
+
const framework = context.globals?.framework || 'react';
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
const doc = globalThis.document;
|
|
52
|
+
if (doc) {
|
|
53
|
+
const installSections = {
|
|
54
|
+
react: doc.querySelector('.install-react'),
|
|
55
|
+
vue: doc.querySelector('.install-vue'),
|
|
56
|
+
webcomponent: doc.querySelector('.install-webcomponent'),
|
|
57
|
+
};
|
|
58
|
+
Object.values(installSections).forEach((section) => {
|
|
59
|
+
if (section) {
|
|
60
|
+
section.setAttribute('style', 'display: none;');
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
const selectedSection = installSections[framework];
|
|
64
|
+
if (selectedSection) {
|
|
65
|
+
selectedSection.setAttribute('style', 'display: block;');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}, 0);
|
|
69
|
+
return story();
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
parameters: {
|
|
73
|
+
docs: {
|
|
74
|
+
description: {
|
|
75
|
+
component: `${generateInstallationDocs('react', 'apollo-data-heat-map')}
|
|
76
|
+
|
|
77
|
+
${generateInstallationDocs('vue', 'apollo-data-heat-map')}
|
|
78
|
+
|
|
79
|
+
${generateInstallationDocs('webcomponent', 'apollo-data-heat-map')}
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Description
|
|
84
|
+
|
|
85
|
+
A Heat Map visualizes values in a matrix of rows and columns using color. Each cell is defined by a row category, a column category, and a numeric value that is encoded on a color scale.
|
|
86
|
+
|
|
87
|
+
**Tip:** Use the Framework selector in the toolbar above to switch between React, Vue, and Web Component installation instructions and code examples.`,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
viewMode: 'story',
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
export default meta;
|
|
94
|
+
const chartWrapper = (args) => html `
|
|
95
|
+
<div style="width: 640px; height: 380px;">
|
|
96
|
+
<apollo-data-heat-map .adData=${args.adData} .adSpec=${args.adSpec}></apollo-data-heat-map>
|
|
97
|
+
</div>
|
|
98
|
+
`;
|
|
99
|
+
const sharedParams = {
|
|
100
|
+
codeGenerator: (args, framework) => getCodeForFramework(args, framework),
|
|
101
|
+
docs: {
|
|
102
|
+
source: {
|
|
103
|
+
language: 'tsx',
|
|
104
|
+
type: 'dynamic',
|
|
105
|
+
transform: (_code, storyContext) => {
|
|
106
|
+
try {
|
|
107
|
+
const framework = storyContext?.globals?.framework || 'react';
|
|
108
|
+
const props = {
|
|
109
|
+
adData: storyContext?.args?.adData || [],
|
|
110
|
+
adSpec: storyContext?.args?.adSpec || {},
|
|
111
|
+
};
|
|
112
|
+
return getCodeForFramework(props, framework);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.error('Error in transform function:', error);
|
|
116
|
+
return `<apollo-data-heat-map />`;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
export const WeatherDayVsMonth = {
|
|
123
|
+
args: {
|
|
124
|
+
adData: heatMapExamples[0].props.adData,
|
|
125
|
+
adSpec: heatMapExamples[0].props.adSpec || {},
|
|
126
|
+
},
|
|
127
|
+
render: chartWrapper,
|
|
128
|
+
parameters: {
|
|
129
|
+
...sharedParams,
|
|
130
|
+
docs: {
|
|
131
|
+
description: {
|
|
132
|
+
story: 'Average high temperature (°F) by day of month and month. Blue = cooler, red = warmer.',
|
|
133
|
+
},
|
|
134
|
+
...sharedParams.docs,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
};
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { h, Host } from "@stencil/core";
|
|
2
|
+
import { ApolloBase } from "../../apollo-data-base";
|
|
3
|
+
import { CHART_COLORS } from "../../utils/constants";
|
|
4
|
+
const FONT_FAMILY = "apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif";
|
|
5
|
+
function lineStyleToStrokeDash(lineStyle) {
|
|
6
|
+
switch (lineStyle) {
|
|
7
|
+
case 'dashed':
|
|
8
|
+
return [6, 4];
|
|
9
|
+
case 'dotted':
|
|
10
|
+
return [2, 2];
|
|
11
|
+
case 'solid':
|
|
12
|
+
default:
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class ApolloDataLineChart extends ApolloBase {
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
}
|
|
20
|
+
el = null;
|
|
21
|
+
adData = [];
|
|
22
|
+
adSpec = null;
|
|
23
|
+
static tooltipStylesInjected = false;
|
|
24
|
+
componentDidLoad() {
|
|
25
|
+
this.injectTooltipStyles();
|
|
26
|
+
}
|
|
27
|
+
async componentDidRender() {
|
|
28
|
+
await this.renderChart();
|
|
29
|
+
}
|
|
30
|
+
injectTooltipStyles() {
|
|
31
|
+
const chartClass = this.constructor;
|
|
32
|
+
if (chartClass.tooltipStylesInjected) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const styleId = 'apollo-data-line-tooltip-styles';
|
|
36
|
+
if (document.getElementById(styleId)) {
|
|
37
|
+
chartClass.tooltipStylesInjected = true;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const style = document.createElement('style');
|
|
41
|
+
style.id = styleId;
|
|
42
|
+
style.textContent = `
|
|
43
|
+
#vg-tooltip-element {
|
|
44
|
+
background-color: #ffffff;
|
|
45
|
+
border: 1px solid #e1e2e8;
|
|
46
|
+
border-radius: 0.25rem;
|
|
47
|
+
box-shadow: 0 4px 6px -1px rgba(48, 45, 59, 0.1), 0 2px 4px -1px rgba(48, 45, 59, 0.05);
|
|
48
|
+
font-family: apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif;
|
|
49
|
+
font-weight: 500;
|
|
50
|
+
padding: 0.25rem 0.75rem;
|
|
51
|
+
pointer-events: none;
|
|
52
|
+
text-align: center;
|
|
53
|
+
transform: translateY(20%);
|
|
54
|
+
white-space: pre;
|
|
55
|
+
z-index: 999999999;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#vg-tooltip-element table tr td.key {
|
|
59
|
+
color: #6a6d7d;
|
|
60
|
+
text-align: center;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#vg-tooltip-element table tr td.value {
|
|
64
|
+
text-align: center;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
#vg-tooltip-element.dark-theme {
|
|
68
|
+
background-color: #292632;
|
|
69
|
+
border: 1px solid #6a6d7d;
|
|
70
|
+
box-shadow: 0 4px 6px -1px rgba(48, 45, 59, 0.1), 0 2px 4px -1px rgba(48, 45, 59, 0.5);
|
|
71
|
+
color: #ffffff;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#vg-tooltip-element::after {
|
|
75
|
+
border-color: rgba(255, 255, 255, 0.95) transparent transparent transparent;
|
|
76
|
+
border-style: solid;
|
|
77
|
+
border-width: 9px;
|
|
78
|
+
bottom: -17px;
|
|
79
|
+
content: '';
|
|
80
|
+
left: 50%;
|
|
81
|
+
position: absolute;
|
|
82
|
+
transform: translateX(-50%);
|
|
83
|
+
}
|
|
84
|
+
`;
|
|
85
|
+
document.head.appendChild(style);
|
|
86
|
+
chartClass.tooltipStylesInjected = true;
|
|
87
|
+
}
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
async getViewData(data, spec) {
|
|
90
|
+
const componentTag = this.el?.tagName?.toLowerCase() ?? 'apollo-data-line-chart';
|
|
91
|
+
if (!spec) {
|
|
92
|
+
throw new Error(`adSpec is required for ${componentTag}`);
|
|
93
|
+
}
|
|
94
|
+
const { tooltipPrefix = '', currencySymbol = '' } = spec;
|
|
95
|
+
if (!data || data.length === 0) {
|
|
96
|
+
throw new Error(`Data is required for ${componentTag}`);
|
|
97
|
+
}
|
|
98
|
+
const uniqueCategories = Array.from(new Set(data.map(item => item.category)));
|
|
99
|
+
const uniqueXValues = [...new Set(data.map(item => item.xValue))].sort((a, b) => a - b);
|
|
100
|
+
const colorSet = spec?.colorSet ?? CHART_COLORS;
|
|
101
|
+
const xLabelData = uniqueXValues.map(x => {
|
|
102
|
+
const first = data.find(d => d.xValue === x);
|
|
103
|
+
return { xValue: x, displayLabel: first?.xLabel != null ? first.xLabel : String(x) };
|
|
104
|
+
});
|
|
105
|
+
const formatNumber = tooltipPrefix ? '.2f' : '.0f';
|
|
106
|
+
const currencyPrefix = tooltipPrefix ? currencySymbol : '';
|
|
107
|
+
const pointShape = spec.pointStyle ?? 'circle';
|
|
108
|
+
const strokeDash = lineStyleToStrokeDash(spec.lineStyle ?? 'solid');
|
|
109
|
+
const dataSpec = [
|
|
110
|
+
{ name: 'raw', values: data },
|
|
111
|
+
{ name: 'xLabelData', values: xLabelData },
|
|
112
|
+
];
|
|
113
|
+
uniqueCategories.forEach((cat, i) => {
|
|
114
|
+
dataSpec.push({
|
|
115
|
+
name: `series_${i}`,
|
|
116
|
+
source: 'raw',
|
|
117
|
+
transform: [
|
|
118
|
+
{ type: 'filter', expr: `datum.category === ${JSON.stringify(cat)}` },
|
|
119
|
+
{ type: 'collect', sort: { field: 'xValue' } },
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
const lineMarks = uniqueCategories.map((_, i) => ({
|
|
124
|
+
type: 'line',
|
|
125
|
+
from: { data: `series_${i}` },
|
|
126
|
+
encode: {
|
|
127
|
+
enter: {
|
|
128
|
+
x: { scale: 'x', field: 'xValue' },
|
|
129
|
+
y: { scale: 'y', field: 'yValue' },
|
|
130
|
+
stroke: { value: colorSet[i % colorSet.length] },
|
|
131
|
+
strokeWidth: { value: 2 },
|
|
132
|
+
interpolate: { value: 'monotone' },
|
|
133
|
+
...(strokeDash.length > 0 ? { strokeDash: { value: strokeDash } } : {}),
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
}));
|
|
137
|
+
return {
|
|
138
|
+
$schema: 'https://vega.github.io/schema/vega/v5.json',
|
|
139
|
+
config: {
|
|
140
|
+
text: {
|
|
141
|
+
fill: '#6a6d7d',
|
|
142
|
+
font: FONT_FAMILY,
|
|
143
|
+
labelFontSize: 12,
|
|
144
|
+
labelFontWeight: 400,
|
|
145
|
+
},
|
|
146
|
+
axis: {
|
|
147
|
+
labelColor: '#6a6d7d',
|
|
148
|
+
titleColor: '#6a6d7d',
|
|
149
|
+
labelFont: FONT_FAMILY,
|
|
150
|
+
titleFont: FONT_FAMILY,
|
|
151
|
+
titleFontWeight: 400,
|
|
152
|
+
},
|
|
153
|
+
legend: {
|
|
154
|
+
labelColor: '#6a6d7d',
|
|
155
|
+
titleColor: '#6a6d7d',
|
|
156
|
+
labelFont: FONT_FAMILY,
|
|
157
|
+
titleFont: FONT_FAMILY,
|
|
158
|
+
labelFontSize: 12,
|
|
159
|
+
labelLimit: 95,
|
|
160
|
+
},
|
|
161
|
+
title: {
|
|
162
|
+
color: '#6a6d7d',
|
|
163
|
+
font: FONT_FAMILY,
|
|
164
|
+
labelFontSize: 12,
|
|
165
|
+
labelFontWeight: 400,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
height: 250,
|
|
169
|
+
autosize: { type: 'fit-x', contains: 'padding', resize: true },
|
|
170
|
+
signals: [
|
|
171
|
+
{
|
|
172
|
+
name: 'containerW',
|
|
173
|
+
update: 'max(containerSize()[0], 400)',
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: 'legendColumns',
|
|
177
|
+
update: 'ceil(containerW / 140)',
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
width: { signal: 'containerW' },
|
|
181
|
+
data: dataSpec,
|
|
182
|
+
scales: [
|
|
183
|
+
{
|
|
184
|
+
name: 'x',
|
|
185
|
+
type: 'point',
|
|
186
|
+
domain: uniqueXValues,
|
|
187
|
+
range: 'width',
|
|
188
|
+
padding: 0.5,
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
name: 'xLabels',
|
|
192
|
+
type: 'ordinal',
|
|
193
|
+
domain: { data: 'xLabelData', field: 'xValue' },
|
|
194
|
+
range: { data: 'xLabelData', field: 'displayLabel' },
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: 'y',
|
|
198
|
+
type: 'linear',
|
|
199
|
+
domain: { data: 'raw', field: 'yValue' },
|
|
200
|
+
nice: true,
|
|
201
|
+
zero: true,
|
|
202
|
+
range: 'height',
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: 'color',
|
|
206
|
+
type: 'ordinal',
|
|
207
|
+
domain: uniqueCategories,
|
|
208
|
+
range: spec?.colorSet ?? CHART_COLORS,
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
axes: [
|
|
212
|
+
{
|
|
213
|
+
orient: 'bottom',
|
|
214
|
+
scale: 'x',
|
|
215
|
+
title: spec?.xAxisTitle,
|
|
216
|
+
labelPadding: 12,
|
|
217
|
+
titlePadding: 12,
|
|
218
|
+
labelAngle: -90,
|
|
219
|
+
labelAlign: 'right',
|
|
220
|
+
labelBaseline: 'middle',
|
|
221
|
+
tickSize: 3,
|
|
222
|
+
labelFontSize: 12,
|
|
223
|
+
titleFontSize: 14,
|
|
224
|
+
ticks: false,
|
|
225
|
+
domain: false,
|
|
226
|
+
encode: {
|
|
227
|
+
labels: {
|
|
228
|
+
update: {
|
|
229
|
+
text: { signal: "scale('xLabels', datum.value)" },
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
orient: 'left',
|
|
236
|
+
scale: 'y',
|
|
237
|
+
title: spec?.yAxisTitle || '',
|
|
238
|
+
format: ',.0f',
|
|
239
|
+
grid: true,
|
|
240
|
+
tickCount: 6,
|
|
241
|
+
labelFontSize: 12,
|
|
242
|
+
titleFontSize: 14,
|
|
243
|
+
ticks: false,
|
|
244
|
+
domain: false,
|
|
245
|
+
tickBand: 'extent',
|
|
246
|
+
labelPadding: 10,
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
legends: [
|
|
250
|
+
{
|
|
251
|
+
stroke: 'color',
|
|
252
|
+
orient: 'bottom',
|
|
253
|
+
direction: 'horizontal',
|
|
254
|
+
columns: { signal: 'legendColumns' },
|
|
255
|
+
title: null,
|
|
256
|
+
symbolType: 'stroke',
|
|
257
|
+
symbolStrokeWidth: 3,
|
|
258
|
+
rowPadding: 8,
|
|
259
|
+
symbolOffset: -35,
|
|
260
|
+
symbolSize: 100,
|
|
261
|
+
labelOffset: 8,
|
|
262
|
+
labelLimit: 95,
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
marks: [
|
|
266
|
+
...lineMarks,
|
|
267
|
+
{
|
|
268
|
+
type: 'symbol',
|
|
269
|
+
from: { data: 'raw' },
|
|
270
|
+
encode: {
|
|
271
|
+
enter: {
|
|
272
|
+
x: { scale: 'x', field: 'xValue' },
|
|
273
|
+
y: { scale: 'y', field: 'yValue' },
|
|
274
|
+
fill: { scale: 'color', field: 'category' },
|
|
275
|
+
size: { value: 50 },
|
|
276
|
+
shape: { value: pointShape },
|
|
277
|
+
tooltip: {
|
|
278
|
+
signal: `(datum.xLabel != null ? datum.xLabel : format(datum.xValue, ',.0f')) + ' · ' + datum.category + ': ' + (datum.yLabel != null ? datum.yLabel : '${currencyPrefix}' + format(datum.yValue, ',${formatNumber}'))`,
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
render() {
|
|
287
|
+
return (h(Host, { key: 'fd64f4abb624b14a878808b23345910c9b23a72c' }, h("div", { key: 'aeda5086730862ca1368a0374caf2d918969839d', id: "container", style: { width: '100%', height: '100%' } })));
|
|
288
|
+
}
|
|
289
|
+
static get is() { return "apollo-data-line-chart"; }
|
|
290
|
+
static get encapsulation() { return "shadow"; }
|
|
291
|
+
static get properties() {
|
|
292
|
+
return {
|
|
293
|
+
"adData": {
|
|
294
|
+
"type": "string",
|
|
295
|
+
"mutable": false,
|
|
296
|
+
"complexType": {
|
|
297
|
+
"original": "string | LineDataItem[]",
|
|
298
|
+
"resolved": "LineDataItem[] | string",
|
|
299
|
+
"references": {
|
|
300
|
+
"LineDataItem": {
|
|
301
|
+
"location": "local",
|
|
302
|
+
"path": "/home/runner/work/apollo/apollo/packages/apollo-data/src/components/apollo-data-line/apollo-data-line.tsx",
|
|
303
|
+
"id": "src/components/apollo-data-line/apollo-data-line.tsx::LineDataItem"
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
"required": false,
|
|
308
|
+
"optional": false,
|
|
309
|
+
"docs": {
|
|
310
|
+
"tags": [],
|
|
311
|
+
"text": ""
|
|
312
|
+
},
|
|
313
|
+
"getter": false,
|
|
314
|
+
"setter": false,
|
|
315
|
+
"reflect": false,
|
|
316
|
+
"attribute": "ad-data",
|
|
317
|
+
"defaultValue": "[]"
|
|
318
|
+
},
|
|
319
|
+
"adSpec": {
|
|
320
|
+
"type": "string",
|
|
321
|
+
"mutable": false,
|
|
322
|
+
"complexType": {
|
|
323
|
+
"original": "string | LineSpec",
|
|
324
|
+
"resolved": "LineSpec | string",
|
|
325
|
+
"references": {
|
|
326
|
+
"LineSpec": {
|
|
327
|
+
"location": "local",
|
|
328
|
+
"path": "/home/runner/work/apollo/apollo/packages/apollo-data/src/components/apollo-data-line/apollo-data-line.tsx",
|
|
329
|
+
"id": "src/components/apollo-data-line/apollo-data-line.tsx::LineSpec"
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
"required": false,
|
|
334
|
+
"optional": false,
|
|
335
|
+
"docs": {
|
|
336
|
+
"tags": [],
|
|
337
|
+
"text": ""
|
|
338
|
+
},
|
|
339
|
+
"getter": false,
|
|
340
|
+
"setter": false,
|
|
341
|
+
"reflect": false,
|
|
342
|
+
"attribute": "ad-spec",
|
|
343
|
+
"defaultValue": "null"
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
static get elementRef() { return "el"; }
|
|
348
|
+
}
|