lit-litelements 2.0.9 → 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 +27 -12
- 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";
|
|
@@ -47,18 +56,21 @@ let ChartElement = class ChartElement extends LitElement {
|
|
|
47
56
|
this._createChart();
|
|
48
57
|
}
|
|
49
58
|
willUpdate(changedProperties) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
}
|
|
60
72
|
}
|
|
61
|
-
}
|
|
73
|
+
});
|
|
62
74
|
}
|
|
63
75
|
_getChartData() {
|
|
64
76
|
const data = {
|
|
@@ -99,9 +111,12 @@ let ChartElement = class ChartElement extends LitElement {
|
|
|
99
111
|
const { dates, closePrices, ma20, ma50, ma200, RSI, MACDLine, SignalLine, MACDHistogram, } = this._getChartData();
|
|
100
112
|
const canvas = this.shadowRoot.getElementById("stockChart");
|
|
101
113
|
const ctx = canvas.getContext("2d");
|
|
114
|
+
if (this.chart) {
|
|
115
|
+
this.chart.destroy(); // Destroy existing chart if necessary
|
|
116
|
+
}
|
|
102
117
|
// Register the custom plugin
|
|
103
118
|
Chart.register(this.customLinePlugin);
|
|
104
|
-
new Chart(ctx, {
|
|
119
|
+
this.chart = new Chart(ctx, {
|
|
105
120
|
type: "line",
|
|
106
121
|
data: {
|
|
107
122
|
labels: dates,
|