lit-litelements 2.0.9 → 2.1.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.
@@ -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,22 +52,19 @@ 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() {
46
- console.log("firstUpdated called");
47
55
  this._createChart();
48
56
  }
49
57
  willUpdate(changedProperties) {
50
- console.log("willUpdate called");
51
- console.log("Updated stockData:1", this.stockData);
52
- if (changedProperties.has("stockData")) {
53
- console.log("Updated stockData:2", this.stockData);
54
- if (this.chart) {
55
- console.log("Updated stockData:3", this.stockData);
56
- this._updateChart();
57
- }
58
- else {
59
- console.log("Chart is undefined, it hasn't been created yet.");
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ if (changedProperties.has("stockData")) {
60
+ if (!this.chart) {
61
+ this._createChart(); // Ensure the chart is created
62
+ }
63
+ else {
64
+ this._updateChart(); // Update the chart if it exists
65
+ }
60
66
  }
61
- }
67
+ });
62
68
  }
63
69
  _getChartData() {
64
70
  const data = {
@@ -72,11 +78,9 @@ let ChartElement = class ChartElement extends LitElement {
72
78
  SignalLine: this.stockData.map((data) => data === null || data === void 0 ? void 0 : data.SignalLine),
73
79
  MACDHistogram: this.stockData.map((data) => data === null || data === void 0 ? void 0 : data.MACDHistogram),
74
80
  };
75
- console.log("Chart data:", data);
76
81
  return data;
77
82
  }
78
83
  _updateChart() {
79
- console.log("_updateChart");
80
84
  if (this.chart) {
81
85
  const { dates, closePrices, ma20, ma50, ma200, RSI, MACDLine, SignalLine, MACDHistogram, } = this._getChartData();
82
86
  // Update labels (dates)
@@ -99,9 +103,12 @@ let ChartElement = class ChartElement extends LitElement {
99
103
  const { dates, closePrices, ma20, ma50, ma200, RSI, MACDLine, SignalLine, MACDHistogram, } = this._getChartData();
100
104
  const canvas = this.shadowRoot.getElementById("stockChart");
101
105
  const ctx = canvas.getContext("2d");
106
+ if (this.chart) {
107
+ this.chart.destroy(); // Destroy existing chart if necessary
108
+ }
102
109
  // Register the custom plugin
103
110
  Chart.register(this.customLinePlugin);
104
- new Chart(ctx, {
111
+ this.chart = new Chart(ctx, {
105
112
  type: "line",
106
113
  data: {
107
114
  labels: dates,