@simon_he/vue-tui 1.0.2 → 1.1.1
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/README.md +44 -26
- package/dist/TMermaidText-CXm_L969.js +885 -0
- package/dist/{TSelect-DR0FomSu.js → TSelect-CiyMvwl-.js} +60 -81
- package/dist/{TTree-kzhlB5P0.js → TTree-DKGiuIcM.js} +140 -103
- package/dist/agent/mermaid.cjs +2 -0
- package/dist/agent/mermaid.d.cts +2 -0
- package/dist/agent/mermaid.d.ts +2 -0
- package/dist/agent/mermaid.js +1 -0
- package/dist/agent.cjs +31184 -24907
- package/dist/agent.d.cts +11 -1
- package/dist/agent.d.ts +11 -1
- package/dist/agent.js +1700 -13
- package/dist/block-source-5CQp4tF8.js +3230 -0
- package/dist/cli/stdin-buffer.d.ts +1 -1
- package/dist/cli.cjs +5037 -6767
- package/dist/cli.d.cts +4 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +2733 -148
- package/dist/core/buffer/eaw-ranges-unicode-17.d.ts +14 -0
- package/dist/core/perf/instrumentation-noop.d.ts +48 -0
- package/dist/core/perf/instrumentation.d.ts +136 -0
- package/dist/core/terminal/create-terminal.d.ts +1 -0
- package/dist/core.cjs +843 -1469
- package/dist/core.js +6 -6
- package/dist/{create-terminal-DBFNYr8f.js → create-terminal-DXuZ2fci.js} +39 -13
- package/dist/debug-logger-ChY_PXVk.js +74 -0
- package/dist/{dom-renderer-BniJSQyX.js → dom-renderer-DNzmg2As.js} +2 -2
- package/dist/experimental.cjs +4115 -5928
- package/dist/experimental.d.cts +2 -0
- package/dist/experimental.d.ts +2 -0
- package/dist/experimental.js +1490 -9
- package/dist/frame-perf-BBhE-iuS.js +111 -0
- package/dist/{sgr-BmzxEjAO.js → hyperlink-B35-O-cW.js} +100 -1
- package/dist/index.cjs +5017 -10339
- package/dist/index.js +16 -14
- package/dist/{linkify-D_gzn9Xq.js → linkify-CuuquMQT.js} +32 -3
- package/dist/markdown.cjs +21295 -12691
- package/dist/markdown.d.cts +1 -1
- package/dist/markdown.d.ts +1 -1
- package/dist/markdown.js +211 -51
- package/dist/mermaid-CWto52Wk.js +123 -0
- package/dist/mermaid.cjs +1707 -0
- package/dist/mermaid.d.cts +3 -0
- package/dist/mermaid.d.ts +3 -0
- package/dist/mermaid.js +6 -0
- package/dist/observability/frame-perf-store.d.ts +2 -1
- package/dist/observability/frame-perf.d.ts +33 -0
- package/dist/observability.cjs +106 -107
- package/dist/observability.d.cts +2 -2
- package/dist/observability.d.ts +2 -2
- package/dist/observability.js +3 -3
- package/dist/{path-suggest-BNqcuE3-.js → path-suggest-fPzRsgPv.js} +1 -1
- package/dist/{wheel-scroll-vBRaQ7p-.js → rect-Ng-3eKzF.js} +253 -117
- package/dist/renderer/cli/stdout-metrics.d.ts +10 -0
- package/dist/renderer/cli/stdout-renderer.d.ts +3 -0
- package/dist/renderer/terminal-graphic-render-queue.d.ts +50 -0
- package/dist/renderer/terminal-graphics-trace.d.ts +53 -0
- package/dist/renderer/terminal-graphics.d.ts +146 -0
- package/dist/renderer-dom.cjs +364 -903
- package/dist/renderer-dom.js +4 -4
- package/dist/runtime/index.d.ts +2 -0
- package/dist/{runtime-rfcZCyJq.js → runtime-D77C03RM.js} +28 -15
- package/dist/runtime.cjs +427 -889
- package/dist/runtime.js +2 -2
- package/dist/{terminal-selection-DBinO6p5.js → terminal-selection-CQYr--26.js} +4 -1
- package/dist/{tlog-theme-CvLFNMwk.js → tlog-theme-CopRt9SC.js} +37 -6
- package/dist/{trace-CjzYeIxN.js → trace-CYHDKM1m.js} +5 -0
- package/dist/vue/agent/create-png-terminal-graphic-renderer.d.ts +19 -0
- package/dist/vue/components/TAgentTerminalGraphic.d.ts +481 -0
- package/dist/vue/components/TCharts.d.ts +1121 -0
- package/dist/vue/components/TFeedback.d.ts +1 -1
- package/dist/vue/components/TFlex.d.ts +389 -0
- package/dist/vue/components/TForm.d.ts +4 -4
- package/dist/vue/components/TLogSearchBar.d.ts +3 -3
- package/dist/vue/components/TLogSearchPager.d.ts +2 -2
- package/dist/vue/components/TMarkdownText.d.ts +162 -4
- package/dist/vue/components/TMermaidText.d.ts +900 -0
- package/dist/vue/components/TVirtualList.d.ts +9 -0
- package/dist/vue/components/TVirtualMarkdown.d.ts +170 -9
- package/dist/vue/components/TVirtualRows.d.ts +9 -0
- package/dist/vue/components/TerminalProvider.d.ts +2 -0
- package/dist/vue/context.d.ts +24 -0
- package/dist/vue/index.d.ts +5 -0
- package/dist/vue/layout/flex.d.ts +67 -0
- package/dist/vue/markdown/ast.d.ts +5 -2
- package/dist/vue/markdown/document.d.ts +5 -0
- package/dist/vue/markdown/image-actions.d.ts +14 -0
- package/dist/vue/markdown/image.d.ts +11 -0
- package/dist/vue/markdown/link-actions.d.ts +14 -0
- package/dist/vue/markdown/math-actions.d.ts +14 -0
- package/dist/vue/markdown/math.d.ts +6 -0
- package/dist/vue/markdown/render.d.ts +28 -0
- package/dist/vue/markdown/types.d.ts +78 -0
- package/dist/vue/mermaid/beautiful-mermaid.d.ts +1436 -0
- package/dist/vue/render/render-manager.d.ts +7 -0
- package/dist/vue.cjs +7207 -12437
- package/dist/vue.js +706 -39
- package/dist/wheel-scroll-CQ22Hcyj.js +106 -0
- package/dist/{hyperlink-Bn02UXJb.js → width-GqllnV8C.js} +166 -111
- package/package.json +85 -14
- package/dist/block-source-CKUOnkgT.js +0 -1663
- package/dist/frame-perf-C6Xfg85O.js +0 -24
- /package/dist/{env-Cl8qmNFN.js → env-DNCzvX8b.js} +0 -0
- /package/dist/{path-mnSgEpCm.js → path-BI9W15Zt.js} +0 -0
package/dist/experimental.js
CHANGED
|
@@ -1,12 +1,1493 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "./
|
|
3
|
-
import "./
|
|
4
|
-
import "./linkify-
|
|
5
|
-
import "./
|
|
6
|
-
import "./
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
1
|
+
import "./width-GqllnV8C.js";
|
|
2
|
+
import { sanitizeTerminalHref } from "./hyperlink-B35-O-cW.js";
|
|
3
|
+
import { EventZIndexContextKey, forEachTextCellSegment, intersectRect, sanitizeInlineText, sliceByCells, spaces, textCellWidth$1 as textCellWidth, translateRect, useLayout, useRenderNode, useTerminal, useTerminalNode, useVisibility } from "./rect-Ng-3eKzF.js";
|
|
4
|
+
import { mergeStyle } from "./linkify-CuuquMQT.js";
|
|
5
|
+
import "./frame-perf-BBhE-iuS.js";
|
|
6
|
+
import "./terminal-selection-CQYr--26.js";
|
|
7
|
+
import "./wheel-scroll-CQ22Hcyj.js";
|
|
8
|
+
import { TLogLinksPanel, TLogMinimap, TLogScrollbar, TLogSearchBar, TLogSearchPager, TLogSearchResults, TLogView, TLogVirtualLinksPanel, TLogVirtualSearchResults, TTranscriptView, TVirtualList, createAppendOnlyLogStore, createTLogDensityBucketsFromMarkers, createTLogLevelPlugin, createTLogLineMatcherPlugin, createTLogLinkActionPlugin, createTLogOsc8LinkPlugin, createTLogUrlPlugin, detectTLogUrls, dispatchTLogPluginLinkAction, getTLogPluginMetadata, handleTLogKeymapEvent, matchesTLogKeyBinding, parseTLogAnnotatedText, resolveTLogLinksPanelTheme, resolveTLogMinimapTheme, resolveTLogScrollbarTheme, resolveTLogSearchBarTheme, resolveTLogSearchPagerTheme, resolveTLogSearchResultsTheme, resolveTLogViewTheme, stripTLogAnsiText, tlogDarkPreset, tlogDarkTheme, tlogDefaultKeymap, tlogDefaultPreset, tlogDefaultTheme, tlogHighContrastKeymap, tlogHighContrastPreset, tlogHighContrastTheme, toTLogExternalLinkFromVisibleLink, useTLogLinkController, useTLogRetainedIndex, useTLogSearchController, useTLogSearchResultsPage, useTLogVirtualSearchResults } from "./tlog-theme-CopRt9SC.js";
|
|
9
|
+
import { computed, defineComponent, h, inject, ref } from "vue";
|
|
9
10
|
|
|
11
|
+
//#region src/vue/components/TCharts.ts
|
|
12
|
+
const DEFAULT_HEATMAP_LEVEL_STYLES = Object.freeze([
|
|
13
|
+
Object.freeze({ fg: "#9be9a8" }),
|
|
14
|
+
Object.freeze({ fg: "#40c463" }),
|
|
15
|
+
Object.freeze({ fg: "#30a14e" }),
|
|
16
|
+
Object.freeze({ fg: "#216e39" })
|
|
17
|
+
]);
|
|
18
|
+
const DEFAULT_PIE_SEGMENT_STYLES = Object.freeze([
|
|
19
|
+
Object.freeze({ fg: "cyanBright" }),
|
|
20
|
+
Object.freeze({ fg: "magentaBright" }),
|
|
21
|
+
Object.freeze({ fg: "yellowBright" }),
|
|
22
|
+
Object.freeze({ fg: "greenBright" }),
|
|
23
|
+
Object.freeze({ fg: "blueBright" }),
|
|
24
|
+
Object.freeze({ fg: "redBright" })
|
|
25
|
+
]);
|
|
26
|
+
const TERMINAL_CELL_HEIGHT_TO_WIDTH = 1.8;
|
|
27
|
+
const PIE_QUADRANT_BLOCKS = Object.freeze([
|
|
28
|
+
" ",
|
|
29
|
+
"▘",
|
|
30
|
+
"▝",
|
|
31
|
+
"▀",
|
|
32
|
+
"▖",
|
|
33
|
+
"▌",
|
|
34
|
+
"▞",
|
|
35
|
+
"▛",
|
|
36
|
+
"▗",
|
|
37
|
+
"▚",
|
|
38
|
+
"▐",
|
|
39
|
+
"▜",
|
|
40
|
+
"▄",
|
|
41
|
+
"▙",
|
|
42
|
+
"▟",
|
|
43
|
+
"█"
|
|
44
|
+
]);
|
|
45
|
+
const PIE_CELL_SAMPLES = Object.freeze([
|
|
46
|
+
Object.freeze({
|
|
47
|
+
dx: .25,
|
|
48
|
+
dy: .25,
|
|
49
|
+
bit: 1
|
|
50
|
+
}),
|
|
51
|
+
Object.freeze({
|
|
52
|
+
dx: .75,
|
|
53
|
+
dy: .25,
|
|
54
|
+
bit: 2
|
|
55
|
+
}),
|
|
56
|
+
Object.freeze({
|
|
57
|
+
dx: .25,
|
|
58
|
+
dy: .75,
|
|
59
|
+
bit: 4
|
|
60
|
+
}),
|
|
61
|
+
Object.freeze({
|
|
62
|
+
dx: .75,
|
|
63
|
+
dy: .75,
|
|
64
|
+
bit: 8
|
|
65
|
+
})
|
|
66
|
+
]);
|
|
67
|
+
function cellCount(value, fallback) {
|
|
68
|
+
const n = Math.floor(Number(value ?? fallback));
|
|
69
|
+
return Number.isFinite(n) ? Math.max(0, n) : Math.max(0, Math.floor(fallback));
|
|
70
|
+
}
|
|
71
|
+
function finiteRange(values) {
|
|
72
|
+
let min = Number.POSITIVE_INFINITY;
|
|
73
|
+
let max = Number.NEGATIVE_INFINITY;
|
|
74
|
+
for (const raw of values) {
|
|
75
|
+
const value = Number(raw);
|
|
76
|
+
if (!Number.isFinite(value)) continue;
|
|
77
|
+
if (value < min) min = value;
|
|
78
|
+
if (value > max) max = value;
|
|
79
|
+
}
|
|
80
|
+
return min === Number.POSITIVE_INFINITY ? null : {
|
|
81
|
+
min,
|
|
82
|
+
max
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function maxPositive(values) {
|
|
86
|
+
let max = 0;
|
|
87
|
+
for (const raw of values) {
|
|
88
|
+
const value = Number(raw);
|
|
89
|
+
if (Number.isFinite(value) && value > max) max = value;
|
|
90
|
+
}
|
|
91
|
+
return max;
|
|
92
|
+
}
|
|
93
|
+
function domainFromValues(values, minValue, maxValue) {
|
|
94
|
+
const range = finiteRange(values);
|
|
95
|
+
const fallbackMin = range?.min ?? 0;
|
|
96
|
+
const fallbackMax = range?.max ?? 0;
|
|
97
|
+
const hasMin = Number.isFinite(Number(minValue));
|
|
98
|
+
const hasMax = Number.isFinite(Number(maxValue));
|
|
99
|
+
const min = hasMin ? Number(minValue) : fallbackMin;
|
|
100
|
+
const max = hasMax ? Number(maxValue) : fallbackMax;
|
|
101
|
+
if (max < min) {
|
|
102
|
+
if (hasMin && !hasMax) return {
|
|
103
|
+
min,
|
|
104
|
+
max: min
|
|
105
|
+
};
|
|
106
|
+
if (!hasMin && hasMax) return {
|
|
107
|
+
min: max,
|
|
108
|
+
max
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return max >= min ? {
|
|
112
|
+
min,
|
|
113
|
+
max
|
|
114
|
+
} : {
|
|
115
|
+
min: max,
|
|
116
|
+
max: min
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function normalizeCandlestick(candle) {
|
|
120
|
+
const open = Number(candle.open);
|
|
121
|
+
const high = Number(candle.high);
|
|
122
|
+
const low = Number(candle.low);
|
|
123
|
+
const close = Number(candle.close);
|
|
124
|
+
if (!Number.isFinite(open) || !Number.isFinite(high) || !Number.isFinite(low) || !Number.isFinite(close)) return null;
|
|
125
|
+
return {
|
|
126
|
+
open,
|
|
127
|
+
high,
|
|
128
|
+
low,
|
|
129
|
+
close
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function candlestickDomainValues(candles) {
|
|
133
|
+
return candles.flatMap((candle) => {
|
|
134
|
+
const values = normalizeCandlestick(candle);
|
|
135
|
+
return values ? [
|
|
136
|
+
values.open,
|
|
137
|
+
values.low,
|
|
138
|
+
values.high,
|
|
139
|
+
values.close
|
|
140
|
+
] : [];
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function finiteLineRuns(values) {
|
|
144
|
+
const runs = [];
|
|
145
|
+
let points = [];
|
|
146
|
+
for (let originalIndex = 0; originalIndex < values.length; originalIndex++) {
|
|
147
|
+
const raw = values[originalIndex];
|
|
148
|
+
const value = Number(raw);
|
|
149
|
+
if (Number.isFinite(value)) {
|
|
150
|
+
points.push({
|
|
151
|
+
value,
|
|
152
|
+
originalIndex
|
|
153
|
+
});
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (points.length > 0) {
|
|
157
|
+
runs.push({ points });
|
|
158
|
+
points = [];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (points.length > 0) runs.push({ points });
|
|
162
|
+
return runs;
|
|
163
|
+
}
|
|
164
|
+
function valueToY(value, min, max, height) {
|
|
165
|
+
if (height <= 1) return 0;
|
|
166
|
+
if (max === min) {
|
|
167
|
+
if (value < min) return height - 1;
|
|
168
|
+
if (value > max) return 0;
|
|
169
|
+
return Math.floor((height - 1) / 2);
|
|
170
|
+
}
|
|
171
|
+
const scale = Math.max(Math.abs(min), Math.abs(max), Math.abs(value), 1);
|
|
172
|
+
const scaledMin = min / scale;
|
|
173
|
+
const scaledMax = max / scale;
|
|
174
|
+
const ratio = (value / scale - scaledMin) / (scaledMax - scaledMin);
|
|
175
|
+
return Math.max(0, Math.min(height - 1, Math.round((1 - ratio) * (height - 1))));
|
|
176
|
+
}
|
|
177
|
+
function yToValue(y, min, max, height) {
|
|
178
|
+
if (height <= 1 || max === min) return max;
|
|
179
|
+
const ratio = 1 - Math.max(0, Math.min(height - 1, y)) / (height - 1);
|
|
180
|
+
const scale = Math.max(Math.abs(min), Math.abs(max), 1);
|
|
181
|
+
const scaledMin = min / scale;
|
|
182
|
+
const scaledMax = max / scale;
|
|
183
|
+
return (scaledMin + ratio * (scaledMax - scaledMin)) * scale;
|
|
184
|
+
}
|
|
185
|
+
function emptyChartRows(height) {
|
|
186
|
+
return Array.from({ length: height }, () => []);
|
|
187
|
+
}
|
|
188
|
+
function samplePositionAtX(x, width, sourceLength) {
|
|
189
|
+
if (width <= 1 || sourceLength <= 1) return 0;
|
|
190
|
+
return x / (width - 1) * (sourceLength - 1);
|
|
191
|
+
}
|
|
192
|
+
function lineXForOriginalIndex(originalIndex, plotX, plotW, sourceLength) {
|
|
193
|
+
if (plotW <= 1 || sourceLength <= 1) return plotX;
|
|
194
|
+
return plotX + Math.round(originalIndex / (sourceLength - 1) * (plotW - 1));
|
|
195
|
+
}
|
|
196
|
+
function lineBucketIndexRange(plotX, plotW, sourceLength) {
|
|
197
|
+
if (sourceLength <= 0) return {
|
|
198
|
+
startIndex: 0,
|
|
199
|
+
endIndex: -1
|
|
200
|
+
};
|
|
201
|
+
if (plotW <= 1 || sourceLength <= 1) return {
|
|
202
|
+
startIndex: 0,
|
|
203
|
+
endIndex: sourceLength - 1
|
|
204
|
+
};
|
|
205
|
+
let startIndex = 0;
|
|
206
|
+
let high = sourceLength;
|
|
207
|
+
while (startIndex < high) {
|
|
208
|
+
const mid = Math.floor((startIndex + high) / 2);
|
|
209
|
+
if (lineXForOriginalIndex(mid, 0, plotW, sourceLength) < plotX) startIndex = mid + 1;
|
|
210
|
+
else high = mid;
|
|
211
|
+
}
|
|
212
|
+
let endExclusive = startIndex;
|
|
213
|
+
high = sourceLength;
|
|
214
|
+
while (endExclusive < high) {
|
|
215
|
+
const mid = Math.floor((endExclusive + high) / 2);
|
|
216
|
+
if (lineXForOriginalIndex(mid, 0, plotW, sourceLength) <= plotX) endExclusive = mid + 1;
|
|
217
|
+
else high = mid;
|
|
218
|
+
}
|
|
219
|
+
return endExclusive <= startIndex ? {
|
|
220
|
+
startIndex: 0,
|
|
221
|
+
endIndex: -1
|
|
222
|
+
} : {
|
|
223
|
+
startIndex,
|
|
224
|
+
endIndex: endExclusive - 1
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function lowerBoundLinePoint(points, position) {
|
|
228
|
+
let low = 0;
|
|
229
|
+
let high = points.length;
|
|
230
|
+
while (low < high) {
|
|
231
|
+
const mid = Math.floor((low + high) / 2);
|
|
232
|
+
if (points[mid].originalIndex < position) low = mid + 1;
|
|
233
|
+
else high = mid;
|
|
234
|
+
}
|
|
235
|
+
return low;
|
|
236
|
+
}
|
|
237
|
+
function lineValueAtPosition(points, position) {
|
|
238
|
+
if (!points.length) return null;
|
|
239
|
+
const first = points[0];
|
|
240
|
+
const last = points[points.length - 1];
|
|
241
|
+
if (position < first.originalIndex || position > last.originalIndex) return null;
|
|
242
|
+
if (points.length === 1) return first.value;
|
|
243
|
+
const index = Math.min(Math.max(1, lowerBoundLinePoint(points, position)), points.length - 1);
|
|
244
|
+
const previous = points[index - 1];
|
|
245
|
+
const current = points[index];
|
|
246
|
+
const span = current.originalIndex - previous.originalIndex;
|
|
247
|
+
if (span <= 0) return current.value;
|
|
248
|
+
const ratio = (position - previous.originalIndex) / span;
|
|
249
|
+
return previous.value * (1 - ratio) + current.value * ratio;
|
|
250
|
+
}
|
|
251
|
+
function lowerBoundLineRun(runs, position) {
|
|
252
|
+
let low = 0;
|
|
253
|
+
let high = runs.length;
|
|
254
|
+
while (low < high) {
|
|
255
|
+
const mid = Math.floor((low + high) / 2);
|
|
256
|
+
const points = runs[mid].points;
|
|
257
|
+
if (points[points.length - 1].originalIndex < position) low = mid + 1;
|
|
258
|
+
else high = mid;
|
|
259
|
+
}
|
|
260
|
+
return low;
|
|
261
|
+
}
|
|
262
|
+
function lineRunAtPosition(runs, position) {
|
|
263
|
+
const run = runs[lowerBoundLineRun(runs, position)];
|
|
264
|
+
if (!run) return null;
|
|
265
|
+
const first = run.points[0];
|
|
266
|
+
const last = run.points[run.points.length - 1];
|
|
267
|
+
return position >= first.originalIndex && position <= last.originalIndex ? run : null;
|
|
268
|
+
}
|
|
269
|
+
function nearestLinePoint(points, position) {
|
|
270
|
+
if (!points.length) return null;
|
|
271
|
+
const index = lowerBoundLinePoint(points, position);
|
|
272
|
+
if (index <= 0) return points[0];
|
|
273
|
+
if (index >= points.length) return points[points.length - 1];
|
|
274
|
+
const previous = points[index - 1];
|
|
275
|
+
const current = points[index];
|
|
276
|
+
return position - previous.originalIndex <= current.originalIndex - position ? previous : current;
|
|
277
|
+
}
|
|
278
|
+
function nearestLinePointAtPlotX(runs, plotX, plotW, sourceLength, position) {
|
|
279
|
+
const { startIndex, endIndex } = lineBucketIndexRange(plotX, plotW, sourceLength);
|
|
280
|
+
if (endIndex < startIndex) return null;
|
|
281
|
+
let best = null;
|
|
282
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
283
|
+
for (let runIndex = lowerBoundLineRun(runs, startIndex); runIndex < runs.length; runIndex++) {
|
|
284
|
+
const points = runs[runIndex].points;
|
|
285
|
+
const first = points[0];
|
|
286
|
+
const last = points[points.length - 1];
|
|
287
|
+
if (first.originalIndex > endIndex) break;
|
|
288
|
+
if (last.originalIndex < startIndex) continue;
|
|
289
|
+
for (let pointIndex = lowerBoundLinePoint(points, startIndex); pointIndex < points.length; pointIndex++) {
|
|
290
|
+
const point = points[pointIndex];
|
|
291
|
+
if (point.originalIndex > endIndex) break;
|
|
292
|
+
if (lineXForOriginalIndex(point.originalIndex, 0, plotW, sourceLength) !== plotX) continue;
|
|
293
|
+
const distance = Math.abs(point.originalIndex - position);
|
|
294
|
+
if (distance < bestDistance) {
|
|
295
|
+
best = point;
|
|
296
|
+
bestDistance = distance;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return best;
|
|
301
|
+
}
|
|
302
|
+
function nearestLinePointInRuns(runs, position, plotX, plotW, sourceLength) {
|
|
303
|
+
const run = lineRunAtPosition(runs, position);
|
|
304
|
+
if (run && run.points.length > 1) return nearestLinePoint(run.points, position);
|
|
305
|
+
return nearestLinePointAtPlotX(runs, plotX, plotW, sourceLength, position);
|
|
306
|
+
}
|
|
307
|
+
function lineBucketsForRun(points, plotW, sourceLength) {
|
|
308
|
+
const buckets = [];
|
|
309
|
+
let current = null;
|
|
310
|
+
for (const point of points) {
|
|
311
|
+
const x = lineXForOriginalIndex(point.originalIndex, 0, plotW, sourceLength);
|
|
312
|
+
if (x < 0 || x >= plotW) continue;
|
|
313
|
+
if (!current || current.x !== x) {
|
|
314
|
+
if (current) buckets.push(current);
|
|
315
|
+
current = {
|
|
316
|
+
x,
|
|
317
|
+
minValue: point.value,
|
|
318
|
+
maxValue: point.value,
|
|
319
|
+
firstIndex: point.originalIndex,
|
|
320
|
+
firstValue: point.value,
|
|
321
|
+
lastIndex: point.originalIndex,
|
|
322
|
+
lastValue: point.value
|
|
323
|
+
};
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
if (point.value < current.minValue) current.minValue = point.value;
|
|
327
|
+
if (point.value > current.maxValue) current.maxValue = point.value;
|
|
328
|
+
current.lastIndex = point.originalIndex;
|
|
329
|
+
current.lastValue = point.value;
|
|
330
|
+
}
|
|
331
|
+
if (current) buckets.push(current);
|
|
332
|
+
return buckets;
|
|
333
|
+
}
|
|
334
|
+
function lineBucketRepresentativeValue(points, bucket, plotW, sourceLength) {
|
|
335
|
+
const position = samplePositionAtX(bucket.x, plotW, sourceLength);
|
|
336
|
+
if (position <= bucket.firstIndex) return bucket.firstValue;
|
|
337
|
+
if (position >= bucket.lastIndex) return bucket.lastValue;
|
|
338
|
+
return lineValueAtPosition(points, position) ?? bucket.lastValue;
|
|
339
|
+
}
|
|
340
|
+
function lineSegmentPointsForRun(points, buckets, plotW, sourceLength) {
|
|
341
|
+
const valuesByX = new Map();
|
|
342
|
+
const first = points[0];
|
|
343
|
+
const last = points[points.length - 1];
|
|
344
|
+
if (first && last) if (plotW <= 1 || sourceLength <= 1) {
|
|
345
|
+
const value = lineValueAtPosition(points, 0);
|
|
346
|
+
if (value != null) valuesByX.set(0, value);
|
|
347
|
+
} else {
|
|
348
|
+
const scale = (sourceLength - 1) / (plotW - 1);
|
|
349
|
+
const startX = Math.max(0, Math.ceil(first.originalIndex / scale));
|
|
350
|
+
const endX = Math.min(plotW - 1, Math.floor(last.originalIndex / scale));
|
|
351
|
+
for (let x = startX; x <= endX; x++) {
|
|
352
|
+
const value = lineValueAtPosition(points, samplePositionAtX(x, plotW, sourceLength));
|
|
353
|
+
if (value != null) valuesByX.set(x, value);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
for (const bucket of buckets) if (!valuesByX.has(bucket.x)) valuesByX.set(bucket.x, lineBucketRepresentativeValue(points, bucket, plotW, sourceLength));
|
|
357
|
+
return Array.from(valuesByX, ([x, value]) => ({
|
|
358
|
+
x,
|
|
359
|
+
value
|
|
360
|
+
})).sort((a, b) => a.x - b.x);
|
|
361
|
+
}
|
|
362
|
+
function putLineGlyph(cells, x, y, ch, style, width, height, occupied) {
|
|
363
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return;
|
|
364
|
+
if (x < 0 || x >= width || y < 0 || y >= height) return;
|
|
365
|
+
cells.push({
|
|
366
|
+
x,
|
|
367
|
+
y,
|
|
368
|
+
ch,
|
|
369
|
+
style
|
|
370
|
+
});
|
|
371
|
+
occupied?.add(y * width + x);
|
|
372
|
+
}
|
|
373
|
+
function pushLineBucketExtrema(cells, bucket, layout, min, max, style, width, height, occupied) {
|
|
374
|
+
const x = layout.plotX + bucket.x;
|
|
375
|
+
const minY = valueToY(bucket.minValue, min, max, layout.plotH);
|
|
376
|
+
const maxY = valueToY(bucket.maxValue, min, max, layout.plotH);
|
|
377
|
+
const top = Math.min(minY, maxY);
|
|
378
|
+
const bottom = Math.max(minY, maxY);
|
|
379
|
+
if (top === bottom) {
|
|
380
|
+
const y = layout.plotY + top;
|
|
381
|
+
if (!occupied.has(y * width + x)) putLineGlyph(cells, x, y, "●", style, width, height, occupied);
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
for (let y = top; y <= bottom; y++) {
|
|
385
|
+
const cellY = layout.plotY + y;
|
|
386
|
+
if (!occupied.has(cellY * width + x)) putLineGlyph(cells, x, cellY, "│", style, width, height, occupied);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function drawSteppedLineSegment(cells, fromX, fromY, toX, toY, style, width, height, occupied) {
|
|
390
|
+
if (toY === fromY) {
|
|
391
|
+
for (let x = fromX + 1; x <= toX; x++) putLineGlyph(cells, x, toY, "─", style, width, height, occupied);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
const rising = toY < fromY;
|
|
395
|
+
for (let x = fromX + 1; x < toX; x++) putLineGlyph(cells, x, fromY, "─", style, width, height, occupied);
|
|
396
|
+
putLineGlyph(cells, toX, fromY, rising ? "╯" : "╮", style, width, height, occupied);
|
|
397
|
+
const top = Math.min(fromY, toY);
|
|
398
|
+
const bottom = Math.max(fromY, toY);
|
|
399
|
+
for (let y = top + 1; y < bottom; y++) putLineGlyph(cells, toX, y, "│", style, width, height, occupied);
|
|
400
|
+
putLineGlyph(cells, toX, toY, rising ? "╭" : "╰", style, width, height, occupied);
|
|
401
|
+
}
|
|
402
|
+
function chartGlyph(value, fallback) {
|
|
403
|
+
const text = sliceByCells(sanitizeInlineText(value || fallback), 1);
|
|
404
|
+
return text && textCellWidth(text) === 1 ? text : fallback;
|
|
405
|
+
}
|
|
406
|
+
function formatChartValue(value) {
|
|
407
|
+
if (!Number.isFinite(value)) return "0";
|
|
408
|
+
const abs = Math.abs(value);
|
|
409
|
+
if (abs >= 1e6) return `${(value / 1e6).toFixed(1)}m`;
|
|
410
|
+
if (abs >= 1e4) return `${Math.round(value / 1e3)}k`;
|
|
411
|
+
if (abs >= 1e3) return `${(value / 1e3).toFixed(1)}k`;
|
|
412
|
+
if (Number.isInteger(value)) return String(value);
|
|
413
|
+
if (abs >= 100) return value.toFixed(0);
|
|
414
|
+
if (abs >= 10) return value.toFixed(1);
|
|
415
|
+
if (abs > 0 && abs < .01) return Number(value.toPrecision(2)).toString();
|
|
416
|
+
return Number(value.toFixed(2)).toString();
|
|
417
|
+
}
|
|
418
|
+
function fitLabel(value, width) {
|
|
419
|
+
return sliceByCells(sanitizeInlineText(value), Math.max(0, width));
|
|
420
|
+
}
|
|
421
|
+
function pushTextCells(cells, x, y, text, style, maxWidth = Number.POSITIVE_INFINITY) {
|
|
422
|
+
const clipped = fitLabel(text, maxWidth);
|
|
423
|
+
let cursor = x;
|
|
424
|
+
forEachTextCellSegment(clipped, (segment) => {
|
|
425
|
+
if (segment.cells <= 0) return;
|
|
426
|
+
cells.push({
|
|
427
|
+
x: cursor,
|
|
428
|
+
y,
|
|
429
|
+
ch: segment.text,
|
|
430
|
+
style
|
|
431
|
+
});
|
|
432
|
+
cursor += segment.cells;
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
function chooseTooltipPlacement(cells, width, height, anchorX, anchorY, textWidth, preferredY, bounds) {
|
|
436
|
+
const boundsX = Math.max(0, Math.min(width, Math.floor(bounds?.x ?? 0)));
|
|
437
|
+
const boundsY = Math.max(0, Math.min(height, Math.floor(bounds?.y ?? 0)));
|
|
438
|
+
const boundsRight = Math.max(boundsX, Math.min(width, Math.floor((bounds?.x ?? 0) + (bounds?.w ?? width))));
|
|
439
|
+
const boundsBottom = Math.max(boundsY, Math.min(height, Math.floor((bounds?.y ?? 0) + (bounds?.h ?? height))));
|
|
440
|
+
const availableW = boundsRight - boundsX;
|
|
441
|
+
if (availableW <= 0 || boundsBottom <= boundsY) return {
|
|
442
|
+
x: 0,
|
|
443
|
+
y: 0
|
|
444
|
+
};
|
|
445
|
+
const tooltipWidth = Math.min(availableW, Math.max(1, textWidth));
|
|
446
|
+
const clampX = (x) => Math.max(boundsX, Math.min(x, Math.max(boundsX, boundsRight - tooltipWidth)));
|
|
447
|
+
const xCandidates = [
|
|
448
|
+
anchorX + 2,
|
|
449
|
+
anchorX - tooltipWidth - 2,
|
|
450
|
+
boundsX,
|
|
451
|
+
boundsRight - tooltipWidth
|
|
452
|
+
].map(clampX).filter((x, index, values) => values.indexOf(x) === index);
|
|
453
|
+
const yCandidates = [
|
|
454
|
+
preferredY,
|
|
455
|
+
anchorY > 0 ? anchorY - 1 : anchorY + 1,
|
|
456
|
+
anchorY + 1,
|
|
457
|
+
anchorY - 2,
|
|
458
|
+
anchorY + 2,
|
|
459
|
+
boundsY,
|
|
460
|
+
boundsBottom - 1
|
|
461
|
+
].filter((y) => y != null && y >= boundsY && y < boundsBottom);
|
|
462
|
+
let best = {
|
|
463
|
+
x: xCandidates[0] ?? 0,
|
|
464
|
+
y: yCandidates[0] ?? 0,
|
|
465
|
+
score: Number.POSITIVE_INFINITY
|
|
466
|
+
};
|
|
467
|
+
for (const y of yCandidates) for (const x of xCandidates) {
|
|
468
|
+
let overlap = 0;
|
|
469
|
+
for (const cell of cells) {
|
|
470
|
+
if (cell.y !== y) continue;
|
|
471
|
+
const cellW = Math.max(1, textCellWidth(cell.ch));
|
|
472
|
+
if (cell.x < x + tooltipWidth && cell.x + cellW > x) overlap++;
|
|
473
|
+
}
|
|
474
|
+
const score = overlap * 1e3 + Math.abs(y - anchorY) + Math.abs(x - anchorX) / Math.max(1, availableW);
|
|
475
|
+
if (score < best.score) best = {
|
|
476
|
+
x,
|
|
477
|
+
y,
|
|
478
|
+
score
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
return {
|
|
482
|
+
x: best.x,
|
|
483
|
+
y: best.y
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
function useChartVisibleRect(props, size) {
|
|
487
|
+
const layout = useLayout();
|
|
488
|
+
return computed(() => {
|
|
489
|
+
const full = translateRect({
|
|
490
|
+
x: Math.floor(props.x),
|
|
491
|
+
y: Math.floor(props.y),
|
|
492
|
+
w: size.value.width,
|
|
493
|
+
h: size.value.height
|
|
494
|
+
}, layout.originX, layout.originY);
|
|
495
|
+
const abs = layout.clipRect ? intersectRect(full, layout.clipRect) : full;
|
|
496
|
+
if (!abs) return {
|
|
497
|
+
x: 0,
|
|
498
|
+
y: 0,
|
|
499
|
+
w: 0,
|
|
500
|
+
h: 0
|
|
501
|
+
};
|
|
502
|
+
return {
|
|
503
|
+
x: abs.x - full.x,
|
|
504
|
+
y: abs.y - full.y,
|
|
505
|
+
w: abs.w,
|
|
506
|
+
h: abs.h
|
|
507
|
+
};
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
function resolveAxisLayout(width, height, min, max, showAxes) {
|
|
511
|
+
if (!showAxes || width < 12 || height < 5) return {
|
|
512
|
+
enabled: false,
|
|
513
|
+
plotX: 0,
|
|
514
|
+
plotY: 0,
|
|
515
|
+
plotW: width,
|
|
516
|
+
plotH: height,
|
|
517
|
+
axisX: -1,
|
|
518
|
+
axisY: height,
|
|
519
|
+
minLabel: formatChartValue(min),
|
|
520
|
+
maxLabel: formatChartValue(max)
|
|
521
|
+
};
|
|
522
|
+
const minLabel = fitLabel(formatChartValue(min), 7);
|
|
523
|
+
const maxLabel = fitLabel(formatChartValue(max), 7);
|
|
524
|
+
const labelW = Math.max(2, textCellWidth(minLabel), textCellWidth(maxLabel));
|
|
525
|
+
const plotX = labelW + 1;
|
|
526
|
+
const plotY = 0;
|
|
527
|
+
const plotW = Math.max(0, width - plotX);
|
|
528
|
+
const plotH = Math.max(0, height - 2);
|
|
529
|
+
if (plotW < 2 || plotH < 2) return {
|
|
530
|
+
enabled: false,
|
|
531
|
+
plotX: 0,
|
|
532
|
+
plotY: 0,
|
|
533
|
+
plotW: width,
|
|
534
|
+
plotH: height,
|
|
535
|
+
axisX: -1,
|
|
536
|
+
axisY: height,
|
|
537
|
+
minLabel,
|
|
538
|
+
maxLabel
|
|
539
|
+
};
|
|
540
|
+
return {
|
|
541
|
+
enabled: true,
|
|
542
|
+
plotX,
|
|
543
|
+
plotY,
|
|
544
|
+
plotW,
|
|
545
|
+
plotH,
|
|
546
|
+
axisX: plotX - 1,
|
|
547
|
+
axisY: plotY + plotH,
|
|
548
|
+
minLabel,
|
|
549
|
+
maxLabel
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function pushAxes(cells, layout, style, labelStyle, xLabel, yLabel, startLabel, endLabel) {
|
|
553
|
+
if (!layout.enabled) return;
|
|
554
|
+
pushTextCells(cells, 0, layout.plotY, layout.maxLabel, labelStyle, layout.axisX);
|
|
555
|
+
pushTextCells(cells, 0, Math.max(layout.plotY, layout.axisY - 1), layout.minLabel, labelStyle, layout.axisX);
|
|
556
|
+
for (let y = layout.plotY; y < layout.axisY; y++) cells.push({
|
|
557
|
+
x: layout.axisX,
|
|
558
|
+
y,
|
|
559
|
+
ch: "│",
|
|
560
|
+
style
|
|
561
|
+
});
|
|
562
|
+
cells.push({
|
|
563
|
+
x: layout.axisX,
|
|
564
|
+
y: layout.axisY,
|
|
565
|
+
ch: "└",
|
|
566
|
+
style
|
|
567
|
+
});
|
|
568
|
+
for (let x = layout.plotX; x < layout.plotX + layout.plotW; x++) cells.push({
|
|
569
|
+
x,
|
|
570
|
+
y: layout.axisY,
|
|
571
|
+
ch: "─",
|
|
572
|
+
style
|
|
573
|
+
});
|
|
574
|
+
if (yLabel) pushTextCells(cells, layout.plotX, layout.plotY, yLabel, labelStyle, layout.plotW);
|
|
575
|
+
if (xLabel) {
|
|
576
|
+
const xLabelW = textCellWidth(sanitizeInlineText(xLabel));
|
|
577
|
+
const x = layout.plotX + Math.max(0, Math.floor((layout.plotW - xLabelW) / 2));
|
|
578
|
+
pushTextCells(cells, x, layout.axisY + 1, xLabel, labelStyle, layout.plotW);
|
|
579
|
+
} else {
|
|
580
|
+
pushTextCells(cells, layout.plotX, layout.axisY + 1, startLabel, labelStyle, layout.plotW);
|
|
581
|
+
const endW = textCellWidth(sanitizeInlineText(endLabel));
|
|
582
|
+
const endX = layout.plotX + Math.max(0, layout.plotW - endW);
|
|
583
|
+
pushTextCells(cells, endX, layout.axisY + 1, endLabel, labelStyle, layout.plotW);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
function createSurface(width, height, clearStyle, cells) {
|
|
587
|
+
const rows = emptyChartRows(height);
|
|
588
|
+
for (const cell of cells) {
|
|
589
|
+
if (!Number.isFinite(cell.x) || !Number.isFinite(cell.y)) continue;
|
|
590
|
+
if (cell.y < 0 || cell.y >= height || cell.x < 0 || cell.x >= width) continue;
|
|
591
|
+
rows[cell.y].push(cell);
|
|
592
|
+
}
|
|
593
|
+
return {
|
|
594
|
+
width,
|
|
595
|
+
height,
|
|
596
|
+
clearStyle,
|
|
597
|
+
rows
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
function useChartRender(props, surface, options) {
|
|
601
|
+
const { terminal } = useTerminal();
|
|
602
|
+
const layout = useLayout();
|
|
603
|
+
const { visible, rootProps } = useVisibility();
|
|
604
|
+
const parentEventZ = inject(EventZIndexContextKey, computed(() => 0));
|
|
605
|
+
const eventZ = computed(() => (parentEventZ.value ?? 0) + (props.zIndex ?? 0));
|
|
606
|
+
const fullRect = computed(() => translateRect({
|
|
607
|
+
x: Math.floor(props.x),
|
|
608
|
+
y: Math.floor(props.y),
|
|
609
|
+
w: surface.value.width,
|
|
610
|
+
h: surface.value.height
|
|
611
|
+
}, layout.originX, layout.originY));
|
|
612
|
+
const absRect = computed(() => {
|
|
613
|
+
const translated = fullRect.value;
|
|
614
|
+
if (!layout.clipRect) return translated;
|
|
615
|
+
return intersectRect(translated, layout.clipRect) ?? {
|
|
616
|
+
x: 0,
|
|
617
|
+
y: 0,
|
|
618
|
+
w: 0,
|
|
619
|
+
h: 0
|
|
620
|
+
};
|
|
621
|
+
});
|
|
622
|
+
const dirtyRowsHint = computed(() => {
|
|
623
|
+
if (!visible.value) return [];
|
|
624
|
+
const r = absRect.value;
|
|
625
|
+
if (r.w <= 0 || r.h <= 0) return [];
|
|
626
|
+
return Array.from({ length: r.h }, (_, index) => r.y + index);
|
|
627
|
+
});
|
|
628
|
+
if (options?.handlers) {
|
|
629
|
+
const handlers = options.handlers({
|
|
630
|
+
fullRect,
|
|
631
|
+
absRect
|
|
632
|
+
});
|
|
633
|
+
useTerminalNode(() => ({
|
|
634
|
+
rect: visible.value ? absRect.value : {
|
|
635
|
+
x: 0,
|
|
636
|
+
y: 0,
|
|
637
|
+
w: 0,
|
|
638
|
+
h: 0
|
|
639
|
+
},
|
|
640
|
+
zIndex: eventZ.value,
|
|
641
|
+
visible: visible.value,
|
|
642
|
+
selectable: options.selectable ?? false,
|
|
643
|
+
handlers
|
|
644
|
+
}));
|
|
645
|
+
}
|
|
646
|
+
useRenderNode(() => ({
|
|
647
|
+
zIndex: props.zIndex,
|
|
648
|
+
rect: visible.value ? absRect.value : {
|
|
649
|
+
x: 0,
|
|
650
|
+
y: 0,
|
|
651
|
+
w: 0,
|
|
652
|
+
h: 0
|
|
653
|
+
},
|
|
654
|
+
dirtyRowsHint: dirtyRowsHint.value,
|
|
655
|
+
deps: [
|
|
656
|
+
visible.value,
|
|
657
|
+
absRect.value,
|
|
658
|
+
fullRect.value,
|
|
659
|
+
surface.value
|
|
660
|
+
],
|
|
661
|
+
paint: (dirtyRows) => {
|
|
662
|
+
if (!visible.value) return;
|
|
663
|
+
const r = absRect.value;
|
|
664
|
+
if (r.w <= 0 || r.h <= 0) return;
|
|
665
|
+
const full = fullRect.value;
|
|
666
|
+
const current = surface.value;
|
|
667
|
+
const blank = spaces(r.w);
|
|
668
|
+
const paintRow = (y) => {
|
|
669
|
+
if (y < r.y || y >= r.y + r.h) return;
|
|
670
|
+
const localY = y - full.y;
|
|
671
|
+
if (localY < 0 || localY >= current.height) return;
|
|
672
|
+
terminal.write(blank, {
|
|
673
|
+
x: r.x,
|
|
674
|
+
y,
|
|
675
|
+
style: current.clearStyle
|
|
676
|
+
});
|
|
677
|
+
for (const cell of current.rows[localY] ?? []) {
|
|
678
|
+
const x = full.x + cell.x;
|
|
679
|
+
const cellWidth = Math.max(1, textCellWidth(cell.ch));
|
|
680
|
+
if (x < r.x || x + cellWidth > r.x + r.w) continue;
|
|
681
|
+
terminal.put(x, y, cell.ch, cell.style);
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
if (!dirtyRows) {
|
|
685
|
+
for (let y = r.y; y < r.y + r.h; y++) paintRow(y);
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
for (const y of dirtyRows) paintRow(y);
|
|
689
|
+
}
|
|
690
|
+
}));
|
|
691
|
+
return () => h("span", rootProps);
|
|
692
|
+
}
|
|
693
|
+
function positiveHeatmapStyle(value, max, styles) {
|
|
694
|
+
if (!styles.length) return {};
|
|
695
|
+
if (max <= 0) return styles[0] ?? {};
|
|
696
|
+
const ratio = Math.max(0, Math.min(1, value / max));
|
|
697
|
+
const index = Math.max(0, Math.min(styles.length - 1, Math.ceil(ratio * styles.length) - 1));
|
|
698
|
+
return styles[index] ?? {};
|
|
699
|
+
}
|
|
700
|
+
const TContributionGraph = defineComponent({
|
|
701
|
+
name: "TContributionGraph",
|
|
702
|
+
props: {
|
|
703
|
+
x: {
|
|
704
|
+
type: Number,
|
|
705
|
+
required: true
|
|
706
|
+
},
|
|
707
|
+
y: {
|
|
708
|
+
type: Number,
|
|
709
|
+
required: true
|
|
710
|
+
},
|
|
711
|
+
w: {
|
|
712
|
+
type: Number,
|
|
713
|
+
default: void 0
|
|
714
|
+
},
|
|
715
|
+
h: {
|
|
716
|
+
type: Number,
|
|
717
|
+
default: void 0
|
|
718
|
+
},
|
|
719
|
+
zIndex: {
|
|
720
|
+
type: Number,
|
|
721
|
+
default: 0
|
|
722
|
+
},
|
|
723
|
+
values: {
|
|
724
|
+
type: Array,
|
|
725
|
+
required: true
|
|
726
|
+
},
|
|
727
|
+
rows: {
|
|
728
|
+
type: Number,
|
|
729
|
+
default: 7
|
|
730
|
+
},
|
|
731
|
+
columns: {
|
|
732
|
+
type: Number,
|
|
733
|
+
default: void 0
|
|
734
|
+
},
|
|
735
|
+
max: {
|
|
736
|
+
type: Number,
|
|
737
|
+
default: void 0
|
|
738
|
+
},
|
|
739
|
+
labels: {
|
|
740
|
+
type: Array,
|
|
741
|
+
default: void 0
|
|
742
|
+
},
|
|
743
|
+
unit: {
|
|
744
|
+
type: String,
|
|
745
|
+
default: ""
|
|
746
|
+
},
|
|
747
|
+
showTooltip: {
|
|
748
|
+
type: Boolean,
|
|
749
|
+
default: true
|
|
750
|
+
},
|
|
751
|
+
emptyStyle: {
|
|
752
|
+
type: Object,
|
|
753
|
+
default: () => ({
|
|
754
|
+
fg: "blackBright",
|
|
755
|
+
dim: true
|
|
756
|
+
})
|
|
757
|
+
},
|
|
758
|
+
levelStyles: {
|
|
759
|
+
type: Array,
|
|
760
|
+
default: () => DEFAULT_HEATMAP_LEVEL_STYLES
|
|
761
|
+
},
|
|
762
|
+
cell: {
|
|
763
|
+
type: String,
|
|
764
|
+
default: "■"
|
|
765
|
+
},
|
|
766
|
+
gap: {
|
|
767
|
+
type: Number,
|
|
768
|
+
default: 1
|
|
769
|
+
},
|
|
770
|
+
hoverStyle: {
|
|
771
|
+
type: Object,
|
|
772
|
+
default: () => ({})
|
|
773
|
+
},
|
|
774
|
+
tooltipStyle: {
|
|
775
|
+
type: Object,
|
|
776
|
+
default: () => ({ fg: "whiteBright" })
|
|
777
|
+
},
|
|
778
|
+
style: {
|
|
779
|
+
type: Object,
|
|
780
|
+
default: void 0
|
|
781
|
+
}
|
|
782
|
+
},
|
|
783
|
+
setup(props) {
|
|
784
|
+
const { defaultStyle } = useTerminal();
|
|
785
|
+
const baseStyle = computed(() => mergeStyle(defaultStyle.value, props.style));
|
|
786
|
+
const hoverPointer = ref(null);
|
|
787
|
+
const graphLayout = computed(() => {
|
|
788
|
+
const rowCount = cellCount(props.rows, 7);
|
|
789
|
+
if (rowCount <= 0) return {
|
|
790
|
+
rowCount,
|
|
791
|
+
gap: 0,
|
|
792
|
+
columnWidth: 1,
|
|
793
|
+
columns: 0,
|
|
794
|
+
width: 0,
|
|
795
|
+
height: 0,
|
|
796
|
+
startIndex: 0,
|
|
797
|
+
maxValue: 0
|
|
798
|
+
};
|
|
799
|
+
const gap = cellCount(props.gap, 1);
|
|
800
|
+
const dataColumns = Math.ceil(props.values.length / rowCount);
|
|
801
|
+
const requestedColumns = props.columns == null ? dataColumns : cellCount(props.columns, 0);
|
|
802
|
+
const columnWidth = 1 + gap;
|
|
803
|
+
const maxColumnsFromWidth = props.w == null ? requestedColumns : Math.floor((cellCount(props.w, 0) + gap) / columnWidth);
|
|
804
|
+
const columns = Math.max(0, Math.min(requestedColumns, maxColumnsFromWidth));
|
|
805
|
+
const width = props.w == null ? Math.max(0, columns * columnWidth - gap) : cellCount(props.w, 0);
|
|
806
|
+
const height = props.h == null ? rowCount + (props.showTooltip ? 1 : 0) : cellCount(props.h, rowCount);
|
|
807
|
+
const maxValue = props.max == null ? maxPositive(props.values) : Math.max(0, Number(props.max) || 0);
|
|
808
|
+
const startIndex = Math.max(0, (dataColumns - columns) * rowCount);
|
|
809
|
+
return {
|
|
810
|
+
rowCount,
|
|
811
|
+
gap,
|
|
812
|
+
columnWidth,
|
|
813
|
+
columns,
|
|
814
|
+
width,
|
|
815
|
+
height,
|
|
816
|
+
startIndex,
|
|
817
|
+
maxValue
|
|
818
|
+
};
|
|
819
|
+
});
|
|
820
|
+
const visibleRect = useChartVisibleRect(props, graphLayout);
|
|
821
|
+
function hitCell(localX, localY) {
|
|
822
|
+
const current = graphLayout.value;
|
|
823
|
+
if (current.width <= 0 || current.height <= 0 || current.columns <= 0) return null;
|
|
824
|
+
const graphHeight = Math.min(current.rowCount, current.height);
|
|
825
|
+
if (localX < 0 || localX >= current.width || localY < 0 || localY >= graphHeight) return null;
|
|
826
|
+
const col = Math.floor(localX / current.columnWidth);
|
|
827
|
+
const cellX = col * current.columnWidth;
|
|
828
|
+
if (col < 0 || col >= current.columns) return null;
|
|
829
|
+
if (localX !== cellX) return null;
|
|
830
|
+
const index = current.startIndex + col * current.rowCount + localY;
|
|
831
|
+
if (index < 0 || index >= props.values.length) return null;
|
|
832
|
+
const value = Number(props.values[index]);
|
|
833
|
+
if (!Number.isFinite(value)) return null;
|
|
834
|
+
const label = props.labels?.[index] ?? `#${index + 1}`;
|
|
835
|
+
return {
|
|
836
|
+
x: cellX,
|
|
837
|
+
y: localY,
|
|
838
|
+
index,
|
|
839
|
+
value,
|
|
840
|
+
label
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
const surface = computed(() => {
|
|
844
|
+
const current = graphLayout.value;
|
|
845
|
+
if (current.rowCount <= 0) return createSurface(0, 0, baseStyle.value, []);
|
|
846
|
+
const clearStyle = mergeStyle(baseStyle.value, props.emptyStyle);
|
|
847
|
+
const levelStyles = props.levelStyles.map((style) => mergeStyle(baseStyle.value, style));
|
|
848
|
+
const cells = [];
|
|
849
|
+
const glyph = chartGlyph(props.cell, "■");
|
|
850
|
+
const pointer = hoverPointer.value;
|
|
851
|
+
const hovered = pointer ? hitCell(pointer.x, pointer.y) : null;
|
|
852
|
+
for (let col = 0; col < current.columns; col++) {
|
|
853
|
+
const cellX = col * current.columnWidth;
|
|
854
|
+
for (let row = 0; row < current.rowCount && row < current.height; row++) {
|
|
855
|
+
const index = current.startIndex + col * current.rowCount + row;
|
|
856
|
+
const value = Number(props.values[index] ?? 0);
|
|
857
|
+
const positive = Number.isFinite(value) && value > 0;
|
|
858
|
+
const baseCellStyle = positive ? levelStyles.length ? positiveHeatmapStyle(value, current.maxValue, levelStyles) : baseStyle.value : clearStyle;
|
|
859
|
+
const style = hovered?.index === index ? mergeStyle(baseCellStyle, props.hoverStyle) : baseCellStyle;
|
|
860
|
+
cells.push({
|
|
861
|
+
x: cellX,
|
|
862
|
+
y: row,
|
|
863
|
+
ch: glyph,
|
|
864
|
+
style
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
const visible = visibleRect.value;
|
|
869
|
+
if (props.showTooltip && hovered && current.width > 0 && current.height > 0 && visible.w > 0 && visible.h > 0) {
|
|
870
|
+
const unit = sanitizeInlineText(props.unit);
|
|
871
|
+
const value = unit ? `${formatChartValue(hovered.value)} ${unit}` : formatChartValue(hovered.value);
|
|
872
|
+
const text = `${sanitizeInlineText(hovered.label)} ${value}`;
|
|
873
|
+
const textWidth = textCellWidth(text);
|
|
874
|
+
const graphHeight = Math.min(current.rowCount, current.height);
|
|
875
|
+
const placement = chooseTooltipPlacement(cells, current.width, current.height, hovered.x, hovered.y, textWidth, current.height > graphHeight ? graphHeight : void 0, visible);
|
|
876
|
+
pushTextCells(cells, placement.x, placement.y, text, mergeStyle(baseStyle.value, props.tooltipStyle), visible.x + visible.w - placement.x);
|
|
877
|
+
}
|
|
878
|
+
return createSurface(current.width, current.height, clearStyle, cells);
|
|
879
|
+
});
|
|
880
|
+
return useChartRender(props, surface, { handlers: ({ fullRect }) => ({
|
|
881
|
+
pointermove: (event) => {
|
|
882
|
+
const next = {
|
|
883
|
+
x: Math.floor(event.cellX - fullRect.value.x),
|
|
884
|
+
y: Math.floor(event.cellY - fullRect.value.y)
|
|
885
|
+
};
|
|
886
|
+
const current = hoverPointer.value;
|
|
887
|
+
if (!current || current.x !== next.x || current.y !== next.y) hoverPointer.value = next;
|
|
888
|
+
},
|
|
889
|
+
pointerleave: () => {
|
|
890
|
+
if (hoverPointer.value != null) hoverPointer.value = null;
|
|
891
|
+
}
|
|
892
|
+
}) });
|
|
893
|
+
}
|
|
894
|
+
});
|
|
895
|
+
const TLineChart = defineComponent({
|
|
896
|
+
name: "TLineChart",
|
|
897
|
+
props: {
|
|
898
|
+
x: {
|
|
899
|
+
type: Number,
|
|
900
|
+
required: true
|
|
901
|
+
},
|
|
902
|
+
y: {
|
|
903
|
+
type: Number,
|
|
904
|
+
required: true
|
|
905
|
+
},
|
|
906
|
+
w: {
|
|
907
|
+
type: Number,
|
|
908
|
+
required: true
|
|
909
|
+
},
|
|
910
|
+
h: {
|
|
911
|
+
type: Number,
|
|
912
|
+
required: true
|
|
913
|
+
},
|
|
914
|
+
zIndex: {
|
|
915
|
+
type: Number,
|
|
916
|
+
default: 0
|
|
917
|
+
},
|
|
918
|
+
values: {
|
|
919
|
+
type: Array,
|
|
920
|
+
required: true
|
|
921
|
+
},
|
|
922
|
+
labels: {
|
|
923
|
+
type: Array,
|
|
924
|
+
default: void 0
|
|
925
|
+
},
|
|
926
|
+
unit: {
|
|
927
|
+
type: String,
|
|
928
|
+
default: ""
|
|
929
|
+
},
|
|
930
|
+
min: {
|
|
931
|
+
type: Number,
|
|
932
|
+
default: void 0
|
|
933
|
+
},
|
|
934
|
+
max: {
|
|
935
|
+
type: Number,
|
|
936
|
+
default: void 0
|
|
937
|
+
},
|
|
938
|
+
style: {
|
|
939
|
+
type: Object,
|
|
940
|
+
default: void 0
|
|
941
|
+
},
|
|
942
|
+
lineStyle: {
|
|
943
|
+
type: Object,
|
|
944
|
+
default: () => ({ fg: "cyanBright" })
|
|
945
|
+
},
|
|
946
|
+
showAxes: {
|
|
947
|
+
type: Boolean,
|
|
948
|
+
default: true
|
|
949
|
+
},
|
|
950
|
+
axisStyle: {
|
|
951
|
+
type: Object,
|
|
952
|
+
default: () => ({
|
|
953
|
+
fg: "white",
|
|
954
|
+
dim: true
|
|
955
|
+
})
|
|
956
|
+
},
|
|
957
|
+
labelStyle: {
|
|
958
|
+
type: Object,
|
|
959
|
+
default: () => ({ fg: "whiteBright" })
|
|
960
|
+
},
|
|
961
|
+
xLabel: {
|
|
962
|
+
type: String,
|
|
963
|
+
default: ""
|
|
964
|
+
},
|
|
965
|
+
yLabel: {
|
|
966
|
+
type: String,
|
|
967
|
+
default: ""
|
|
968
|
+
},
|
|
969
|
+
startLabel: {
|
|
970
|
+
type: String,
|
|
971
|
+
default: ""
|
|
972
|
+
},
|
|
973
|
+
endLabel: {
|
|
974
|
+
type: String,
|
|
975
|
+
default: ""
|
|
976
|
+
},
|
|
977
|
+
showTooltip: {
|
|
978
|
+
type: Boolean,
|
|
979
|
+
default: true
|
|
980
|
+
},
|
|
981
|
+
hoverStyle: {
|
|
982
|
+
type: Object,
|
|
983
|
+
default: () => ({
|
|
984
|
+
fg: "whiteBright",
|
|
985
|
+
bold: true
|
|
986
|
+
})
|
|
987
|
+
},
|
|
988
|
+
tooltipStyle: {
|
|
989
|
+
type: Object,
|
|
990
|
+
default: () => ({ fg: "whiteBright" })
|
|
991
|
+
}
|
|
992
|
+
},
|
|
993
|
+
setup(props) {
|
|
994
|
+
const { defaultStyle } = useTerminal();
|
|
995
|
+
const clearStyle = computed(() => mergeStyle(defaultStyle.value, props.style));
|
|
996
|
+
const lineStyle = computed(() => mergeStyle(clearStyle.value, props.lineStyle));
|
|
997
|
+
const axisStyle = computed(() => mergeStyle(clearStyle.value, props.axisStyle));
|
|
998
|
+
const labelStyle = computed(() => mergeStyle(clearStyle.value, props.labelStyle));
|
|
999
|
+
const hoverPointer = ref(null);
|
|
1000
|
+
const lineLayout = computed(() => {
|
|
1001
|
+
const width = cellCount(props.w, 0);
|
|
1002
|
+
const height = cellCount(props.h, 0);
|
|
1003
|
+
const runs = finiteLineRuns(props.values);
|
|
1004
|
+
const sourceLength = props.values.length;
|
|
1005
|
+
const { min, max } = domainFromValues(props.values, props.min, props.max);
|
|
1006
|
+
const layout = resolveAxisLayout(width, height, min, max, props.showAxes);
|
|
1007
|
+
return {
|
|
1008
|
+
width,
|
|
1009
|
+
height,
|
|
1010
|
+
layout,
|
|
1011
|
+
runs,
|
|
1012
|
+
sourceLength,
|
|
1013
|
+
min,
|
|
1014
|
+
max
|
|
1015
|
+
};
|
|
1016
|
+
});
|
|
1017
|
+
const visibleRect = useChartVisibleRect(props, lineLayout);
|
|
1018
|
+
function hitLine(localX, localY) {
|
|
1019
|
+
const current = lineLayout.value;
|
|
1020
|
+
const { layout, runs, sourceLength, min, max } = current;
|
|
1021
|
+
if (!runs.length || layout.plotW <= 0 || layout.plotH <= 0) return null;
|
|
1022
|
+
const plotX = localX - layout.plotX;
|
|
1023
|
+
const plotY = localY - layout.plotY;
|
|
1024
|
+
if (plotX < 0 || plotX >= layout.plotW || plotY < 0 || plotY >= layout.plotH) return null;
|
|
1025
|
+
const position = samplePositionAtX(plotX, layout.plotW, sourceLength);
|
|
1026
|
+
const point = nearestLinePointInRuns(runs, position, plotX, layout.plotW, sourceLength);
|
|
1027
|
+
if (!point) return null;
|
|
1028
|
+
const value = point.value;
|
|
1029
|
+
const x = lineXForOriginalIndex(point.originalIndex, layout.plotX, layout.plotW, sourceLength);
|
|
1030
|
+
const y = layout.plotY + valueToY(value, min, max, layout.plotH);
|
|
1031
|
+
const label = props.labels?.[point.originalIndex] ?? `#${point.originalIndex + 1}`;
|
|
1032
|
+
return {
|
|
1033
|
+
x,
|
|
1034
|
+
y,
|
|
1035
|
+
index: point.originalIndex,
|
|
1036
|
+
label,
|
|
1037
|
+
value
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
const baseCells = computed(() => {
|
|
1041
|
+
const { width, height, layout, runs, sourceLength, min, max } = lineLayout.value;
|
|
1042
|
+
const cells = [];
|
|
1043
|
+
if (layout.plotW > 0 && layout.plotH > 0 && runs.length > 0) {
|
|
1044
|
+
const occupiedLineCells = new Set();
|
|
1045
|
+
for (const run of runs) {
|
|
1046
|
+
const buckets = lineBucketsForRun(run.points, layout.plotW, sourceLength);
|
|
1047
|
+
let prevX = null;
|
|
1048
|
+
let prevY = null;
|
|
1049
|
+
for (const point of lineSegmentPointsForRun(run.points, buckets, layout.plotW, sourceLength)) {
|
|
1050
|
+
const x = layout.plotX + point.x;
|
|
1051
|
+
const y = layout.plotY + valueToY(point.value, min, max, layout.plotH);
|
|
1052
|
+
if (prevX == null || prevY == null) putLineGlyph(cells, x, y, "●", lineStyle.value, width, height, occupiedLineCells);
|
|
1053
|
+
else drawSteppedLineSegment(cells, prevX, prevY, x, y, lineStyle.value, width, height, occupiedLineCells);
|
|
1054
|
+
prevX = x;
|
|
1055
|
+
prevY = y;
|
|
1056
|
+
}
|
|
1057
|
+
for (const bucket of buckets) pushLineBucketExtrema(cells, bucket, layout, min, max, lineStyle.value, width, height, occupiedLineCells);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
pushAxes(cells, layout, axisStyle.value, labelStyle.value, props.xLabel, props.yLabel, props.startLabel || (sourceLength > 0 ? "1" : ""), props.endLabel || (sourceLength > 0 ? String(sourceLength) : ""));
|
|
1061
|
+
return cells;
|
|
1062
|
+
});
|
|
1063
|
+
const surface = computed(() => {
|
|
1064
|
+
const { width, height, layout } = lineLayout.value;
|
|
1065
|
+
const cells = baseCells.value.slice();
|
|
1066
|
+
const pointer = hoverPointer.value;
|
|
1067
|
+
const hovered = pointer ? hitLine(pointer.x, pointer.y) : null;
|
|
1068
|
+
if (hovered) cells.push({
|
|
1069
|
+
x: hovered.x,
|
|
1070
|
+
y: hovered.y,
|
|
1071
|
+
ch: "●",
|
|
1072
|
+
style: mergeStyle(lineStyle.value, props.hoverStyle)
|
|
1073
|
+
});
|
|
1074
|
+
const visible = visibleRect.value;
|
|
1075
|
+
if (props.showTooltip && hovered && width > 0 && height > 0 && visible.w > 0 && visible.h > 0) {
|
|
1076
|
+
const unit = sanitizeInlineText(props.unit);
|
|
1077
|
+
const yValue = unit ? `${formatChartValue(hovered.value)} ${unit}` : formatChartValue(hovered.value);
|
|
1078
|
+
const text = `${sanitizeInlineText(hovered.label)} x=${hovered.index + 1} y=${yValue}`;
|
|
1079
|
+
const textWidth = textCellWidth(text);
|
|
1080
|
+
const placement = chooseTooltipPlacement(cells, width, height, hovered.x, hovered.y, textWidth, layout.enabled ? layout.axisY + 1 : void 0, visible);
|
|
1081
|
+
pushTextCells(cells, placement.x, placement.y, text, mergeStyle(clearStyle.value, props.tooltipStyle), visible.x + visible.w - placement.x);
|
|
1082
|
+
}
|
|
1083
|
+
return createSurface(width, height, clearStyle.value, cells);
|
|
1084
|
+
});
|
|
1085
|
+
return useChartRender(props, surface, { handlers: ({ fullRect }) => ({
|
|
1086
|
+
pointermove: (event) => {
|
|
1087
|
+
const next = {
|
|
1088
|
+
x: Math.floor(event.cellX - fullRect.value.x),
|
|
1089
|
+
y: Math.floor(event.cellY - fullRect.value.y)
|
|
1090
|
+
};
|
|
1091
|
+
const current = hoverPointer.value;
|
|
1092
|
+
if (!current || current.x !== next.x || current.y !== next.y) hoverPointer.value = next;
|
|
1093
|
+
},
|
|
1094
|
+
pointerleave: () => {
|
|
1095
|
+
if (hoverPointer.value != null) hoverPointer.value = null;
|
|
1096
|
+
}
|
|
1097
|
+
}) });
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
const TCandlestickChart = defineComponent({
|
|
1101
|
+
name: "TCandlestickChart",
|
|
1102
|
+
props: {
|
|
1103
|
+
x: {
|
|
1104
|
+
type: Number,
|
|
1105
|
+
required: true
|
|
1106
|
+
},
|
|
1107
|
+
y: {
|
|
1108
|
+
type: Number,
|
|
1109
|
+
required: true
|
|
1110
|
+
},
|
|
1111
|
+
w: {
|
|
1112
|
+
type: Number,
|
|
1113
|
+
required: true
|
|
1114
|
+
},
|
|
1115
|
+
h: {
|
|
1116
|
+
type: Number,
|
|
1117
|
+
required: true
|
|
1118
|
+
},
|
|
1119
|
+
zIndex: {
|
|
1120
|
+
type: Number,
|
|
1121
|
+
default: 0
|
|
1122
|
+
},
|
|
1123
|
+
candles: {
|
|
1124
|
+
type: Array,
|
|
1125
|
+
required: true
|
|
1126
|
+
},
|
|
1127
|
+
labels: {
|
|
1128
|
+
type: Array,
|
|
1129
|
+
default: void 0
|
|
1130
|
+
},
|
|
1131
|
+
min: {
|
|
1132
|
+
type: Number,
|
|
1133
|
+
default: void 0
|
|
1134
|
+
},
|
|
1135
|
+
max: {
|
|
1136
|
+
type: Number,
|
|
1137
|
+
default: void 0
|
|
1138
|
+
},
|
|
1139
|
+
style: {
|
|
1140
|
+
type: Object,
|
|
1141
|
+
default: void 0
|
|
1142
|
+
},
|
|
1143
|
+
upStyle: {
|
|
1144
|
+
type: Object,
|
|
1145
|
+
default: () => ({ fg: "greenBright" })
|
|
1146
|
+
},
|
|
1147
|
+
downStyle: {
|
|
1148
|
+
type: Object,
|
|
1149
|
+
default: () => ({ fg: "redBright" })
|
|
1150
|
+
},
|
|
1151
|
+
wickStyle: {
|
|
1152
|
+
type: Object,
|
|
1153
|
+
default: void 0
|
|
1154
|
+
},
|
|
1155
|
+
showAxes: {
|
|
1156
|
+
type: Boolean,
|
|
1157
|
+
default: true
|
|
1158
|
+
},
|
|
1159
|
+
axisStyle: {
|
|
1160
|
+
type: Object,
|
|
1161
|
+
default: () => ({
|
|
1162
|
+
fg: "white",
|
|
1163
|
+
dim: true
|
|
1164
|
+
})
|
|
1165
|
+
},
|
|
1166
|
+
labelStyle: {
|
|
1167
|
+
type: Object,
|
|
1168
|
+
default: () => ({ fg: "whiteBright" })
|
|
1169
|
+
},
|
|
1170
|
+
xLabel: {
|
|
1171
|
+
type: String,
|
|
1172
|
+
default: ""
|
|
1173
|
+
},
|
|
1174
|
+
yLabel: {
|
|
1175
|
+
type: String,
|
|
1176
|
+
default: ""
|
|
1177
|
+
},
|
|
1178
|
+
startLabel: {
|
|
1179
|
+
type: String,
|
|
1180
|
+
default: ""
|
|
1181
|
+
},
|
|
1182
|
+
endLabel: {
|
|
1183
|
+
type: String,
|
|
1184
|
+
default: ""
|
|
1185
|
+
},
|
|
1186
|
+
showTooltip: {
|
|
1187
|
+
type: Boolean,
|
|
1188
|
+
default: true
|
|
1189
|
+
},
|
|
1190
|
+
hoverStyle: {
|
|
1191
|
+
type: Object,
|
|
1192
|
+
default: () => ({})
|
|
1193
|
+
},
|
|
1194
|
+
tooltipStyle: {
|
|
1195
|
+
type: Object,
|
|
1196
|
+
default: () => ({ fg: "whiteBright" })
|
|
1197
|
+
}
|
|
1198
|
+
},
|
|
1199
|
+
setup(props) {
|
|
1200
|
+
const { defaultStyle } = useTerminal();
|
|
1201
|
+
const baseStyle = computed(() => mergeStyle(defaultStyle.value, props.style));
|
|
1202
|
+
const axisStyle = computed(() => mergeStyle(baseStyle.value, props.axisStyle));
|
|
1203
|
+
const labelStyle = computed(() => mergeStyle(baseStyle.value, props.labelStyle));
|
|
1204
|
+
const hoverPointer = ref(null);
|
|
1205
|
+
const candleLayout = computed(() => {
|
|
1206
|
+
const width = cellCount(props.w, 0);
|
|
1207
|
+
const height = cellCount(props.h, 0);
|
|
1208
|
+
let min = 0;
|
|
1209
|
+
let max = 0;
|
|
1210
|
+
let layout = resolveAxisLayout(width, height, min, max, props.showAxes);
|
|
1211
|
+
let startIndex = props.candles.length;
|
|
1212
|
+
let visibleCandles = [];
|
|
1213
|
+
for (let capacity = Math.min(props.candles.length, width); capacity >= 0; capacity--) {
|
|
1214
|
+
startIndex = Math.max(0, props.candles.length - capacity);
|
|
1215
|
+
visibleCandles = props.candles.slice(startIndex);
|
|
1216
|
+
({min, max} = domainFromValues(candlestickDomainValues(visibleCandles), props.min, props.max));
|
|
1217
|
+
layout = resolveAxisLayout(width, height, min, max, props.showAxes);
|
|
1218
|
+
if (visibleCandles.length <= layout.plotW) break;
|
|
1219
|
+
}
|
|
1220
|
+
const candleOffsetX = Math.max(0, layout.plotW - visibleCandles.length);
|
|
1221
|
+
return {
|
|
1222
|
+
width,
|
|
1223
|
+
height,
|
|
1224
|
+
layout,
|
|
1225
|
+
visibleCandles,
|
|
1226
|
+
startIndex,
|
|
1227
|
+
candleOffsetX,
|
|
1228
|
+
min,
|
|
1229
|
+
max
|
|
1230
|
+
};
|
|
1231
|
+
});
|
|
1232
|
+
const visibleRect = useChartVisibleRect(props, candleLayout);
|
|
1233
|
+
function hitCandle(localX, localY) {
|
|
1234
|
+
const current = candleLayout.value;
|
|
1235
|
+
const { layout } = current;
|
|
1236
|
+
if (current.width <= 0 || current.height <= 0 || layout.plotW <= 0 || layout.plotH <= 0) return null;
|
|
1237
|
+
const plotX = localX - layout.plotX - current.candleOffsetX;
|
|
1238
|
+
const plotY = localY - layout.plotY;
|
|
1239
|
+
if (plotX < 0 || plotX >= current.visibleCandles.length || current.visibleCandles.length <= 0) return null;
|
|
1240
|
+
if (plotY < 0 || plotY >= layout.plotH) return null;
|
|
1241
|
+
const candleX = plotX;
|
|
1242
|
+
const candle = current.visibleCandles[candleX];
|
|
1243
|
+
const values = normalizeCandlestick(candle);
|
|
1244
|
+
if (!values) return null;
|
|
1245
|
+
const { open, high, low, close } = values;
|
|
1246
|
+
const index = current.startIndex + candleX;
|
|
1247
|
+
const label = props.labels?.[index] ?? `#${index + 1}`;
|
|
1248
|
+
return {
|
|
1249
|
+
x: layout.plotX + current.candleOffsetX + candleX,
|
|
1250
|
+
y: localY,
|
|
1251
|
+
index,
|
|
1252
|
+
label,
|
|
1253
|
+
value: yToValue(plotY, current.min, current.max, layout.plotH),
|
|
1254
|
+
open,
|
|
1255
|
+
high,
|
|
1256
|
+
low,
|
|
1257
|
+
close
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
const surface = computed(() => {
|
|
1261
|
+
const current = candleLayout.value;
|
|
1262
|
+
const { width, height, layout, visibleCandles, candleOffsetX, min, max } = current;
|
|
1263
|
+
const cells = [];
|
|
1264
|
+
const upStyle = mergeStyle(baseStyle.value, props.upStyle);
|
|
1265
|
+
const downStyle = mergeStyle(baseStyle.value, props.downStyle);
|
|
1266
|
+
const upWickStyle = mergeStyle(baseStyle.value, props.upStyle, props.wickStyle);
|
|
1267
|
+
const downWickStyle = mergeStyle(baseStyle.value, props.downStyle, props.wickStyle);
|
|
1268
|
+
const pointer = hoverPointer.value;
|
|
1269
|
+
const hovered = pointer ? hitCandle(pointer.x, pointer.y) : null;
|
|
1270
|
+
for (let x = 0; x < visibleCandles.length; x++) {
|
|
1271
|
+
const candle = visibleCandles[x];
|
|
1272
|
+
const values = normalizeCandlestick(candle);
|
|
1273
|
+
if (!values) continue;
|
|
1274
|
+
const { open, high, low, close } = values;
|
|
1275
|
+
const up = close >= open;
|
|
1276
|
+
const baseBodyStyle = up ? upStyle : downStyle;
|
|
1277
|
+
const baseWickStyle = up ? upWickStyle : downWickStyle;
|
|
1278
|
+
const hoveredCandle = hovered?.index === current.startIndex + x;
|
|
1279
|
+
const bodyStyle = hoveredCandle ? mergeStyle(baseBodyStyle, props.hoverStyle) : baseBodyStyle;
|
|
1280
|
+
const wickStyle = hoveredCandle ? mergeStyle(baseWickStyle, props.hoverStyle) : baseWickStyle;
|
|
1281
|
+
const highY = valueToY(Math.max(high, low, open, close), min, max, layout.plotH);
|
|
1282
|
+
const lowY = valueToY(Math.min(high, low, open, close), min, max, layout.plotH);
|
|
1283
|
+
const openY = valueToY(open, min, max, layout.plotH);
|
|
1284
|
+
const closeY = valueToY(close, min, max, layout.plotH);
|
|
1285
|
+
const bodyTop = Math.min(openY, closeY);
|
|
1286
|
+
const bodyBottom = Math.max(openY, closeY);
|
|
1287
|
+
for (let y = highY; y <= lowY; y++) {
|
|
1288
|
+
const inBody = y >= bodyTop && y <= bodyBottom;
|
|
1289
|
+
cells.push({
|
|
1290
|
+
x: layout.plotX + candleOffsetX + x,
|
|
1291
|
+
y: layout.plotY + y,
|
|
1292
|
+
ch: inBody ? "█" : "│",
|
|
1293
|
+
style: inBody ? bodyStyle : wickStyle
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
const firstVisible = props.candles.length - visibleCandles.length + 1;
|
|
1298
|
+
pushAxes(cells, layout, axisStyle.value, labelStyle.value, props.xLabel, props.yLabel, props.startLabel || (visibleCandles.length > 0 ? String(firstVisible) : ""), props.endLabel || (visibleCandles.length > 0 ? String(props.candles.length) : ""));
|
|
1299
|
+
const visible = visibleRect.value;
|
|
1300
|
+
if (props.showTooltip && hovered && width > 0 && height > 0 && visible.w > 0 && visible.h > 0) {
|
|
1301
|
+
const text = `${sanitizeInlineText(hovered.label)} x=${hovered.index + 1} y=${formatChartValue(hovered.value)} O:${formatChartValue(hovered.open)} H:${formatChartValue(hovered.high)} L:${formatChartValue(hovered.low)} C:${formatChartValue(hovered.close)}`;
|
|
1302
|
+
const textWidth = textCellWidth(text);
|
|
1303
|
+
const placement = chooseTooltipPlacement(cells, width, height, hovered.x, hovered.y, textWidth, void 0, visible);
|
|
1304
|
+
pushTextCells(cells, placement.x, placement.y, text, mergeStyle(baseStyle.value, props.tooltipStyle), visible.x + visible.w - placement.x);
|
|
1305
|
+
}
|
|
1306
|
+
return createSurface(width, height, baseStyle.value, cells);
|
|
1307
|
+
});
|
|
1308
|
+
return useChartRender(props, surface, { handlers: ({ fullRect }) => ({
|
|
1309
|
+
pointermove: (event) => {
|
|
1310
|
+
const next = {
|
|
1311
|
+
x: Math.floor(event.cellX - fullRect.value.x),
|
|
1312
|
+
y: Math.floor(event.cellY - fullRect.value.y)
|
|
1313
|
+
};
|
|
1314
|
+
const current = hoverPointer.value;
|
|
1315
|
+
if (!current || current.x !== next.x || current.y !== next.y) hoverPointer.value = next;
|
|
1316
|
+
},
|
|
1317
|
+
pointerleave: () => {
|
|
1318
|
+
if (hoverPointer.value != null) hoverPointer.value = null;
|
|
1319
|
+
}
|
|
1320
|
+
}) });
|
|
1321
|
+
}
|
|
1322
|
+
});
|
|
1323
|
+
const TPieChart = defineComponent({
|
|
1324
|
+
name: "TPieChart",
|
|
1325
|
+
props: {
|
|
1326
|
+
x: {
|
|
1327
|
+
type: Number,
|
|
1328
|
+
required: true
|
|
1329
|
+
},
|
|
1330
|
+
y: {
|
|
1331
|
+
type: Number,
|
|
1332
|
+
required: true
|
|
1333
|
+
},
|
|
1334
|
+
w: {
|
|
1335
|
+
type: Number,
|
|
1336
|
+
required: true
|
|
1337
|
+
},
|
|
1338
|
+
h: {
|
|
1339
|
+
type: Number,
|
|
1340
|
+
required: true
|
|
1341
|
+
},
|
|
1342
|
+
zIndex: {
|
|
1343
|
+
type: Number,
|
|
1344
|
+
default: 0
|
|
1345
|
+
},
|
|
1346
|
+
values: {
|
|
1347
|
+
type: Array,
|
|
1348
|
+
required: true
|
|
1349
|
+
},
|
|
1350
|
+
labels: {
|
|
1351
|
+
type: Array,
|
|
1352
|
+
default: void 0
|
|
1353
|
+
},
|
|
1354
|
+
style: {
|
|
1355
|
+
type: Object,
|
|
1356
|
+
default: void 0
|
|
1357
|
+
},
|
|
1358
|
+
segmentStyles: {
|
|
1359
|
+
type: Array,
|
|
1360
|
+
default: () => DEFAULT_PIE_SEGMENT_STYLES
|
|
1361
|
+
},
|
|
1362
|
+
cell: {
|
|
1363
|
+
type: String,
|
|
1364
|
+
default: "█"
|
|
1365
|
+
},
|
|
1366
|
+
showLegend: {
|
|
1367
|
+
type: Boolean,
|
|
1368
|
+
default: true
|
|
1369
|
+
},
|
|
1370
|
+
legendStyle: {
|
|
1371
|
+
type: Object,
|
|
1372
|
+
default: () => ({ fg: "whiteBright" })
|
|
1373
|
+
}
|
|
1374
|
+
},
|
|
1375
|
+
setup(props) {
|
|
1376
|
+
const { defaultStyle } = useTerminal();
|
|
1377
|
+
const baseStyle = computed(() => mergeStyle(defaultStyle.value, props.style));
|
|
1378
|
+
const legendStyle = computed(() => mergeStyle(baseStyle.value, props.legendStyle));
|
|
1379
|
+
const surface = computed(() => {
|
|
1380
|
+
const width = cellCount(props.w, 0);
|
|
1381
|
+
const height = cellCount(props.h, 0);
|
|
1382
|
+
const values = props.values.map((value) => {
|
|
1383
|
+
const n = Number(value);
|
|
1384
|
+
return Number.isFinite(n) ? Math.max(0, n) : 0;
|
|
1385
|
+
});
|
|
1386
|
+
const scale = maxPositive(values);
|
|
1387
|
+
const normalizedValues = scale > 0 ? values.map((value) => value / scale) : values;
|
|
1388
|
+
const total = normalizedValues.reduce((sum, value) => sum + value, 0);
|
|
1389
|
+
const cells = [];
|
|
1390
|
+
const glyph = chartGlyph(props.cell, "█");
|
|
1391
|
+
const segmentStyles = props.segmentStyles.map((style) => mergeStyle(baseStyle.value, style));
|
|
1392
|
+
const visibleSegments = values.map((value, index) => ({
|
|
1393
|
+
value,
|
|
1394
|
+
normalizedValue: normalizedValues[index] ?? 0,
|
|
1395
|
+
index
|
|
1396
|
+
})).filter((segment) => segment.value > 0);
|
|
1397
|
+
const legendItems = visibleSegments.map((segment) => {
|
|
1398
|
+
const label = props.labels?.[segment.index] ?? `S${segment.index + 1}`;
|
|
1399
|
+
const percent = total > 0 ? Math.round(segment.normalizedValue / total * 100) : 0;
|
|
1400
|
+
const text = `${label} ${formatChartValue(segment.value)} ${percent}%`;
|
|
1401
|
+
return {
|
|
1402
|
+
...segment,
|
|
1403
|
+
text
|
|
1404
|
+
};
|
|
1405
|
+
});
|
|
1406
|
+
const showLegend = props.showLegend && visibleSegments.length > 0 && width >= 18 && height >= 3;
|
|
1407
|
+
const desiredLegendWidth = legendItems.reduce((maxWidth, item) => Math.max(maxWidth, textCellWidth(sanitizeInlineText(item.text)) + 2), 0) || 12;
|
|
1408
|
+
const rightLegendWidth = showLegend ? Math.min(Math.max(12, desiredLegendWidth), Math.max(0, width - 6)) : 0;
|
|
1409
|
+
const rightPlotWidth = Math.max(0, width - rightLegendWidth - 1);
|
|
1410
|
+
const legendRows = Math.min(legendItems.length, height);
|
|
1411
|
+
const rightLegend = showLegend && rightPlotWidth >= 8;
|
|
1412
|
+
const bottomLegend = showLegend && !rightLegend && height >= legendRows + 4;
|
|
1413
|
+
const legendPlacement = rightLegend ? "right" : bottomLegend ? "bottom" : "none";
|
|
1414
|
+
const plotWidth = legendPlacement === "right" ? rightPlotWidth : width;
|
|
1415
|
+
const plotHeight = legendPlacement === "bottom" ? Math.max(0, height - legendRows - 1) : height;
|
|
1416
|
+
if (plotWidth > 0 && plotHeight > 0 && total > 0) {
|
|
1417
|
+
const segments = [];
|
|
1418
|
+
let cursor = 0;
|
|
1419
|
+
for (let i = 0; i < normalizedValues.length; i++) {
|
|
1420
|
+
const value = normalizedValues[i];
|
|
1421
|
+
if (value <= 0) continue;
|
|
1422
|
+
cursor += value / total * Math.PI * 2;
|
|
1423
|
+
segments.push({
|
|
1424
|
+
end: cursor,
|
|
1425
|
+
index: i,
|
|
1426
|
+
style: segmentStyles[i % Math.max(1, segmentStyles.length)] ?? baseStyle.value
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
const cx = plotWidth / 2;
|
|
1430
|
+
const cy = plotHeight / 2;
|
|
1431
|
+
const maxRx = plotWidth / 2;
|
|
1432
|
+
const maxRy = plotHeight / 2;
|
|
1433
|
+
const ry = Math.max(.5, Math.min(maxRy, maxRx / TERMINAL_CELL_HEIGHT_TO_WIDTH));
|
|
1434
|
+
const rx = Math.max(.5, Math.min(maxRx, ry * TERMINAL_CELL_HEIGHT_TO_WIDTH));
|
|
1435
|
+
const smoothEdge = glyph === "█";
|
|
1436
|
+
const segmentAt = (nx, ny) => {
|
|
1437
|
+
let angle = Math.atan2(ny, nx) + Math.PI / 2;
|
|
1438
|
+
if (angle < 0) angle += Math.PI * 2;
|
|
1439
|
+
return segments.find((candidate) => angle <= candidate.end) ?? segments.at(-1);
|
|
1440
|
+
};
|
|
1441
|
+
for (let y = 0; y < plotHeight; y++) for (let x = 0; x < plotWidth; x++) {
|
|
1442
|
+
let mask = 0;
|
|
1443
|
+
const hits = new Map();
|
|
1444
|
+
for (const sample of PIE_CELL_SAMPLES) {
|
|
1445
|
+
const nx = (x + sample.dx - cx) / rx;
|
|
1446
|
+
const ny = (y + sample.dy - cy) / ry;
|
|
1447
|
+
if (nx * nx + ny * ny > 1) continue;
|
|
1448
|
+
mask |= sample.bit;
|
|
1449
|
+
const segment = segmentAt(nx, ny);
|
|
1450
|
+
if (!segment) continue;
|
|
1451
|
+
const previous = hits.get(segment.index);
|
|
1452
|
+
hits.set(segment.index, {
|
|
1453
|
+
segment,
|
|
1454
|
+
count: (previous?.count ?? 0) + 1
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
if (!mask) continue;
|
|
1458
|
+
const selected = Array.from(hits.values()).sort((a, b) => b.count - a.count)[0];
|
|
1459
|
+
const ch = smoothEdge ? PIE_QUADRANT_BLOCKS[mask] ?? glyph : glyph;
|
|
1460
|
+
cells.push({
|
|
1461
|
+
x,
|
|
1462
|
+
y,
|
|
1463
|
+
ch,
|
|
1464
|
+
style: selected?.segment.style ?? baseStyle.value
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
if (legendPlacement !== "none") {
|
|
1469
|
+
const legendX = legendPlacement === "right" ? plotWidth + 1 : 0;
|
|
1470
|
+
const legendY = legendPlacement === "right" ? 0 : plotHeight + 1;
|
|
1471
|
+
const maxTextWidth = legendPlacement === "right" ? Math.max(0, width - legendX - 2) : Math.max(0, width - 2);
|
|
1472
|
+
for (let row = 0; row < legendItems.length && legendY + row < height; row++) {
|
|
1473
|
+
const segment = legendItems[row];
|
|
1474
|
+
const style = segmentStyles[segment.index % Math.max(1, segmentStyles.length)] ?? baseStyle.value;
|
|
1475
|
+
cells.push({
|
|
1476
|
+
x: legendX,
|
|
1477
|
+
y: legendY + row,
|
|
1478
|
+
ch: glyph,
|
|
1479
|
+
style
|
|
1480
|
+
});
|
|
1481
|
+
pushTextCells(cells, legendX + 2, legendY + row, segment.text, legendStyle.value, maxTextWidth);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
return createSurface(width, height, baseStyle.value, cells);
|
|
1485
|
+
});
|
|
1486
|
+
return useChartRender(props, surface);
|
|
1487
|
+
}
|
|
1488
|
+
});
|
|
1489
|
+
|
|
1490
|
+
//#endregion
|
|
10
1491
|
//#region src/vue/log/tlog-session.ts
|
|
11
1492
|
function clamp(n, min, max) {
|
|
12
1493
|
return Math.max(min, Math.min(max, n));
|
|
@@ -111,4 +1592,4 @@ function restoreTLogViewSessionState(bindings, state) {
|
|
|
111
1592
|
}
|
|
112
1593
|
|
|
113
1594
|
//#endregion
|
|
114
|
-
export { TLogLinksPanel, TLogMinimap, TLogScrollbar, TLogSearchBar, TLogSearchPager, TLogSearchResults, TLogView, TLogVirtualLinksPanel, TLogVirtualSearchResults, TTranscriptView, TVirtualList, captureTLogViewSessionState, createAppendOnlyLogStore, createTLogDensityBucketsFromMarkers, createTLogLevelPlugin, createTLogLineMatcherPlugin, createTLogLinkActionPlugin, createTLogOsc8LinkPlugin, createTLogUrlPlugin, createTLogViewSessionStore, deserializeTLogViewSessionState, detectTLogUrls, dispatchTLogPluginLinkAction, getTLogPluginMetadata, handleTLogKeymapEvent, matchesTLogKeyBinding, parseTLogAnnotatedText, resolveTLogLinksPanelTheme, resolveTLogMinimapTheme, resolveTLogScrollbarTheme, resolveTLogSearchBarTheme, resolveTLogSearchPagerTheme, resolveTLogSearchResultsTheme, resolveTLogViewTheme, restoreTLogViewSessionState, sanitizeTerminalHref, serializeTLogViewSessionState, stripTLogAnsiText, tlogDarkPreset, tlogDarkTheme, tlogDefaultKeymap, tlogDefaultPreset, tlogDefaultTheme, tlogHighContrastKeymap, tlogHighContrastPreset, tlogHighContrastTheme, toTLogExternalLinkFromVisibleLink, useTLogLinkController, useTLogRetainedIndex, useTLogSearchController, useTLogSearchResultsPage, useTLogVirtualSearchResults };
|
|
1595
|
+
export { TCandlestickChart, TContributionGraph, TLineChart, TLogLinksPanel, TLogMinimap, TLogScrollbar, TLogSearchBar, TLogSearchPager, TLogSearchResults, TLogView, TLogVirtualLinksPanel, TLogVirtualSearchResults, TPieChart, TTranscriptView, TVirtualList, captureTLogViewSessionState, createAppendOnlyLogStore, createTLogDensityBucketsFromMarkers, createTLogLevelPlugin, createTLogLineMatcherPlugin, createTLogLinkActionPlugin, createTLogOsc8LinkPlugin, createTLogUrlPlugin, createTLogViewSessionStore, deserializeTLogViewSessionState, detectTLogUrls, dispatchTLogPluginLinkAction, getTLogPluginMetadata, handleTLogKeymapEvent, matchesTLogKeyBinding, parseTLogAnnotatedText, resolveTLogLinksPanelTheme, resolveTLogMinimapTheme, resolveTLogScrollbarTheme, resolveTLogSearchBarTheme, resolveTLogSearchPagerTheme, resolveTLogSearchResultsTheme, resolveTLogViewTheme, restoreTLogViewSessionState, sanitizeTerminalHref, serializeTLogViewSessionState, stripTLogAnsiText, tlogDarkPreset, tlogDarkTheme, tlogDefaultKeymap, tlogDefaultPreset, tlogDefaultTheme, tlogHighContrastKeymap, tlogHighContrastPreset, tlogHighContrastTheme, toTLogExternalLinkFromVisibleLink, useTLogLinkController, useTLogRetainedIndex, useTLogSearchController, useTLogSearchResultsPage, useTLogVirtualSearchResults };
|