-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathbraille-chart.ts
More file actions
65 lines (52 loc) · 2.12 KB
/
Copy pathbraille-chart.ts
File metadata and controls
65 lines (52 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { App } from '@termuijs/core';
import { Box, Text, LineChart, BrailleCanvas } from '@termuijs/widgets';
async function main() {
const root = new Box({ flexDirection: 'column', gap: 1, padding: { left: 2, top: 1 } });
root.addChild(new Text(' 📊 Braille High-Resolution Terminal Graphing Demo', {
bold: true, fg: { type: 'named', name: 'cyan' }, height: 1,
}));
root.addChild(new Text(' Rendering high-resolution continuous line charts & shapes • q to quit', {
fg: { type: 'named', name: 'brightBlack' }, height: 1,
}));
root.addChild(new Text('─'.repeat(70), { fg: { type: 'named', name: 'brightBlack' }, height: 1 }));
// Generate a smooth sine wave
const data: number[] = [];
for (let i = 0; i < 80; i++) {
data.push(Math.sin(i * 0.15) * 50 + 50);
}
const chartsContainer = new Box({ flexDirection: 'row', gap: 4, height: 12 });
// Smooth line chart using Braille canvas
const lineChart = new LineChart(data, { height: 10, width: 35 }, {
useBraille: true,
showYAxis: true,
showXAxis: true,
color: { type: 'named', name: 'green' }
});
// Custom shape drawing on BrailleCanvas
const shapesCanvas = new BrailleCanvas({
width: 60, // 30 cells wide
height: 40, // 10 cells high
color: { type: 'named', name: 'magenta' }
}, { height: 10, width: 30 });
// Draw some test shapes on the canvas
// 1. Draw a circle in the center
shapesCanvas.drawCircle(30, 20, 15);
// 2. Draw crossing diagonal lines
shapesCanvas.drawLine(5, 5, 55, 35);
shapesCanvas.drawLine(5, 35, 55, 5);
chartsContainer.addChild(lineChart);
chartsContainer.addChild(shapesCanvas);
root.addChild(chartsContainer);
const app = new App(root, { fullscreen: true, fps: 10, title: 'Braille Chart Demo' });
app.events.on('key', (event) => {
if (event.key === 'q' || (event.ctrl && event.key === 'c')) {
app.exit(0);
}
});
const exitCode = await app.mount();
process.exit(exitCode);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});