Skip to content

Commit 05b85f0

Browse files
Copilot0xrinegade
andcommitted
Convert ASCII line chart to vertical bar chart as requested
Co-authored-by: 0xrinegade <[email protected]>
1 parent 91b161f commit 05b85f0

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

src/components/analytics/VolumePerDayChart.js

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,21 @@ export default function VolumePerDayChart({ data, network, timeframe }) {
2828
// Create chart grid
2929
const chart = Array(height).fill().map(() => Array(width).fill(' '));
3030

31-
// Plot data points
31+
// Plot vertical bars for each data point
3232
for (let i = 0; i < data.length && i < width; i++) {
3333
const volume = volumes[i];
3434
const normalizedHeight = Math.round(((volume - minVolume) / range) * (height - 1));
35-
const y = height - 1 - normalizedHeight;
35+
const barHeight = normalizedHeight + 1; // +1 to ensure at least 1 character for non-zero values
3636

37-
if (y >= 0 && y < height) {
38-
chart[y][i] = '*';
39-
40-
// Connect points with lines if not first point
41-
if (i > 0) {
42-
const prevVolume = volumes[i - 1];
43-
const prevNormalizedHeight = Math.round(((prevVolume - minVolume) / range) * (height - 1));
44-
const prevY = height - 1 - prevNormalizedHeight;
45-
46-
// Draw connecting line
47-
const startY = Math.min(y, prevY);
48-
const endY = Math.max(y, prevY);
49-
50-
for (let lineY = startY; lineY <= endY; lineY++) {
51-
if (lineY >= 0 && lineY < height && chart[lineY][i] === ' ') {
52-
if (y > prevY) {
53-
chart[lineY][i] = '/';
54-
} else if (y < prevY) {
55-
chart[lineY][i] = '\\';
56-
} else {
57-
chart[lineY][i] = '-';
58-
}
59-
}
37+
// Draw vertical bar from bottom up
38+
for (let barY = 0; barY < barHeight && barY < height; barY++) {
39+
const y = height - 1 - barY;
40+
if (y >= 0 && y < height) {
41+
// Use different characters for better bar visualization
42+
if (barY === barHeight - 1) {
43+
chart[y][i] = '█'; // Top of bar
44+
} else {
45+
chart[y][i] = '█'; // Body of bar
6046
}
6147
}
6248
}
@@ -158,7 +144,7 @@ export default function VolumePerDayChart({ data, network, timeframe }) {
158144
{data.length > 0 ? (
159145
<div className="ascii-chart">
160146
<div className="chart-legend">
161-
<span className="legend-item">[*] Protocol Volume (SOL)</span>
147+
<span className="legend-item">[] Protocol Volume (SOL)</span>
162148
</div>
163149

164150
<div className="ascii-chart-grid">

0 commit comments

Comments
 (0)