@qtsurfer/sveltecharts 0.10.1 → 0.12.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/LightweightTimeSeriesChartBuilder.d.ts +7 -2
- package/dist/LightweightTimeSeriesChartBuilder.d.ts.map +1 -1
- package/dist/LightweightTimeSeriesChartBuilder.js +48 -8
- package/dist/TimeSeriesChartBuilder.d.ts +6 -1
- package/dist/TimeSeriesChartBuilder.d.ts.map +1 -1
- package/dist/TimeSeriesChartBuilder.js +47 -4
- package/dist/chartAdapter.d.ts +7 -1
- package/dist/chartAdapter.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type IChartApi } from 'lightweight-charts';
|
|
2
|
-
import type { ChartDataset, ChartDatasetFormatSimpleObject, ChartMarkerPointOptions, OHLCDimensions, TimeSeriesChartAdapter } from './chartAdapter';
|
|
2
|
+
import type { ChartDataset, ChartDataValue, ChartDatasetFormatSimpleObject, ChartMarkerPointOptions, OHLCDimensions, TimeSeriesChartAdapter } from './chartAdapter';
|
|
3
3
|
type ConfigBuilder = {
|
|
4
4
|
externalManagerLegend?: boolean;
|
|
5
5
|
};
|
|
6
|
-
export declare function getPricePrecision(values:
|
|
6
|
+
export declare function getPricePrecision(values: readonly ChartDataValue[]): number;
|
|
7
7
|
export declare function formatPreciseValue(value: number): string;
|
|
8
8
|
export declare class LightweightTimeSeriesChartBuilder implements TimeSeriesChartAdapter {
|
|
9
9
|
LightweightChart: IChartApi;
|
|
@@ -37,6 +37,10 @@ export declare class LightweightTimeSeriesChartBuilder implements TimeSeriesChar
|
|
|
37
37
|
goToZoom(start: number, end: number): this;
|
|
38
38
|
scrollToTime(timestamp: number): this;
|
|
39
39
|
getTotalRows(): number;
|
|
40
|
+
getLoadedDimensions(): string[];
|
|
41
|
+
getActiveDimensions(): string[];
|
|
42
|
+
updateDimension(data: ChartDatasetFormatSimpleObject, dimName: string): this;
|
|
43
|
+
updateDimensions(data: ChartDatasetFormatSimpleObject, dimNames: string[]): this;
|
|
40
44
|
getRangeValues(): [number, number];
|
|
41
45
|
toggleMarkers(id: number, dimName: string, shape: string): this;
|
|
42
46
|
clearMarkers(): this;
|
|
@@ -54,6 +58,7 @@ export declare class LightweightTimeSeriesChartBuilder implements TimeSeriesChar
|
|
|
54
58
|
private toChartTime;
|
|
55
59
|
private forceTimeRangeToDataset;
|
|
56
60
|
private isPercentageDimension;
|
|
61
|
+
private normalizeDataValue;
|
|
57
62
|
private syncPriceScales;
|
|
58
63
|
private mapMarkerShape;
|
|
59
64
|
private mapMarkerPosition;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LightweightTimeSeriesChartBuilder.d.ts","sourceRoot":"","sources":["../src/lib/LightweightTimeSeriesChartBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"LightweightTimeSeriesChartBuilder.d.ts","sourceRoot":"","sources":["../src/lib/LightweightTimeSeriesChartBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,SAAS,EAWd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EACX,YAAY,EACZ,cAAc,EAGd,8BAA8B,EAC9B,uBAAuB,EACvB,cAAc,EACd,sBAAsB,EACtB,MAAM,gBAAgB,CAAC;AAExB,KAAK,aAAa,GAAG;IACpB,qBAAqB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AA6BF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,UAYlE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,UAW/C;AAED,qBAAa,iCAAkC,YAAW,sBAAsB;IACxE,gBAAgB,EAAE,SAAS,CAAC;IACnC,OAAO,CAAC,aAAa,CAEnB;IACF,OAAO,CAAC,OAAO,CAAsC;IACr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B,EAAE,OAAO,EAAE,MAAM;IAIrE,gBAAgB,CAAC,IAAI,EAAE,8BAA8B,EAAE,QAAQ,EAAE,MAAM,EAAE;IAazE,cAAc,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;IAUlC,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAmBxD,YAAY,IAAI,IAAI;IAQpB,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,qBAAqB;IAqB7B,OAAO,CAAC,oBAAoB;IA2B5B,OAAO,CAAC,eAAe;IAsCvB,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,SAAS;IAuBjB,OAAO,CAAC,iBAAiB;IAoCzB,OAAO,CAAC,yBAAyB;IA4BjC,OAAO,CAAC,WAAW;IAsBnB,OAAO,CAAC,iBAAiB;IA6BzB,OAAO,CAAC,UAAU;IAyBlB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,uBAAuB;IA8B/B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,eAAe;IAcvB,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,iBAAiB;CAWzB"}
|
|
@@ -14,6 +14,8 @@ function getDecimalPrecision(value) {
|
|
|
14
14
|
export function getPricePrecision(values) {
|
|
15
15
|
let precision = DEFAULT_PRICE_PRECISION;
|
|
16
16
|
for (const value of values) {
|
|
17
|
+
if (value === null)
|
|
18
|
+
continue;
|
|
17
19
|
precision = Math.max(precision, getDecimalPrecision(value));
|
|
18
20
|
if (precision >= MAX_PRICE_PRECISION) {
|
|
19
21
|
return MAX_PRICE_PRECISION;
|
|
@@ -71,6 +73,8 @@ export class LightweightTimeSeriesChartBuilder {
|
|
|
71
73
|
setCandlestickSeries(data, dims) {
|
|
72
74
|
this._tsColumn = Object.keys(data)[0];
|
|
73
75
|
this.dataset = data;
|
|
76
|
+
this.yDimensions = [dims.open, dims.high, dims.low, dims.close];
|
|
77
|
+
this.yDimensionNames = [...this.yDimensions];
|
|
74
78
|
this._ohlcDims = dims;
|
|
75
79
|
// Remove existing candlestick series before recreating
|
|
76
80
|
if (this._candlestickSeries) {
|
|
@@ -199,8 +203,29 @@ export class LightweightTimeSeriesChartBuilder {
|
|
|
199
203
|
getTotalRows() {
|
|
200
204
|
return this.dataset[this._tsColumn]?.length ?? 0;
|
|
201
205
|
}
|
|
206
|
+
getLoadedDimensions() {
|
|
207
|
+
return [...this.yDimensions];
|
|
208
|
+
}
|
|
209
|
+
getActiveDimensions() {
|
|
210
|
+
return this.getLoadedDimensions();
|
|
211
|
+
}
|
|
212
|
+
updateDimension(data, dimName) {
|
|
213
|
+
return this.updateDimensions(data, [dimName]);
|
|
214
|
+
}
|
|
215
|
+
updateDimensions(data, dimNames) {
|
|
216
|
+
if (data[this._tsColumn]) {
|
|
217
|
+
this.dataset[this._tsColumn] = data[this._tsColumn];
|
|
218
|
+
}
|
|
219
|
+
for (const dimName of dimNames) {
|
|
220
|
+
if (data[dimName]) {
|
|
221
|
+
this.dataset[dimName] = data[dimName];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
this._dataDirty = true;
|
|
225
|
+
return this.build();
|
|
226
|
+
}
|
|
202
227
|
getRangeValues() {
|
|
203
|
-
const timestamps = this.dataset[this._tsColumn] ?? [];
|
|
228
|
+
const timestamps = (this.dataset[this._tsColumn] ?? []).filter((timestamp) => timestamp !== null);
|
|
204
229
|
if (!timestamps.length) {
|
|
205
230
|
return [0, 0];
|
|
206
231
|
}
|
|
@@ -264,10 +289,10 @@ export class LightweightTimeSeriesChartBuilder {
|
|
|
264
289
|
throw new Error('No time dimension found.');
|
|
265
290
|
}
|
|
266
291
|
const dataset = {
|
|
267
|
-
[tsColumn]: data.map((row) =>
|
|
292
|
+
[tsColumn]: data.map((row) => this.normalizeDataValue(row[tsColumn]))
|
|
268
293
|
};
|
|
269
294
|
for (const key of keys) {
|
|
270
|
-
dataset[key] = data.map((row) =>
|
|
295
|
+
dataset[key] = data.map((row) => this.normalizeDataValue(row[key]));
|
|
271
296
|
}
|
|
272
297
|
return {
|
|
273
298
|
tsColumn,
|
|
@@ -421,12 +446,20 @@ export class LightweightTimeSeriesChartBuilder {
|
|
|
421
446
|
const seen = new Set();
|
|
422
447
|
const result = [];
|
|
423
448
|
for (let i = 0; i < timestamps.length; i++) {
|
|
424
|
-
const
|
|
449
|
+
const timestamp = timestamps[i];
|
|
450
|
+
const open = opens[i];
|
|
451
|
+
const high = highs[i];
|
|
452
|
+
const low = lows[i];
|
|
453
|
+
const close = closes[i];
|
|
454
|
+
if (timestamp == null || open == null || high == null || low == null || close == null) {
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
const t = this.toChartTime(timestamp);
|
|
425
458
|
const tNum = t;
|
|
426
459
|
if (seen.has(tNum))
|
|
427
460
|
continue;
|
|
428
461
|
seen.add(tNum);
|
|
429
|
-
result.push({ time: t, open
|
|
462
|
+
result.push({ time: t, open, high, low, close });
|
|
430
463
|
}
|
|
431
464
|
return result;
|
|
432
465
|
}
|
|
@@ -439,12 +472,16 @@ export class LightweightTimeSeriesChartBuilder {
|
|
|
439
472
|
const seen = new Set();
|
|
440
473
|
const result = [];
|
|
441
474
|
for (let i = 0; i < timestamps.length; i++) {
|
|
442
|
-
const
|
|
475
|
+
const timestamp = timestamps[i];
|
|
476
|
+
if (timestamp == null)
|
|
477
|
+
continue;
|
|
478
|
+
const t = this.toChartTime(timestamp);
|
|
443
479
|
const tNum = t;
|
|
444
480
|
if (seen.has(tNum))
|
|
445
481
|
continue;
|
|
446
482
|
seen.add(tNum);
|
|
447
|
-
|
|
483
|
+
const value = values[i];
|
|
484
|
+
result.push(value == null ? { time: t } : { time: t, value });
|
|
448
485
|
}
|
|
449
486
|
return result;
|
|
450
487
|
}
|
|
@@ -456,7 +493,7 @@ export class LightweightTimeSeriesChartBuilder {
|
|
|
456
493
|
return;
|
|
457
494
|
}
|
|
458
495
|
this._timeRangeForced = true;
|
|
459
|
-
const timestamps = this.dataset[this._tsColumn] ?? [];
|
|
496
|
+
const timestamps = (this.dataset[this._tsColumn] ?? []).filter((timestamp) => timestamp !== null);
|
|
460
497
|
if (timestamps.length === 0) {
|
|
461
498
|
return;
|
|
462
499
|
}
|
|
@@ -479,6 +516,9 @@ export class LightweightTimeSeriesChartBuilder {
|
|
|
479
516
|
isPercentageDimension(dim) {
|
|
480
517
|
return !dim.startsWith('_') && dim.endsWith('%');
|
|
481
518
|
}
|
|
519
|
+
normalizeDataValue(value) {
|
|
520
|
+
return value == null ? null : Number(value);
|
|
521
|
+
}
|
|
482
522
|
syncPriceScales() {
|
|
483
523
|
const hasPercentageSeries = this.yDimensions.some((dim) => this.isPercentageDimension(dim));
|
|
484
524
|
const hasValueSeries = this.yDimensions.some((dim) => !this.isPercentageDimension(dim));
|
|
@@ -4,7 +4,7 @@ import type { ChartDatasetFormatSimpleObject, ChartMarkerPointOptions, OHLCDimen
|
|
|
4
4
|
import type { GridOption } from 'echarts/types/dist/shared';
|
|
5
5
|
import type { ZRColor } from 'echarts/types/src/util/types.js';
|
|
6
6
|
type IconType = 'circle' | 'rect' | 'roundRect' | 'triangle' | 'diamond' | 'pin' | 'arrowUp' | 'arrowDown' | 'none';
|
|
7
|
-
type DatasetFormatSimpleObject =
|
|
7
|
+
type DatasetFormatSimpleObject = ChartDatasetFormatSimpleObject;
|
|
8
8
|
type DatasetFormatObject = Record<string, any>[];
|
|
9
9
|
type DatasetFormatArray = number[][];
|
|
10
10
|
/**
|
|
@@ -132,6 +132,11 @@ export declare class TimeSeriesChartBuilder {
|
|
|
132
132
|
};
|
|
133
133
|
getLegendStatus(): Record<string, boolean>;
|
|
134
134
|
getTotalRows(): number;
|
|
135
|
+
getLoadedDimensions(): string[];
|
|
136
|
+
getActiveDimensions(): string[];
|
|
137
|
+
updateDimension(data: DatasetFormatSimpleObject, dimName: string): this;
|
|
138
|
+
updateDimensions(data: DatasetFormatSimpleObject, dimNames: string[]): this;
|
|
139
|
+
setDataRange(start: number, end: number): this;
|
|
135
140
|
private isSimpleObject;
|
|
136
141
|
private isRecordArray;
|
|
137
142
|
private isNumberMatrix;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeSeriesChartBuilder.d.ts","sourceRoot":"","sources":["../src/lib/TimeSeriesChartBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAE5B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAsB,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,KAAK,EACX,8BAA8B,EAC9B,uBAAuB,EACvB,cAAc,EACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAG/D,KAAK,QAAQ,GACV,QAAQ,GACR,MAAM,GACN,WAAW,GACX,UAAU,GACV,SAAS,GACT,KAAK,GACL,SAAS,GACT,WAAW,GACX,MAAM,CAAC;AAwBV,KAAK,yBAAyB,GAAG,
|
|
1
|
+
{"version":3,"file":"TimeSeriesChartBuilder.d.ts","sourceRoot":"","sources":["../src/lib/TimeSeriesChartBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAE5B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAsB,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,KAAK,EACX,8BAA8B,EAC9B,uBAAuB,EACvB,cAAc,EACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAG/D,KAAK,QAAQ,GACV,QAAQ,GACR,MAAM,GACN,WAAW,GACX,UAAU,GACV,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M,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,MAAM,CAAC;KACd,EACD,OAAO,CAAC,EAAE,uBAAuB,GAC/B,IAAI;IA6EP,OAAO,CAAC,aAAa;IAIrB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAoBxB;;OAEG;IACH,OAAO,CAAC,qCAAqC;IAuC7C;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAW9B,KAAK;IAqBL,gBAAgB;;;;IAOhB,eAAe;IAIf,YAAY;IAYZ,mBAAmB,IAAI,MAAM,EAAE;IAI/B,mBAAmB,IAAI,MAAM,EAAE;IAI/B,eAAe,CAAC,IAAI,EAAE,yBAAyB,EAAE,OAAO,EAAE,MAAM;IAIhE,gBAAgB,CAAC,IAAI,EAAE,yBAAyB,EAAE,QAAQ,EAAE,MAAM,EAAE;IAmBpE,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAYvC,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,cAAc;IAMtB,cAAc,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;IAiDlC,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IA2BxD,YAAY,IAAI,IAAI;CAcpB"}
|
|
@@ -231,9 +231,12 @@ export class TimeSeriesChartBuilder {
|
|
|
231
231
|
if (!ts.length)
|
|
232
232
|
return 0;
|
|
233
233
|
let closest = 0;
|
|
234
|
-
let minDiff =
|
|
235
|
-
for (let i =
|
|
236
|
-
const
|
|
234
|
+
let minDiff = Number.POSITIVE_INFINITY;
|
|
235
|
+
for (let i = 0; i < ts.length; i++) {
|
|
236
|
+
const value = ts[i];
|
|
237
|
+
if (value === null)
|
|
238
|
+
continue;
|
|
239
|
+
const diff = Math.abs(value - timestamp);
|
|
237
240
|
if (diff < minDiff) {
|
|
238
241
|
minDiff = diff;
|
|
239
242
|
closest = i;
|
|
@@ -600,6 +603,8 @@ export class TimeSeriesChartBuilder {
|
|
|
600
603
|
if (!seriesDimension)
|
|
601
604
|
throw new Error(`Dimension ${data.dimName} not found`);
|
|
602
605
|
let value = this.searchValueByDimensionKeyAndTimestamp(data.dimName, data.timestamp);
|
|
606
|
+
if (value == null)
|
|
607
|
+
return this;
|
|
603
608
|
/**
|
|
604
609
|
* Creates a data point for the marker
|
|
605
610
|
*/
|
|
@@ -742,6 +747,41 @@ export class TimeSeriesChartBuilder {
|
|
|
742
747
|
return dataset.source[this._tsColumn].length;
|
|
743
748
|
}
|
|
744
749
|
}
|
|
750
|
+
getLoadedDimensions() {
|
|
751
|
+
return [...this.yDimensions];
|
|
752
|
+
}
|
|
753
|
+
getActiveDimensions() {
|
|
754
|
+
return this.getLoadedDimensions();
|
|
755
|
+
}
|
|
756
|
+
updateDimension(data, dimName) {
|
|
757
|
+
return this.updateDimensions(data, [dimName]);
|
|
758
|
+
}
|
|
759
|
+
updateDimensions(data, dimNames) {
|
|
760
|
+
const dataset = this.option.dataset;
|
|
761
|
+
if (!dataset || Array.isArray(dataset) || !this.isSimpleObject(dataset.source))
|
|
762
|
+
return this;
|
|
763
|
+
const source = dataset.source;
|
|
764
|
+
if (data[this._tsColumn]) {
|
|
765
|
+
source[this._tsColumn] = data[this._tsColumn];
|
|
766
|
+
}
|
|
767
|
+
for (const dimName of dimNames) {
|
|
768
|
+
if (data[dimName]) {
|
|
769
|
+
source[dimName] = data[dimName];
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
this.build();
|
|
773
|
+
return this;
|
|
774
|
+
}
|
|
775
|
+
setDataRange(start, end) {
|
|
776
|
+
const xAxis = this.option.xAxis;
|
|
777
|
+
if (Array.isArray(xAxis)) {
|
|
778
|
+
this.option.xAxis = xAxis.map((axis, index) => index === 0 ? { ...axis, min: start, max: end } : axis);
|
|
779
|
+
}
|
|
780
|
+
else {
|
|
781
|
+
this.option.xAxis = { ...xAxis, min: start, max: end };
|
|
782
|
+
}
|
|
783
|
+
return this.build();
|
|
784
|
+
}
|
|
745
785
|
isSimpleObject(s) {
|
|
746
786
|
return !Array.isArray(s) && typeof s === 'object' && s !== null;
|
|
747
787
|
}
|
|
@@ -783,7 +823,10 @@ export class TimeSeriesChartBuilder {
|
|
|
783
823
|
const col = source[this._tsColumn];
|
|
784
824
|
if (!col?.length)
|
|
785
825
|
return [0, 0];
|
|
786
|
-
|
|
826
|
+
const timestamps = col.filter((timestamp) => timestamp !== null);
|
|
827
|
+
if (!timestamps.length)
|
|
828
|
+
return [0, 0];
|
|
829
|
+
return [timestamps[0], timestamps[timestamps.length - 1]];
|
|
787
830
|
}
|
|
788
831
|
return [0, 0];
|
|
789
832
|
}
|
package/dist/chartAdapter.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type ChartDataValue = number | null;
|
|
2
|
+
export type ChartDatasetFormatSimpleObject = Record<string, ChartDataValue[]>;
|
|
2
3
|
export type ChartDatasetFormatObject = Record<string, any>[];
|
|
3
4
|
export type ChartDatasetFormatArray = number[][];
|
|
4
5
|
export type OHLCDimensions = {
|
|
@@ -34,5 +35,10 @@ export interface TimeSeriesChartAdapter {
|
|
|
34
35
|
getTotalRows(): number;
|
|
35
36
|
toggleMarkers(id: number, dimName: string, shape: string): this;
|
|
36
37
|
clearMarkers(): this;
|
|
38
|
+
getLoadedDimensions?(): string[];
|
|
39
|
+
getActiveDimensions(): string[];
|
|
40
|
+
updateDimension(data: ChartDatasetFormatSimpleObject, dimName: string): this;
|
|
41
|
+
updateDimensions?(data: ChartDatasetFormatSimpleObject, dimNames: string[]): this;
|
|
42
|
+
setDataRange?(start: number, end: number): this;
|
|
37
43
|
}
|
|
38
44
|
//# sourceMappingURL=chartAdapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chartAdapter.d.ts","sourceRoot":"","sources":["../src/lib/chartAdapter.ts"],"names":[],"mappings":"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I,CAAC;IACvF,KAAK,IAAI,IAAI,CAAC;IACd,YAAY,CAAC,IAAI,EAAE,8BAA8B,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1E,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAC;IAC5F,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,cAAc,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,YAAY,IAAI,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAChE,YAAY,IAAI,IAAI,CAAC;IACrB,mBAAmB,CAAC,IAAI,MAAM,EAAE,CAAC;IACjC,mBAAmB,IAAI,MAAM,EAAE,CAAC;IAChC,eAAe,CAAC,IAAI,EAAE,8BAA8B,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7E,gBAAgB,CAAC,CAAC,IAAI,EAAE,8BAA8B,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAClF,YAAY,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAChD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { default as SVECharts } from './SVECharts.svelte';
|
|
2
2
|
export { default as SVELightweightCharts } from './SVELightweightCharts.svelte';
|
|
3
|
-
export type { TimeSeriesChartAdapter } from './chartAdapter';
|
|
3
|
+
export type { ChartDataValue, ChartDatasetFormatSimpleObject, TimeSeriesChartAdapter } from './chartAdapter';
|
|
4
4
|
export { LightweightTimeSeriesChartBuilder } from './LightweightTimeSeriesChartBuilder';
|
|
5
5
|
export { TimeSeriesChartBuilder } from './TimeSeriesChartBuilder';
|
|
6
6
|
export * from './types';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAChF,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAChF,YAAY,EACX,cAAc,EACd,8BAA8B,EAC9B,sBAAsB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,cAAc,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": false,
|
|
3
3
|
"name": "@qtsurfer/sveltecharts",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "QTSurfer (https://github.com/QTSurfer)",
|
|
7
7
|
"homepage": "https://github.com/QTSurfer/svelte-timeseries/tree/main/packages/sveltecharts",
|