lit-litelements 2.2.4 → 2.2.6
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/component/chart.lit.d.ts +3 -0
- package/dist/component/chart.lit.js +53 -12
- package/dist/main.js +29 -10
- package/package.json +2 -1
|
@@ -20,9 +20,12 @@ interface StockData {
|
|
|
20
20
|
}
|
|
21
21
|
declare class ChartElement extends LitElement {
|
|
22
22
|
stockData: StockData[];
|
|
23
|
+
zoomEnabled: boolean;
|
|
23
24
|
chart: Chart | null;
|
|
24
25
|
constructor();
|
|
25
26
|
firstUpdated(): void;
|
|
27
|
+
_resetZoom(): void;
|
|
28
|
+
_Zoomenalbe(): void;
|
|
26
29
|
willUpdate(changedProperties: {
|
|
27
30
|
has: (arg0: string) => any;
|
|
28
31
|
}): Promise<void>;
|
|
@@ -18,11 +18,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
18
|
};
|
|
19
19
|
import { LitElement, html } from "lit";
|
|
20
20
|
import Chart from "chart.js/auto";
|
|
21
|
+
import zoomPlugin from "chartjs-plugin-zoom";
|
|
21
22
|
import { customElement, property } from "lit/decorators.js";
|
|
22
23
|
let ChartElement = class ChartElement extends LitElement {
|
|
23
24
|
constructor() {
|
|
24
25
|
super();
|
|
25
26
|
this.stockData = [];
|
|
27
|
+
this.zoomEnabled = false;
|
|
26
28
|
this.chart = null;
|
|
27
29
|
// Define the custom plugin
|
|
28
30
|
this.customLinePlugin = {
|
|
@@ -109,17 +111,6 @@ let ChartElement = class ChartElement extends LitElement {
|
|
|
109
111
|
ctx.fillText("Bear", x + 6, y - 6);
|
|
110
112
|
const stop = currClose * (1 + RISK_PERCENT);
|
|
111
113
|
const target = currClose - (stop - currClose) * REWARD_RATIO;
|
|
112
|
-
const yStop = scales.yPrice.getPixelForValue(stop);
|
|
113
|
-
const yTarget = scales.yPrice.getPixelForValue(target);
|
|
114
|
-
// // Stop-Loss (SL) line
|
|
115
|
-
// ctx.fillStyle = "purple";
|
|
116
|
-
// ctx.fillRect(x, yStop, 100, 1); // 100px wide, 1px high
|
|
117
|
-
// ctx.font = "bold 12px sans-serif";
|
|
118
|
-
// ctx.fillText("BEAR-SL", x + 12, yStop - 4);
|
|
119
|
-
// // Take-Profit (TP) line
|
|
120
|
-
// ctx.fillStyle = "purple";
|
|
121
|
-
// ctx.fillRect(x, yTarget, 100, 1); // 100px wide, 1px high
|
|
122
|
-
// ctx.fillText("BEAR-TP", x + 12, yTarget - 4);
|
|
123
114
|
}
|
|
124
115
|
ctx.setLineDash([]);
|
|
125
116
|
}
|
|
@@ -131,6 +122,25 @@ let ChartElement = class ChartElement extends LitElement {
|
|
|
131
122
|
firstUpdated() {
|
|
132
123
|
this._createChart();
|
|
133
124
|
}
|
|
125
|
+
_resetZoom() {
|
|
126
|
+
var _a;
|
|
127
|
+
(_a = this.chart) === null || _a === void 0 ? void 0 : _a.resetZoom();
|
|
128
|
+
}
|
|
129
|
+
_Zoomenalbe() {
|
|
130
|
+
var _a, _b, _c, _d;
|
|
131
|
+
if ((_b = (_a = this.chart) === null || _a === void 0 ? void 0 : _a.options.plugins) === null || _b === void 0 ? void 0 : _b.zoom) {
|
|
132
|
+
const zoomOptions = this.chart.options.plugins.zoom;
|
|
133
|
+
const newState = !this.zoomEnabled;
|
|
134
|
+
if ((_c = zoomOptions.zoom) === null || _c === void 0 ? void 0 : _c.wheel)
|
|
135
|
+
zoomOptions.zoom.wheel.enabled = newState;
|
|
136
|
+
if ((_d = zoomOptions.zoom) === null || _d === void 0 ? void 0 : _d.pinch)
|
|
137
|
+
zoomOptions.zoom.pinch.enabled = newState;
|
|
138
|
+
if (zoomOptions.pan)
|
|
139
|
+
zoomOptions.pan.enabled = newState;
|
|
140
|
+
this.zoomEnabled = newState;
|
|
141
|
+
this.chart.update();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
134
144
|
willUpdate(changedProperties) {
|
|
135
145
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
146
|
if (changedProperties.has("stockData")) {
|
|
@@ -200,6 +210,7 @@ let ChartElement = class ChartElement extends LitElement {
|
|
|
200
210
|
}
|
|
201
211
|
// Register the custom plugin
|
|
202
212
|
Chart.register(this.customLinePlugin);
|
|
213
|
+
Chart.register(zoomPlugin);
|
|
203
214
|
this.chart = new Chart(ctx, {
|
|
204
215
|
type: "line",
|
|
205
216
|
data: {
|
|
@@ -389,18 +400,48 @@ let ChartElement = class ChartElement extends LitElement {
|
|
|
389
400
|
interaction: { mode: "index", intersect: false },
|
|
390
401
|
plugins: {
|
|
391
402
|
tooltip: { mode: "index", axis: "x" },
|
|
403
|
+
zoom: {
|
|
404
|
+
pan: {
|
|
405
|
+
enabled: false,
|
|
406
|
+
mode: "xy",
|
|
407
|
+
modifierKey: undefined, // Optional: only pan while holding Ctrl
|
|
408
|
+
},
|
|
409
|
+
zoom: {
|
|
410
|
+
wheel: {
|
|
411
|
+
enabled: false,
|
|
412
|
+
},
|
|
413
|
+
pinch: {
|
|
414
|
+
enabled: false,
|
|
415
|
+
},
|
|
416
|
+
mode: "x",
|
|
417
|
+
},
|
|
418
|
+
limits: {
|
|
419
|
+
x: { minRange: 10 }, // prevent zooming too far
|
|
420
|
+
},
|
|
421
|
+
},
|
|
392
422
|
},
|
|
393
423
|
},
|
|
394
424
|
});
|
|
395
425
|
}
|
|
396
426
|
render() {
|
|
397
|
-
return html
|
|
427
|
+
return html `
|
|
428
|
+
<button @click="${this._Zoomenalbe}">
|
|
429
|
+
${this.zoomEnabled ? "Disable Zoom" : "Enable Zoom"}
|
|
430
|
+
</button>
|
|
431
|
+
|
|
432
|
+
<button @click="${this._resetZoom}">Reset Zoom</button>
|
|
433
|
+
<canvas id="stockChart"></canvas>
|
|
434
|
+
`;
|
|
398
435
|
}
|
|
399
436
|
};
|
|
400
437
|
__decorate([
|
|
401
438
|
property({ type: Array }),
|
|
402
439
|
__metadata("design:type", Array)
|
|
403
440
|
], ChartElement.prototype, "stockData", void 0);
|
|
441
|
+
__decorate([
|
|
442
|
+
property({ type: Boolean }),
|
|
443
|
+
__metadata("design:type", Boolean)
|
|
444
|
+
], ChartElement.prototype, "zoomEnabled", void 0);
|
|
404
445
|
ChartElement = __decorate([
|
|
405
446
|
customElement("stock-chart-display"),
|
|
406
447
|
__metadata("design:paramtypes", [])
|