@oicl/openbridge-webcomponents-full-bundle 2.0.0-next.67 → 2.0.0-next.68

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.
Files changed (21) hide show
  1. package/bundle/openbridge-webcomponents.bundle.js +18332 -18087
  2. package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
  3. package/custom-elements.json +209 -0
  4. package/dist/navigation-instruments/graph-mini/graph-mini.css.js +2 -1
  5. package/dist/navigation-instruments/graph-mini/graph-mini.css.js.map +1 -1
  6. package/dist/navigation-instruments/graph-mini/graph-mini.d.ts.map +1 -1
  7. package/dist/navigation-instruments/graph-mini/graph-mini.js +7 -5
  8. package/dist/navigation-instruments/graph-mini/graph-mini.js.map +1 -1
  9. package/dist/navigation-instruments/indicator-graph/indicator-graph.css.js +66 -0
  10. package/dist/navigation-instruments/indicator-graph/indicator-graph.css.js.map +1 -0
  11. package/dist/navigation-instruments/indicator-graph/indicator-graph.d.ts +54 -0
  12. package/dist/navigation-instruments/indicator-graph/indicator-graph.d.ts.map +1 -0
  13. package/dist/navigation-instruments/indicator-graph/indicator-graph.js +203 -0
  14. package/dist/navigation-instruments/indicator-graph/indicator-graph.js.map +1 -0
  15. package/package.json +1 -1
  16. package/src/navigation-instruments/graph-mini/graph-mini.css +2 -1
  17. package/src/navigation-instruments/graph-mini/graph-mini.stories.ts +11 -3
  18. package/src/navigation-instruments/graph-mini/graph-mini.ts +7 -5
  19. package/src/navigation-instruments/indicator-graph/indicator-graph.css +55 -0
  20. package/src/navigation-instruments/indicator-graph/indicator-graph.stories.ts +116 -0
  21. package/src/navigation-instruments/indicator-graph/indicator-graph.ts +222 -0
@@ -27,7 +27,8 @@
27
27
  position: absolute;
28
28
  width: 4px;
29
29
  height: 4px;
30
- right: -3px;
30
+ right: -3.5px;
31
+ bottom: 0;
31
32
  border-radius: 50%;
32
33
  background: var(--element-neutral-color);
33
34
  border: 1px solid var(--border-silhouette-color);
@@ -19,13 +19,22 @@ type Story = StoryObj<ObcGraphMini>;
19
19
 
20
20
  export const Primary: Story = {};
21
21
 
