@operato/chart 10.29.81 → 10.29.84
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/src/report/chart-math.d.ts +34 -0
- package/dist/src/report/chart-math.js +71 -0
- package/dist/src/report/report-charts.d.ts +118 -0
- package/dist/src/report/report-charts.js +573 -0
- package/dist/stories/common.d.ts +8 -0
- package/dist/stories/common.js +78 -0
- package/dist/stories/ox-chart-annotations.stories.d.ts +26 -0
- package/dist/stories/ox-chart-annotations.stories.js +267 -0
- package/dist/stories/ox-input-chart-bar.stories.d.ts +26 -0
- package/dist/stories/ox-input-chart-bar.stories.js +173 -0
- package/dist/stories/ox-input-chart-doughnut.stories.d.ts +28 -0
- package/dist/stories/ox-input-chart-doughnut.stories.js +115 -0
- package/dist/stories/ox-input-chart-hbar.stories.d.ts +26 -0
- package/dist/stories/ox-input-chart-hbar.stories.js +174 -0
- package/dist/stories/ox-input-chart-line.stories.d.ts +26 -0
- package/dist/stories/ox-input-chart-line.stories.js +184 -0
- package/dist/stories/ox-input-chart-pie.stories.d.ts +28 -0
- package/dist/stories/ox-input-chart-pie.stories.js +115 -0
- package/dist/stories/ox-input-chart-polar-area.stories.d.ts +28 -0
- package/dist/stories/ox-input-chart-polar-area.stories.js +115 -0
- package/dist/stories/ox-input-chart-radar.stories.d.ts +28 -0
- package/dist/stories/ox-input-chart-radar.stories.js +126 -0
- package/dist/stories/ox-input-chart-timeseries.stories.d.ts +27 -0
- package/dist/stories/ox-input-chart-timeseries.stories.js +281 -0
- package/package.json +31 -7
- package/CHANGELOG.md +0 -2823
- package/dist/src/chartjs/config-converter.js.map +0 -1
- package/dist/src/chartjs/ox-chart-js.js.map +0 -1
- package/dist/src/editors/configurer.js.map +0 -1
- package/dist/src/editors/index.js.map +0 -1
- package/dist/src/editors/input-chart-abstract.js.map +0 -1
- package/dist/src/editors/input-chart-styles.js.map +0 -1
- package/dist/src/editors/ox-input-chart-hbar.js.map +0 -1
- package/dist/src/editors/ox-input-chart-mixed.js.map +0 -1
- package/dist/src/editors/ox-input-chart-pie.js.map +0 -1
- package/dist/src/editors/ox-input-chart-radar.js.map +0 -1
- package/dist/src/editors/ox-input-chart-timeseries.js.map +0 -1
- package/dist/src/editors/ox-property-editor-chart.js.map +0 -1
- package/dist/src/editors/templates/annotations.js.map +0 -1
- package/dist/src/editors/templates/display-value.js.map +0 -1
- package/dist/src/editors/templates/series.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/progress/ox-progress-circle.js.map +0 -1
- package/dist/src/scichart/ox-scichart.js.map +0 -1
- package/dist/src/scichart/scichart-builder.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { css, html, LitElement, nothing, svg } from 'lit';
|
|
3
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
|
4
|
+
import { arcPath, niceTicks, pieSlices, stackRanges } from './chart-math.js';
|
|
5
|
+
/*
|
|
6
|
+
* The charts of the report and status screens — light SVG drawn at the width they are given, in the theme's colours,
|
|
7
|
+
* for a document page: columns over categories, a ring of shares, a band over time, a whole on one line, and bars in a
|
|
8
|
+
* list. A categorical palette (colour-blind distinguishable, mid lightness so it reads on a light and a dark surface)
|
|
9
|
+
* marks series and slices; a caller may give a series its own colour.
|
|
10
|
+
*
|
|
11
|
+
* A chart given `scale` writes every number it draws in one unit, chosen from what it draws — the axis, the bars, the
|
|
12
|
+
* legend — so 「0.9억」 sits under 「4.6억」 (the application's money format makes the scale).
|
|
13
|
+
*
|
|
14
|
+
* Came from operato-office (client/charts) so every application draws the same charts (2026-11-14).
|
|
15
|
+
*/
|
|
16
|
+
const PALETTE = ['#4e79a7', '#f28e2b', '#59a14f', '#e15759', '#76b7b2', '#edc948', '#b07aa1', '#9c755f'];
|
|
17
|
+
/** 「기타」 — what the largest slices leave over; also the rest bars beside a donut. */
|
|
18
|
+
export const REST_COLOR = '#bab0ac';
|
|
19
|
+
export const colorAt = (index) => PALETTE[index % PALETTE.length];
|
|
20
|
+
/* A line over bars — a balance beside flows — in plain ink, apart from every bar colour. */
|
|
21
|
+
const LINE_COLOR = 'var(--ui-muted, var(--md-sys-color-on-surface-variant))';
|
|
22
|
+
const plain = (value) => Math.round(value).toLocaleString();
|
|
23
|
+
const chartStyles = css `
|
|
24
|
+
:host {
|
|
25
|
+
display: block;
|
|
26
|
+
color: var(--ui-muted, var(--md-sys-color-on-surface-variant));
|
|
27
|
+
font-size: var(--ui-t-micro, 11px);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
svg {
|
|
31
|
+
display: block;
|
|
32
|
+
overflow: visible;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.axis text,
|
|
36
|
+
text.axis {
|
|
37
|
+
fill: var(--ui-muted, var(--md-sys-color-on-surface-variant));
|
|
38
|
+
font-size: var(--ui-t-micro, 11px);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.grid line {
|
|
42
|
+
stroke: var(--ui-line-soft, var(--md-sys-color-outline-variant));
|
|
43
|
+
stroke-width: 1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.grid line.zero {
|
|
47
|
+
stroke: var(--ui-line, var(--md-sys-color-outline));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.legend {
|
|
51
|
+
display: flex;
|
|
52
|
+
flex-wrap: wrap;
|
|
53
|
+
gap: var(--spacing-small, 4px) var(--spacing-large, 12px);
|
|
54
|
+
margin-top: var(--spacing-medium, 8px);
|
|
55
|
+
font-size: var(--ui-t-small, 11.5px);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.swatch {
|
|
59
|
+
display: inline-block;
|
|
60
|
+
width: 10px;
|
|
61
|
+
height: 10px;
|
|
62
|
+
border-radius: var(--spacing-tiny, 2px);
|
|
63
|
+
margin-right: var(--spacing-small, 4px);
|
|
64
|
+
vertical-align: -1px;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.swatch.line {
|
|
68
|
+
height: 3px;
|
|
69
|
+
border-radius: var(--spacing-tiny, 2px);
|
|
70
|
+
vertical-align: 2px;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
[clickable] {
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
}
|
|
76
|
+
`;
|
|
77
|
+
/** Watches its own width so the SVG is drawn at pixel size — text keeps its size at any width. */
|
|
78
|
+
class SizedChart extends LitElement {
|
|
79
|
+
constructor() {
|
|
80
|
+
super(...arguments);
|
|
81
|
+
this.width = 0;
|
|
82
|
+
}
|
|
83
|
+
connectedCallback() {
|
|
84
|
+
super.connectedCallback();
|
|
85
|
+
this.observer = new ResizeObserver(entries => {
|
|
86
|
+
const width = Math.floor(entries[0]?.contentRect.width ?? 0);
|
|
87
|
+
if (width && width !== this.width)
|
|
88
|
+
this.width = width;
|
|
89
|
+
});
|
|
90
|
+
this.observer.observe(this);
|
|
91
|
+
}
|
|
92
|
+
disconnectedCallback() {
|
|
93
|
+
this.observer?.disconnect();
|
|
94
|
+
super.disconnectedCallback();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
__decorate([
|
|
98
|
+
state()
|
|
99
|
+
], SizedChart.prototype, "width", void 0);
|
|
100
|
+
/**
|
|
101
|
+
* Columns over categories (months, years, departments) — grouped side by side, or stacked; a line
|
|
102
|
+
* series is drawn over them on the same axis. `pick` tells which category was clicked.
|
|
103
|
+
*/
|
|
104
|
+
let OxColumnChart = class OxColumnChart extends SizedChart {
|
|
105
|
+
constructor() {
|
|
106
|
+
super(...arguments);
|
|
107
|
+
this.labels = [];
|
|
108
|
+
this.series = [];
|
|
109
|
+
this.stacked = false;
|
|
110
|
+
this.height = 220;
|
|
111
|
+
this.format = plain;
|
|
112
|
+
this.scale = null;
|
|
113
|
+
/** The whole value for a tooltip — `won` beside a money scale, so 「3.6억」 can be read as every won on hover. */
|
|
114
|
+
this.exact = null;
|
|
115
|
+
this.pickable = false;
|
|
116
|
+
}
|
|
117
|
+
static { this.styles = chartStyles; }
|
|
118
|
+
render() {
|
|
119
|
+
const width = this.width;
|
|
120
|
+
if (!width || !this.labels.length)
|
|
121
|
+
return html `<div style="height:${this.height}px"></div>`;
|
|
122
|
+
const bars = this.series.filter(one => (one.type ?? 'bar') === 'bar');
|
|
123
|
+
const lines = this.series.filter(one => one.type === 'line');
|
|
124
|
+
const ranges = this.stacked ? stackRanges(bars.map(one => one.values.map(value => value ?? 0))) : null;
|
|
125
|
+
const extent = [
|
|
126
|
+
...(ranges ? ranges.flat().flatMap(one => [one.from, one.to]) : bars.flatMap(one => one.values.map(value => value ?? 0))),
|
|
127
|
+
...lines.flatMap(one => one.values.filter((value) => value !== null))
|
|
128
|
+
];
|
|
129
|
+
const ticks = niceTicks(Math.min(0, ...extent), Math.max(0, ...extent), 4);
|
|
130
|
+
const [lo, hi] = [ticks[0], ticks[ticks.length - 1]];
|
|
131
|
+
const format = this.scale ? this.scale([...ticks, ...extent]) : this.format;
|
|
132
|
+
const left = Math.max(...ticks.map(one => format(one).length)) * 6 + 10;
|
|
133
|
+
const [top, bottom, right] = [8, 22, 6];
|
|
134
|
+
const plotW = Math.max(10, width - left - right);
|
|
135
|
+
const plotH = this.height - top - bottom;
|
|
136
|
+
const y = (value) => top + plotH - ((value - lo) / (hi - lo || 1)) * plotH;
|
|
137
|
+
const band = plotW / this.labels.length;
|
|
138
|
+
const every = Math.max(1, Math.ceil(46 / band));
|
|
139
|
+
const groupW = band * 0.72;
|
|
140
|
+
const barW = this.stacked || !bars.length ? groupW : groupW / bars.length;
|
|
141
|
+
const x0 = (at) => left + at * band + (band - groupW) / 2;
|
|
142
|
+
const pick = (at) => this.pickable && this.dispatchEvent(new CustomEvent('pick', { detail: { index: at, label: this.labels[at] } }));
|
|
143
|
+
const barMarks = [];
|
|
144
|
+
bars.forEach((one, s) => {
|
|
145
|
+
const color = one.color ?? colorAt(this.series.indexOf(one));
|
|
146
|
+
this.labels.forEach((label, at) => {
|
|
147
|
+
const value = one.values[at];
|
|
148
|
+
if (value === null || value === undefined || value === 0)
|
|
149
|
+
return;
|
|
150
|
+
const range = ranges ? ranges[s][at] : { from: 0, to: value };
|
|
151
|
+
const [a, b] = [y(range.from), y(range.to)];
|
|
152
|
+
const bx = ranges ? x0(at) : x0(at) + s * barW;
|
|
153
|
+
barMarks.push(svg `<rect x=${bx} y=${Math.min(a, b)} width=${Math.max(1, barW - 1)} height=${Math.max(1, Math.abs(a - b))} rx="2" fill=${color} ?clickable=${this.pickable} @click=${() => pick(at)}><title>${label} · ${one.name}: ${(this.exact ?? format)(value)}</title></rect>`);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
const lineMarks = lines.map(one => {
|
|
157
|
+
const color = one.color ?? LINE_COLOR;
|
|
158
|
+
const points = one.values.map((value, at) => (value === null ? null : [left + at * band + band / 2, y(value)])).filter((p) => !!p);
|
|
159
|
+
return svg `<polyline points=${points.map(p => p.join(',')).join(' ')} fill="none" stroke=${color} stroke-width="2" />
|
|
160
|
+
${one.values.map((value, at) => (value === null ? nothing : svg `<circle cx=${left + at * band + band / 2} cy=${y(value)} r="3" fill=${color}><title>${this.labels[at]} · ${one.name}: ${(this.exact ?? format)(value)}</title></circle>`))}`;
|
|
161
|
+
});
|
|
162
|
+
return html `
|
|
163
|
+
<svg width=${width} height=${this.height} role="img">
|
|
164
|
+
<g class="grid">${ticks.map(tick => svg `<line class=${tick === 0 ? 'zero' : ''} x1=${left} x2=${left + plotW} y1=${y(tick)} y2=${y(tick)} />`)}</g>
|
|
165
|
+
<g class="axis">
|
|
166
|
+
${ticks.map(tick => svg `<text x=${left - 6} y=${y(tick) + 3} text-anchor="end">${format(tick)}</text>`)}
|
|
167
|
+
${this.labels.map((label, at) => (at % every ? nothing : svg `<text x=${left + at * band + band / 2} y=${this.height - 6} text-anchor="middle">${label}</text>`))}
|
|
168
|
+
</g>
|
|
169
|
+
${barMarks} ${lineMarks}
|
|
170
|
+
</svg>
|
|
171
|
+
${this.series.length > 1
|
|
172
|
+
? html `<div class="legend">
|
|
173
|
+
${this.series.map((one, s) => html `<span><span class="swatch ${one.type === 'line' ? 'line' : ''}" style="background:${one.color ?? (one.type === 'line' ? LINE_COLOR : colorAt(s))}"></span>${one.name}</span>`)}
|
|
174
|
+
</div>`
|
|
175
|
+
: nothing}
|
|
176
|
+
`;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
__decorate([
|
|
180
|
+
property({ type: Array })
|
|
181
|
+
], OxColumnChart.prototype, "labels", void 0);
|
|
182
|
+
__decorate([
|
|
183
|
+
property({ type: Array })
|
|
184
|
+
], OxColumnChart.prototype, "series", void 0);
|
|
185
|
+
__decorate([
|
|
186
|
+
property({ type: Boolean })
|
|
187
|
+
], OxColumnChart.prototype, "stacked", void 0);
|
|
188
|
+
__decorate([
|
|
189
|
+
property({ type: Number })
|
|
190
|
+
], OxColumnChart.prototype, "height", void 0);
|
|
191
|
+
__decorate([
|
|
192
|
+
property({ attribute: false })
|
|
193
|
+
], OxColumnChart.prototype, "format", void 0);
|
|
194
|
+
__decorate([
|
|
195
|
+
property({ attribute: false })
|
|
196
|
+
], OxColumnChart.prototype, "scale", void 0);
|
|
197
|
+
__decorate([
|
|
198
|
+
property({ attribute: false })
|
|
199
|
+
], OxColumnChart.prototype, "exact", void 0);
|
|
200
|
+
__decorate([
|
|
201
|
+
property({ type: Boolean })
|
|
202
|
+
], OxColumnChart.prototype, "pickable", void 0);
|
|
203
|
+
OxColumnChart = __decorate([
|
|
204
|
+
customElement('ox-column-chart')
|
|
205
|
+
], OxColumnChart);
|
|
206
|
+
export { OxColumnChart };
|
|
207
|
+
/**
|
|
208
|
+
* A ring of shares — parts of one whole, the largest few and 「기타」, with a legend giving each
|
|
209
|
+
* amount and share. `pick` tells which slice was clicked (not the 「기타」 one).
|
|
210
|
+
*/
|
|
211
|
+
let OxDonutChart = class OxDonutChart extends SizedChart {
|
|
212
|
+
constructor() {
|
|
213
|
+
super(...arguments);
|
|
214
|
+
this.items = [];
|
|
215
|
+
this.keep = 6;
|
|
216
|
+
this.size = 170;
|
|
217
|
+
/** The name of the slice that folds the rest - the caller's word for it, such as 「기타」. */
|
|
218
|
+
this.restLabel = 'Other';
|
|
219
|
+
this.centerLabel = '';
|
|
220
|
+
this.format = plain;
|
|
221
|
+
this.scale = null;
|
|
222
|
+
/** The whole value for a tooltip — `won` beside a money scale, so 「3.6억」 can be read as every won on hover. */
|
|
223
|
+
this.exact = null;
|
|
224
|
+
this.pickable = false;
|
|
225
|
+
}
|
|
226
|
+
static { this.styles = [
|
|
227
|
+
chartStyles,
|
|
228
|
+
css `
|
|
229
|
+
.wrap {
|
|
230
|
+
display: flex;
|
|
231
|
+
flex-wrap: wrap;
|
|
232
|
+
align-items: center;
|
|
233
|
+
gap: var(--spacing-large, 12px) var(--spacing-huge, 24px);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.center-value {
|
|
237
|
+
fill: var(--ui-ink, var(--md-sys-color-on-surface));
|
|
238
|
+
font-size: var(--ui-t-body, 13px);
|
|
239
|
+
font-weight: 600;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
table {
|
|
243
|
+
border-collapse: collapse;
|
|
244
|
+
font-size: var(--ui-t-small, 11.5px);
|
|
245
|
+
font-variant-numeric: tabular-nums;
|
|
246
|
+
flex: 1 1 200px;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
td {
|
|
250
|
+
padding: var(--spacing-tiny, 2px) var(--spacing-small, 4px);
|
|
251
|
+
white-space: nowrap;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
td.label {
|
|
255
|
+
max-width: 180px;
|
|
256
|
+
overflow: hidden;
|
|
257
|
+
text-overflow: ellipsis;
|
|
258
|
+
color: var(--ui-ink, var(--md-sys-color-on-surface));
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
td.num {
|
|
262
|
+
text-align: right;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
tr[clickable]:hover td {
|
|
266
|
+
background: var(--ui-hover, var(--md-sys-color-surface-container-high));
|
|
267
|
+
}
|
|
268
|
+
`
|
|
269
|
+
]; }
|
|
270
|
+
render() {
|
|
271
|
+
const slices = pieSlices(this.items, this.keep, this.restLabel);
|
|
272
|
+
if (!slices.length)
|
|
273
|
+
return nothing;
|
|
274
|
+
const total = slices.reduce((sum, one) => sum + one.value, 0);
|
|
275
|
+
const format = this.scale ? this.scale([total, ...slices.map(one => one.value)]) : this.format;
|
|
276
|
+
const r = this.size / 2;
|
|
277
|
+
let at = 0;
|
|
278
|
+
const pick = (key, rest) => this.pickable && !rest && this.dispatchEvent(new CustomEvent('pick', { detail: { key } }));
|
|
279
|
+
const colorOf = (index, rest) => (rest ? REST_COLOR : colorAt(index));
|
|
280
|
+
return html `<div class="wrap">
|
|
281
|
+
<svg width=${this.size} height=${this.size} role="img">
|
|
282
|
+
${slices.map((one, index) => {
|
|
283
|
+
const path = arcPath(r, r, r - 2, r * 0.58, at, at + one.value / total);
|
|
284
|
+
at += one.value / total;
|
|
285
|
+
return svg `<path d=${path} fill=${colorOf(index, one.rest)} ?clickable=${this.pickable && !one.rest} @click=${() => pick(one.key, one.rest)}><title>${one.label}: ${(this.exact ?? format)(one.value)} (${one.percent.toFixed(1)}%)</title></path>`;
|
|
286
|
+
})}
|
|
287
|
+
${this.centerLabel ? svg `<text class="axis" x=${r} y=${r - 5} text-anchor="middle">${this.centerLabel}</text>` : nothing}
|
|
288
|
+
<text class="center-value" x=${r} y=${r + (this.centerLabel ? 12 : 5)} text-anchor="middle">${format(total)}</text>
|
|
289
|
+
</svg>
|
|
290
|
+
<table>
|
|
291
|
+
${slices.map((one, index) => html `<tr ?clickable=${this.pickable && !one.rest} @click=${() => pick(one.key, one.rest)}>
|
|
292
|
+
<td><span class="swatch" style="background:${colorOf(index, one.rest)}"></span></td>
|
|
293
|
+
<td class="label" title=${one.label}>${one.label}</td>
|
|
294
|
+
<td class="num" title=${this.exact ? this.exact(one.value) : nothing}>${format(one.value)}</td>
|
|
295
|
+
<td class="num">${one.percent.toFixed(1)}%</td>
|
|
296
|
+
</tr>`)}
|
|
297
|
+
</table>
|
|
298
|
+
</div>`;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
__decorate([
|
|
302
|
+
property({ type: Array })
|
|
303
|
+
], OxDonutChart.prototype, "items", void 0);
|
|
304
|
+
__decorate([
|
|
305
|
+
property({ type: Number })
|
|
306
|
+
], OxDonutChart.prototype, "keep", void 0);
|
|
307
|
+
__decorate([
|
|
308
|
+
property({ type: Number })
|
|
309
|
+
], OxDonutChart.prototype, "size", void 0);
|
|
310
|
+
__decorate([
|
|
311
|
+
property()
|
|
312
|
+
], OxDonutChart.prototype, "restLabel", void 0);
|
|
313
|
+
__decorate([
|
|
314
|
+
property()
|
|
315
|
+
], OxDonutChart.prototype, "centerLabel", void 0);
|
|
316
|
+
__decorate([
|
|
317
|
+
property({ attribute: false })
|
|
318
|
+
], OxDonutChart.prototype, "format", void 0);
|
|
319
|
+
__decorate([
|
|
320
|
+
property({ attribute: false })
|
|
321
|
+
], OxDonutChart.prototype, "scale", void 0);
|
|
322
|
+
__decorate([
|
|
323
|
+
property({ attribute: false })
|
|
324
|
+
], OxDonutChart.prototype, "exact", void 0);
|
|
325
|
+
__decorate([
|
|
326
|
+
property({ type: Boolean })
|
|
327
|
+
], OxDonutChart.prototype, "pickable", void 0);
|
|
328
|
+
OxDonutChart = __decorate([
|
|
329
|
+
customElement('ox-donut-chart')
|
|
330
|
+
], OxDonutChart);
|
|
331
|
+
export { OxDonutChart };
|
|
332
|
+
/**
|
|
333
|
+
* A range over time — the band between a low and a high, the middle as a line: where the balance
|
|
334
|
+
* is likely to be. A dashed line marks zero when the band reaches it.
|
|
335
|
+
*/
|
|
336
|
+
let OxBandChart = class OxBandChart extends SizedChart {
|
|
337
|
+
constructor() {
|
|
338
|
+
super(...arguments);
|
|
339
|
+
this.labels = [];
|
|
340
|
+
this.low = [];
|
|
341
|
+
this.mid = [];
|
|
342
|
+
this.high = [];
|
|
343
|
+
this.lowName = '';
|
|
344
|
+
this.midName = '';
|
|
345
|
+
this.highName = '';
|
|
346
|
+
this.height = 240;
|
|
347
|
+
this.format = plain;
|
|
348
|
+
this.scale = null;
|
|
349
|
+
/** The whole value for a tooltip — `won` beside a money scale, so 「3.6억」 can be read as every won on hover. */
|
|
350
|
+
this.exact = null;
|
|
351
|
+
}
|
|
352
|
+
static { this.styles = chartStyles; }
|
|
353
|
+
render() {
|
|
354
|
+
const width = this.width;
|
|
355
|
+
if (!width || !this.labels.length)
|
|
356
|
+
return html `<div style="height:${this.height}px"></div>`;
|
|
357
|
+
const ticks = niceTicks(Math.min(0, ...this.low), Math.max(0, ...this.high), 4);
|
|
358
|
+
const [lo, hi] = [ticks[0], ticks[ticks.length - 1]];
|
|
359
|
+
const format = this.scale ? this.scale([...ticks, ...this.low, ...this.mid, ...this.high]) : this.format;
|
|
360
|
+
const left = Math.max(...ticks.map(one => format(one).length)) * 6 + 10;
|
|
361
|
+
const [top, bottom, right] = [8, 22, 10];
|
|
362
|
+
const plotW = Math.max(10, width - left - right);
|
|
363
|
+
const plotH = this.height - top - bottom;
|
|
364
|
+
const step = this.labels.length > 1 ? plotW / (this.labels.length - 1) : 0;
|
|
365
|
+
const x = (at) => left + at * step;
|
|
366
|
+
const y = (value) => top + plotH - ((value - lo) / (hi - lo || 1)) * plotH;
|
|
367
|
+
const every = Math.max(1, Math.ceil(46 / (step || 46)));
|
|
368
|
+
const color = colorAt(0);
|
|
369
|
+
const area = [...this.high.map((value, at) => `${x(at)},${y(value)}`), ...this.low.map((value, at) => `${x(at)},${y(value)}`).reverse()].join(' ');
|
|
370
|
+
return html `
|
|
371
|
+
<svg width=${width} height=${this.height} role="img">
|
|
372
|
+
<g class="grid">${ticks.map(tick => svg `<line class=${tick === 0 ? 'zero' : ''} x1=${left} x2=${left + plotW} y1=${y(tick)} y2=${y(tick)} stroke-dasharray=${tick === 0 ? '4 3' : ''} />`)}</g>
|
|
373
|
+
<g class="axis">
|
|
374
|
+
${ticks.map(tick => svg `<text x=${left - 6} y=${y(tick) + 3} text-anchor="end">${format(tick)}</text>`)}
|
|
375
|
+
${this.labels.map((label, at) => (at % every ? nothing : svg `<text x=${x(at)} y=${this.height - 6} text-anchor="middle">${label}</text>`))}
|
|
376
|
+
</g>
|
|
377
|
+
<polygon points=${area} fill=${color} fill-opacity="0.18" />
|
|
378
|
+
<polyline points=${this.low.map((value, at) => `${x(at)},${y(value)}`).join(' ')} fill="none" stroke=${colorAt(3)} stroke-width="1.2" stroke-dasharray="3 3" />
|
|
379
|
+
<polyline points=${this.high.map((value, at) => `${x(at)},${y(value)}`).join(' ')} fill="none" stroke=${colorAt(2)} stroke-width="1.2" stroke-dasharray="3 3" />
|
|
380
|
+
<polyline points=${this.mid.map((value, at) => `${x(at)},${y(value)}`).join(' ')} fill="none" stroke=${color} stroke-width="2.2" />
|
|
381
|
+
${this.mid.map((value, at) => svg `<circle cx=${x(at)} cy=${y(value)} r="3" fill=${color}><title>${this.labels[at]} · ${this.lowName} ${(this.exact ?? format)(this.low[at])} · ${this.midName} ${(this.exact ?? format)(value)} · ${this.highName} ${(this.exact ?? format)(this.high[at])}</title></circle>`)}
|
|
382
|
+
</svg>
|
|
383
|
+
<div class="legend">
|
|
384
|
+
<span><span class="swatch line" style="background:${colorAt(3)}"></span>${this.lowName}</span>
|
|
385
|
+
<span><span class="swatch line" style="background:${color}"></span>${this.midName}</span>
|
|
386
|
+
<span><span class="swatch line" style="background:${colorAt(2)}"></span>${this.highName}</span>
|
|
387
|
+
</div>
|
|
388
|
+
`;
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
__decorate([
|
|
392
|
+
property({ type: Array })
|
|
393
|
+
], OxBandChart.prototype, "labels", void 0);
|
|
394
|
+
__decorate([
|
|
395
|
+
property({ type: Array })
|
|
396
|
+
], OxBandChart.prototype, "low", void 0);
|
|
397
|
+
__decorate([
|
|
398
|
+
property({ type: Array })
|
|
399
|
+
], OxBandChart.prototype, "mid", void 0);
|
|
400
|
+
__decorate([
|
|
401
|
+
property({ type: Array })
|
|
402
|
+
], OxBandChart.prototype, "high", void 0);
|
|
403
|
+
__decorate([
|
|
404
|
+
property()
|
|
405
|
+
], OxBandChart.prototype, "lowName", void 0);
|
|
406
|
+
__decorate([
|
|
407
|
+
property()
|
|
408
|
+
], OxBandChart.prototype, "midName", void 0);
|
|
409
|
+
__decorate([
|
|
410
|
+
property()
|
|
411
|
+
], OxBandChart.prototype, "highName", void 0);
|
|
412
|
+
__decorate([
|
|
413
|
+
property({ type: Number })
|
|
414
|
+
], OxBandChart.prototype, "height", void 0);
|
|
415
|
+
__decorate([
|
|
416
|
+
property({ attribute: false })
|
|
417
|
+
], OxBandChart.prototype, "format", void 0);
|
|
418
|
+
__decorate([
|
|
419
|
+
property({ attribute: false })
|
|
420
|
+
], OxBandChart.prototype, "scale", void 0);
|
|
421
|
+
__decorate([
|
|
422
|
+
property({ attribute: false })
|
|
423
|
+
], OxBandChart.prototype, "exact", void 0);
|
|
424
|
+
OxBandChart = __decorate([
|
|
425
|
+
customElement('ox-band-chart')
|
|
426
|
+
], OxBandChart);
|
|
427
|
+
export { OxBandChart };
|
|
428
|
+
/**
|
|
429
|
+
* A whole as one line of coloured parts, each as wide as its share, the legend under it naming each part with its value.
|
|
430
|
+
* Parts with nothing are left off the line and stay in the legend, so every step is still named.
|
|
431
|
+
*/
|
|
432
|
+
let OxShareLine = class OxShareLine extends LitElement {
|
|
433
|
+
constructor() {
|
|
434
|
+
super(...arguments);
|
|
435
|
+
this.items = [];
|
|
436
|
+
this.format = plain;
|
|
437
|
+
}
|
|
438
|
+
static { this.styles = [
|
|
439
|
+
chartStyles,
|
|
440
|
+
css `
|
|
441
|
+
.line {
|
|
442
|
+
display: flex;
|
|
443
|
+
gap: 2px;
|
|
444
|
+
height: 14px;
|
|
445
|
+
border-radius: var(--ui-r-small, 6px);
|
|
446
|
+
overflow: hidden;
|
|
447
|
+
background: var(--ui-line-soft, var(--md-sys-color-outline-variant));
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
.line span {
|
|
451
|
+
min-width: 4px;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
.legend b {
|
|
455
|
+
color: var(--ui-ink, var(--md-sys-color-on-surface));
|
|
456
|
+
font-weight: 600;
|
|
457
|
+
margin-left: var(--spacing-tiny, 2px);
|
|
458
|
+
}
|
|
459
|
+
`
|
|
460
|
+
]; }
|
|
461
|
+
render() {
|
|
462
|
+
const total = this.items.reduce((sum, one) => sum + one.value, 0);
|
|
463
|
+
const said = this.items.map(one => `${one.label} ${this.format(one.value)}`).join(', ');
|
|
464
|
+
return html `
|
|
465
|
+
<div class="line" role="img" aria-label=${said}>
|
|
466
|
+
${this.items
|
|
467
|
+
.filter(one => one.value > 0)
|
|
468
|
+
.map(one => html `<span style="flex: ${one.value / (total || 1)} 1 0; background: ${one.color}" title=${[`${one.label} ${this.format(one.value)}`, one.detail].filter(Boolean).join(' — ')}></span>`)}
|
|
469
|
+
</div>
|
|
470
|
+
<div class="legend">
|
|
471
|
+
${this.items.map(one => html `<span title=${one.detail ?? ''}><span class="swatch" style="background:${one.color}"></span>${one.label}<b>${this.format(one.value)}</b></span>`)}
|
|
472
|
+
</div>
|
|
473
|
+
`;
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
__decorate([
|
|
477
|
+
property({ type: Array })
|
|
478
|
+
], OxShareLine.prototype, "items", void 0);
|
|
479
|
+
__decorate([
|
|
480
|
+
property({ attribute: false })
|
|
481
|
+
], OxShareLine.prototype, "format", void 0);
|
|
482
|
+
OxShareLine = __decorate([
|
|
483
|
+
customElement('ox-share-line')
|
|
484
|
+
], OxShareLine);
|
|
485
|
+
export { OxShareLine };
|
|
486
|
+
/**
|
|
487
|
+
* Horizontal bars, one a row, in the order given - the caller sorts them and puts a rest row where it belongs. Every bar
|
|
488
|
+
* is measured against the largest; the value is written at the row's end.
|
|
489
|
+
*/
|
|
490
|
+
let OxBarList = class OxBarList extends LitElement {
|
|
491
|
+
constructor() {
|
|
492
|
+
super(...arguments);
|
|
493
|
+
this.items = [];
|
|
494
|
+
this.format = plain;
|
|
495
|
+
this.color = PALETTE[0];
|
|
496
|
+
}
|
|
497
|
+
static { this.styles = [
|
|
498
|
+
chartStyles,
|
|
499
|
+
css `
|
|
500
|
+
ol {
|
|
501
|
+
list-style: none;
|
|
502
|
+
margin: 0;
|
|
503
|
+
padding: 0;
|
|
504
|
+
display: grid;
|
|
505
|
+
grid-template-columns: minmax(8em, 36%) 1fr auto;
|
|
506
|
+
gap: var(--spacing-small, 4px) var(--spacing-medium, 8px);
|
|
507
|
+
align-items: center;
|
|
508
|
+
font-size: var(--ui-t-small, 11.5px);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
li {
|
|
512
|
+
display: contents;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
.label {
|
|
516
|
+
color: var(--ui-ink, var(--md-sys-color-on-surface));
|
|
517
|
+
overflow: hidden;
|
|
518
|
+
text-overflow: ellipsis;
|
|
519
|
+
white-space: nowrap;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
.tag {
|
|
523
|
+
color: var(--ui-muted, var(--md-sys-color-on-surface-variant));
|
|
524
|
+
margin-right: var(--spacing-small, 4px);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
.track {
|
|
528
|
+
height: 10px;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
.bar {
|
|
532
|
+
height: 100%;
|
|
533
|
+
min-width: 2px;
|
|
534
|
+
border-radius: 0 var(--spacing-tiny, 2px) var(--spacing-tiny, 2px) 0;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
.value {
|
|
538
|
+
color: var(--ui-ink, var(--md-sys-color-on-surface));
|
|
539
|
+
text-align: right;
|
|
540
|
+
font-variant-numeric: tabular-nums;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
.rest .label,
|
|
544
|
+
.rest .value {
|
|
545
|
+
color: var(--ui-muted, var(--md-sys-color-on-surface-variant));
|
|
546
|
+
}
|
|
547
|
+
`
|
|
548
|
+
]; }
|
|
549
|
+
render() {
|
|
550
|
+
const most = Math.max(0, ...this.items.map(one => one.value));
|
|
551
|
+
return html `<ol>
|
|
552
|
+
${this.items.map(one => html `<li class=${one.rest ? 'rest' : ''}>
|
|
553
|
+
<span class="label" title=${[one.tag, one.label].filter(Boolean).join(' ')}>${one.tag ? html `<span class="tag">${one.tag}</span>` : nothing}${one.label}</span>
|
|
554
|
+
<span class="track"><div class="bar" style="width: ${most ? (one.value / most) * 100 : 0}%; background: ${one.rest ? REST_COLOR : this.color}" title=${`${one.label} ${this.format(one.value)}`}></div></span>
|
|
555
|
+
<span class="value">${this.format(one.value)}</span>
|
|
556
|
+
</li>`)}
|
|
557
|
+
</ol>`;
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
__decorate([
|
|
561
|
+
property({ type: Array })
|
|
562
|
+
], OxBarList.prototype, "items", void 0);
|
|
563
|
+
__decorate([
|
|
564
|
+
property({ attribute: false })
|
|
565
|
+
], OxBarList.prototype, "format", void 0);
|
|
566
|
+
__decorate([
|
|
567
|
+
property()
|
|
568
|
+
], OxBarList.prototype, "color", void 0);
|
|
569
|
+
OxBarList = __decorate([
|
|
570
|
+
customElement('ox-bar-list')
|
|
571
|
+
], OxBarList);
|
|
572
|
+
export { OxBarList };
|
|
573
|
+
//# sourceMappingURL=report-charts.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { OperatoChart } from '../types/types';
|
|
2
|
+
export declare function getDefaultChartConfig(type: OperatoChart.ChartType, datasets?: OperatoChart.Dataset[]): OperatoChart.ChartConfig;
|
|
3
|
+
export declare function getDefaultAxisOptions(): OperatoChart.AxisOptions;
|
|
4
|
+
export declare const data: {
|
|
5
|
+
timestamp: number;
|
|
6
|
+
count: number | null;
|
|
7
|
+
average: number | null;
|
|
8
|
+
}[];
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export function getDefaultChartConfig(type, datasets) {
|
|
2
|
+
return {
|
|
3
|
+
data: {
|
|
4
|
+
datasets: datasets || [],
|
|
5
|
+
labelDataKey: ''
|
|
6
|
+
},
|
|
7
|
+
options: {
|
|
8
|
+
theme: 'light',
|
|
9
|
+
tooltip: true,
|
|
10
|
+
animation: true,
|
|
11
|
+
legend: {
|
|
12
|
+
display: true,
|
|
13
|
+
position: 'top'
|
|
14
|
+
},
|
|
15
|
+
scales: {
|
|
16
|
+
xAxes: [getDefaultAxisOptions()],
|
|
17
|
+
yAxes: [getDefaultAxisOptions(), getDefaultAxisOptions()] // Two y-axes for multi-axis support
|
|
18
|
+
},
|
|
19
|
+
stacked: false,
|
|
20
|
+
xGridLine: true,
|
|
21
|
+
yGridLine: true,
|
|
22
|
+
y2ndGridLine: false,
|
|
23
|
+
multiAxis: false
|
|
24
|
+
},
|
|
25
|
+
type
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function getDefaultAxisOptions() {
|
|
29
|
+
return {
|
|
30
|
+
axisTitle: '',
|
|
31
|
+
barSpacing: 0,
|
|
32
|
+
categorySpacing: 0,
|
|
33
|
+
barPercentage: 0.9,
|
|
34
|
+
ticks: {
|
|
35
|
+
display: true,
|
|
36
|
+
autoMin: true,
|
|
37
|
+
autoMax: true,
|
|
38
|
+
min: undefined,
|
|
39
|
+
max: undefined,
|
|
40
|
+
stepSize: undefined
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// export const data = [
|
|
45
|
+
// { timestamp: 2010, count: 10, average: 120 },
|
|
46
|
+
// { timestamp: 2011, count: 20, average: 110 },
|
|
47
|
+
// { timestamp: 2012, count: 15, average: 80 },
|
|
48
|
+
// { timestamp: 2013, count: 25, average: 130 },
|
|
49
|
+
// { timestamp: 2014, count: 22, average: 120 },
|
|
50
|
+
// { timestamp: 2015, count: 30, average: 60 },
|
|
51
|
+
// { timestamp: 2016, count: 28, average: 90 }
|
|
52
|
+
// ]
|
|
53
|
+
// 랜덤한 범위의 숫자를 생성하는 함수
|
|
54
|
+
function getRandomInRange(i, min, max) {
|
|
55
|
+
if (!(i % 11)) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
59
|
+
}
|
|
60
|
+
// 랜덤 데이터를 생성하는 함수
|
|
61
|
+
function generateRandomData(count) {
|
|
62
|
+
const randomData = [];
|
|
63
|
+
const startTimestamp = Math.floor(Date.now()); // 현재 시간을 Unix 타임스탬프로 설정
|
|
64
|
+
for (let i = 0; i < count; i++) {
|
|
65
|
+
const timestamp = startTimestamp + i * 360 * 30 * 1000; // 3초씩 증가하는 타임스탬프 설정
|
|
66
|
+
const randomCount = getRandomInRange(i, 5, 35); // count 값을 5에서 35 사이로 랜덤 생성
|
|
67
|
+
const randomAverage = getRandomInRange(i, 50, 150); // average 값을 50에서 150 사이로 랜덤 생성
|
|
68
|
+
randomData.push({
|
|
69
|
+
timestamp: timestamp,
|
|
70
|
+
count: randomCount,
|
|
71
|
+
average: randomAverage
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return randomData;
|
|
75
|
+
}
|
|
76
|
+
// 100개의 랜덤 데이터를 생성
|
|
77
|
+
export const data = generateRandomData(100);
|
|
78
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TemplateResult } from 'lit';
|
|
2
|
+
import '../src/editors/ox-input-chart-timeseries.js';
|
|
3
|
+
import '../src/scichart/ox-scichart.js';
|
|
4
|
+
import '../src/chartjs/ox-chart-js.js';
|
|
5
|
+
import type { OperatoChart } from '../types/types';
|
|
6
|
+
declare const _default: {
|
|
7
|
+
title: string;
|
|
8
|
+
component: string;
|
|
9
|
+
argTypes: {
|
|
10
|
+
value: {
|
|
11
|
+
control: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
16
|
+
interface Story<T> {
|
|
17
|
+
(args: T): TemplateResult;
|
|
18
|
+
args?: Partial<T>;
|
|
19
|
+
argTypes?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
interface ArgTypes {
|
|
22
|
+
value: OperatoChart.ChartConfig;
|
|
23
|
+
}
|
|
24
|
+
export declare const StatusChangeAnnotation: Story<ArgTypes>;
|
|
25
|
+
export declare const DataValueTextAnnotation: Story<ArgTypes>;
|
|
26
|
+
export declare const CombinedAnnotations: Story<ArgTypes>;
|