lit-litelements 1.0.2 → 2.0.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.
- package/dist/component/chart.lit.d.ts +18 -0
- package/dist/component/chart.lit.js +99 -0
- package/dist/component/icon.lit.d.ts +17 -0
- package/dist/component/icon.lit.js +75 -0
- package/dist/main.d.ts +1 -1
- package/dist/main.js +529 -3
- package/package.json +10 -6
- package/readme.md +2 -27
- package/dist/component/markdown.lit.d.ts +0 -8
- package/dist/component/markdown.lit.js +0 -65
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LitElement } from "lit";
|
|
2
|
+
declare class ChartElement extends LitElement {
|
|
3
|
+
stockData: any[];
|
|
4
|
+
constructor();
|
|
5
|
+
firstUpdated(): void;
|
|
6
|
+
customLinePlugin: {
|
|
7
|
+
id: string;
|
|
8
|
+
afterDraw: (chart: any) => void;
|
|
9
|
+
};
|
|
10
|
+
_createChart(): void;
|
|
11
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
12
|
+
}
|
|
13
|
+
declare global {
|
|
14
|
+
interface HTMLElementTagNameMap {
|
|
15
|
+
"stock-chart-display": ChartElement;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { LitElement, html } from "lit";
|
|
11
|
+
import Chart from 'chart.js/auto';
|
|
12
|
+
import { customElement, property } from "lit/decorators.js";
|
|
13
|
+
let ChartElement = class ChartElement extends LitElement {
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this.stockData = [];
|
|
17
|
+
// Define the custom plugin
|
|
18
|
+
this.customLinePlugin = {
|
|
19
|
+
id: 'customLinePlugin', // Ensure you give it an id
|
|
20
|
+
afterDraw: function (chart) {
|
|
21
|
+
if (chart.tooltip._active && chart.tooltip._active.length) {
|
|
22
|
+
const ctx = chart.ctx;
|
|
23
|
+
const activePoint = chart.tooltip._active[0];
|
|
24
|
+
const x = activePoint.element.x;
|
|
25
|
+
const topY = chart.scales.yPrice.top;
|
|
26
|
+
const bottomY = chart.scales.yPrice.bottom;
|
|
27
|
+
ctx.save();
|
|
28
|
+
ctx.beginPath();
|
|
29
|
+
ctx.moveTo(x, topY);
|
|
30
|
+
ctx.lineTo(x, bottomY);
|
|
31
|
+
ctx.lineWidth = 1;
|
|
32
|
+
ctx.strokeStyle = "rgba(0, 0, 0, 0.5)";
|
|
33
|
+
ctx.stroke();
|
|
34
|
+
ctx.restore();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
this.stockData = [];
|
|
39
|
+
}
|
|
40
|
+
// First updated is called after the element has been rendered into the DOM
|
|
41
|
+
firstUpdated() {
|
|
42
|
+
this._createChart();
|
|
43
|
+
}
|
|
44
|
+
// This will handle creating the Chart.js chart
|
|
45
|
+
_createChart() {
|
|
46
|
+
const dates = this.stockData.map((data) => data === null || data === void 0 ? void 0 : data.date);
|
|
47
|
+
const closePrices = this.stockData.map((data) => data === null || data === void 0 ? void 0 : data.close);
|
|
48
|
+
const ma20 = this.stockData.map((data) => data === null || data === void 0 ? void 0 : data.MA20);
|
|
49
|
+
const ma50 = this.stockData.map((data) => data === null || data === void 0 ? void 0 : data.MA50);
|
|
50
|
+
const ma200 = this.stockData.map((data) => data === null || data === void 0 ? void 0 : data.MA200);
|
|
51
|
+
const RSI = this.stockData.map((data) => data === null || data === void 0 ? void 0 : data.RSI);
|
|
52
|
+
const MACDLine = this.stockData.map((data) => data === null || data === void 0 ? void 0 : data.MACDLine);
|
|
53
|
+
const SignalLine = this.stockData.map((data) => data === null || data === void 0 ? void 0 : data.SignalLine);
|
|
54
|
+
const MACDHistogram = this.stockData.map((data) => data === null || data === void 0 ? void 0 : data.MACDHistogram);
|
|
55
|
+
const canvas = this.shadowRoot.getElementById("stockChart");
|
|
56
|
+
const ctx = canvas.getContext("2d");
|
|
57
|
+
// Register the custom plugin
|
|
58
|
+
Chart.register(this.customLinePlugin);
|
|
59
|
+
new Chart(ctx, {
|
|
60
|
+
type: "line",
|
|
61
|
+
data: {
|
|
62
|
+
labels: dates,
|
|
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" },
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
options: {
|
|
75
|
+
responsive: true,
|
|
76
|
+
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 } },
|
|
80
|
+
},
|
|
81
|
+
interaction: { mode: "index", intersect: false },
|
|
82
|
+
plugins: {
|
|
83
|
+
tooltip: { mode: "index", axis: "x" },
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
render() {
|
|
89
|
+
return html `<canvas id="stockChart"></canvas>`;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
__decorate([
|
|
93
|
+
property({ type: Array }),
|
|
94
|
+
__metadata("design:type", Object)
|
|
95
|
+
], ChartElement.prototype, "stockData", void 0);
|
|
96
|
+
ChartElement = __decorate([
|
|
97
|
+
customElement("stock-chart-display"),
|
|
98
|
+
__metadata("design:paramtypes", [])
|
|
99
|
+
], ChartElement);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LitElement } from "lit";
|
|
2
|
+
declare class MyElement extends LitElement {
|
|
3
|
+
firstName: string;
|
|
4
|
+
lastName: string;
|
|
5
|
+
iconSize: string;
|
|
6
|
+
textSize: string;
|
|
7
|
+
backgroundColor: string;
|
|
8
|
+
static styles: import("lit").CSSResult;
|
|
9
|
+
updated(changedProperties: any): void;
|
|
10
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
11
|
+
}
|
|
12
|
+
declare global {
|
|
13
|
+
interface HTMLElementTagNameMap {
|
|
14
|
+
"icon-element": MyElement;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { LitElement, html, css } from "lit";
|
|
11
|
+
import { customElement, property } from "lit/decorators.js";
|
|
12
|
+
let MyElement = class MyElement extends LitElement {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.firstName = "L";
|
|
16
|
+
this.lastName = "L";
|
|
17
|
+
this.iconSize = "64px";
|
|
18
|
+
this.textSize = "16px";
|
|
19
|
+
this.backgroundColor = "red";
|
|
20
|
+
}
|
|
21
|
+
updated(changedProperties) {
|
|
22
|
+
if (changedProperties.has("iconSize")) {
|
|
23
|
+
this.style.setProperty("--lds-dual-ring-size", this.iconSize);
|
|
24
|
+
}
|
|
25
|
+
if (changedProperties.has("textSize")) {
|
|
26
|
+
this.style.setProperty("--textSize", this.textSize);
|
|
27
|
+
}
|
|
28
|
+
if (changedProperties.has("backgroundColor")) {
|
|
29
|
+
this.style.setProperty("--lds-backgroundColor", this.backgroundColor);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
render() {
|
|
33
|
+
return html `
|
|
34
|
+
<div class="icon">${this.firstName.charAt(0).toUpperCase()}${this.lastName.charAt(0).toUpperCase()}</div>
|
|
35
|
+
`;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
MyElement.styles = css `
|
|
39
|
+
.icon {
|
|
40
|
+
border-radius: 50%;
|
|
41
|
+
display: flex;
|
|
42
|
+
justify-content: center;
|
|
43
|
+
align-items: center;
|
|
44
|
+
font-weight: 500;
|
|
45
|
+
line-height: 150%;
|
|
46
|
+
width: var(--lds-dual-ring-size, 64px);
|
|
47
|
+
height: var(--lds-dual-ring-size, 64px);
|
|
48
|
+
font-size: var(--textSize, 16px);
|
|
49
|
+
background-color: var(--backgroundColor, rgb(153, 153, 153));
|
|
50
|
+
color: black;
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
__decorate([
|
|
54
|
+
property({ type: String }),
|
|
55
|
+
__metadata("design:type", Object)
|
|
56
|
+
], MyElement.prototype, "firstName", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
property({ type: String }),
|
|
59
|
+
__metadata("design:type", Object)
|
|
60
|
+
], MyElement.prototype, "lastName", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
property({ type: String }),
|
|
63
|
+
__metadata("design:type", Object)
|
|
64
|
+
], MyElement.prototype, "iconSize", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
property({ type: String }),
|
|
67
|
+
__metadata("design:type", Object)
|
|
68
|
+
], MyElement.prototype, "textSize", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
property({ type: String }),
|
|
71
|
+
__metadata("design:type", Object)
|
|
72
|
+
], MyElement.prototype, "backgroundColor", void 0);
|
|
73
|
+
MyElement = __decorate([
|
|
74
|
+
customElement("icon-element")
|
|
75
|
+
], MyElement);
|
package/dist/main.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import './component/spinner.lit';
|
|
2
|
-
import './component/
|
|
2
|
+
import './component/chart.lit';
|