annotate web/calibrate/XyPlot.ts @ 2419:e3af0ac507c8

new exposure-finder algorithm
author drewp@bigasterisk.com
date Tue, 21 May 2024 14:08:17 -0700
parents ae4b90efb55a
children
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[][] = [];
2419
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
21
2417
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 }
2419
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
55
2417
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 }
2419
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
61 setXMarklines(lines: { txt: string; x: number }[]) {
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
62 const markLineData = (row: { txt: string; x: number }, i: number) => ({ name: row.txt, label: { distance: 10*i, formatter: "{b} {c}", color: "#fff", textBorderWidth: 0 }, xAxis: row.x });
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
63 this.chart.setOption(
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
64 {
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
65 series: [
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
66 {
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
67 name: "d",
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
68 markLine: {
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
69 data: lines.map(markLineData),
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
70 },
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
71 },
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
72 ],
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
73 } //
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
74 );
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
75 }
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
76 }