lit-litelements 2.0.0 → 2.0.2

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.
@@ -1,7 +1,6 @@
1
1
  import { LitElement } from "lit";
2
2
  declare class ChartElement extends LitElement {
3
3
  stockData: any[];
4
- constructor();
5
4
  firstUpdated(): void;
6
5
  customLinePlugin: {
7
6
  id: string;
@@ -8,17 +8,18 @@ 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
10
  import { LitElement, html } from "lit";
11
- import Chart from 'chart.js/auto';
11
+ import Chart from "chart.js/auto";
12
12
  import { customElement, property } from "lit/decorators.js";
13
13
  let ChartElement = class ChartElement extends LitElement {
14
14
  constructor() {
15
- super();
15
+ super(...arguments);
16
16
  this.stockData = [];
17
17
  // Define the custom plugin
18
18
  this.customLinePlugin = {
19
- id: 'customLinePlugin', // Ensure you give it an id
19
+ id: 'customLinePlugin',
20
20
  afterDraw: function (chart) {
21
- if (chart.tooltip._active && chart.tooltip._active.length) {
21
+ // Check if tooltip is defined and active
22
+ if (chart.tooltip && chart.tooltip._active && chart.tooltip._active.length) {
22
23
  const ctx = chart.ctx;
23
24
  const activePoint = chart.tooltip._active[0];
24
25
  const x = activePoint.element.x;
@@ -35,7 +36,6 @@ let ChartElement = class ChartElement extends LitElement {
35
36
  }
36
37
  }
37
38
  };
38
- this.stockData = [];
39
39
  }
40
40
  // First updated is called after the element has been rendered into the DOM
41
41
  firstUpdated() {
@@ -61,22 +61,103 @@ let ChartElement = class ChartElement extends LitElement {
61
61
  data: {
62
62
  labels: dates,
63
63
  datasets: [
64
- { label: "RSI", data: RSI, borderColor: "rgba(15, 92, 92, 1)", backgroundColor: "rgba(15, 92, 92, 0.2)", fill: false, borderWidth: 2, yAxisID: "yRSI" },
65
- { label: "MACDHistogram", data: MACDHistogram, borderColor: "rgba(175, 92, 92, 1)", backgroundColor: "rgba(175, 92, 92, 0.2)", fill: false, borderWidth: 2, yAxisID: "yMACD" },
66
- { label: "SignalLine", data: SignalLine, borderColor: "rgba(75, 92, 192, 1)", backgroundColor: "rgba(75, 92, 192, 0.2)", fill: false, borderWidth: 1, yAxisID: "yMACD" },
67
- { label: "MACDLine", data: MACDLine, borderColor: "rgba(175, 192, 192, 1)", backgroundColor: "rgba(175, 192, 192, 0.2)", fill: false, borderWidth: 1, yAxisID: "yMACD" },
68
- { label: "Close Price", data: closePrices, borderColor: "rgba(75, 192, 192, 1)", backgroundColor: "rgba(75, 192, 192, 0.2)", fill: true, borderWidth: 1, yAxisID: "yPrice" },
69
- { label: "MA20", data: ma20, borderColor: "rgba(255, 99, 132, 1)", backgroundColor: "rgba(255, 99, 132, 0.2)", fill: false, borderWidth: 2, yAxisID: "yPrice" },
70
- { label: "MA50", data: ma50, borderColor: "rgba(255, 206, 86, 1)", backgroundColor: "rgba(255, 206, 86, 0.2)", fill: false, borderWidth: 2, yAxisID: "yPrice" },
71
- { label: "MA200", data: ma200, borderColor: "rgba(153, 102, 255, 1)", backgroundColor: "rgba(153, 102, 255, 0.2)", fill: false, borderWidth: 2, yAxisID: "yPrice" },
64
+ {
65
+ label: "RSI",
66
+ data: RSI,
67
+ borderColor: "rgba(15, 92, 92, 1)",
68
+ backgroundColor: "rgba(15, 92, 92, 0.2)",
69
+ fill: false,
70
+ borderWidth: 2,
71
+ yAxisID: "yRSI",
72
+ },
73
+ {
74
+ label: "MACDHistogram",
75
+ data: MACDHistogram,
76
+ borderColor: "rgba(175, 92, 92, 1)",
77
+ backgroundColor: "rgba(175, 92, 92, 0.2)",
78
+ fill: false,
79
+ borderWidth: 2,
80
+ yAxisID: "yMACD",
81
+ },
82
+ {
83
+ label: "SignalLine",
84
+ data: SignalLine,
85
+ borderColor: "rgba(75, 92, 192, 1)",
86
+ backgroundColor: "rgba(75, 92, 192, 0.2)",
87
+ fill: false,
88
+ borderWidth: 1,
89
+ yAxisID: "yMACD",
90
+ },
91
+ {
92
+ label: "MACDLine",
93
+ data: MACDLine,
94
+ borderColor: "rgba(175, 192, 192, 1)",
95
+ backgroundColor: "rgba(175, 192, 192, 0.2)",
96
+ fill: false,
97
+ borderWidth: 1,
98
+ yAxisID: "yMACD",
99
+ },
100
+ {
101
+ label: "Close Price",
102
+ data: closePrices,
103
+ borderColor: "rgba(75, 192, 192, 1)",
104
+ backgroundColor: "rgba(75, 192, 192, 0.2)",
105
+ fill: true,
106
+ borderWidth: 1,
107
+ yAxisID: "yPrice",
108
+ },
109
+ {
110
+ label: "MA20",
111
+ data: ma20,
112
+ borderColor: "rgba(255, 99, 132, 1)",
113
+ backgroundColor: "rgba(255, 99, 132, 0.2)",
114
+ fill: false,
115
+ borderWidth: 2,
116
+ yAxisID: "yPrice",
117
+ },
118
+ {
119
+ label: "MA50",
120
+ data: ma50,
121
+ borderColor: "rgba(255, 206, 86, 1)",
122
+ backgroundColor: "rgba(255, 206, 86, 0.2)",
123
+ fill: false,
124
+ borderWidth: 2,
125
+ yAxisID: "yPrice",
126
+ },
127
+ {
128
+ label: "MA200",
129
+ data: ma200,
130
+ borderColor: "rgba(153, 102, 255, 1)",
131
+ backgroundColor: "rgba(153, 102, 255, 0.2)",
132
+ fill: false,
133
+ borderWidth: 2,
134
+ yAxisID: "yPrice",
135
+ },
72
136
  ],
73
137
  },
74
138
  options: {
75
139
  responsive: true,
76
140
  scales: {
77
- yPrice: { type: "linear", position: "left", beginAtZero: false, title: { display: true, text: "Price" } },
78
- yRSI: { type: "linear", position: "right", beginAtZero: true, title: { display: true, text: "RSI" }, grid: { drawOnChartArea: false } },
79
- yMACD: { type: "linear", position: "right", beginAtZero: true, title: { display: true, text: "MACD" }, grid: { drawOnChartArea: false } },
141
+ yPrice: {
142
+ type: "linear",
143
+ position: "left",
144
+ beginAtZero: false,
145
+ title: { display: true, text: "Price" },
146
+ },
147
+ yRSI: {
148
+ type: "linear",
149
+ position: "right",
150
+ beginAtZero: true,
151
+ title: { display: true, text: "RSI" },
152
+ grid: { drawOnChartArea: false },
153
+ },
154
+ yMACD: {
155
+ type: "linear",
156
+ position: "right",
157
+ beginAtZero: true,
158
+ title: { display: true, text: "MACD" },
159
+ grid: { drawOnChartArea: false },
160
+ },
80
161
  },
81
162
  interaction: { mode: "index", intersect: false },
82
163
  plugins: {
@@ -94,6 +175,5 @@ __decorate([
94
175
  __metadata("design:type", Object)
95
176
  ], ChartElement.prototype, "stockData", void 0);
96
177
  ChartElement = __decorate([
97
- customElement("stock-chart-display"),
98
- __metadata("design:paramtypes", [])
178
+ customElement("stock-chart-display")
99
179
  ], ChartElement);