@xplortech/apollo-data 0.0.5 → 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/README.md +15 -91
- package/dist/apollo-data/apollo-data.esm.js +1 -1
- package/dist/apollo-data/p-4d3f0792.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-b7471c12.entry.js → p-e2c3a317.entry.js} +1 -1
- package/dist/cjs/apollo-data-bar-chart_5.cjs.entry.js +1193 -0
- package/dist/cjs/{apollo-data-base-CxVQ-WVP.js → apollo-data-base-COGMOEqL.js} +7 -11
- package/dist/cjs/apollo-data-donut-chart.cjs.entry.js +3 -3
- package/dist/cjs/apollo-data.cjs.js +3 -3
- 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 +5 -2
- package/dist/collection/components/apollo-data-bar/apollo-data-bar.js +10 -9
- 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 +8 -6
- 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 +1 -1
- 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-world-map.examples.js +45 -0
- package/dist/collection/examples/index.js +2 -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.js +1 -1
- package/dist/components/apollo-data-scatter-chart.js +1 -1
- 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-CfbMSXKd.js +11 -0
- package/dist/components/p-gcjU8DVr.js +1 -0
- package/dist/esm/apollo-data-bar-chart_5.entry.js +1187 -0
- package/dist/esm/{apollo-data-base-BWkrM8dc.js → apollo-data-base-C2k3WBpi.js} +7 -11
- package/dist/esm/apollo-data-donut-chart.entry.js +3 -3
- package/dist/esm/apollo-data.js +4 -4
- 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.stories.d.ts +5 -0
- package/dist/types/components/apollo-data-scatter/apollo-data-scatter.d.ts +1 -3
- 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 +128 -8
- package/dist/types/examples/apollo-data-heat-map.examples.d.ts +11 -0
- package/dist/types/examples/apollo-data-scatter.examples.d.ts +1 -1
- package/dist/types/examples/apollo-data-world-map.examples.d.ts +11 -0
- package/dist/types/examples/index.d.ts +2 -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 +91 -91
- package/src/examples/apollo-data-scatter.examples.ts +1 -1
- package/src/examples/apollo-data-world-map.examples.ts +57 -0
- package/src/examples/index.ts +3 -1
- package/dist/apollo-data/p-2nuV5Vny.js +0 -1
- package/dist/apollo-data/p-4ac3c97c.entry.js +0 -1
- package/dist/apollo-data/p-BWkrM8dc.js +0 -11
- package/dist/apollo-data/p-Bb2nY-Tf.js +0 -2
- package/dist/apollo-data/p-e518baac.entry.js +0 -1
- package/dist/cjs/apollo-data-bar-chart.cjs.entry.js +0 -314
- package/dist/cjs/apollo-data-line-chart_2.cjs.entry.js +0 -534
- package/dist/cjs/constants-B3weDEpc.js +0 -5
- package/dist/components/p-7XF5Cax8.js +0 -11
- package/dist/components/p-Dws5s-Xe.js +0 -1
- package/dist/esm/apollo-data-bar-chart.entry.js +0 -312
- package/dist/esm/apollo-data-line-chart_2.entry.js +0 -531
- package/dist/esm/constants-2nuV5Vny.js +0 -3
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { html } from "lit-html";
|
|
2
|
+
import { donutExamples } from "../../examples/apollo-data-donut.examples";
|
|
3
|
+
import { generateReactCode, generateVueCode, generateWebComponentCode, generateInstallationDocs } from "../../utils/code-generator";
|
|
4
|
+
// Helper function to generate code based on framework
|
|
5
|
+
function getCodeForFramework(props, framework) {
|
|
6
|
+
switch (framework) {
|
|
7
|
+
case 'vue':
|
|
8
|
+
return generateVueCode('apollo-data-donut-chart', props);
|
|
9
|
+
case 'webcomponent':
|
|
10
|
+
return generateWebComponentCode('apollo-data-donut-chart', props);
|
|
11
|
+
case 'react':
|
|
12
|
+
default:
|
|
13
|
+
return generateReactCode('apollo-data-donut-chart', props);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const meta = {
|
|
17
|
+
title: 'Apollo Data/Donut Chart',
|
|
18
|
+
tags: ['autodocs'],
|
|
19
|
+
argTypes: {
|
|
20
|
+
adData: {
|
|
21
|
+
control: 'object',
|
|
22
|
+
description: 'Array of data items to display in the donut chart. Each item must have a category (string) and value (number).',
|
|
23
|
+
table: {
|
|
24
|
+
type: {
|
|
25
|
+
summary: 'DonutDataItem[]',
|
|
26
|
+
detail: 'interface DonutDataItem {\n category: string;\n value: number;\n}',
|
|
27
|
+
},
|
|
28
|
+
defaultValue: { summary: '[]' },
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
adSpec: {
|
|
32
|
+
control: 'object',
|
|
33
|
+
description: 'Optional specification object for customizing the chart appearance, such as custom color sets, prefix , suffix and center text',
|
|
34
|
+
table: {
|
|
35
|
+
type: {
|
|
36
|
+
summary: 'DonutSpec',
|
|
37
|
+
detail: 'interface DonutSpec {\n colorSet?: string[];\n prefix?: string;\n suffix?: string;\n centerText: string;\n}',
|
|
38
|
+
},
|
|
39
|
+
defaultValue: { summary: '{}' },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
decorators: [
|
|
44
|
+
(story, context) => {
|
|
45
|
+
const framework = context.globals?.framework || 'react';
|
|
46
|
+
// Update visibility of installation sections when framework changes
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
const doc = globalThis.document;
|
|
49
|
+
if (doc) {
|
|
50
|
+
const installSections = {
|
|
51
|
+
react: doc.querySelector('.install-react'),
|
|
52
|
+
vue: doc.querySelector('.install-vue'),
|
|
53
|
+
webcomponent: doc.querySelector('.install-webcomponent'),
|
|
54
|
+
};
|
|
55
|
+
// Hide all sections first
|
|
56
|
+
Object.values(installSections).forEach((section) => {
|
|
57
|
+
if (section) {
|
|
58
|
+
section.setAttribute('style', 'display: none;');
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
// Show only the selected framework
|
|
62
|
+
const selectedSection = installSections[framework];
|
|
63
|
+
if (selectedSection) {
|
|
64
|
+
selectedSection.setAttribute('style', 'display: block;');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, 0);
|
|
68
|
+
return story();
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
parameters: {
|
|
72
|
+
docs: {
|
|
73
|
+
description: {
|
|
74
|
+
component: `${generateInstallationDocs('react', 'apollo-data-donut-chart')}
|
|
75
|
+
|
|
76
|
+
${generateInstallationDocs('vue', 'apollo-data-donut-chart')}
|
|
77
|
+
|
|
78
|
+
${generateInstallationDocs('webcomponent', 'apollo-data-donut-chart')}
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Description
|
|
83
|
+
|
|
84
|
+
A donut chart component built with Vega that displays data in a circular format with interactive hover effects. Use the controls below to modify the data and see the code examples update automatically.
|
|
85
|
+
|
|
86
|
+
**Tip:** Use the Framework selector in the toolbar above to switch between React, Vue, and Web Component installation instructions and code examples.`,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
viewMode: 'story',
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
export default meta;
|
|
93
|
+
// Single interactive story
|
|
94
|
+
export const ApolloDataDonut = {
|
|
95
|
+
args: {
|
|
96
|
+
adData: donutExamples[5].props.adData,
|
|
97
|
+
adSpec: donutExamples[5].props.adSpec || {},
|
|
98
|
+
},
|
|
99
|
+
render: args => html `
|
|
100
|
+
<div style="width: 600px; height: 400px;">
|
|
101
|
+
<apollo-data-donut-chart .adData=${args.adData} .adSpec=${args.adSpec}></apollo-data-donut-chart>
|
|
102
|
+
</div>
|
|
103
|
+
`,
|
|
104
|
+
parameters: {
|
|
105
|
+
// Code generator function for the Code addon panel
|
|
106
|
+
codeGenerator: (args, framework) => getCodeForFramework(args, framework),
|
|
107
|
+
docs: {
|
|
108
|
+
description: {
|
|
109
|
+
story: 'Interactive donut chart. Modify the data and spec using the controls below, switch between React, Vue, or Web Component using the Framework selector in the toolbar, and view the generated code in the Code tab.',
|
|
110
|
+
},
|
|
111
|
+
source: {
|
|
112
|
+
language: 'tsx',
|
|
113
|
+
type: 'dynamic',
|
|
114
|
+
transform: (_code, storyContext) => {
|
|
115
|
+
try {
|
|
116
|
+
const framework = storyContext?.globals?.framework || 'react';
|
|
117
|
+
const props = {
|
|
118
|
+
adData: storyContext?.args?.adData || [],
|
|
119
|
+
adSpec: storyContext?.args?.adSpec || {},
|
|
120
|
+
};
|
|
121
|
+
return getCodeForFramework(props, framework);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
// eslint-disable-next-line no-console
|
|
125
|
+
console.error('Error in transform function:', error);
|
|
126
|
+
return `<apollo-data-donut-chart />`;
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -28,12 +28,13 @@ export class ApolloDataLineChart extends ApolloBase {
|
|
|
28
28
|
await this.renderChart();
|
|
29
29
|
}
|
|
30
30
|
injectTooltipStyles() {
|
|
31
|
-
|
|
31
|
+
const chartClass = this.constructor;
|
|
32
|
+
if (chartClass.tooltipStylesInjected) {
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
34
35
|
const styleId = 'apollo-data-line-tooltip-styles';
|
|
35
36
|
if (document.getElementById(styleId)) {
|
|
36
|
-
|
|
37
|
+
chartClass.tooltipStylesInjected = true;
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
39
40
|
const style = document.createElement('style');
|
|
@@ -82,16 +83,17 @@ export class ApolloDataLineChart extends ApolloBase {
|
|
|
82
83
|
}
|
|
83
84
|
`;
|
|
84
85
|
document.head.appendChild(style);
|
|
85
|
-
|
|
86
|
+
chartClass.tooltipStylesInjected = true;
|
|
86
87
|
}
|
|
87
88
|
// @ts-ignore
|
|
88
89
|
async getViewData(data, spec) {
|
|
90
|
+
const componentTag = this.el?.tagName?.toLowerCase() ?? 'apollo-data-line-chart';
|
|
89
91
|
if (!spec) {
|
|
90
|
-
throw new Error(
|
|
92
|
+
throw new Error(`adSpec is required for ${componentTag}`);
|
|
91
93
|
}
|
|
92
94
|
const { tooltipPrefix = '', currencySymbol = '' } = spec;
|
|
93
95
|
if (!data || data.length === 0) {
|
|
94
|
-
throw new Error(
|
|
96
|
+
throw new Error(`Data is required for ${componentTag}`);
|
|
95
97
|
}
|
|
96
98
|
const uniqueCategories = Array.from(new Set(data.map(item => item.category)));
|
|
97
99
|
const uniqueXValues = [...new Set(data.map(item => item.xValue))].sort((a, b) => a - b);
|
|
@@ -282,7 +284,7 @@ export class ApolloDataLineChart extends ApolloBase {
|
|
|
282
284
|
};
|
|
283
285
|
}
|
|
284
286
|
render() {
|
|
285
|
-
return (h(Host, { key: '
|
|
287
|
+
return (h(Host, { key: 'fd64f4abb624b14a878808b23345910c9b23a72c' }, h("div", { key: 'aeda5086730862ca1368a0374caf2d918969839d', id: "container", style: { width: '100%', height: '100%' } })));
|
|
286
288
|
}
|
|
287
289
|
static get is() { return "apollo-data-line-chart"; }
|
|
288
290
|
static get encapsulation() { return "shadow"; }
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { html } from "lit-html";
|
|
2
|
+
import { lineExamples } from "../../examples/apollo-data-line.examples";
|
|
3
|
+
import { generateReactCode, generateVueCode, generateWebComponentCode, generateInstallationDocs } from "../../utils/code-generator";
|
|
4
|
+
function getCodeForFramework(props, framework) {
|
|
5
|
+
switch (framework) {
|
|
6
|
+
case 'vue':
|
|
7
|
+
return generateVueCode('apollo-data-line-chart', props);
|
|
8
|
+
case 'webcomponent':
|
|
9
|
+
return generateWebComponentCode('apollo-data-line-chart', props);
|
|
10
|
+
case 'react':
|
|
11
|
+
default:
|
|
12
|
+
return generateReactCode('apollo-data-line-chart', props);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const meta = {
|
|
16
|
+
title: 'Apollo Data/Line Chart',
|
|
17
|
+
tags: ['autodocs'],
|
|
18
|
+
argTypes: {
|
|
19
|
+
adData: {
|
|
20
|
+
control: 'object',
|
|
21
|
+
description: 'Array of data items. Each item has category, xValue, yValue, and optional xLabel/yLabel. When labels are omitted, numeric values are shown on axes and tooltip.',
|
|
22
|
+
table: {
|
|
23
|
+
type: {
|
|
24
|
+
summary: 'LineDataItem[]',
|
|
25
|
+
detail: 'interface LineDataItem {\n category: string;\n xValue: number;\n yValue: number;\n xLabel?: string;\n yLabel?: string;\n}',
|
|
26
|
+
},
|
|
27
|
+
defaultValue: { summary: '[]' },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
adSpec: {
|
|
31
|
+
control: 'object',
|
|
32
|
+
description: 'Specification object for customizing the chart appearance.',
|
|
33
|
+
table: {
|
|
34
|
+
type: {
|
|
35
|
+
summary: 'LineSpec',
|
|
36
|
+
detail: 'interface LineSpec {\n colorSet?: string[];\n tooltipPrefix?: string;\n currencySymbol?: string;\n yAxisTitle?: string;\n xAxisTitle?: string;\n pointStyle?: LinePointStyle;\n lineStyle?: LineLineStyle;\n}',
|
|
37
|
+
},
|
|
38
|
+
defaultValue: { summary: '{}' },
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
decorators: [
|
|
43
|
+
(story, context) => {
|
|
44
|
+
const framework = context.globals?.framework || 'react';
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
const doc = globalThis.document;
|
|
47
|
+
if (doc) {
|
|
48
|
+
const installSections = {
|
|
49
|
+
react: doc.querySelector('.install-react'),
|
|
50
|
+
vue: doc.querySelector('.install-vue'),
|
|
51
|
+
webcomponent: doc.querySelector('.install-webcomponent'),
|
|
52
|
+
};
|
|
53
|
+
Object.values(installSections).forEach((section) => {
|
|
54
|
+
if (section)
|
|
55
|
+
section.setAttribute('style', 'display: none;');
|
|
56
|
+
});
|
|
57
|
+
const selectedSection = installSections[framework];
|
|
58
|
+
if (selectedSection)
|
|
59
|
+
selectedSection.setAttribute('style', 'display: block;');
|
|
60
|
+
}
|
|
61
|
+
}, 0);
|
|
62
|
+
return story();
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
parameters: {
|
|
66
|
+
docs: {
|
|
67
|
+
description: {
|
|
68
|
+
component: `${generateInstallationDocs('react', 'apollo-data-line-chart')}
|
|
69
|
+
|
|
70
|
+
${generateInstallationDocs('vue', 'apollo-data-line-chart')}
|
|
71
|
+
|
|
72
|
+
${generateInstallationDocs('webcomponent', 'apollo-data-line-chart')}
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Description
|
|
77
|
+
|
|
78
|
+
A multi-series line chart component built with Vega. Each data item has \`category\` (one line per category), \`xValue\` and \`yValue\` (numeric axes), and optional \`xLabel\`/\`yLabel\` for display; when labels are omitted, numeric values are shown. Use \`adSpec.xAxisTitle\`, \`adSpec.yAxisTitle\`, \`adSpec.pointStyle\`, and \`adSpec.lineStyle\` (\`'solid' | 'dashed' | 'dotted'\`) to customize the chart. The example uses the monthly sales by product preset from \`lineExamples\`.
|
|
79
|
+
|
|
80
|
+
**Tip:** Use the Framework selector in the toolbar to switch between React, Vue, and Web Component installation and code examples.`,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
viewMode: 'story',
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
export default meta;
|
|
87
|
+
const chartWrapper = (args) => html `
|
|
88
|
+
<div style="width: 800px; height: 400px;">
|
|
89
|
+
<apollo-data-line-chart .adData=${args.adData} .adSpec=${args.adSpec}></apollo-data-line-chart>
|
|
90
|
+
</div>
|
|
91
|
+
`;
|
|
92
|
+
export const MonthlySalesByProduct = {
|
|
93
|
+
args: {
|
|
94
|
+
adData: lineExamples[1].props.adData,
|
|
95
|
+
adSpec: lineExamples[1].props.adSpec ?? {},
|
|
96
|
+
},
|
|
97
|
+
render: args => chartWrapper(args),
|
|
98
|
+
parameters: {
|
|
99
|
+
codeGenerator: (args, framework) => getCodeForFramework({ adData: args.adData ?? lineExamples[1].props.adData, adSpec: args.adSpec ?? lineExamples[1].props.adSpec ?? {} }, framework),
|
|
100
|
+
docs: {
|
|
101
|
+
description: { story: lineExamples[1].description },
|
|
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 ?? lineExamples[1].props.adData,
|
|
110
|
+
adSpec: storyContext?.args?.adSpec ?? lineExamples[1].props.adSpec ?? {},
|
|
111
|
+
};
|
|
112
|
+
return getCodeForFramework(props, framework);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.error('Error in transform function:', error);
|
|
116
|
+
return `<apollo-data-line-chart />`;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
};
|
|
@@ -235,7 +235,7 @@ export class ApolloDataScatterChart extends ApolloBase {
|
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
render() {
|
|
238
|
-
return (h(Host, { key: '
|
|
238
|
+
return (h(Host, { key: 'f6c1e8d9e9a6ba41dbbf8c2c5737895b96b0915d' }, h("div", { key: '2aeba82bc31c5995a3d5b532c339f5b45ae850f7', id: "container", style: { width: '100%', height: '100%' } })));
|
|
239
239
|
}
|
|
240
240
|
static get is() { return "apollo-data-scatter-chart"; }
|
|
241
241
|
static get encapsulation() { return "shadow"; }
|