Skip to content

Instantly share code, notes, and snippets.

@zz85
Last active December 14, 2020 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zz85/93c60ffe8dbba2e6e9065281db7433b1 to your computer and use it in GitHub Desktop.
Save zz85/93c60ffe8dbba2e6e9065281db7433b1 to your computer and use it in GitHub Desktop.
Ascii Charts
// '█' -> '▏'
times = (x) => new Array(x).fill(0);
var blocks = times(8).map((_, i) => String.fromCharCode(9608 + i));
var values = times(8).map(() => Math.random() * 10000);
// values = [0, 4, 10, 20, 50]
// values = [5, 5, 5, 5, 5]
// values = [ 0, 1,2,3,4,5,6,7,]
// values = [0, 0, 0]
// take care of extremes
// 10, 40, 50, 80
// 2 4 8 12
var width = 4;
let max = Math.max(...values, 1);
// 1. use sum as max
// 2. use max as length + buffer
// red \u001b[31m
var clear_screen = '\u001b[0J';
var up = (n) => `\u001b[${n}A`;
// https://en.wikipedia.org/wiki/ANSI_escape_code
// "←↖↑↗→↘↓↙"
// https://stackoverflow.com/questions/2685435/cooler-ascii-spinners
// https://jrgraphix.net/r/Unicode/2800-28FF
// https://alexwlchan.net/2018/05/ascii-bar-charts/
// https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html#completeness
// https://bennuttall.com/ascii-bar-charts/
// http://code.openark.org/blog/mysql/sql-pie-chart
// https://firebearstudio.com/blog/node-js-command-line-apps-utilities.html
// https://github.com/sindresorhus/sparkly
// ASCII dashboards
// https://github.com/msleal/asciivmssdashboard
// https://github.com/yaronn/blessed-contrib
// asciiflow
// bashplotlib
// https://github.com/bitly/data_hacks
// plotters
// https://github.com/Evizero/UnicodePlots.jl
// https://github.com/linkedin/asciietch
// https://firebearstudio.com/blog/node-js-command-line-apps-utilities.html
// https://www.radare.org/n/cutter.html
// https://www.npmjs.com/package/cli-spinners
// -o
// ===|
// brasille
// xxxxxx
// ########
// 2D Charts
// ||||||||||||||
// *****
// floor, *, end
// bar
// javascript href animation progress bar???
// █░
// http://glench.com/hash/#______/|______________________#
var fill = _ => blocks[0];
var fill = _ => "-" //"⣿⠛⣤⣠⠶⢠⢸ \u2836" // " " // "@#=*#.=-|
fractions = "#%$!.".split('');
fractions = "@Oo.".split('');
fractions = "█▇▆▅▄▃▁".split('')
fractions = "◇◈◆".split('')
fractions = "⣇⠸⠰⠠".split('')
fractions = blocks;
var partials = (remainder) => {
if (remainder == 0) return '';
var b = fractions.length - (remainder * fractions.length | 0) - 1;
// return fractions[b];
return '◈' // '|' // 'o' // '|]>'
}
function fit(v, w) {
w = w || 10;
return Array(w-v.length + 1).join(' ') + v;
}
function fitleft(v, w) {
w = w || 10;
return v + Array(w-v.length).join(' ') ;
}
function plot(values, max) {
var min = Math.min(...values, 0);
// normalize
values = values.map(v => v - min)
max = max - min;
let sum = values.reduce((x, y) => x + y, 0);
var bow = values.map((v, i) => {
var chars = v / max * width;
var a = chars | 0;
var remainder = (chars % 1);
var partial = remainder !== 0;
var p = partial ? partials(remainder): '';
var c = width - a - p.length;
var bar = times(a).map(fill).join('');
var percentage = (v/sum * 100).toFixed(2) + '%';
var value = fit(v.toFixed(0), 7)
var label = fit(`Item ${i}` + '', 10)
console.log(`${label} | ${value} |${bar}${p}${Array(c + 1).join(' ')}| ${percentage}`);
});
// console.log(bow);
// console.log('max', max, 'sum', sum);
}
plot(values, max);
setInterval(() => {
process.stdout.write(up(values.length) + clear_screen);
// values = values.map(v => v + (Math.random() - 0.5) * 100)
values = values.map((v, i) => v + Math.sin(Date.now() * 0.0007 + i) * 200)
max = Math.max(...values, 1, max);
plot(values, max);
}, 300)
/*
Thoughts
- These are Fun!
- Good Visualizations, Informational and Presentable
- Useful - Make CLI Terminal tools
- Just like colors, use it!
*/
@zz85
Copy link
Author

zz85 commented Dec 14, 2020

