lit-litelements 2.0.8 → 2.0.10
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 +1 -1
- package/dist/component/chart.lit.js +28 -9
- package/dist/main.js +12 -12
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ declare class ChartElement extends LitElement {
|
|
|
4
4
|
chart: any;
|
|
5
5
|
constructor();
|
|
6
6
|
firstUpdated(): void;
|
|
7
|
-
willUpdate(changedProperties: any): void
|
|
7
|
+
willUpdate(changedProperties: any): Promise<void>;
|
|
8
8
|
customLinePlugin: {
|
|
9
9
|
id: string;
|
|
10
10
|
afterDraw: (chart: any) => void;
|
|
@@ -7,6 +7,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
11
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
12
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
14
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
15
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
16
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
17
|
+
});
|
|
18
|
+
};
|
|
10
19
|
import { LitElement, html } from "lit";
|
|
11
20
|
import Chart from "chart.js/auto";
|
|
12
21
|
import { customElement, property } from "lit/decorators.js";
|
|
@@ -43,18 +52,25 @@ let ChartElement = class ChartElement extends LitElement {
|
|
|
43
52
|
}
|
|
44
53
|
// First updated is called after the element has been rendered into the DOM
|
|
45
54
|
firstUpdated() {
|
|
55
|
+
console.log("firstUpdated called");
|
|
46
56
|
this._createChart();
|
|
47
57
|
}
|
|
48
|
-
// Called when properties (like stockData) are about to be updated
|
|
49
58
|
willUpdate(changedProperties) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
console.log("Updated stockData:
|
|
53
|
-
if (
|
|
54
|
-
console.log("Updated stockData:
|
|
55
|
-
this.
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
console.log("willUpdate called");
|
|
61
|
+
console.log("Updated stockData:1", this.stockData);
|
|
62
|
+
if (changedProperties.has("stockData")) {
|
|
63
|
+
console.log("Updated stockData:2", this.stockData);
|
|
64
|
+
if (!this.chart) {
|
|
65
|
+
console.log("Chart is undefined, creating chart now.");
|
|
66
|
+
this._createChart(); // Ensure the chart is created
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
console.log("Updated stockData:3", this.stockData);
|
|
70
|
+
this._updateChart(); // Update the chart if it exists
|
|
71
|
+
}
|
|
56
72
|
}
|
|
57
|
-
}
|
|
73
|
+
});
|
|
58
74
|
}
|
|
59
75
|
_getChartData() {
|
|
60
76
|
const data = {
|
|
@@ -95,9 +111,12 @@ let ChartElement = class ChartElement extends LitElement {
|
|
|
95
111
|
const { dates, closePrices, ma20, ma50, ma200, RSI, MACDLine, SignalLine, MACDHistogram, } = this._getChartData();
|
|
96
112
|
const canvas = this.shadowRoot.getElementById("stockChart");
|
|
97
113
|
const ctx = canvas.getContext("2d");
|
|
114
|
+
if (this.chart) {
|
|
115
|
+
this.chart.destroy(); // Destroy existing chart if necessary
|
|
116
|
+
}
|
|
98
117
|
// Register the custom plugin
|
|
99
118
|
Chart.register(this.customLinePlugin);
|
|
100
|
-
new Chart(ctx, {
|
|
119
|
+
this.chart = new Chart(ctx, {
|
|
101
120
|
type: "line",
|
|
102
121
|
data: {
|
|
103
122
|
labels: dates,
|