@xyo-network/react-price-forecast-plugin 2.78.10 → 2.79.0
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/dist/browser/components/DetailsBox.d.cts +1 -0
- package/dist/browser/components/DetailsBox.d.cts.map +1 -1
- package/dist/browser/components/DetailsBox.d.mts +1 -0
- package/dist/browser/components/DetailsBox.d.mts.map +1 -1
- package/dist/browser/components/DetailsBox.d.ts +1 -0
- package/dist/browser/components/DetailsBox.d.ts.map +1 -1
- package/dist/browser/components/index.d.cts +1 -1
- package/dist/browser/components/index.d.cts.map +1 -1
- package/dist/browser/components/index.d.mts +1 -1
- package/dist/browser/components/index.d.mts.map +1 -1
- package/dist/browser/components/index.d.ts +1 -1
- package/dist/browser/components/index.d.ts.map +1 -1
- package/dist/browser/index.cjs +107 -42
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +2 -2
- package/dist/browser/index.d.mts +2 -2
- package/dist/browser/index.d.ts +2 -2
- package/dist/browser/{index.js → index.mjs} +101 -54
- package/dist/browser/index.mjs.map +1 -0
- package/dist/browser/lib/ForecastLineChartConfigBuilder.d.cts.map +1 -1
- package/dist/browser/lib/ForecastLineChartConfigBuilder.d.mts.map +1 -1
- package/dist/browser/lib/ForecastLineChartConfigBuilder.d.ts.map +1 -1
- package/dist/browser/lib/index.d.cts +3 -3
- package/dist/browser/lib/index.d.mts +3 -3
- package/dist/browser/lib/index.d.ts +3 -3
- package/dist/neutral/components/DetailsBox.d.cts +1 -0
- package/dist/neutral/components/DetailsBox.d.cts.map +1 -1
- package/dist/neutral/components/DetailsBox.d.mts +1 -0
- package/dist/neutral/components/DetailsBox.d.mts.map +1 -1
- package/dist/neutral/components/DetailsBox.d.ts +1 -0
- package/dist/neutral/components/DetailsBox.d.ts.map +1 -1
- package/dist/neutral/components/index.d.cts +1 -1
- package/dist/neutral/components/index.d.cts.map +1 -1
- package/dist/neutral/components/index.d.mts +1 -1
- package/dist/neutral/components/index.d.mts.map +1 -1
- package/dist/neutral/components/index.d.ts +1 -1
- package/dist/neutral/components/index.d.ts.map +1 -1
- package/dist/neutral/index.cjs +107 -42
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.d.cts +2 -2
- package/dist/neutral/index.d.mts +2 -2
- package/dist/neutral/index.d.ts +2 -2
- package/dist/neutral/{index.js → index.mjs} +101 -54
- package/dist/neutral/index.mjs.map +1 -0
- package/dist/neutral/lib/ForecastLineChartConfigBuilder.d.cts.map +1 -1
- package/dist/neutral/lib/ForecastLineChartConfigBuilder.d.mts.map +1 -1
- package/dist/neutral/lib/ForecastLineChartConfigBuilder.d.ts.map +1 -1
- package/dist/neutral/lib/index.d.cts +3 -3
- package/dist/neutral/lib/index.d.mts +3 -3
- package/dist/neutral/lib/index.d.ts +3 -3
- package/dist/node/components/DetailsBox.d.cts +1 -0
- package/dist/node/components/DetailsBox.d.cts.map +1 -1
- package/dist/node/components/DetailsBox.d.mts +1 -0
- package/dist/node/components/DetailsBox.d.mts.map +1 -1
- package/dist/node/components/DetailsBox.d.ts +1 -0
- package/dist/node/components/DetailsBox.d.ts.map +1 -1
- package/dist/node/components/index.d.cts +1 -1
- package/dist/node/components/index.d.cts.map +1 -1
- package/dist/node/components/index.d.mts +1 -1
- package/dist/node/components/index.d.mts.map +1 -1
- package/dist/node/components/index.d.ts +1 -1
- package/dist/node/components/index.d.ts.map +1 -1
- package/dist/node/index.cjs +107 -44
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +2 -2
- package/dist/node/index.d.mts +2 -2
- package/dist/node/index.d.ts +2 -2
- package/dist/node/{index.js → index.mjs} +101 -56
- package/dist/node/index.mjs.map +1 -0
- package/dist/node/lib/ForecastLineChartConfigBuilder.d.cts.map +1 -1
- package/dist/node/lib/ForecastLineChartConfigBuilder.d.mts.map +1 -1
- package/dist/node/lib/ForecastLineChartConfigBuilder.d.ts.map +1 -1
- package/dist/node/lib/index.d.cts +3 -3
- package/dist/node/lib/index.d.mts +3 -3
- package/dist/node/lib/index.d.ts +3 -3
- package/package.json +14 -14
- package/src/Plugin.ts +1 -1
- package/src/components/DetailsBox.stories.tsx +10 -7
- package/src/components/DetailsBox.tsx +6 -6
- package/src/components/index.ts +1 -1
- package/src/index.ts +2 -2
- package/src/lib/ForecastLineChartConfigBuilder.ts +5 -4
- package/src/lib/SourcePayloads.ts +1 -1
- package/src/lib/index.ts +3 -3
- package/dist/browser/index.js.map +0 -1
- package/dist/neutral/index.js.map +0 -1
- package/dist/node/index.js.map +0 -1
|
@@ -1,65 +1,80 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
1
4
|
// src/components/DetailsBox.tsx
|
|
2
5
|
import "chartjs-adapter-luxon";
|
|
3
6
|
import { useTheme } from "@mui/material";
|
|
4
7
|
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
5
8
|
import { FlexCol } from "@xylabs/react-flexbox";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
Chart as ChartJS,
|
|
9
|
-
Legend,
|
|
10
|
-
LinearScale,
|
|
11
|
-
LineElement,
|
|
12
|
-
PointElement,
|
|
13
|
-
TimeScale,
|
|
14
|
-
Title,
|
|
15
|
-
Tooltip
|
|
16
|
-
} from "chart.js";
|
|
17
|
-
import { useState } from "react";
|
|
9
|
+
import { CategoryScale, Chart as ChartJS, Legend, LinearScale, LineElement, PointElement, TimeScale, Title, Tooltip } from "chart.js";
|
|
10
|
+
import React, { useState } from "react";
|
|
18
11
|
import { Line } from "react-chartjs-2";
|
|
19
12
|
|
|
20
13
|
// src/lib/DataLineStyles.ts
|
|
21
14
|
import { alpha } from "@mui/material";
|
|
22
|
-
var DataLineStyles = (color) => ({
|
|
15
|
+
var DataLineStyles = /* @__PURE__ */ __name((color) => ({
|
|
23
16
|
backgroundColor: color ? alpha(color, 0.5) : void 0,
|
|
24
17
|
borderColor: color
|
|
25
|
-
});
|
|
18
|
+
}), "DataLineStyles");
|
|
26
19
|
|
|
27
20
|
// src/lib/DataPointStyles.ts
|
|
28
|
-
var DataPointStyles = (pointHoverBackgroundColor) => ({
|
|
21
|
+
var DataPointStyles = /* @__PURE__ */ __name((pointHoverBackgroundColor) => ({
|
|
29
22
|
pointHitRadius: 20,
|
|
30
23
|
pointHoverBackgroundColor,
|
|
31
24
|
pointHoverRadius: 10,
|
|
32
25
|
pointRadius: 5,
|
|
33
26
|
pointStyle: "circle"
|
|
34
|
-
});
|
|
27
|
+
}), "DataPointStyles");
|
|
35
28
|
|
|
36
29
|
// src/lib/MockSourcePayloads.ts
|
|
37
|
-
var MockSourcePayloads = () => {
|
|
30
|
+
var MockSourcePayloads = /* @__PURE__ */ __name(() => {
|
|
38
31
|
const tenMin = 6e5;
|
|
39
32
|
return [
|
|
40
33
|
{
|
|
41
34
|
baseFee: 38.90155387825,
|
|
42
|
-
feePerGas: {
|
|
43
|
-
|
|
35
|
+
feePerGas: {
|
|
36
|
+
high: 47.9945864396,
|
|
37
|
+
low: 39.006868093,
|
|
38
|
+
medium: 39.306868093,
|
|
39
|
+
veryHigh: 44.45384380525
|
|
40
|
+
},
|
|
41
|
+
priorityFeePerGas: {
|
|
42
|
+
high: 1.0266666666666666,
|
|
43
|
+
low: -0.41000000000000003,
|
|
44
|
+
medium: 0.38,
|
|
45
|
+
veryHigh: 1.3900000000000001
|
|
46
|
+
},
|
|
44
47
|
schema: "network.xyo.blockchain.ethereum.gas",
|
|
45
48
|
timestamp: Date.now() - tenMin
|
|
46
49
|
},
|
|
47
50
|
{
|
|
48
51
|
baseFee: 38.90155387825,
|
|
49
|
-
feePerGas: {
|
|
50
|
-
|
|
52
|
+
feePerGas: {
|
|
53
|
+
high: 47.9945864396,
|
|
54
|
+
low: 39.006868093,
|
|
55
|
+
medium: 100,
|
|
56
|
+
veryHigh: 44.45384380525
|
|
57
|
+
},
|
|
58
|
+
priorityFeePerGas: {
|
|
59
|
+
high: 1.0266666666666666,
|
|
60
|
+
low: -0.41000000000000003,
|
|
61
|
+
medium: 0.38,
|
|
62
|
+
veryHigh: 1.3900000000000001
|
|
63
|
+
},
|
|
51
64
|
schema: "network.xyo.blockchain.ethereum.gas",
|
|
52
65
|
timestamp: Date.now()
|
|
53
66
|
}
|
|
54
67
|
];
|
|
55
|
-
};
|
|
68
|
+
}, "MockSourcePayloads");
|
|
56
69
|
|
|
57
70
|
// src/lib/SourcePayloads.ts
|
|
58
|
-
var
|
|
71
|
+
var _SourcePayloads = class _SourcePayloads {
|
|
72
|
+
sourcePayloads;
|
|
73
|
+
sourcePrices;
|
|
59
74
|
constructor(sourcePayloads) {
|
|
60
75
|
this.sourcePayloads = sourcePayloads;
|
|
76
|
+
this.sourcePrices = [];
|
|
61
77
|
}
|
|
62
|
-
sourcePrices = [];
|
|
63
78
|
get payloads() {
|
|
64
79
|
return this.sourcePayloads;
|
|
65
80
|
}
|
|
@@ -68,7 +83,10 @@ var SourcePayloads = class {
|
|
|
68
83
|
const instance = new this(sourcePayloads);
|
|
69
84
|
const paths = jsonPath.split(".");
|
|
70
85
|
instance.sourcePrices = sourcePayloads.map((payload) => {
|
|
71
|
-
return {
|
|
86
|
+
return {
|
|
87
|
+
x: payload.timestamp,
|
|
88
|
+
y: instance.jsonPathTraverser(payload, paths)
|
|
89
|
+
};
|
|
72
90
|
});
|
|
73
91
|
return instance;
|
|
74
92
|
}
|
|
@@ -91,26 +109,31 @@ var SourcePayloads = class {
|
|
|
91
109
|
return result;
|
|
92
110
|
}
|
|
93
111
|
};
|
|
112
|
+
__name(_SourcePayloads, "SourcePayloads");
|
|
113
|
+
var SourcePayloads = _SourcePayloads;
|
|
94
114
|
|
|
95
115
|
// src/lib/ForecastLineChartConfigBuilder.ts
|
|
96
|
-
var defaultOptions = () => ({
|
|
116
|
+
var defaultOptions = /* @__PURE__ */ __name(() => ({
|
|
97
117
|
plugins: {
|
|
98
118
|
legend: {
|
|
99
119
|
position: "top"
|
|
100
120
|
}
|
|
101
121
|
},
|
|
102
122
|
responsive: true
|
|
103
|
-
});
|
|
104
|
-
var
|
|
123
|
+
}), "defaultOptions");
|
|
124
|
+
var _ForecastLineChartConfigBuilder = class _ForecastLineChartConfigBuilder {
|
|
125
|
+
payload;
|
|
126
|
+
data;
|
|
127
|
+
options;
|
|
128
|
+
themeColors;
|
|
105
129
|
constructor(theme, payload) {
|
|
106
130
|
this.payload = payload;
|
|
131
|
+
this.data = {
|
|
132
|
+
datasets: []
|
|
133
|
+
};
|
|
134
|
+
this.options = defaultOptions();
|
|
107
135
|
this.themeColors = this.parseTheme(theme);
|
|
108
136
|
}
|
|
109
|
-
data = {
|
|
110
|
-
datasets: []
|
|
111
|
-
};
|
|
112
|
-
options = defaultOptions();
|
|
113
|
-
themeColors;
|
|
114
137
|
get forecastPayload() {
|
|
115
138
|
if (this.payload) {
|
|
116
139
|
return this.payload;
|
|
@@ -131,7 +154,9 @@ var ForecastLineChartConfigBuilder = class _ForecastLineChartConfigBuilder {
|
|
|
131
154
|
}
|
|
132
155
|
async buildData(includeSources) {
|
|
133
156
|
const forecastData = this.generateDataSetForecastData();
|
|
134
|
-
const datasets = [
|
|
157
|
+
const datasets = [
|
|
158
|
+
forecastData
|
|
159
|
+
];
|
|
135
160
|
if (includeSources) {
|
|
136
161
|
const sourceData = await this.generateDataSetSourcePayloads();
|
|
137
162
|
datasets.unshift(sourceData);
|
|
@@ -152,8 +177,12 @@ var ForecastLineChartConfigBuilder = class _ForecastLineChartConfigBuilder {
|
|
|
152
177
|
return this;
|
|
153
178
|
}
|
|
154
179
|
refreshValues() {
|
|
155
|
-
this.data = {
|
|
156
|
-
|
|
180
|
+
this.data = {
|
|
181
|
+
...this.data
|
|
182
|
+
};
|
|
183
|
+
this.options = {
|
|
184
|
+
...this.options
|
|
185
|
+
};
|
|
157
186
|
}
|
|
158
187
|
generateLegend() {
|
|
159
188
|
return {
|
|
@@ -200,9 +229,14 @@ var ForecastLineChartConfigBuilder = class _ForecastLineChartConfigBuilder {
|
|
|
200
229
|
generateDataSetForecastData() {
|
|
201
230
|
var _a, _b;
|
|
202
231
|
return {
|
|
203
|
-
borderDash: [
|
|
232
|
+
borderDash: [
|
|
233
|
+
5
|
|
234
|
+
],
|
|
204
235
|
borderDashOffset: 0.5,
|
|
205
|
-
data: this.forecastPayload.values.map((price) => ({
|
|
236
|
+
data: this.forecastPayload.values.map((price) => ({
|
|
237
|
+
x: price.timestamp ?? 0,
|
|
238
|
+
y: price.value
|
|
239
|
+
})),
|
|
206
240
|
label: "Forecast Price",
|
|
207
241
|
...DataPointStyles((_a = this.themeColors) == null ? void 0 : _a.dataSetColorPrimary),
|
|
208
242
|
...DataLineStyles((_b = this.themeColors) == null ? void 0 : _b.dataSetColorPrimary)
|
|
@@ -219,34 +253,45 @@ var ForecastLineChartConfigBuilder = class _ForecastLineChartConfigBuilder {
|
|
|
219
253
|
};
|
|
220
254
|
}
|
|
221
255
|
};
|
|
256
|
+
__name(_ForecastLineChartConfigBuilder, "ForecastLineChartConfigBuilder");
|
|
257
|
+
var ForecastLineChartConfigBuilder = _ForecastLineChartConfigBuilder;
|
|
222
258
|
|
|
223
259
|
// src/components/DetailsBox.tsx
|
|
224
|
-
import { jsx } from "react/jsx-runtime";
|
|
225
260
|
ChartJS.register(CategoryScale, TimeScale, PointElement, LineElement, LinearScale, Title, Tooltip, Legend);
|
|
226
|
-
var PriceForecastDetailsBox = ({ payload, ...props }) => {
|
|
261
|
+
var PriceForecastDetailsBox = /* @__PURE__ */ __name(({ payload, ...props }) => {
|
|
227
262
|
const priceForecastPayload = payload;
|
|
228
263
|
const theme = useTheme();
|
|
229
|
-
const [data, setData] = useState({
|
|
264
|
+
const [data, setData] = useState({
|
|
265
|
+
datasets: []
|
|
266
|
+
});
|
|
230
267
|
const [options, setOptions] = useState({});
|
|
231
|
-
useAsyncEffect(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
268
|
+
useAsyncEffect(async (mounted) => {
|
|
269
|
+
const { data: data2, options: options2 } = await ForecastLineChartConfigBuilder.create(theme, priceForecastPayload, {
|
|
270
|
+
fetch: true
|
|
271
|
+
});
|
|
272
|
+
if (mounted()) {
|
|
273
|
+
setData(data2);
|
|
274
|
+
setOptions(options2);
|
|
275
|
+
}
|
|
276
|
+
}, [
|
|
277
|
+
priceForecastPayload,
|
|
278
|
+
theme
|
|
279
|
+
]);
|
|
280
|
+
return /* @__PURE__ */ React.createElement(FlexCol, {
|
|
281
|
+
...props,
|
|
282
|
+
busy: priceForecastPayload === void 0,
|
|
283
|
+
minHeight: "25vh"
|
|
284
|
+
}, priceForecastPayload ? /* @__PURE__ */ React.createElement(Line, {
|
|
285
|
+
options,
|
|
286
|
+
data
|
|
287
|
+
}) : null);
|
|
288
|
+
}, "PriceForecastDetailsBox");
|
|
244
289
|
|
|
245
290
|
// src/Plugin.ts
|
|
246
291
|
import { createPayloadRenderPlugin } from "@xyo-network/react-payload-plugin";
|
|
247
292
|
var PriceForecastRenderPlugin = {
|
|
248
293
|
...createPayloadRenderPlugin({
|
|
249
|
-
canRender: () => true,
|
|
294
|
+
canRender: /* @__PURE__ */ __name(() => true, "canRender"),
|
|
250
295
|
components: {
|
|
251
296
|
box: {
|
|
252
297
|
detailsBox: PriceForecastDetailsBox
|
|
@@ -259,4 +304,4 @@ export {
|
|
|
259
304
|
PriceForecastDetailsBox,
|
|
260
305
|
PriceForecastRenderPlugin
|
|
261
306
|
};
|
|
262
|
-
//# sourceMappingURL=index.
|
|
307
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/DetailsBox.tsx","../../src/lib/DataLineStyles.ts","../../src/lib/DataPointStyles.ts","../../src/lib/MockSourcePayloads.ts","../../src/lib/SourcePayloads.ts","../../src/lib/ForecastLineChartConfigBuilder.ts","../../src/Plugin.ts"],"sourcesContent":["import 'chartjs-adapter-luxon'\n\nimport { useTheme } from '@mui/material'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { FlexBoxProps, FlexCol } from '@xylabs/react-flexbox'\nimport { ForecastPayload } from '@xyo-network/diviner-forecasting-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n CategoryScale,\n Chart as ChartJS,\n ChartData,\n ChartOptions,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n TimeScale,\n Title,\n Tooltip,\n} from 'chart.js'\nimport React, { useState } from 'react'\nimport { Line } from 'react-chartjs-2'\n\nimport { ForecastLineChartConfigBuilder } from '../lib/index.ts'\n\nChartJS.register(CategoryScale, TimeScale, PointElement, LineElement, LinearScale, Title, Tooltip, Legend)\n\nexport interface PriceForecastDetailsBoxProps extends FlexBoxProps {\n payload?: Payload\n}\n\nexport const PriceForecastDetailsBox: React.FC<PriceForecastDetailsBoxProps> = ({ payload, ...props }) => {\n const priceForecastPayload = payload as ForecastPayload | undefined\n const theme = useTheme()\n const [data, setData] = useState<ChartData<'line'>>({ datasets: [] })\n const [options, setOptions] = useState<ChartOptions<'line'>>({})\n\n useAsyncEffect(\n\n async (mounted) => {\n const { data, options } = await ForecastLineChartConfigBuilder.create(theme, priceForecastPayload, { fetch: true })\n if (mounted()) {\n setData(data)\n setOptions(options)\n }\n },\n [priceForecastPayload, theme],\n )\n\n return (\n <FlexCol {...props} busy={priceForecastPayload === undefined} minHeight=\"25vh\">\n {priceForecastPayload\n ? <Line options={options} data={data} />\n : null}\n </FlexCol>\n )\n}\n","import { alpha } from '@mui/material'\n\nexport const DataLineStyles = (color?: string) => ({\n backgroundColor: color ? alpha(color, 0.5) : undefined,\n borderColor: color,\n})\n","export const DataPointStyles = (pointHoverBackgroundColor?: string) => ({\n pointHitRadius: 20,\n pointHoverBackgroundColor,\n pointHoverRadius: 10,\n pointRadius: 5,\n pointStyle: 'circle',\n})\n","export const MockSourcePayloads = () => {\n const tenMin = 600_000\n return [\n {\n baseFee: 38.901_553_878_25,\n feePerGas: { high: 47.994_586_439_6, low: 39.006_868_093, medium: 39.306_868_093, veryHigh: 44.453_843_805_25 },\n priorityFeePerGas: { high: 1.026_666_666_666_666_6, low: -0.410_000_000_000_000_03, medium: 0.38, veryHigh: 1.390_000_000_000_000_1 },\n schema: 'network.xyo.blockchain.ethereum.gas',\n timestamp: Date.now() - tenMin,\n },\n {\n baseFee: 38.901_553_878_25,\n feePerGas: { high: 47.994_586_439_6, low: 39.006_868_093, medium: 100, veryHigh: 44.453_843_805_25 },\n priorityFeePerGas: { high: 1.026_666_666_666_666_6, low: -0.410_000_000_000_000_03, medium: 0.38, veryHigh: 1.390_000_000_000_000_1 },\n schema: 'network.xyo.blockchain.ethereum.gas',\n timestamp: Date.now(),\n },\n ]\n}\n","import { Payload } from '@xyo-network/payload-model'\nimport { Point } from 'chart.js'\n\nimport { MockSourcePayloads } from './MockSourcePayloads.ts'\n\nexport class SourcePayloads {\n sourcePrices: Point[] = []\n\n constructor(public sourcePayloads: Payload[]) {}\n\n get payloads() {\n return this.sourcePayloads\n }\n\n static async build(jsonPath: string) {\n const sourcePayloads = await this.fetchSourcePayloads()\n const instance = new this(sourcePayloads)\n\n const paths = jsonPath.split('.')\n instance.sourcePrices = sourcePayloads.map((payload) => {\n return { x: payload.timestamp, y: instance.jsonPathTraverser(payload, paths) }\n })\n return instance\n }\n\n // TODO - fetch from archivist\n static async fetchSourcePayloads() {\n const payloads = await Promise.resolve(MockSourcePayloads())\n return payloads\n }\n\n jsonPathTraverser(obj: Payload, path: string[]) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let result: any = obj\n for (const key of path) {\n if (key in result) {\n const foundKey = key as keyof typeof result\n result = result[foundKey]\n } else {\n result = undefined\n break\n }\n }\n\n return result\n }\n}\n","import { Theme } from '@mui/material'\nimport { ForecastPayload } from '@xyo-network/diviner-forecasting-model'\nimport { ChartData, ChartDataset, ChartOptions, LegendOptions, Point, ScaleChartOptions } from 'chart.js'\n\nimport { DataLineStyles } from './DataLineStyles.ts'\nimport { DataPointStyles } from './DataPointStyles.ts'\nimport { SourcePayloads } from './SourcePayloads.ts'\n\ninterface SourcePayloadConfig {\n fetch: boolean\n sampleSize?: number\n}\n\ninterface ThemeColors {\n dataSetColorPrimary: string\n dataSetColorSecondary: string\n gridColor: string\n}\n\nconst defaultOptions: () => ChartOptions<'line'> = () => ({\n plugins: {\n legend: {\n position: 'top' as const,\n },\n },\n responsive: true,\n})\n\nexport class ForecastLineChartConfigBuilder {\n data: ChartData<'line'> = {\n datasets: [],\n }\n\n options: ChartOptions<'line'> = defaultOptions()\n themeColors: ThemeColors | undefined\n\n constructor(\n theme: Theme,\n private payload?: ForecastPayload,\n ) {\n this.themeColors = this.parseTheme(theme)\n }\n\n get forecastPayload() {\n if (this.payload) {\n return this.payload\n } else {\n throw new Error('ForecastPayload was not defined')\n }\n }\n\n static async create(theme: Theme, payload?: ForecastPayload, sourcePayloadConfig?: SourcePayloadConfig) {\n const instance = new ForecastLineChartConfigBuilder(theme, payload)\n\n await instance.build(sourcePayloadConfig?.fetch)\n\n instance.refreshValues()\n\n return instance\n }\n\n async build(includeSources?: boolean) {\n this.buildOptions()\n await this.buildData(includeSources)\n return this\n }\n\n async buildData(includeSources?: boolean) {\n const forecastData = this.generateDataSetForecastData()\n\n const datasets: ChartDataset<'line'>[] = [forecastData]\n\n if (includeSources) {\n // build data from sources in forecastPayload\n const sourceData = await this.generateDataSetSourcePayloads()\n datasets.unshift(sourceData)\n\n // add last source point as first item in prediction to connect the lines\n const lastSourceDataItem = sourceData.data.at(-1) as Point\n forecastData.data.unshift(lastSourceDataItem)\n }\n\n this.data = {\n datasets,\n }\n\n return this\n }\n\n buildOptions() {\n if (this.options.plugins) {\n this.options.plugins.title = this.generateTitle()\n this.options.plugins.legend = this.generateLegend()\n }\n this.options.scales = this.generateScales()\n\n return this\n }\n\n refreshValues() {\n this.data = { ...this.data }\n this.options = { ...this.options }\n }\n\n protected generateLegend() {\n return {\n labels: {\n pointStyle: 'circle',\n usePointStyle: true,\n },\n } as LegendOptions<'line'>\n }\n\n protected generateScales() {\n return {\n x: {\n grid: {\n color: this.themeColors?.gridColor,\n },\n time: {\n unit: 'minute',\n },\n type: 'time',\n },\n y: {\n grid: {\n color: this.themeColors?.gridColor,\n },\n },\n } as unknown as ScaleChartOptions<'line'>['scales']\n }\n\n protected generateTitle() {\n return {\n display: true,\n text: `Gas Price Forecaster (GWEI over time from ${\n this.forecastPayload?.values[0].timestamp ? new Date(this.forecastPayload.values[0].timestamp).toLocaleDateString() : ''\n })`,\n }\n }\n\n protected parseTheme(theme: Theme) {\n const dark = theme.palette.mode === 'dark'\n return {\n dataSetColorPrimary: theme.palette.primary.light,\n dataSetColorSecondary: theme.palette.secondary.light,\n gridColor: dark ? theme.palette.grey[800] : theme.palette.grey[300],\n }\n }\n\n private generateDataSetForecastData(): ChartDataset<'line'> {\n return {\n borderDash: [5],\n borderDashOffset: 0.5,\n data: this.forecastPayload.values.map(price => ({ x: price.timestamp ?? 0, y: price.value })),\n label: 'Forecast Price',\n ...DataPointStyles(this.themeColors?.dataSetColorPrimary),\n ...DataLineStyles(this.themeColors?.dataSetColorPrimary),\n }\n }\n\n private async generateDataSetSourcePayloads(): Promise<ChartDataset<'line'>> {\n const { sourcePrices } = await SourcePayloads.build('feePerGas.medium')\n return {\n data: sourcePrices,\n label: 'Source Prices',\n ...DataLineStyles(this.themeColors?.dataSetColorSecondary),\n ...DataPointStyles(this.themeColors?.dataSetColorSecondary),\n }\n }\n}\n","import { createPayloadRenderPlugin, PayloadRenderPlugin } from '@xyo-network/react-payload-plugin'\n\nimport { PriceForecastDetailsBox } from './components/index.ts'\n\nexport const PriceForecastRenderPlugin: PayloadRenderPlugin = {\n ...createPayloadRenderPlugin({\n canRender: () => true,\n components: {\n box: {\n detailsBox: PriceForecastDetailsBox,\n },\n },\n name: 'PriceForecast',\n }),\n}\n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iBAEE,OAAOC,YAAAA;AACL,UAAM,EAAEP,MAAAA,OAAMI,SAAAA,SAAO,IAAK,MAAMI,+BAA+BC,OAAOX,OAAOD,sBAAsB;MAAEa,OAAO;IAAK,CAAA;AACjH,QAAIH,QAAAA,GAAW;AACbN,cAAQD,KAAAA;AACRK,iBAAWD,QAAAA;IACb;EACF,GACA;IAACP;IAAsBC;GAAM;AAG/B,SACE,sBAAA,cAACa,SAAAA;IAAS,GAAGf;IAAOgB,MAAMf,yBAAyBgB;IAAWC,WAAU;KACrEjB,uBACG,sBAAA,cAACkB,MAAAA;IAAKX;IAAkBJ;OACxB,IAAA;AAGV,GAzB+E;;;AM/B/E,SAASgB,iCAAsD;AAIxD,IAAMC,4BAAiD;EAC5D,GAAGC,0BAA0B;IAC3BC,WAAW,6BAAM,MAAN;IACXC,YAAY;MACVC,KAAK;QACHC,YAAYC;MACd;IACF;IACAC,MAAM;EACR,CAAA;AACF;","names":["useTheme","useAsyncEffect","FlexCol","CategoryScale","Chart","ChartJS","Legend","LinearScale","LineElement","PointElement","TimeScale","Title","Tooltip","React","useState","Line","alpha","DataLineStyles","color","backgroundColor","alpha","undefined","borderColor","DataPointStyles","pointHoverBackgroundColor","pointHitRadius","pointHoverRadius","pointRadius","pointStyle","MockSourcePayloads","tenMin","baseFee","feePerGas","high","low","medium","veryHigh","priorityFeePerGas","schema","timestamp","Date","now","SourcePayloads","sourcePrices","constructor","sourcePayloads","payloads","build","jsonPath","fetchSourcePayloads","instance","paths","split","map","payload","x","timestamp","y","jsonPathTraverser","Promise","resolve","MockSourcePayloads","obj","path","result","key","foundKey","undefined","defaultOptions","plugins","legend","position","responsive","ForecastLineChartConfigBuilder","data","options","themeColors","constructor","theme","payload","datasets","parseTheme","forecastPayload","Error","create","sourcePayloadConfig","instance","build","fetch","refreshValues","includeSources","buildOptions","buildData","forecastData","generateDataSetForecastData","sourceData","generateDataSetSourcePayloads","unshift","lastSourceDataItem","at","title","generateTitle","generateLegend","scales","generateScales","labels","pointStyle","usePointStyle","x","grid","color","gridColor","time","unit","type","y","display","text","values","timestamp","Date","toLocaleDateString","dark","palette","mode","dataSetColorPrimary","primary","light","dataSetColorSecondary","secondary","grey","borderDash","borderDashOffset","map","price","value","label","DataPointStyles","DataLineStyles","sourcePrices","SourcePayloads","ChartJS","register","CategoryScale","TimeScale","PointElement","LineElement","LinearScale","Title","Tooltip","Legend","PriceForecastDetailsBox","payload","props","priceForecastPayload","theme","useTheme","data","setData","useState","datasets","options","setOptions","useAsyncEffect","mounted","ForecastLineChartConfigBuilder","create","fetch","FlexCol","busy","undefined","minHeight","Line","createPayloadRenderPlugin","PriceForecastRenderPlugin","createPayloadRenderPlugin","canRender","components","box","detailsBox","PriceForecastDetailsBox","name"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForecastLineChartConfigBuilder.d.ts","sourceRoot":"","sources":["../../../src/lib/ForecastLineChartConfigBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AACxE,OAAO,EAAE,SAAS,EAAgB,YAAY,EAAE,aAAa,EAAS,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAMzG,UAAU,mBAAmB;IAC3B,KAAK,EAAE,OAAO,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,UAAU,WAAW;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,qBAAqB,EAAE,MAAM,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB;AAWD,qBAAa,8BAA8B;
|
|
1
|
+
{"version":3,"file":"ForecastLineChartConfigBuilder.d.ts","sourceRoot":"","sources":["../../../src/lib/ForecastLineChartConfigBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;A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,OAAO,CAAC,EAAE,eAAe,EAAE,mBAAmB,CAAC,EAAE,mBAAmB;IAUhG,KAAK,CAAC,cAAc,CAAC,EAAE,OAAO;IAM9B,SAAS,CAAC,cAAc,CAAC,EAAE,OAAO;IAsBxC,YAAY;IAUZ,aAAa;IAKb,SAAS,CAAC,cAAc,IAMjB,aAAa,CAAC,MAAM,CAAC;IAG5B,SAAS,CAAC,cAAc,IAgBN,iBAAiB,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC;IAGrD,SAAS,CAAC,aAAa;;;;IASvB,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK;;;;;IASjC,OAAO,CAAC,2BAA2B;YAWrB,6BAA6B;CAS5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForecastLineChartConfigBuilder.d.ts","sourceRoot":"","sources":["../../../src/lib/ForecastLineChartConfigBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AACxE,OAAO,EAAE,SAAS,EAAgB,YAAY,EAAE,aAAa,EAAS,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAMzG,UAAU,mBAAmB;IAC3B,KAAK,EAAE,OAAO,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,UAAU,WAAW;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,qBAAqB,EAAE,MAAM,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB;AAWD,qBAAa,8BAA8B;
|
|
1
|
+
{"version":3,"file":"ForecastLineChartConfigBuilder.d.ts","sourceRoot":"","sources":["../../../src/lib/ForecastLineChartConfigBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AACxE,OAAO,EAAE,SAAS,EAAgB,YAAY,EAAE,aAAa,EAAS,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAMzG,UAAU,mBAAmB;IAC3B,KAAK,EAAE,OAAO,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,UAAU,WAAW;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,qBAAqB,EAAE,MAAM,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB;AAWD,qBAAa,8BAA8B;IAUvC,OAAO,CAAC,OAAO,CAAC;IATlB,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,CAEtB;IAED,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,CAAmB;IAChD,WAAW,EAAE,WAAW,GAAG,SAAS,CAAA;gBAGlC,KAAK,EAAE,KAAK,EACJ,OAAO,CAAC,EAAE,eAAe,YAAA;IAKnC,IAAI,eAAe;;;;MAMlB;WAEY,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,eAAe,EAAE,mBAAmB,CAAC,EAAE,mBAAmB;IAUhG,KAAK,CAAC,cAAc,CAAC,EAAE,OAAO;IAM9B,SAAS,CAAC,cAAc,CAAC,EAAE,OAAO;IAsBxC,YAAY;IAUZ,aAAa;IAKb,SAAS,CAAC,cAAc,IAMjB,aAAa,CAAC,MAAM,CAAC;IAG5B,SAAS,CAAC,cAAc,IAgBN,iBAAiB,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC;IAGrD,SAAS,CAAC,aAAa;;;;IASvB,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK;;;;;IASjC,OAAO,CAAC,2BAA2B;YAWrB,6BAA6B;CAS5C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './ForecastLineChartConfigBuilder.
|
|
2
|
-
export * from './MockSourcePayloads.
|
|
3
|
-
export * from './SourcePayloads.
|
|
1
|
+
export * from './ForecastLineChartConfigBuilder.ts';
|
|
2
|
+
export * from './MockSourcePayloads.ts';
|
|
3
|
+
export * from './SourcePayloads.ts';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './ForecastLineChartConfigBuilder.
|
|
2
|
-
export * from './MockSourcePayloads.
|
|
3
|
-
export * from './SourcePayloads.
|
|
1
|
+
export * from './ForecastLineChartConfigBuilder.ts';
|
|
2
|
+
export * from './MockSourcePayloads.ts';
|
|
3
|
+
export * from './SourcePayloads.ts';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/node/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './ForecastLineChartConfigBuilder.
|
|
2
|
-
export * from './MockSourcePayloads.
|
|
3
|
-
export * from './SourcePayloads.
|
|
1
|
+
export * from './ForecastLineChartConfigBuilder.ts';
|
|
2
|
+
export * from './MockSourcePayloads.ts';
|
|
3
|
+
export * from './SourcePayloads.ts';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -10,20 +10,20 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xylabs/react-async-effect": "^3.4.
|
|
14
|
-
"@xylabs/react-flexbox": "^3.4.
|
|
15
|
-
"@xyo-network/diviner-forecasting-model": "^2.
|
|
16
|
-
"@xyo-network/payload-model": "^2.
|
|
17
|
-
"@xyo-network/react-payload-plugin": "^2.
|
|
13
|
+
"@xylabs/react-async-effect": "^3.4.2",
|
|
14
|
+
"@xylabs/react-flexbox": "^3.4.2",
|
|
15
|
+
"@xyo-network/diviner-forecasting-model": "^2.111.3",
|
|
16
|
+
"@xyo-network/payload-model": "^2.111.3",
|
|
17
|
+
"@xyo-network/react-payload-plugin": "^2.82.0",
|
|
18
18
|
"chart.js": "^4.4.3",
|
|
19
19
|
"chartjs-adapter-luxon": "^1.3.1",
|
|
20
|
-
"luxon": "^3.
|
|
20
|
+
"luxon": "^3.5.0",
|
|
21
21
|
"react-chartjs-2": "^5.2.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@storybook/react": "^
|
|
25
|
-
"@xylabs/ts-scripts-yarn3": "^3.
|
|
26
|
-
"@xylabs/tsconfig-react": "^3.
|
|
24
|
+
"@storybook/react": "^8.2.7",
|
|
25
|
+
"@xylabs/ts-scripts-yarn3": "^3.15.16",
|
|
26
|
+
"@xylabs/tsconfig-react": "^3.15.16",
|
|
27
27
|
"typescript": "^5.5.4"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"node": {
|
|
43
43
|
"import": {
|
|
44
44
|
"types": "./dist/node/index.d.mts",
|
|
45
|
-
"default": "./dist/node/index.
|
|
45
|
+
"default": "./dist/node/index.mjs"
|
|
46
46
|
},
|
|
47
47
|
"require": {
|
|
48
48
|
"types": "./dist/node/index.d.cts",
|
|
@@ -52,19 +52,19 @@
|
|
|
52
52
|
"browser": {
|
|
53
53
|
"import": {
|
|
54
54
|
"types": "./dist/browser/index.d.mts",
|
|
55
|
-
"default": "./dist/browser/index.
|
|
55
|
+
"default": "./dist/browser/index.mjs"
|
|
56
56
|
},
|
|
57
57
|
"require": {
|
|
58
58
|
"types": "./dist/browser/index.d.cts",
|
|
59
59
|
"default": "./dist/browser/index.cjs"
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
|
-
"default": "./dist/browser/index.
|
|
62
|
+
"default": "./dist/browser/index.mjs"
|
|
63
63
|
},
|
|
64
64
|
"./package.json": "./package.json"
|
|
65
65
|
},
|
|
66
66
|
"main": "dist/browser/index.cjs",
|
|
67
|
-
"module": "dist/browser/index.
|
|
67
|
+
"module": "dist/browser/index.mjs",
|
|
68
68
|
"homepage": "https://xyo.network",
|
|
69
69
|
"keywords": [
|
|
70
70
|
"xyo",
|
|
@@ -86,6 +86,6 @@
|
|
|
86
86
|
},
|
|
87
87
|
"sideEffects": false,
|
|
88
88
|
"types": "dist/browser/index.d.ts",
|
|
89
|
-
"version": "2.
|
|
89
|
+
"version": "2.79.0",
|
|
90
90
|
"type": "module"
|
|
91
91
|
}
|
package/src/Plugin.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createPayloadRenderPlugin, PayloadRenderPlugin } from '@xyo-network/react-payload-plugin'
|
|
2
2
|
|
|
3
|
-
import { PriceForecastDetailsBox } from './components/index.
|
|
3
|
+
import { PriceForecastDetailsBox } from './components/index.ts'
|
|
4
4
|
|
|
5
5
|
export const PriceForecastRenderPlugin: PayloadRenderPlugin = {
|
|
6
6
|
...createPayloadRenderPlugin({
|
|
@@ -2,16 +2,16 @@ import { Button, ButtonGroup, Typography } from '@mui/material'
|
|
|
2
2
|
import { Meta, StoryFn } from '@storybook/react'
|
|
3
3
|
import { FlexCol } from '@xylabs/react-flexbox'
|
|
4
4
|
import { ForecastPayloadSchema } from '@xyo-network/diviner-forecasting-model'
|
|
5
|
-
import { RefObject, useRef, useState } from 'react'
|
|
5
|
+
import React, { RefObject, useRef, useState } from 'react'
|
|
6
6
|
|
|
7
|
-
import { MockSourcePayloads } from '../lib/index.
|
|
8
|
-
import { PriceForecastDetailsBox } from './DetailsBox.
|
|
7
|
+
import { MockSourcePayloads } from '../lib/index.ts'
|
|
8
|
+
import { PriceForecastDetailsBox } from './DetailsBox.tsx'
|
|
9
9
|
|
|
10
10
|
const tenMin = 600_000
|
|
11
11
|
|
|
12
12
|
const ForecastingDivinerPayload = {
|
|
13
13
|
schema: ForecastPayloadSchema,
|
|
14
|
-
values: [1, 2, 3, 4, 5, 6, 7, 8].map(
|
|
14
|
+
values: [1, 2, 3, 4, 5, 6, 7, 8].map(item => ({
|
|
15
15
|
error: 0,
|
|
16
16
|
timestamp: Date.now() + tenMin * item,
|
|
17
17
|
value: 100 * item,
|
|
@@ -52,12 +52,16 @@ const Template: StoryFn<typeof PriceForecastDetailsBox> = (args) => {
|
|
|
52
52
|
</FlexCol>
|
|
53
53
|
<pre>
|
|
54
54
|
<Typography ref={forecastPayloadRef}>
|
|
55
|
-
ForecastPayload:
|
|
55
|
+
ForecastPayload:
|
|
56
|
+
{' '}
|
|
57
|
+
<code>{JSON.stringify(args.payload, null, 2)}</code>
|
|
56
58
|
</Typography>
|
|
57
59
|
</pre>
|
|
58
60
|
<pre>
|
|
59
61
|
<Typography ref={sourcePayloadsRef}>
|
|
60
|
-
SourcePayloads:
|
|
62
|
+
SourcePayloads:
|
|
63
|
+
{' '}
|
|
64
|
+
<pre>{JSON.stringify(MockSourcePayloads(), null, 2)}</pre>
|
|
61
65
|
</Typography>
|
|
62
66
|
</pre>
|
|
63
67
|
</>
|
|
@@ -74,5 +78,4 @@ WithData.args = {
|
|
|
74
78
|
|
|
75
79
|
export { Default, WithData }
|
|
76
80
|
|
|
77
|
-
// eslint-disable-next-line import/no-default-export
|
|
78
81
|
export default StorybookEntry
|
|
@@ -18,10 +18,10 @@ import {
|
|
|
18
18
|
Title,
|
|
19
19
|
Tooltip,
|
|
20
20
|
} from 'chart.js'
|
|
21
|
-
import { useState } from 'react'
|
|
21
|
+
import React, { useState } from 'react'
|
|
22
22
|
import { Line } from 'react-chartjs-2'
|
|
23
23
|
|
|
24
|
-
import { ForecastLineChartConfigBuilder } from '../lib/index.
|
|
24
|
+
import { ForecastLineChartConfigBuilder } from '../lib/index.ts'
|
|
25
25
|
|
|
26
26
|
ChartJS.register(CategoryScale, TimeScale, PointElement, LineElement, LinearScale, Title, Tooltip, Legend)
|
|
27
27
|
|
|
@@ -36,7 +36,7 @@ export const PriceForecastDetailsBox: React.FC<PriceForecastDetailsBoxProps> = (
|
|
|
36
36
|
const [options, setOptions] = useState<ChartOptions<'line'>>({})
|
|
37
37
|
|
|
38
38
|
useAsyncEffect(
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
async (mounted) => {
|
|
41
41
|
const { data, options } = await ForecastLineChartConfigBuilder.create(theme, priceForecastPayload, { fetch: true })
|
|
42
42
|
if (mounted()) {
|
|
@@ -49,9 +49,9 @@ export const PriceForecastDetailsBox: React.FC<PriceForecastDetailsBoxProps> = (
|
|
|
49
49
|
|
|
50
50
|
return (
|
|
51
51
|
<FlexCol {...props} busy={priceForecastPayload === undefined} minHeight="25vh">
|
|
52
|
-
{priceForecastPayload
|
|
53
|
-
<Line options={options} data={data} />
|
|
54
|
-
|
|
52
|
+
{priceForecastPayload
|
|
53
|
+
? <Line options={options} data={data} />
|
|
54
|
+
: null}
|
|
55
55
|
</FlexCol>
|
|
56
56
|
)
|
|
57
57
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './DetailsBox.
|
|
1
|
+
export * from './DetailsBox.tsx'
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './components/index.
|
|
2
|
-
export * from './Plugin.
|
|
1
|
+
export * from './components/index.ts'
|
|
2
|
+
export * from './Plugin.ts'
|
|
@@ -2,9 +2,9 @@ import { Theme } from '@mui/material'
|
|
|
2
2
|
import { ForecastPayload } from '@xyo-network/diviner-forecasting-model'
|
|
3
3
|
import { ChartData, ChartDataset, ChartOptions, LegendOptions, Point, ScaleChartOptions } from 'chart.js'
|
|
4
4
|
|
|
5
|
-
import { DataLineStyles } from './DataLineStyles.
|
|
6
|
-
import { DataPointStyles } from './DataPointStyles.
|
|
7
|
-
import { SourcePayloads } from './SourcePayloads.
|
|
5
|
+
import { DataLineStyles } from './DataLineStyles.ts'
|
|
6
|
+
import { DataPointStyles } from './DataPointStyles.ts'
|
|
7
|
+
import { SourcePayloads } from './SourcePayloads.ts'
|
|
8
8
|
|
|
9
9
|
interface SourcePayloadConfig {
|
|
10
10
|
fetch: boolean
|
|
@@ -30,6 +30,7 @@ export class ForecastLineChartConfigBuilder {
|
|
|
30
30
|
data: ChartData<'line'> = {
|
|
31
31
|
datasets: [],
|
|
32
32
|
}
|
|
33
|
+
|
|
33
34
|
options: ChartOptions<'line'> = defaultOptions()
|
|
34
35
|
themeColors: ThemeColors | undefined
|
|
35
36
|
|
|
@@ -151,7 +152,7 @@ export class ForecastLineChartConfigBuilder {
|
|
|
151
152
|
return {
|
|
152
153
|
borderDash: [5],
|
|
153
154
|
borderDashOffset: 0.5,
|
|
154
|
-
data: this.forecastPayload.values.map(
|
|
155
|
+
data: this.forecastPayload.values.map(price => ({ x: price.timestamp ?? 0, y: price.value })),
|
|
155
156
|
label: 'Forecast Price',
|
|
156
157
|
...DataPointStyles(this.themeColors?.dataSetColorPrimary),
|
|
157
158
|
...DataLineStyles(this.themeColors?.dataSetColorPrimary),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Payload } from '@xyo-network/payload-model'
|
|
2
2
|
import { Point } from 'chart.js'
|
|
3
3
|
|
|
4
|
-
import { MockSourcePayloads } from './MockSourcePayloads.
|
|
4
|
+
import { MockSourcePayloads } from './MockSourcePayloads.ts'
|
|
5
5
|
|
|
6
6
|
export class SourcePayloads {
|
|
7
7
|
sourcePrices: Point[] = []
|
package/src/lib/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './ForecastLineChartConfigBuilder.
|
|
2
|
-
export * from './MockSourcePayloads.
|
|
3
|
-
export * from './SourcePayloads.
|
|
1
|
+
export * from './ForecastLineChartConfigBuilder.ts'
|
|
2
|
+
export * from './MockSourcePayloads.ts'
|
|
3
|
+
export * from './SourcePayloads.ts'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/DetailsBox.tsx","../../src/lib/DataLineStyles.ts","../../src/lib/DataPointStyles.ts","../../src/lib/MockSourcePayloads.ts","../../src/lib/SourcePayloads.ts","../../src/lib/ForecastLineChartConfigBuilder.ts","../../src/Plugin.ts"],"sourcesContent":["import 'chartjs-adapter-luxon'\n\nimport { useTheme } from '@mui/material'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { FlexBoxProps, FlexCol } from '@xylabs/react-flexbox'\nimport { ForecastPayload } from '@xyo-network/diviner-forecasting-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n CategoryScale,\n Chart as ChartJS,\n ChartData,\n ChartOptions,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n TimeScale,\n Title,\n Tooltip,\n} from 'chart.js'\nimport { useState } from 'react'\nimport { Line } from 'react-chartjs-2'\n\nimport { ForecastLineChartConfigBuilder } from '../lib/index.js'\n\nChartJS.register(CategoryScale, TimeScale, PointElement, LineElement, LinearScale, Title, Tooltip, Legend)\n\nexport interface PriceForecastDetailsBoxProps extends FlexBoxProps {\n payload?: Payload\n}\n\nexport const PriceForecastDetailsBox: React.FC<PriceForecastDetailsBoxProps> = ({ payload, ...props }) => {\n const priceForecastPayload = payload as ForecastPayload | undefined\n const theme = useTheme()\n const [data, setData] = useState<ChartData<'line'>>({ datasets: [] })\n const [options, setOptions] = useState<ChartOptions<'line'>>({})\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n const { data, options } = await ForecastLineChartConfigBuilder.create(theme, priceForecastPayload, { fetch: true })\n if (mounted()) {\n setData(data)\n setOptions(options)\n }\n },\n [priceForecastPayload, theme],\n )\n\n return (\n <FlexCol {...props} busy={priceForecastPayload === undefined} minHeight=\"25vh\">\n {priceForecastPayload ?\n <Line options={options} data={data} />\n : null}\n </FlexCol>\n )\n}\n","import { alpha } from '@mui/material'\n\nexport const DataLineStyles = (color?: string) => ({\n backgroundColor: color ? alpha(color, 0.5) : undefined,\n borderColor: color,\n})\n","export const DataPointStyles = (pointHoverBackgroundColor?: string) => ({\n pointHitRadius: 20,\n pointHoverBackgroundColor,\n pointHoverRadius: 10,\n pointRadius: 5,\n pointStyle: 'circle',\n})\n","export const MockSourcePayloads = () => {\n const tenMin = 600_000\n return [\n {\n baseFee: 38.901_553_878_25,\n feePerGas: { high: 47.994_586_439_6, low: 39.006_868_093, medium: 39.306_868_093, veryHigh: 44.453_843_805_25 },\n priorityFeePerGas: { high: 1.026_666_666_666_666_6, low: -0.410_000_000_000_000_03, medium: 0.38, veryHigh: 1.390_000_000_000_000_1 },\n schema: 'network.xyo.blockchain.ethereum.gas',\n timestamp: Date.now() - tenMin,\n },\n {\n baseFee: 38.901_553_878_25,\n feePerGas: { high: 47.994_586_439_6, low: 39.006_868_093, medium: 100, veryHigh: 44.453_843_805_25 },\n priorityFeePerGas: { high: 1.026_666_666_666_666_6, low: -0.410_000_000_000_000_03, medium: 0.38, veryHigh: 1.390_000_000_000_000_1 },\n schema: 'network.xyo.blockchain.ethereum.gas',\n timestamp: Date.now(),\n },\n ]\n}\n","import { Payload } from '@xyo-network/payload-model'\nimport { Point } from 'chart.js'\n\nimport { MockSourcePayloads } from './MockSourcePayloads.js'\n\nexport class SourcePayloads {\n sourcePrices: Point[] = []\n\n constructor(public sourcePayloads: Payload[]) {}\n\n get payloads() {\n return this.sourcePayloads\n }\n\n static async build(jsonPath: string) {\n const sourcePayloads = await this.fetchSourcePayloads()\n const instance = new this(sourcePayloads)\n\n const paths = jsonPath.split('.')\n instance.sourcePrices = sourcePayloads.map((payload) => {\n return { x: payload.timestamp, y: instance.jsonPathTraverser(payload, paths) }\n })\n return instance\n }\n\n // TODO - fetch from archivist\n static async fetchSourcePayloads() {\n const payloads = await Promise.resolve(MockSourcePayloads())\n return payloads\n }\n\n jsonPathTraverser(obj: Payload, path: string[]) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let result: any = obj\n for (const key of path) {\n if (key in result) {\n const foundKey = key as keyof typeof result\n result = result[foundKey]\n } else {\n result = undefined\n break\n }\n }\n\n return result\n }\n}\n","import { Theme } from '@mui/material'\nimport { ForecastPayload } from '@xyo-network/diviner-forecasting-model'\nimport { ChartData, ChartDataset, ChartOptions, LegendOptions, Point, ScaleChartOptions } from 'chart.js'\n\nimport { DataLineStyles } from './DataLineStyles.js'\nimport { DataPointStyles } from './DataPointStyles.js'\nimport { SourcePayloads } from './SourcePayloads.js'\n\ninterface SourcePayloadConfig {\n fetch: boolean\n sampleSize?: number\n}\n\ninterface ThemeColors {\n dataSetColorPrimary: string\n dataSetColorSecondary: string\n gridColor: string\n}\n\nconst defaultOptions: () => ChartOptions<'line'> = () => ({\n plugins: {\n legend: {\n position: 'top' as const,\n },\n },\n responsive: true,\n})\n\nexport class ForecastLineChartConfigBuilder {\n data: ChartData<'line'> = {\n datasets: [],\n }\n options: ChartOptions<'line'> = defaultOptions()\n themeColors: ThemeColors | undefined\n\n constructor(\n theme: Theme,\n private payload?: ForecastPayload,\n ) {\n this.themeColors = this.parseTheme(theme)\n }\n\n get forecastPayload() {\n if (this.payload) {\n return this.payload\n } else {\n throw new Error('ForecastPayload was not defined')\n }\n }\n\n static async create(theme: Theme, payload?: ForecastPayload, sourcePayloadConfig?: SourcePayloadConfig) {\n const instance = new ForecastLineChartConfigBuilder(theme, payload)\n\n await instance.build(sourcePayloadConfig?.fetch)\n\n instance.refreshValues()\n\n return instance\n }\n\n async build(includeSources?: boolean) {\n this.buildOptions()\n await this.buildData(includeSources)\n return this\n }\n\n async buildData(includeSources?: boolean) {\n const forecastData = this.generateDataSetForecastData()\n\n const datasets: ChartDataset<'line'>[] = [forecastData]\n\n if (includeSources) {\n // build data from sources in forecastPayload\n const sourceData = await this.generateDataSetSourcePayloads()\n datasets.unshift(sourceData)\n\n // add last source point as first item in prediction to connect the lines\n const lastSourceDataItem = sourceData.data.at(-1) as Point\n forecastData.data.unshift(lastSourceDataItem)\n }\n\n this.data = {\n datasets,\n }\n\n return this\n }\n\n buildOptions() {\n if (this.options.plugins) {\n this.options.plugins.title = this.generateTitle()\n this.options.plugins.legend = this.generateLegend()\n }\n this.options.scales = this.generateScales()\n\n return this\n }\n\n refreshValues() {\n this.data = { ...this.data }\n this.options = { ...this.options }\n }\n\n protected generateLegend() {\n return {\n labels: {\n pointStyle: 'circle',\n usePointStyle: true,\n },\n } as LegendOptions<'line'>\n }\n\n protected generateScales() {\n return {\n x: {\n grid: {\n color: this.themeColors?.gridColor,\n },\n time: {\n unit: 'minute',\n },\n type: 'time',\n },\n y: {\n grid: {\n color: this.themeColors?.gridColor,\n },\n },\n } as unknown as ScaleChartOptions<'line'>['scales']\n }\n\n protected generateTitle() {\n return {\n display: true,\n text: `Gas Price Forecaster (GWEI over time from ${\n this.forecastPayload?.values[0].timestamp ? new Date(this.forecastPayload.values[0].timestamp).toLocaleDateString() : ''\n })`,\n }\n }\n\n protected parseTheme(theme: Theme) {\n const dark = theme.palette.mode === 'dark'\n return {\n dataSetColorPrimary: theme.palette.primary.light,\n dataSetColorSecondary: theme.palette.secondary.light,\n gridColor: dark ? theme.palette.grey[800] : theme.palette.grey[300],\n }\n }\n\n private generateDataSetForecastData(): ChartDataset<'line'> {\n return {\n borderDash: [5],\n borderDashOffset: 0.5,\n data: this.forecastPayload.values.map((price) => ({ x: price.timestamp ?? 0, y: price.value })),\n label: 'Forecast Price',\n ...DataPointStyles(this.themeColors?.dataSetColorPrimary),\n ...DataLineStyles(this.themeColors?.dataSetColorPrimary),\n }\n }\n\n private async generateDataSetSourcePayloads(): Promise<ChartDataset<'line'>> {\n const { sourcePrices } = await SourcePayloads.build('feePerGas.medium')\n return {\n data: sourcePrices,\n label: 'Source Prices',\n ...DataLineStyles(this.themeColors?.dataSetColorSecondary),\n ...DataPointStyles(this.themeColors?.dataSetColorSecondary),\n }\n }\n}\n","import { createPayloadRenderPlugin, PayloadRenderPlugin } from '@xyo-network/react-payload-plugin'\n\nimport { PriceForecastDetailsBox } from './components/index.js'\n\nexport const PriceForecastRenderPlugin: PayloadRenderPlugin = {\n ...createPayloadRenderPlugin({\n canRender: () => true,\n components: {\n box: {\n detailsBox: PriceForecastDetailsBox,\n },\n },\n name: 'PriceForecast',\n }),\n}\n"],"mappings":";AAAA,OAAO;AAEP,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAuB,eAAe;AAGtC;AAAA,EACE;AAAA,EACA,SAAS;AAAA,EAGT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