Skip to content

Instantly share code, notes, and snippets.

@cawa87
Created July 25, 2023 19:11
Show Gist options
  • Save cawa87/3b8c2fc73a22028d34bd71e0759a4e22 to your computer and use it in GitHub Desktop.
Save cawa87/3b8c2fc73a22028d34bd71e0759a4e22 to your computer and use it in GitHub Desktop.
cosole graph
<?php
$data = [1.1066, 1.1048, 1.1023, 1.1003, 1.0969, 1.0951, 1.0901, 1.0914, 1.0867, 1.0842, 1.0835, 1.0816, 1.08,
1.079, 1.0801, 1.0818, 1.084, 1.0875, 1.0964, 1.0977, 1.1122, 1.1117, 1.1125, 1.1187, 1.1336, 1.1456,
1.139, 1.1336, 1.124, 1.1104, 1.1157, 1.0982, 1.0934, 1.0801, 1.0707, 1.0783, 1.0843, 1.0827, 1.0981,
1.0977, 1.1034, 1.0956, 1.0936, 1.0906, 1.0785, 1.0791, 1.0885, 1.0871, 1.0867, 1.0963];
$terminalWidth = 80;
$maxValue = max($data);
$minValue = min($data);
$range = $maxValue - $minValue;
$scaleFactor = $range != 0 ? $terminalWidth / $range : 0;
foreach ($data as $value) {
$scaledValue = round(($value - $minValue) * $scaleFactor);
$graphLine = str_repeat(' ', $scaledValue) . 'o';
echo $graphLine . PHP_EOL;
}
@cawa87
Copy link
Author

cawa87 commented Jul 25, 2023

d4230ec7-2da3-4f3f-a6be-c77cdbfd8730

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