annotate web/calibrate/XyPlot.ts @ 2417:ae4b90efb55a

start calibration tool
author drewp@bigasterisk.com
date Mon, 20 May 2024 01:28:12 -0700
parents
children e3af0ac507c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
1 import debug from "debug";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
2 import * as echarts from "echarts";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
3 import { css, html, LitElement, PropertyValueMap } from "lit";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
4 import { customElement, property } from "lit/decorators.js";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
5 debug.enable("*");
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
6 const log = debug("calibrate");
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
7
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
8 @customElement("xy-plot")
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
9 export class XyPlot extends LitElement {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
10 static styles = [
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
11 css`
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
12 #chart {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
13 width: 800px;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
14 height: 300px;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
15 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
16 `,
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
17 ];
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
18 chart!: echarts.ECharts;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
19 @property() label: string = "";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
20 @property() data: number[][] = [];
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
21
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
22 render() {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
23 return html`
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
24 <fieldset>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
25 <legend>${this.label}</legend>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
26 <div id="chart"></div>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
27 </fieldset>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
28 `;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
29 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
30
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
31 protected async firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>) {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
32 var chartDom = this.shadowRoot!.getElementById("chart")!;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
33 this.chart = echarts.init(chartDom);
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
34 this.chart.setOption({
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
35 animation: false,
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
36 xAxis: {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
37 type: "value",
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
38 },
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
39 yAxis: {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
40 type: "value",
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
41 },
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
42 series: [
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
43 {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
44 name: "d",
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
45 data: [],
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
46 type: "line",
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
47 },
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
48 ],
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
49 });
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
50 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
51
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
52 clear() {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
53 this.data.length = 0;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
54 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
55
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
56 insertPoint(x: number, y: number) {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
57 this.data.push([x, y]);
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
58 this.data.sort((a, b) => a[0] - b[0]);
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
59 this.chart.setOption({ series: [{ name: "d", data: this.data }] });
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
60 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
61 }