Packet sizes:
       20 - 40 bytes      80 ------------------------------------------------------------o 19.70%
       40 - 60 bytes      63 -----------------------------------------------o              15.52%
       60 - 80 bytes       7 -----o                                                        1.72%
      80 - 100 bytes       8 ------o                                                       1.97%
     100 - 120 bytes       5 ---o                                                          1.23%
     140 - 160 bytes       5 ---o                                                          1.23%
     160 - 180 bytes       2 -o                                                            0.49%
     180 - 200 bytes       1 o                                                             0.25%
     220 - 240 bytes       2 -o                                                            0.49%
     240 - 260 bytes       7 -----o                                                        1.72%
     260 - 280 bytes       8 ------o                                                       1.97%
     280 - 300 bytes      18 -------------o                                                4.43%
     300 - 320 bytes      38 ----------------------------o                                 9.36%
     320 - 340 bytes       6 ----o                                                         1.48%
     340 - 360 bytes       1 o                                                             0.25%
     360 - 380 bytes       5 ---o                                                          1.23%
     380 - 400 bytes      11 --------o                                                     2.71%
     400 - 420 bytes       6 ----o                                                         1.48%
     420 - 440 bytes       3 --o                                                           0.74%
     480 - 500 bytes       4 ---o                                                          0.99%
     500 - 520 bytes      10 -------o                                                      2.46%
     560 - 580 bytes       2 -o                                                            0.49%
     600 - 620 bytes       1 o                                                             0.25%
     620 - 640 bytes       4 ---o                                                          0.99%
     640 - 660 bytes       2 -o                                                            0.49%
     660 - 680 bytes       1 o                                                             0.25%
     680 - 700 bytes       4 ---o                                                          0.99%
     700 - 720 bytes       1 o                                                             0.25%
     840 - 860 bytes       3 --o                                                           0.74%
     860 - 880 bytes       1 o                                                             0.25%
     920 - 940 bytes       2 -o                                                            0.49%
     940 - 960 bytes       1 o                                                             0.25%
     960 - 980 bytes       2 -o                                                            0.49%
   1000 - 1020 bytes       3 --o                                                           0.74%
   1020 - 1040 bytes       1 o                                                             0.25%
   1060 - 1080 bytes       1 o                                                             0.25%
   1080 - 1100 bytes       1 o                                                             0.25%
   1120 - 1140 bytes       2 -o                                                            0.49%
   1200 - 1220 bytes       1 o                                                             0.25%
   1220 - 1240 bytes       1 o                                                             0.25%
   1240 - 1260 bytes       4 ---o                                                          0.99%
   1260 - 1280 bytes       3 --o                                                           0.74%
   1300 - 1320 bytes       1 o                                                             0.25%
   1320 - 1340 bytes      12 ---------o                                                    2.96%
   1360 - 1380 bytes       1 o                                                             0.25%
   1480 - 1500 bytes      61 ---------------------------------------------o                15.02%
Packet sizes:
       20 - 30 bytes      14 ---------------o                                              5.58%
       30 - 40 bytes      55 ------------------------------------------------------------o 21.91%
       40 - 50 bytes      33 ------------------------------------o                         13.15%
       50 - 60 bytes      10 ----------o                                                   3.98%
       60 - 70 bytes       7 -------o                                                      2.79%
       70 - 80 bytes       3 ---o                                                          1.20%
       80 - 90 bytes       2 --o                                                           0.80%
      90 - 100 bytes       5 -----o                                                        1.99%
     100 - 110 bytes       4 ----o                                                         1.59%
     110 - 120 bytes       5 -----o                                                        1.99%
     120 - 130 bytes       1 -o                                                            0.40%
     140 - 150 bytes       1 -o                                                            0.40%
     150 - 160 bytes       5 -----o                                                        1.99%
     160 - 170 bytes       1 -o                                                            0.40%
     180 - 190 bytes       1 -o                                                            0.40%
     210 - 220 bytes       1 -o                                                            0.40%
     230 - 240 bytes       1 -o                                                            0.40%
     240 - 250 bytes       3 ---o                                                          1.20%
     250 - 260 bytes       2 --o                                                           0.80%
     260 - 270 bytes       2 --o                                                           0.80%
     270 - 280 bytes       1 -o                                                            0.40%
     280 - 290 bytes       3 ---o                                                          1.20%
     290 - 300 bytes       1 -o                                                            0.40%
     300 - 310 bytes       3 ---o                                                          1.20%
     310 - 320 bytes      10 ----------o                                                   3.98%
     320 - 330 bytes       1 -o                                                            0.40%
     330 - 340 bytes       3 ---o                                                          1.20%
     380 - 390 bytes       5 -----o                                                        1.99%
     390 - 400 bytes       2 --o                                                           0.80%
     400 - 410 bytes       1 -o                                                            0.40%
     410 - 420 bytes       1 -o                                                            0.40%
     490 - 500 bytes       1 -o                                                            0.40%
     500 - 510 bytes       2 --o                                                           0.80%
     510 - 520 bytes       2 --o                                                           0.80%
     530 - 540 bytes       1 -o                                                            0.40%
     560 - 570 bytes       1 -o                                                            0.40%
     610 - 620 bytes       2 --o                                                           0.80%
     630 - 640 bytes       1 -o                                                            0.40%
     650 - 660 bytes       1 -o                                                            0.40%
     680 - 690 bytes       1 -o                                                            0.40%
     710 - 720 bytes       1 -o                                                            0.40%
     720 - 730 bytes       1 -o                                                            0.40%
     820 - 830 bytes       1 -o                                                            0.40%
     840 - 850 bytes       1 -o                                                            0.40%
     850 - 860 bytes       2 --o                                                           0.80%
     860 - 870 bytes       1 -o                                                            0.40%
     930 - 940 bytes       1 -o                                                            0.40%
     960 - 970 bytes       1 -o                                                            0.40%
     970 - 980 bytes       1 -o                                                            0.40%
   1200 - 1210 bytes       1 -o                                                            0.40%
   1230 - 1240 bytes       1 -o                                                            0.40%
   1250 - 1260 bytes       1 -o                                                            0.40%
   1270 - 1280 bytes       1 -o                                                            0.40%
   1330 - 1340 bytes       7 -------o                                                      2.79%
   1350 - 1360 bytes       1 -o                                                            0.40%
   1380 - 1390 bytes       2 --o                                                           0.80%
   1470 - 1480 bytes       1 -o                                                            0.40%
   1480 - 1490 bytes      27 -----------------------------o                                10.76%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment