@barchart/chart-lib 2.199.5 → 2.200.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.
- chart-lib/barchart.chart.js +1 -1
- chart-lib/index.js +34 -3
- chart-lib/package.json +1 -1
chart-lib/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
ChunkPart,
|
|
11
11
|
Topics,
|
|
12
12
|
SeriesKind,
|
|
13
|
+
OHLCDataPointBuilder,
|
|
13
14
|
} from "./barchart.chart.js";
|
|
14
15
|
|
|
15
16
|
const ohlcFields = [
|
|
@@ -42,11 +43,36 @@ class ExampleTimeSeries {
|
|
|
42
43
|
this.container = null;
|
|
43
44
|
this.canLoadMoreData = true;
|
|
44
45
|
this.isLoading = false;
|
|
46
|
+
this.builder = null;
|
|
45
47
|
}
|
|
46
48
|
get hasData() {
|
|
47
49
|
return this.container !== null;
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
scheduleUpdate() {
|
|
53
|
+
const delay = Math.floor(500 + 500 * Math.random());
|
|
54
|
+
setTimeout(() => this.onUpdate(), delay);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
onUpdate() {
|
|
58
|
+
const last = this.container.getLastDataPoint(Fields.Close);
|
|
59
|
+
const sign = Math.random() < 0.5 ? -1 : 1;
|
|
60
|
+
const trade = {
|
|
61
|
+
isTrade: true,
|
|
62
|
+
time: new Date(),
|
|
63
|
+
tradePrice: last + last * sign * 0.001,
|
|
64
|
+
tradeSize: Math.floor(5000 * Math.random()),
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const result = this.builder.process(trade);
|
|
68
|
+
|
|
69
|
+
const topic = result.isUpdate ? Topics.TS_DATAPOINTCHANGED : Topics.TS_DATAPOINTADDED;
|
|
70
|
+
const payload = { series: this, index: result.index };
|
|
71
|
+
PubSub.publish(topic, payload);
|
|
72
|
+
|
|
73
|
+
this.scheduleUpdate();
|
|
74
|
+
}
|
|
75
|
+
|
|
50
76
|
async loadMoreData(headChunk = true) {
|
|
51
77
|
if (this.isLoading) return Promise.resolve();
|
|
52
78
|
this.isLoading = true;
|
|
@@ -74,9 +100,14 @@ class ExampleTimeSeries {
|
|
|
74
100
|
precedingClose = row.close;
|
|
75
101
|
}
|
|
76
102
|
|
|
77
|
-
if (!headChunk)
|
|
78
|
-
|
|
103
|
+
if (!headChunk) {
|
|
104
|
+
this.container = container;
|
|
105
|
+
this.builder = new OHLCDataPointBuilder(this.container, this.query.aggregation);
|
|
106
|
+
this.scheduleUpdate();
|
|
107
|
+
} else this.container.prepend(container);
|
|
108
|
+
|
|
79
109
|
this.isLoading = false;
|
|
110
|
+
|
|
80
111
|
if (headChunk) {
|
|
81
112
|
// the first chunk is loaded implicitly during the call to ready method below
|
|
82
113
|
// so there's no need for notification
|
|
@@ -183,7 +214,7 @@ class ExampleFeed extends BaseDataFeed {
|
|
|
183
214
|
|
|
184
215
|
const feed = initFeed(ExampleFeed, {
|
|
185
216
|
throttleMillis: 250,
|
|
186
|
-
apiKey: "
|
|
217
|
+
apiKey: "c3fd90ea7e38b87566c508a3f3f4bdab",
|
|
187
218
|
});
|
|
188
219
|
|
|
189
220
|
feed.ready().then(done => {
|