@openremote/or-chart 1.3.0-snapshot.20250117163129 → 1.3.0-snapshot.20250117163435
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/component.stories.js +130 -0
- package/dist/umd/index.orbundle.js +3 -3
- package/package.json +9 -9
- package/README.md +0 -31
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { getWcStorybookHelpers } from "wc-storybook-helpers";
|
|
2
|
+
import {OrChart} from "@openremote/or-chart";
|
|
3
|
+
import "@openremote/or-chart";
|
|
4
|
+
import { html } from 'lit';
|
|
5
|
+
|
|
6
|
+
const { events, args, argTypes, template } = getWcStorybookHelpers("or-chart");
|
|
7
|
+
|
|
8
|
+
/** @type { import('@storybook/web-components').Meta } */
|
|
9
|
+
const meta = {
|
|
10
|
+
title: "Playground/or-chart",
|
|
11
|
+
component: "or-chart",
|
|
12
|
+
args,
|
|
13
|
+
argTypes: {
|
|
14
|
+
...argTypes,
|
|
15
|
+
datapointQuery: {
|
|
16
|
+
control: {
|
|
17
|
+
type: "object"
|
|
18
|
+
},
|
|
19
|
+
description: "Query object to get data"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
parameters: {
|
|
23
|
+
actions: {
|
|
24
|
+
handles: events
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** @type { import('@storybook/web-components').StoryObj } */
|
|
30
|
+
export const Primary = {
|
|
31
|
+
args: {
|
|
32
|
+
dataProvider: async () => ([{
|
|
33
|
+
data: [
|
|
34
|
+
{x: new Date(Date.now() - 60000 * 60).getTime(), y: 5},
|
|
35
|
+
{x: new Date(Date.now() - 50000 * 60).getTime(), y: 8},
|
|
36
|
+
{x: new Date(Date.now() - 40000 * 60).getTime(), y: 3},
|
|
37
|
+
{x: new Date(Date.now() - 30000 * 60).getTime(), y: 4},
|
|
38
|
+
{x: new Date(Date.now() - 20000 * 60).getTime(), y: 10},
|
|
39
|
+
{x: new Date(Date.now() - 10000 * 60).getTime(), y: 2},
|
|
40
|
+
{x: new Date().getTime(), y: 4}
|
|
41
|
+
]
|
|
42
|
+
}])
|
|
43
|
+
},
|
|
44
|
+
loaders: [
|
|
45
|
+
async (args) => ({
|
|
46
|
+
orChart: await loadOrChart(args.allArgs)
|
|
47
|
+
})
|
|
48
|
+
],
|
|
49
|
+
parameters: {
|
|
50
|
+
docs: {
|
|
51
|
+
source: {
|
|
52
|
+
code: getExampleCode(),
|
|
53
|
+
/*transform: (code: string, storyContext: StoryContext) => {
|
|
54
|
+
return code;
|
|
55
|
+
}*/
|
|
56
|
+
},
|
|
57
|
+
story: {
|
|
58
|
+
height: "370px"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
render: (args, { loaded: { orChart }}) => html`${orChart}`
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/* ------------------------------------------------------- */
|
|
66
|
+
/* UTILITY FUNCTIONS */
|
|
67
|
+
/* ------------------------------------------------------- */
|
|
68
|
+
|
|
69
|
+
function getExampleCode() {
|
|
70
|
+
|
|
71
|
+
//language=javascript
|
|
72
|
+
return `
|
|
73
|
+
import "@openremote/or-chart";
|
|
74
|
+
|
|
75
|
+
// If using Lit; you can use the dataProvider attribute to manually insert data;
|
|
76
|
+
const dataProvider = async () => ([{
|
|
77
|
+
data: [
|
|
78
|
+
{x: new Date(Date.now() - 10000).getTime(), y: 2},
|
|
79
|
+
{x: new Date().getTime(), y: 4}
|
|
80
|
+
]
|
|
81
|
+
}])
|
|
82
|
+
|
|
83
|
+
// ----
|
|
84
|
+
// OR you can insert (already fetched) assets
|
|
85
|
+
const assets = [];
|
|
86
|
+
|
|
87
|
+
// And, specify what attributes of these assets to include in the chart.
|
|
88
|
+
// It uses the 'index within the assets array' and the attribute object.
|
|
89
|
+
const assetAttributes = [
|
|
90
|
+
[0, {name: "temperature", type: "positiveInteger"}],
|
|
91
|
+
[0, {name: "humidity", type: "positiveInteger"}],
|
|
92
|
+
[1, {name: "temperature", type: "positiveInteger"}],
|
|
93
|
+
[1, {name: "humidity", type: "positiveInteger"}]
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
// And use the datapointQuery attribute to specify what asset data to fetch
|
|
97
|
+
const datapointQuery = {
|
|
98
|
+
type: "lttb", // algorithm to apply
|
|
99
|
+
fromTimestamp: new Date(Date.now() - 10000).getTime(),
|
|
100
|
+
toTimestamp: new Date().getTime(),
|
|
101
|
+
amountOfPoints: 100
|
|
102
|
+
}
|
|
103
|
+
// -----
|
|
104
|
+
|
|
105
|
+
// in your HTML code use this, and inject them like this;
|
|
106
|
+
<or-chart dataProvider="{dataProvider}"></or-chart>
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
// (IF NOT USING LIT; you should parse the objects to JSON strings)
|
|
110
|
+
// const datapointQueryStr = JSON.stringify(datapointQuery);
|
|
111
|
+
// const assetsStr = JSON.stringify(assets);
|
|
112
|
+
// const assetAttributesStr = JSON.stringify(assetAttributes);
|
|
113
|
+
|
|
114
|
+
// ... and inject the JSON like this
|
|
115
|
+
// <or-chart assets="assetsStr" assetAttributes="assetAttributeStr" datapointQuery="datapointQuery" />
|
|
116
|
+
`
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function loadOrChart(args) {
|
|
120
|
+
|
|
121
|
+
const newArgs = Object.fromEntries(Object.entries(args).filter(([key, value]) => (
|
|
122
|
+
value != null && String(value).length > 0
|
|
123
|
+
)));
|
|
124
|
+
|
|
125
|
+
const orChart = Object.assign(new OrChart(), newArgs);
|
|
126
|
+
|
|
127
|
+
return orChart;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export default meta;
|