22
+ export const WithRange: Story = {
23
+ args: {
24
+ minY: -10,
25
+ maxY: 10,
26
+ },
27
+ };
28
+
22
29
  export const Realtime: Story = {
23
30
  tags: ['skip-test'],
24
31
  args: {
25
32
  data: [
26
33
  Array.from({length: 60}, (_, i) => i),
27
- Array.from({length: 60}, (_, i) => Math.sin((i / 60) * 2 * Math.PI)),
34
+ Array.from({length: 60}, (_, i) => Math.sin((i / 60 / 5) * 2 * Math.PI)),
28
35
  ],
36
+ minY: -1.1,
37
+ maxY: 1.1,
29
38
  },
30
39
  play: async ({canvasElement}) => {
31
40
  const graph = canvasElement.querySelector('obc-graph-mini') as ObcGraphMini;
@@ -35,10 +44,9 @@ export const Realtime: Story = {
35
44
 
36
45
  let i = graph.data[0].length;
37
46
  setInterval(() => {
38
- console.log('updating', i);
39
47
  const data = graph.data;
40
48
  const x = [...data[0], i];
41
- const y = [...data[1], Math.sin((i / 60) * 2 * Math.PI)];
49
+ const y = [...data[1], Math.sin((i / 60 / 5) * 2 * Math.PI)];
42
50
  x.shift();
43
51
  y.shift();
44
52
  const newData: [number[], number[]] = [x, y];
@@ -36,8 +36,8 @@ export class ObcGraphMini extends LitElement {
36
36
 
37
37
  override firstUpdated() {
38
38
  const opts = {
39
- width: 48,
40
- height: 48,
39
+ width: 32,
40
+ height: 32,
41
41
  scales: {
42
42
  x: {time: false, show: false},
43
43
  y: {
@@ -61,7 +61,7 @@ export class ObcGraphMini extends LitElement {
61
61
  {},
62
62
  {
63
63
  stroke: this.getCssColor('--element-neutral-color'),
64
- width: 2,
64
+ width: 1,
65
65
  points: {show: false},
66
66
  },
67
67
  ],
@@ -83,7 +83,7 @@ export class ObcGraphMini extends LitElement {
83
83
  }
84
84
  const stroke = this.getCssColor('--element-neutral-color');
85
85
  // @ts-expect-error - stroke is not a property of the Series interface
86
- this.uplot.setSeries(1, {stroke: stroke, width: 2, points: {show: false}});
86
+ this.uplot.setSeries(1, {stroke: stroke, width: 1, points: {show: false}});
87
87
  }
88
88
 
89
89
  private updateY() {
@@ -107,7 +107,9 @@ export class ObcGraphMini extends LitElement {
107
107
  override render() {
108
108
  return html`
109
109
  <div class="chart-container">
110
- <div id="chart"><div id="dot" style="bottom: ${this.y}px; "></div></div>
110
+ <div id="chart">
111
+ <div id="dot" style="transform: translateY(${-this.y}px);"></div>
112
+ </div>
111
113
  </div>
112
114
  `;
113
115
  }
@@ -0,0 +1,55 @@
1
+ .chart-container {
2
+ width: 100%;
3
+ height: 100%;
4
+ display: flex;
5
+ align-items: center;
6
+ justify-content: center;
7
+ position: relative;
8
+ }
9
+
10
+ canvas {
11
+ position: absolute;
12
+ width: 100%;
13
+ height: 100%;
14
+ top: 0;
15
+ left: 0;
16
+ }
17
+
18
+ #dot {
19
+ position: absolute;
20
+ width: 4px;
21
+ height: 4px;
22
+ right: -3px;
23
+ bottom: -3px;
24
+ border-radius: 50%;
25
+ background: var(--element-neutral-color);
26
+ border: 1px solid var(--border-silhouette-color);
27
+ z-index: 1;
28
+ }
29
+
30
+ .enhanced #dot {
31
+ background: var(--element-neutral-enhanced-color);
32
+ }
33
+
34
+ .medium #dot {
35
+ width: 6px;
36
+ height: 6px;
37
+ right: -4px;
38
+ bottom: -4px;
39
+ }
40
+
41
+ .large #dot {
42
+ width: 8px;
43
+ height: 8px;
44
+ right: -5px;
45
+ bottom: -5px;
46
+ }
47
+
48
+ #zero-line {
49
+ position: absolute;
50
+ width: 100%;
51
+ height: 1px;
52
+ bottom: -0.5px;
53
+ background: var(--element-disabled-color);
54
+ border-radius: 2px;
55
+ }
@@ -0,0 +1,116 @@
1
+ import type {Meta, StoryObj} from '@storybook/web-components-vite';
2
+ import {
3
+ ObcIndicatorGraph,
4
+ ObcIndicatorGraphPriority,
5
+ ObcIndicatorGraphSize,
6
+ } from './indicator-graph.js';
7
+ import './indicator-graph.js';
8
+ import {widthDecorator} from '../../storybook-util.js';
9
+ const meta: Meta<typeof ObcIndicatorGraph> = {
10
+ title: 'Bars and Graphs/Indicator Graph',
11
+ tags: ['6.0', 'autodocs'],
12
+ component: 'obc-indicator-graph',
13
+ decorators: [widthDecorator],
14
+ args: {
15
+ data: [
16
+ Array.from({length: 30}, (_, i) => i),
17
+ Array.from({length: 30}, (_, i) => 2 + Math.sin((i / 30) * 2 * Math.PI)),
18
+ ],
19
+ width: 400,
20
+ height: 400,
21
+ },
22
+ argTypes: {
23
+ width: {control: {type: 'range', min: 100, max: 1000, step: 1}},
24
+ height: {control: {type: 'range', min: 100, max: 1000, step: 1}},
25
+ },
26
+ } satisfies Meta<ObcIndicatorGraph>;
27
+
28
+ export default meta;
29
+ type Story = StoryObj<ObcIndicatorGraph>;
30
+
31
+ export const Primary: Story = {};
32
+
33
+ export const WithRange: Story = {
34
+ args: {
35
+ layout: {
36
+ size: ObcIndicatorGraphSize.medium,
37
+ priority: ObcIndicatorGraphPriority.regular,
38
+ y: {min: -10, max: 10},
39
+ },
40
+ },
41
+ };
42
+
43
+ export const Enhanced: Story = {
44
+ args: {
45
+ layout: {
46
+ size: ObcIndicatorGraphSize.medium,
47
+ priority: ObcIndicatorGraphPriority.enhanced,
48
+ },
49
+ },
50
+ };
51
+
52
+ export const Small: Story = {
53
+ args: {
54
+ layout: {
55
+ size: ObcIndicatorGraphSize.small,
56
+ },
57
+ },
58
+ };
59
+
60
+ export const Medium: Story = {
61
+ args: {
62
+ layout: {
63
+ size: ObcIndicatorGraphSize.medium,
64
+ },
65
+ },
66
+ };
67
+
68
+ export const Large: Story = {
69
+ args: {
70
+ layout: {
71
+ size: ObcIndicatorGraphSize.large,
72
+ },
73
+ },
74
+ };
75
+
76
+ export const Realtime: Story = {
77
+ tags: ['skip-test'],
78
+ args: {
79
+ data: [
80
+ Array.from({length: 60}, (_, i) => i),
81
+ Array.from(
82
+ {length: 60},
83
+ (_, i) => 2 + Math.sin((i / 60 / 5) * 2 * Math.PI)
84
+ ),
85
+ ],
86
+ layout: {
87
+ size: ObcIndicatorGraphSize.medium,
88
+ priority: ObcIndicatorGraphPriority.regular,
89
+ y: {max: 4},
90
+ },
91
+ },
92
+ play: async ({canvasElement}) => {
93
+ const graph = canvasElement.querySelector(
94
+ 'obc-indicator-graph'
95
+ ) as ObcIndicatorGraph;
96
+ if (!graph) {
97
+ throw new Error('Graph not found');
98
+ }
99
+
100
+ let i = graph.data[0].length;
101
+ const intervalId = setInterval(() => {
102
+ if (!graph.isConnected) {
103
+ clearInterval(intervalId);
104
+ return;
105
+ }
106
+ const data = graph.data;
107
+ const x = [...data[0], i];
108
+ const y = [...data[1], 2 + Math.sin((i / 60 / 5) * 2 * Math.PI)];
109
+ x.shift();
110
+ y.shift();
111
+ const newData: [number[], number[]] = [x, y];
112
+ graph.data = newData;
113
+ i++;
114
+ }, 1000 / 60);
115
+ },
116
+ };
@@ -0,0 +1,222 @@
1
+ import {LitElement, PropertyValues, html, unsafeCSS} from 'lit';
2
+ import {property, query, state} from 'lit/decorators.js';
3
+ import compentStyle from './indicator-graph.css?inline';
4
+ import uPlot from 'uplot';
5
+ import {customElement} from '../../decorator.js';
6
+
7
+ export enum ObcIndicatorGraphSize {
8
+ small = 'small',
9
+ medium = 'medium',
10
+ large = 'large',
11
+ }
12
+
13
+ export enum ObcIndicatorGraphPriority {
14
+ regular = 'regular',
15
+ enhanced = 'enhanced',
16
+ }
17
+
18
+ export interface ObcIndicatorGraphLayout {
19
+ size?: ObcIndicatorGraphSize;
20
+ priority?: ObcIndicatorGraphPriority;
21
+ y?: {min?: number; max?: number};
22
+ }
23
+
24
+ /**
25
+ * @element obc-indicator-graph
26
+ * @description A mini graph component
27
+ *
28
+ * @property {Array} data - The data to display in the graph, first array is the x values, second array is the y values
29
+ */
30
+ @customElement('obc-indicator-graph')
31
+ export class ObcIndicatorGraph extends LitElement {
32
+ @property({type: Array})
33
+ data: [number[], number[]] = [[], []];
34
+
35
+ @property({type: Object})
36
+ layout: ObcIndicatorGraphLayout = {};
37
+
38
+ @query('.chart-container')
39
+ private chart!: HTMLDivElement;
40
+
41
+ @state()
42
+ private y: number = 24;
43
+
44
+ @state()
45
+ private zeroLineY: number = 0;
46
+
47
+ private uplot: uPlot | null = null;
48
+ private resizeObserver: ResizeObserver | null = null;
49
+
50
+ private getCssColor(name: string) {
51
+ const color = getComputedStyle(this).getPropertyValue(name).trim();
52
+ return color;
53
+ }
54
+
55
+ override firstUpdated() {
56
+ const opts = {
57
+ width: this.chart.clientWidth,
58
+ height: this.chart.clientHeight,
59
+ scales: {
60
+ x: {time: false, show: false},
61
+ y: {
62
+ auto: true,
63
+ show: false,
64
+ range: this._range.bind(this),
65
+ },
66
+ },
67
+ series: [
68
+ {},
69
+ {
70
+ stroke: this._getStrokeColor(),
71
+ width: this._getStrokeWidth(),
72
+ points: {show: false},
73
+ },
74
+ ],
75
+ axes: [
76
+ {show: false},
77
+ {ticks: {show: false}, show: false, grid: {show: false}},
78
+ ],
79
+ legend: {show: false},
80
+ cursor: {show: false},
81
+ };
82
+
83
+ this.uplot = new uPlot(opts, this.data, this.chart);
84
+ requestAnimationFrame(() => this.updateY());
85
+
86
+ this.resizeObserver = new ResizeObserver(() => this.updateSize());
87
+ this.resizeObserver.observe(this.chart);
88
+ }
89
+
90
+ override disconnectedCallback() {
91
+ super.disconnectedCallback();
92
+ this.resizeObserver?.disconnect();
93
+ this.resizeObserver = null;
94
+ this.uplot?.destroy();
95
+ this.uplot = null;
96
+ }
97
+
98
+ private updateSize() {
99
+ if (!this.uplot) {
100
+ return;
101
+ }
102
+ this.uplot.setSize({
103
+ width: this.chart.clientWidth,
104
+ height: this.chart.clientHeight,
105
+ });
106
+ this.updateY();
107
+ }
108
+
109
+ private _range(
110
+ _self: uPlot,
111
+ initMin: number,
112
+ initMax: number,
113
+ _scaleKey: string
114
+ ): [number, number] {
115
+ const {min: minY, max: maxY} = this.layout.y ?? {};
116
+ const range = maxY ?? initMax - (minY ?? initMin);
117
+ let min = minY ?? initMin - range * 0.1;
118
+ if (minY === undefined) {
119
+ min = Math.min(0, min);
120
+ }
121
+ return [min, maxY ?? initMax + range * 0.1] as [number, number];
122
+ }
123
+
124
+ private get _effectiveSize() {
125
+ return this.layout.size ?? ObcIndicatorGraphSize.medium;
126
+ }
127
+
128
+ private get _effectivePriority() {
129
+ return this.layout.priority ?? ObcIndicatorGraphPriority.regular;
130
+ }
131
+
132
+ private _getStrokeWidth() {
133
+ switch (this._effectiveSize) {
134
+ case ObcIndicatorGraphSize.small:
135
+ return 1;
136
+ case ObcIndicatorGraphSize.medium:
137
+ return 1.5;
138
+ case ObcIndicatorGraphSize.large:
139
+ return 2;
140
+ }
141
+ }
142
+
143
+ private _getStrokeColor() {
144
+ switch (this._effectivePriority) {
145
+ case ObcIndicatorGraphPriority.regular:
146
+ return this.getCssColor('--element-neutral-color');
147
+ case ObcIndicatorGraphPriority.enhanced:
148
+ return this.getCssColor('--element-neutral-enhanced-color');
149
+ }
150
+ }
151
+
152
+ updatePalette() {
153
+ if (!this.uplot) {
154
+ return;
155
+ }
156
+ const stroke = this._getStrokeColor();
157
+ this.uplot.setSeries(1, {
158
+ // @ts-expect-error - stroke is not a property of the Series interface
159
+ stroke: stroke,
160
+ width: this._getStrokeWidth(),
161
+ points: {show: false},
162
+ });
163
+ }
164
+
165
+ private updateY() {
166
+ if (!this.uplot) {
167
+ return;
168
+ }
169
+ const lastY = this.data[1][this.data[1].length - 1];
170
+ // @ts-expect-error - valToPct is not a property of the Scale interface
171
+ const yRatio = this.uplot.scales.y.valToPct(lastY);
172
+ this.y = yRatio * this.chart.clientHeight;
173
+ this.updateZeroLine();
174
+ }
175
+
176
+ private updateZeroLine() {
177
+ if (!this.uplot) {
178
+ return;
179
+ }
180
+ // @ts-expect-error - valToPct is not a property of the Scale interface
181
+ const yRatio = this.uplot.scales.y.valToPct(0);
182
+ this.zeroLineY = yRatio * this.chart.clientHeight;
183
+ }
184
+
185
+ override updated(changedProperties: PropertyValues) {
186
+ if (changedProperties.has('data') || changedProperties.has('layout')) {
187
+ this.updatePalette();
188
+ this.uplot?.setData(this.data);
189
+ requestAnimationFrame(() => this.updateY());
190
+ }
191
+ }
192
+
193
+ override render() {
194
+ return html`
195
+ <div
196
+ class="chart-container ${this._effectivePriority} ${this
197
+ ._effectiveSize}"
198
+ >
199
+ <div
200
+ id="zero-line"
201
+ style="transform: translateY(${-this.zeroLineY}px);
202
+ display: ${this.zeroLineY > -0.5 ? 'block' : 'none'};
203
+ "
204
+ ></div>
205
+ <div
206
+ id="dot"
207
+ style="transform: translateY(${-this.y}px);
208
+ display: ${this.y > -0.5 ? 'block' : 'none'};
209
+ "
210
+ ></div>
211
+ </div>
212
+ `;
213
+ }
214
+
215
+ static override styles = unsafeCSS(compentStyle);
216
+ }
217
+
218
+ declare global {
219
+ interface HTMLElementTagNameMap {
220
+ 'obc-indicator-graph': ObcIndicatorGraph;
221
+ }
222
+ }