@ixfx/components 0.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.
Files changed (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/charts/frequency-histogram-plot.d.ts +33 -0
  4. package/dist/charts/frequency-histogram-plot.d.ts.map +1 -0
  5. package/dist/charts/frequency-histogram-plot.js +54 -0
  6. package/dist/charts/frequency-histogram-plot.js.map +1 -0
  7. package/dist/charts/histogram-vis.d.ts +57 -0
  8. package/dist/charts/histogram-vis.d.ts.map +1 -0
  9. package/dist/charts/histogram-vis.js +222 -0
  10. package/dist/charts/histogram-vis.js.map +1 -0
  11. package/dist/charts/plot.d.ts +128 -0
  12. package/dist/charts/plot.d.ts.map +1 -0
  13. package/dist/charts/plot.js +456 -0
  14. package/dist/charts/plot.js.map +1 -0
  15. package/dist/crumb-nav.d.ts +41 -0
  16. package/dist/crumb-nav.d.ts.map +1 -0
  17. package/dist/crumb-nav.js +198 -0
  18. package/dist/crumb-nav.js.map +1 -0
  19. package/dist/crumb-navigation.d.ts +30 -0
  20. package/dist/crumb-navigation.d.ts.map +1 -0
  21. package/dist/crumb-navigation.js +307 -0
  22. package/dist/crumb-navigation.js.map +1 -0
  23. package/dist/data-display.d.ts +15 -0
  24. package/dist/data-display.d.ts.map +1 -0
  25. package/dist/data-display.js +110 -0
  26. package/dist/data-display.js.map +1 -0
  27. package/dist/dial.d.ts +89 -0
  28. package/dist/dial.d.ts.map +1 -0
  29. package/dist/dial.js +506 -0
  30. package/dist/dial.js.map +1 -0
  31. package/dist/index.d.ts +11 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +13 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/my-element.d.ts +14 -0
  36. package/dist/my-element.d.ts.map +1 -0
  37. package/dist/my-element.js +44 -0
  38. package/dist/my-element.js.map +1 -0
  39. package/dist/selecthorizontal.d.ts +12 -0
  40. package/dist/selecthorizontal.d.ts.map +1 -0
  41. package/dist/selecthorizontal.js +46 -0
  42. package/dist/selecthorizontal.js.map +1 -0
  43. package/dist/split-layout/split-layout.d.ts +35 -0
  44. package/dist/split-layout/split-layout.d.ts.map +1 -0
  45. package/dist/split-layout/split-layout.js +220 -0
  46. package/dist/split-layout/split-layout.js.map +1 -0
  47. package/dist/svg-edit-label.d.ts +2 -0
  48. package/dist/svg-edit-label.d.ts.map +1 -0
  49. package/dist/svg-edit-label.js +110 -0
  50. package/dist/svg-edit-label.js.map +1 -0
  51. package/dist/tabs/tab-layout-item.d.ts +10 -0
  52. package/dist/tabs/tab-layout-item.d.ts.map +1 -0
  53. package/dist/tabs/tab-layout-item.js +20 -0
  54. package/dist/tabs/tab-layout-item.js.map +1 -0
  55. package/dist/tabs/tab-layout.d.ts +10 -0
  56. package/dist/tabs/tab-layout.d.ts.map +1 -0
  57. package/dist/tabs/tab-layout.js +25 -0
  58. package/dist/tabs/tab-layout.js.map +1 -0
  59. package/dist/tabs/tab-list-item.d.ts +18 -0
  60. package/dist/tabs/tab-list-item.d.ts.map +1 -0
  61. package/dist/tabs/tab-list-item.js +63 -0
  62. package/dist/tabs/tab-list-item.js.map +1 -0
  63. package/dist/tabs/tab-list.d.ts +21 -0
  64. package/dist/tabs/tab-list.d.ts.map +1 -0
  65. package/dist/tabs/tab-list.js +148 -0
  66. package/dist/tabs/tab-list.js.map +1 -0
  67. package/dist/tabs/tab-panel.d.ts +11 -0
  68. package/dist/tabs/tab-panel.d.ts.map +1 -0
  69. package/dist/tabs/tab-panel.js +30 -0
  70. package/dist/tabs/tab-panel.js.map +1 -0
  71. package/dist/tabs/tab-panels.d.ts +30 -0
  72. package/dist/tabs/tab-panels.d.ts.map +1 -0
  73. package/dist/tabs/tab-panels.js +80 -0
  74. package/dist/tabs/tab-panels.js.map +1 -0
  75. package/dist/util/circle-arc.d.ts +34 -0
  76. package/dist/util/circle-arc.d.ts.map +1 -0
  77. package/dist/util/circle-arc.js +77 -0
  78. package/dist/util/circle-arc.js.map +1 -0
  79. package/dist/util/compare.d.ts +53 -0
  80. package/dist/util/compare.d.ts.map +1 -0
  81. package/dist/util/compare.js +91 -0
  82. package/dist/util/compare.js.map +1 -0
  83. package/dist/util/content-editable.d.ts +2 -0
  84. package/dist/util/content-editable.d.ts.map +1 -0
  85. package/dist/util/content-editable.js +13 -0
  86. package/dist/util/content-editable.js.map +1 -0
  87. package/dist/util/drag-controller.d.ts +13 -0
  88. package/dist/util/drag-controller.d.ts.map +1 -0
  89. package/dist/util/drag-controller.js +21 -0
  90. package/dist/util/drag-controller.js.map +1 -0
  91. package/dist/util/key-value.d.ts +5 -0
  92. package/dist/util/key-value.d.ts.map +1 -0
  93. package/dist/util/key-value.js +30 -0
  94. package/dist/util/key-value.js.map +1 -0
  95. package/dist/util/primitive-types.d.ts +6 -0
  96. package/dist/util/primitive-types.d.ts.map +1 -0
  97. package/dist/util/primitive-types.js +2 -0
  98. package/dist/util/primitive-types.js.map +1 -0
  99. package/dist/util/svg-editable-text.d.ts +22 -0
  100. package/dist/util/svg-editable-text.d.ts.map +1 -0
  101. package/dist/util/svg-editable-text.js +121 -0
  102. package/dist/util/svg-editable-text.js.map +1 -0
  103. package/dist/util/time.d.ts +2 -0
  104. package/dist/util/time.d.ts.map +1 -0
  105. package/dist/util/time.js +2 -0
  106. package/dist/util/time.js.map +1 -0
  107. package/package.json +48 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 CH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # components
2
+
@@ -0,0 +1,33 @@
1
+ import type { HistogramVis } from "./histogram-vis.js";
2
+ /**
3
+ * Creates and drives a HistogramVis instance.
4
+ * Data should be an outer array containing two-element arrays for each
5
+ * data point. The first element of the inner array is expected to be the key, the second the frequency.
6
+ * For example, `[`apples`, 2]` means the key `apples` was counted twice.
7
+ *
8
+ * Usage:
9
+ * .sortBy() automatically sorts prior to visualisation. By default off.
10
+ * .update(data) full set of data to plot
11
+ * .clear() empties plot - same as calling `update([])`
12
+ * .el - The `HistogramVis` instance, or undefined if not created/disposed
13
+ *
14
+ * ```
15
+ * const plot = new FrequencyHistogramPlot(document.getElementById('histogram'));
16
+ * plot.sortBy('key'); // Automatically sort by key
17
+ * ...
18
+ * plot.update([[`apples`, 2], [`oranges', 0], [`bananas`, 5]])
19
+ * ```
20
+ *
21
+ * @export
22
+ * @class FrequencyHistogramPlot
23
+ */
24
+ export declare class FrequencyHistogramPlot {
25
+ #private;
26
+ readonly el: HistogramVis | undefined;
27
+ constructor(el: HistogramVis);
28
+ setAutoSort(sortStyle: `value` | `value-reverse` | `key` | `key-reverse`): void;
29
+ clear(): void;
30
+ dispose(): void;
31
+ update(data: readonly (readonly [key: string, count: number])[]): void;
32
+ }
33
+ //# sourceMappingURL=frequency-histogram-plot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frequency-histogram-plot.d.ts","sourceRoot":"","sources":["../../src/charts/frequency-histogram-plot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,sBAAsB;;IAClC,QAAQ,CAAC,EAAE,EAAE,YAAY,GAAG,SAAS,CAAC;gBAE1B,EAAE,EAAE,YAAY;IAI5B,WAAW,CACV,SAAS,EAAE,OAAO,GAAG,eAAe,GAAG,KAAK,GAAG,aAAa,GAC1D,IAAI;IAIP,KAAK;IAKL,OAAO;IAMP,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE;CAW/D"}
@@ -0,0 +1,54 @@
1
+ import { getSorter } from "../util/key-value.js";
2
+ /**
3
+ * Creates and drives a HistogramVis instance.
4
+ * Data should be an outer array containing two-element arrays for each
5
+ * data point. The first element of the inner array is expected to be the key, the second the frequency.
6
+ * For example, `[`apples`, 2]` means the key `apples` was counted twice.
7
+ *
8
+ * Usage:
9
+ * .sortBy() automatically sorts prior to visualisation. By default off.
10
+ * .update(data) full set of data to plot
11
+ * .clear() empties plot - same as calling `update([])`
12
+ * .el - The `HistogramVis` instance, or undefined if not created/disposed
13
+ *
14
+ * ```
15
+ * const plot = new FrequencyHistogramPlot(document.getElementById('histogram'));
16
+ * plot.sortBy('key'); // Automatically sort by key
17
+ * ...
18
+ * plot.update([[`apples`, 2], [`oranges', 0], [`bananas`, 5]])
19
+ * ```
20
+ *
21
+ * @export
22
+ * @class FrequencyHistogramPlot
23
+ */
24
+ export class FrequencyHistogramPlot {
25
+ #sorter;
26
+ constructor(el) {
27
+ this.el = el;
28
+ }
29
+ setAutoSort(sortStyle) {
30
+ this.#sorter = getSorter(sortStyle);
31
+ }
32
+ clear() {
33
+ if (this.el === undefined)
34
+ return;
35
+ this.el.data = [];
36
+ }
37
+ dispose() {
38
+ const el = this.el;
39
+ if (el === undefined)
40
+ return; // already disposed
41
+ el.remove();
42
+ }
43
+ update(data) {
44
+ if (this.el === undefined) {
45
+ console.warn(`FrequencyHistogramPlot this.el undefined`);
46
+ return;
47
+ }
48
+ this.el.data =
49
+ this.#sorter === undefined
50
+ ? [...data]
51
+ : this.#sorter(data);
52
+ }
53
+ }
54
+ //# sourceMappingURL=frequency-histogram-plot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frequency-histogram-plot.js","sourceRoot":"","sources":["../../src/charts/frequency-histogram-plot.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,SAAS,EAAC,MAAM,sBAAsB,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,sBAAsB;IAElC,OAAO,CAA6B;IACpC,YAAY,EAAgB;QAC3B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACd,CAAC;IAED,WAAW,CACV,SAA4D;QAE5D,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC;IAED,KAAK;QACJ,IAAI,IAAI,CAAC,EAAE,KAAK,SAAS;YAAE,OAAO;QAClC,IAAI,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC;IACnB,CAAC;IAED,OAAO;QACN,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QACnB,IAAI,EAAE,KAAK,SAAS;YAAE,OAAO,CAAC,mBAAmB;QACjD,EAAE,CAAC,MAAM,EAAE,CAAC;IACb,CAAC;IAED,MAAM,CAAC,IAAwD;QAC9D,IAAI,IAAI,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;YACzD,OAAO;QACR,CAAC;QAED,IAAI,CAAC,EAAE,CAAC,IAAI;YACX,IAAI,CAAC,OAAO,KAAK,SAAS;gBACzB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;gBACX,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;CACD"}
@@ -0,0 +1,57 @@
1
+ import { LitElement } from "lit";
2
+ import { type KeyValue } from "../util/primitive-types.js";
3
+ type Bar = {
4
+ readonly percentage: number;
5
+ readonly data: KeyValue;
6
+ };
7
+ /**
8
+ * Usage in HTML:
9
+ * ```html
10
+ * <style>
11
+ * histogram-vis {
12
+ * display: block;
13
+ * height: 7em;
14
+ * --histogram-bar-color: pink;
15
+ * }
16
+ * </style>
17
+ * <histogram-vis>
18
+ * [
19
+ * ["apples", 5],
20
+ * ["oranges", 3],
21
+ * ["pineapple", 0],
22
+ * ["limes", 9]
23
+ * ]
24
+ * </histogram-vis>
25
+ * ```
26
+ *
27
+ * CSS colour theming:
28
+ * --histogram-bar-color
29
+ * --histogram-label-color
30
+ *
31
+ * HTML tag attributes
32
+ * showXAxis (boolean)
33
+ * showDataLabels (boolean)
34
+ *
35
+ * @export
36
+ * @class HistogramVis
37
+ * @extends {LitElement}
38
+ **/
39
+ export declare class HistogramVis extends LitElement {
40
+ static readonly styles: import("lit").CSSResult;
41
+ data: readonly KeyValue[];
42
+ showDataLabels: boolean;
43
+ height: string;
44
+ showXAxis: boolean;
45
+ json: readonly KeyValue[] | undefined;
46
+ constructor();
47
+ connectedCallback(): void;
48
+ barTemplate(bar: Bar, index: number, _totalBars: number): import("lit-html").TemplateResult<1>;
49
+ render(): import("lit-html").TemplateResult<1>;
50
+ }
51
+ declare global {
52
+ interface HTMLElementTagNameMap {
53
+ readonly "histogram-vis": HistogramVis;
54
+ }
55
+ }
56
+ export {};
57
+ //# sourceMappingURL=histogram-vis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"histogram-vis.d.ts","sourceRoot":"","sources":["../../src/charts/histogram-vis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAI5C,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE3D,KAAK,GAAG,GAAG;IACV,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;CACxB,CAAC;AA+CF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA+BI;AACJ,qBACa,YAAa,SAAQ,UAAU;IAC3C,MAAM,CAAC,QAAQ,CAAC,MAAM,0BA2CnB;IAGK,IAAI,EAAE,SAAS,QAAQ,EAAE,CAAC;IAG1B,cAAc,EAAE,OAAO,CAAC;IAGxB,MAAM,EAAE,MAAM,CAAC;IAGf,SAAS,EAAE,OAAO,CAAC;IAGnB,IAAI,EAAE,SAAS,QAAQ,EAAE,GAAG,SAAS,CAAC;;IAW9C,iBAAiB;IAOjB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IA+BvD,MAAM;CAyCN;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,QAAQ,CAAC,eAAe,EAAE,YAAY,CAAC;KACvC;CACD"}
@@ -0,0 +1,222 @@
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
+ import { LitElement, css, html } from "lit";
8
+ import { customElement } from "lit/decorators/custom-element.js";
9
+ import { property } from "lit/decorators/property.js";
10
+ import { repeat } from "lit/directives/repeat.js";
11
+ import {} from "../util/primitive-types.js";
12
+ const jsonData = (object) => {
13
+ if (object === null || object === undefined || object === `undefined`)
14
+ return;
15
+ try {
16
+ if (typeof object === `string`) {
17
+ if (object.length === 0)
18
+ return;
19
+ const o = JSON.parse(object);
20
+ if (!Array.isArray(o)) {
21
+ console.error(`Histogram innerText should be JSON array`);
22
+ return;
23
+ }
24
+ for (const [index, element] of o.entries()) {
25
+ if (!Array.isArray(element)) {
26
+ console.error(`Histogram array should consist of inner arrays`);
27
+ return;
28
+ }
29
+ if (element.length !== 2) {
30
+ console.error(`Histogram inner arrays should consist of two elements`);
31
+ return;
32
+ }
33
+ if (typeof element[0] !== `string`) {
34
+ console.error(`First element of inner array should be a string (index ${index})`);
35
+ return;
36
+ }
37
+ if (typeof element[1] !== `number`) {
38
+ console.error(`Second element of inner array should be a number (index ${index})`);
39
+ return;
40
+ }
41
+ }
42
+ return o;
43
+ }
44
+ }
45
+ catch (error) {
46
+ console.log(object);
47
+ console.error(error);
48
+ }
49
+ return;
50
+ };
51
+ /**
52
+ * Usage in HTML:
53
+ * ```html
54
+ * <style>
55
+ * histogram-vis {
56
+ * display: block;
57
+ * height: 7em;
58
+ * --histogram-bar-color: pink;
59
+ * }
60
+ * </style>
61
+ * <histogram-vis>
62
+ * [
63
+ * ["apples", 5],
64
+ * ["oranges", 3],
65
+ * ["pineapple", 0],
66
+ * ["limes", 9]
67
+ * ]
68
+ * </histogram-vis>
69
+ * ```
70
+ *
71
+ * CSS colour theming:
72
+ * --histogram-bar-color
73
+ * --histogram-label-color
74
+ *
75
+ * HTML tag attributes
76
+ * showXAxis (boolean)
77
+ * showDataLabels (boolean)
78
+ *
79
+ * @export
80
+ * @class HistogramVis
81
+ * @extends {LitElement}
82
+ **/
83
+ let HistogramVis = class HistogramVis extends LitElement {
84
+ static { this.styles = css `
85
+ :host {
86
+ }
87
+ div.container {
88
+ display: flex;
89
+ flex-direction: column;
90
+ height: 100%;
91
+ }
92
+ div.chart {
93
+ display: grid;
94
+ flex: 1;
95
+ grid-template-rows: 1fr 1px min-content;
96
+ justify-items: center;
97
+ }
98
+ div.bar {
99
+ display: flex;
100
+ flex-direction: column-reverse;
101
+ align-items: center;
102
+ justify-self: normal;
103
+ padding-left: 0.3vw;
104
+ padding-right: 0.3vw;
105
+ }
106
+ div.bar > div.barTrack {
107
+ background-color: var(--histogram-bar-color, gray);
108
+ align-self: stretch;
109
+ }
110
+ div.xAxisLabels,
111
+ div.data {
112
+ font-size: min(1vw, 1em);
113
+ color: var(--histogram-label-color, currentColor);
114
+ }
115
+ div.xAxisLabels {
116
+ width: 100%;
117
+ text-overflow: ellipsis;
118
+ overflow: hidden;
119
+ white-space: nowrap;
120
+ text-align: center;
121
+ }
122
+ div.xAxis {
123
+ background-color: var(--histogram-axis-color, silver);
124
+ width: 100%;
125
+ height: 100%;
126
+ }
127
+ `; }
128
+ constructor() {
129
+ super();
130
+ this.data = [];
131
+ this.showDataLabels = true;
132
+ this.height = `100%`;
133
+ this.showXAxis = true;
134
+ this.json = undefined;
135
+ }
136
+ connectedCallback() {
137
+ if (!this.hasAttribute(`json`)) {
138
+ this.setAttribute(`json`, this.innerText);
139
+ }
140
+ super.connectedCallback();
141
+ }
142
+ barTemplate(bar, index, _totalBars) {
143
+ const { percentage } = bar;
144
+ const [key, freq] = bar.data;
145
+ // grid-area: rowStart / gridColStart / gridRowEnd / gridColEnd
146
+ const rowStart = 1;
147
+ const rowEnd = 2;
148
+ const colStart = index + 1;
149
+ const colEnd = colStart + 1;
150
+ const dataLabel = html `<div class="data">${freq}</div>`;
151
+ const xAxis = html `${key}`;
152
+ return html `
153
+ <div
154
+ class="bar"
155
+ style="grid-area: ${rowStart} / ${colStart} / ${rowEnd} / ${colEnd}"
156
+ >
157
+ <div class="barTrack" style="height: ${(percentage ?? 0) * 100}%"></div>
158
+ ${this.showDataLabels ? dataLabel : ``}
159
+ </div>
160
+ <div
161
+ class="xAxisLabels"
162
+ style="grid-area: ${rowStart + 2} / ${colStart} / ${rowEnd + 2} / ${colEnd}"
163
+ >
164
+ ${this.showXAxis ? xAxis : ``}
165
+ </div>
166
+ `;
167
+ }
168
+ render() {
169
+ if ((this.data === undefined || this.data.length === 0) &&
170
+ this.json === undefined) {
171
+ return html ``;
172
+ }
173
+ const d = this.data ?? this.json;
174
+ const length = d.length;
175
+ const highestCount = Math.max(...d.map((d) => d[1]));
176
+ const bars = d.map((kv) => ({
177
+ data: kv,
178
+ percentage: kv[1] / highestCount,
179
+ }));
180
+ const xAxis = html `
181
+ <div
182
+ class="xAxis"
183
+ style="grid-area: 2 / 1 / 3 / ${d.length + 1}"
184
+ ></div>
185
+ `;
186
+ const height = this.height ? `height: ${this.height};` : ``;
187
+ const h = html `
188
+ <style>
189
+ div.chart {
190
+ grid-template-columns: repeat(${d.length}, minmax(2px, 1fr));
191
+ }
192
+ </style>
193
+ <div class="container" style="${height}">
194
+ <div class="chart">
195
+ ${repeat(bars, (bar) => bar.data[0], (b, index) => this.barTemplate(b, index, length))}
196
+ ${this.showXAxis ? xAxis : ``}
197
+ </div>
198
+ </div>
199
+ `;
200
+ return h;
201
+ }
202
+ };
203
+ __decorate([
204
+ property()
205
+ ], HistogramVis.prototype, "data", void 0);
206
+ __decorate([
207
+ property()
208
+ ], HistogramVis.prototype, "showDataLabels", void 0);
209
+ __decorate([
210
+ property()
211
+ ], HistogramVis.prototype, "height", void 0);
212
+ __decorate([
213
+ property()
214
+ ], HistogramVis.prototype, "showXAxis", void 0);
215
+ __decorate([
216
+ property({ converter: jsonData, type: Object })
217
+ ], HistogramVis.prototype, "json", void 0);
218
+ HistogramVis = __decorate([
219
+ customElement(`histogram-vis`)
220
+ ], HistogramVis);
221
+ export { HistogramVis };
222
+ //# sourceMappingURL=histogram-vis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"histogram-vis.js","sourceRoot":"","sources":["../../src/charts/histogram-vis.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,aAAa,EAA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CAAC,CAAY,GAAG,YAAY;SAC5C,CAAC,CAAC,CAAC;QAEJ,MAAM,KAAK,GAAG,IAAI,CAAA;;;4CAGwB,CAAC,CAAC,MAAM,GAAG,CAAC;;KAEnD,CAAC;QACJ,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5D,MAAM,CAAC,GAAG,IAAI,CAAA;;;+CAG+B,CAAC,CAAC,MAAM;;;2CAGZ,MAAM;;iBAEhC,MAAM,CACd,IAAI,EACJ,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EACpB,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAChD;iBACQ,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;;;KAGvC,CAAC;QACJ,OAAO,CAAC,CAAC;IACV,CAAC;;AArGO;IADP,QAAQ,EAAE;0CACuB;AAG1B;IADP,QAAQ,EAAE;oDACqB;AAGxB;IADP,QAAQ,EAAE;4CACY;AAGf;IADP,QAAQ,EAAE;+CACgB;AAGnB;IADP,QAAQ,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;0CACF;AA3DlC,YAAY;IADxB,aAAa,CAAC,eAAe,CAAC;GAClB,YAAY,CAqJxB"}
@@ -0,0 +1,128 @@
1
+ import { LitElement, type PropertyValues } from "lit";
2
+ import { type Ref } from "lit/directives/ref.js";
3
+ import { CanvasHelper } from "@ixfx/visual";
4
+ import type { Rect, RectPositioned } from "@ixfx/geometry/rect";
5
+ import { Drawing } from "@ixfx/visual";
6
+ import type { Colourish } from "@ixfx/visual/colour";
7
+ /**
8
+ * Attributes
9
+ * * streaming: true/false (default: true)
10
+ * * max-length: number (default: 500). How many data points per series to store
11
+ * * data-width: when streaming, how much horizontal width per point
12
+ * * fixed-max/fixed-min: global input scaling (default: NaN, ie. disabled)
13
+ *
14
+ * * line-width: stroke width of drawing line (default:2)
15
+ *
16
+ * * render: 'dot' or 'line' (default: 'dot')
17
+ * * hide-legend: If added, legend is not shown
18
+ * * manual-draw: If added, automatic drawning is disabled
19
+ *
20
+ * Styling variables
21
+ * * --legend-fg: legend foreground text
22
+ */
23
+ export declare class PlotElement extends LitElement {
24
+ #private;
25
+ streaming: boolean;
26
+ hideLegend: boolean;
27
+ maxLength: number;
28
+ dataWidth: number;
29
+ fixedMax: number;
30
+ fixedMin: number;
31
+ lineWidth: number;
32
+ renderStyle: string;
33
+ manualDraw: boolean;
34
+ padding: number;
35
+ paused: boolean;
36
+ canvasEl: Ref<HTMLCanvasElement>;
37
+ seriesRanges: Map<string, [min: number, max: number]>;
38
+ get series(): PlotSeries[];
39
+ get seriesCount(): number;
40
+ /**
41
+ * Returns a `PlotElement` instance based on a query
42
+ * ```js
43
+ * PlotElement.fromQuery(`#someplot`); // PlotElement
44
+ * ```
45
+ *
46
+ * Throws an error if query does not match.
47
+ * @param query
48
+ * @returns
49
+ */
50
+ static fromQuery(query: string): PlotElement;
51
+ /**
52
+ * Delete a series.
53
+ * Returns _true_ if there was a series to delete
54
+ * @param name
55
+ * @returns
56
+ */
57
+ deleteSeries(name: string): boolean;
58
+ /**
59
+ * Keeps the series, but deletes its data
60
+ * @param name
61
+ * @returns
62
+ */
63
+ clearSeries(name: string): boolean;
64
+ /**
65
+ * Delete all data & series
66
+ */
67
+ clear(): void;
68
+ /**
69
+ * Keeps all series, but deletes their data
70
+ */
71
+ clearData(): void;
72
+ render(): import("lit-html").TemplateResult<1>;
73
+ connectedCallback(): void;
74
+ protected firstUpdated(_changedProperties: PropertyValues): void;
75
+ updateColours(): void;
76
+ plot(value: number, seriesName?: string, skipDrawing?: boolean): PlotSeries;
77
+ /**
78
+ * Draw a set of key-value pairs as a batch.
79
+ * @param value
80
+ */
81
+ plotObject(value: object): void;
82
+ colourGenerator(_series: string): Colourish;
83
+ draw(): void;
84
+ drawLegend(cl: RectPositioned, d: Drawing.DrawingHelper): void;
85
+ drawLineSeries(data: number[], cp: Rect, d: Drawing.DrawingHelper, colour: string): void;
86
+ drawDotSeries(data: number[], cp: Rect, d: Drawing.DrawingHelper, colour: string): void;
87
+ computePlot(c: CanvasHelper, plotHeight: number, axisYwidth: number, padding: number): {
88
+ x: number;
89
+ y: number;
90
+ width: number;
91
+ height: number;
92
+ };
93
+ computeAxisYWidth(_c: CanvasHelper): number;
94
+ computeLegend(c: CanvasHelper, maxWidth: number, padding: number): {
95
+ bounds: {
96
+ width: number;
97
+ height: number;
98
+ };
99
+ parts: {
100
+ width: number;
101
+ height: number;
102
+ x: number;
103
+ y: number;
104
+ }[];
105
+ };
106
+ getSeries(name: string): PlotSeries | undefined;
107
+ static styles: import("lit").CSSResult;
108
+ }
109
+ export declare class PlotSeries {
110
+ name: string;
111
+ colour: Colourish;
112
+ private plot;
113
+ data: number[];
114
+ minSeen: number;
115
+ maxSeen: number;
116
+ constructor(name: string, colour: Colourish, plot: PlotElement);
117
+ clear(): void;
118
+ /**
119
+ * Returns a copy of the data scaled by the current
120
+ * range of the data
121
+ * @returns
122
+ */
123
+ getScaled(): number[];
124
+ getScaledBy(scaler: (v: number) => number): number[];
125
+ push(value: number): void;
126
+ resetScale(): void;
127
+ }
128
+ //# sourceMappingURL=plot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plot.d.ts","sourceRoot":"","sources":["../../src/charts/plot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAGjE,OAAO,EAAa,KAAK,GAAG,EAAO,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE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