reconstruct and build @anthropic-ai/claude-code source from source map

- Extract 4756 source files from cli.js.map (57MB)
- Set up Bun build system with bun:bundle feature flag shim
- Configure 90+ compile-time feature flags matching production defaults
- Inject MACRO constants (VERSION, BUILD_TIME, etc.)
- Create stubs for private packages (color-diff-napi, modifiers-napi, etc.)
- Install all public dependencies via pnpm
- Patch commander v14 to allow multi-char short flags (-d2e)
- Build output: dist/cli.js (22MB), verified working
This commit is contained in:
janlaywss
2026-03-31 19:19:50 +08:00
commit 6187147b74
37865 changed files with 5438634 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
}
}

View File

@@ -0,0 +1,2 @@
* text=auto
*.js text eol=lf

View File

@@ -0,0 +1,27 @@
os: linux
dist: focal
language: python
python:
- "3.8"
cache:
directories:
- $HOME/.cache/pip
- $HOME/.npm
- node_modules
before_install:
- set -e
- . $HOME/.nvm/nvm.sh
- nvm install stable
- nvm use stable
- npm install
- python3 --version
- pip3 --version
install: pip install flake8 pytest
script:
- npm run lint
- npm run lint-test
- npm test
# - tox -e qa
- flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- pytest --doctest-modules
after_success: npm run coverage

View File

@@ -0,0 +1 @@
# Recent Updates

View File

@@ -0,0 +1,21 @@
MIT License
Copyright © 2016 Igor Kroitor
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,5 @@
# Include the license file
include LICENSE.txt
# Include the package.json file
include package.json

View File

@@ -0,0 +1,182 @@
# asciichart
[![npm](https://img.shields.io/npm/v/asciichart.svg)](https://npmjs.com/package/asciichart) [![PyPI](https://img.shields.io/pypi/v/asciichartpy.svg)](https://pypi.python.org/pypi/asciichartpy) [![Travis](https://travis-ci.org/kroitor/asciichart.svg?branch=master)](https://travis-ci.org/kroitor/asciichart) [![Coverage Status](https://coveralls.io/repos/github/kroitor/asciichart/badge.svg?branch=master)](https://coveralls.io/github/kroitor/asciichart?branch=master) [![license](https://img.shields.io/github/license/kroitor/asciichart.svg)](https://github.com/kroitor/asciichart/blob/master/LICENSE.txt)
Console ASCII line charts in pure Javascript (for NodeJS and browsers) with no dependencies. This code is absolutely free for any usage, you just do whatever the fuck you want.
<img width="789" alt="Console ASCII Line charts in pure Javascript (for NodeJS and browsers)" src="https://cloud.githubusercontent.com/assets/1294454/22818709/9f14e1c2-ef7f-11e6-978f-34b5b595fb63.png">
## Usage
### NodeJS
```sh
npm install asciichart
```
```javascript
var asciichart = require ('asciichart')
var s0 = new Array (120)
for (var i = 0; i < s0.length; i++)
s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciichart.plot (s0))
```
### Browsers
```html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="UTF-8">
<title>asciichart</title>
<script src="asciichart.js"></script>
<script type="text/javascript">
var s0 = new Array (120)
for (var i = 0; i < s0.length; i++)
s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciichart.plot (s0))
</script>
</head>
<body>
</body>
</html>
```
### Options
The width of the chart will always equal the length of data series. The height and range are determined automatically.
```javascript
var s0 = new Array (120)
for (var i = 0; i < s0.length; i++)
s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciichart.plot (s0))
```
<img width="788" alt="Console ASCII Line charts in pure Javascript (for NodeJS and browsers)" src="https://cloud.githubusercontent.com/assets/1294454/22818807/313cd636-ef80-11e6-9d1a-7a90abdb38c8.png">
The output can be configured by passing a second parameter to the `plot (series, config)` function. The following options are supported:
```javascript
var config = {
offset: 3, // axis offset from the left (min 2)
padding: ' ', // padding string for label formatting (can be overrided)
height: 10, // any height you want
// the label format function applies default padding
format: function (x, i) { return (padding + x.toFixed (2)).slice (-padding.length) }
}
```
### Scale To Desired Height
<img width="791" alt="Console ASCII Line charts in pure Javascript (for NodeJS and browsers)" src="https://cloud.githubusercontent.com/assets/1294454/22818711/9f166128-ef7f-11e6-9748-b23b151974ed.png">
```javascript
var s = []
for (var i = 0; i < 120; i++)
s[i] = 15 * Math.cos (i * ((Math.PI * 8) / 120)) // values range from -15 to +15
console.log (asciichart.plot (s, { height: 6 })) // this rescales the graph to ±3 lines
```
<img width="787" alt="Console ASCII Line charts in pure Javascript (for NodeJS and browsers)" src="https://cloud.githubusercontent.com/assets/1294454/22825525/dd295294-ef9e-11e6-93d1-0beb80b93133.png">
### Auto-range
```javascript
var s2 = new Array (120)
s2[0] = Math.round (Math.random () * 15)
for (i = 1; i < s2.length; i++)
s2[i] = s2[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
console.log (asciichart.plot (s2))
```
<img width="788" alt="Console ASCII Line charts in pure Javascript (for NodeJS and browsers)" src="https://cloud.githubusercontent.com/assets/1294454/22818710/9f157a74-ef7f-11e6-893a-f7494b5abef1.png">
### Multiple Series
```javascript
var s2 = new Array (120)
s2[0] = Math.round (Math.random () * 15)
for (i = 1; i < s2.length; i++)
s2[i] = s2[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
var s3 = new Array (120)
s3[0] = Math.round (Math.random () * 15)
for (i = 1; i < s3.length; i++)
s3[i] = s3[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
console.log (asciichart.plot ([ s2, s3 ]))
```
<img width="788" alt="Console ASCII Line charts in pure Javascript (for NodeJS and browsers)" src="https://user-images.githubusercontent.com/27967284/79398277-5322da80-7f91-11ea-8da8-e47976b76c12.png">
### Colors
```javascript
var arr1 = new Array (120)
arr1[0] = Math.round (Math.random () * 15)
for (i = 1; i < arr1.length; i++)
arr1[i] = arr1[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
var arr2 = new Array (120)
arr2[0] = Math.round (Math.random () * 15)
for (i = 1; i < arr2.length; i++)
arr2[i] = arr2[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
var arr3 = new Array (120)
arr3[0] = Math.round (Math.random () * 15)
for (i = 1; i < arr3.length; i++)
arr3[i] = arr3[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
var arr4 = new Array (120)
arr4[0] = Math.round (Math.random () * 15)
for (i = 1; i < arr4.length; i++)
arr4[i] = arr4[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
var config = {
colors: [
asciichart.blue,
asciichart.green,
asciichart.default, // default color
undefined, // equivalent to default
]
}
console.log (asciichart.plot([ arr1, arr2, arr3, arr4 ], config))
```
<img width="788" alt="Console ASCII Line charts in pure Javascript (for NodeJS and browsers)" src="https://user-images.githubusercontent.com/27967284/79398700-51a5e200-7f92-11ea-9048-8dbdeeb60830.png">
### See Also
A util by [madnight](https://github.com/madnight) for drawing Bitcoin/Ether/altcoin charts in command-line console: [bitcoin-chart-cli](https://github.com/madnight/bitcoin-chart-cli).
![bitcoin-chart-cli](https://camo.githubusercontent.com/494806efd925c4cd56d8370c1d4e8b751812030a/68747470733a2f2f692e696d6775722e636f6d2f635474467879362e706e67)
### Ports
Special thx to all who helped port it to other languages, great stuff!
- [Python port](https://pypi.org/project/asciichartpy) included!
- Java: [ASCIIGraph](https://github.com/MitchTalmadge/ASCIIGraph), ported by [MitchTalmadge](https://github.com/MitchTalmadge). If you're a Java-person, check it out!
- Go: [asciigraph](https://github.com/guptarohit/asciigraph), ported by [guptarohit](https://github.com/guptarohit), Go people! )
- Haskell: [asciichart](https://github.com/madnight/asciichart), ported by [madnight](https://github.com/madnight) to Haskell world!
- Ruby: [ascii_chart](https://github.com/zhustec/ascii_chart), ported by [zhustec](https://github.com/zhustec)!
- Elixir: [asciichart](https://github.com/sndnv/asciichart), ported by [sndv](https://github.com/sndnv)!
- Perl: [App::AsciiChart](https://github.com/vti/app-asciichart), ported by [vti](https://github.com/vti)!
- C: [plot](https://github.com/annacrombie/plot), ported by [annacrombie](https://github.com/annacrombie) with a ruby extension!
- R: [asciichartr](https://github.com/blmayer/asciichartr), ported by [blmayer](https://github.com/blmayer)!
- Rust: [rasciigraph](https://github.com/orhanbalci/rasciigraph), ported by [orhanbalci](https://github.com/orhanbalci)!
- PHP: [PHP-colored-ascii-linechart](https://github.com/noximo/PHP-colored-ascii-linechart), ported by [noximo](https://github.com/noximo)!
- C#: [asciichart-sharp](https://github.com/samcarton/asciichart-sharp), ported by [samcarton](https://github.com/samcarton)!
### Future work (coming soon, hopefully)
- levels and points on the graph!
- even better value formatting and auto-scaling!
![preview](https://user-images.githubusercontent.com/1294454/31798504-ca2af4cc-b53c-11e7-946c-620d744f6d16.gif)

View File

@@ -0,0 +1,115 @@
asciichart
==========
|npm| |Travis| |Coverage Status| |license|
Console ASCII line charts in pure Javascript (for NodeJS and browsers) with no dependencies. This code is absolutely free for any usage, you just do whatever the fuck you want.
Usage
-----
NodeJS
~~~~~~
.. code:: sh
npm install asciichart
.. code:: javascript
var asciichart = require ('asciichart')
var s0 = new Array (120)
for (var i = 0; i < s0.length; i++)
s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciichart.plot (s0))
Browsers
~~~~~~~~
.. code:: html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="UTF-8">
<title>asciichart</title>
<script src="asciichart.js"></script>
<script type="text/javascript">
var s0 = new Array (120)
for (var i = 0; i < s0.length; i++)
s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciichart.plot (s0))
</script>
</head>
<body>
</body>
</html>
Options
~~~~~~~
The width of the chart will always equal the length of data series. The height and range are determined automatically.
.. code:: javascript
var s0 = new Array (120)
for (var i = 0; i < s0.length; i++)
s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciichart.plot (s0))
The output can be configured by passing a second parameter to the ``plot (series, config)`` function. The following options are supported:
.. code:: javascript
var config = {
offset: 3, // axis offset from the left (min 2)
padding: ' ', // padding string for label formatting (can be overrided)
height: 10, // any height you want
// the label format function applies default padding
format: function (x, i) { return (padding + x.toFixed (2)).slice (-padding.length) }
}
Scale To Desired Height
~~~~~~~~~~~~~~~~~~~~~~~
.. code:: javascript
var s = []
for (var i = 0; i < 120; i++)
s[i] = 15 * Math.cos (i * ((Math.PI * 8) / 120)) // values range from -15 to +15
console.log (asciichart.plot (s, { height: 6 })) // this rescales the graph to ±3 lines
Auto-range
~~~~~~~~~~
.. code:: javascript
var s2 = new Array (120)
s2[0] = Math.round (Math.random () * 15)
for (i = 1; i < s2.length; i++)
s2[i] = s2[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
console.log (asciichart.plot (s2))
See Also
~~~~~~~~
A util by `madnight <https://github.com/madnight>`__ for drawing Bitcoin/Ether/altcoin charts in command-line console: `bitcoin-chart-cli <https://github.com/madnight/bitcoin-chart-cli>`__.
.. figure:: https://camo.githubusercontent.com/494806efd925c4cd56d8370c1d4e8b751812030a/68747470733a2f2f692e696d6775722e636f6d2f635474467879362e706e67
:alt: bitcoin-chart-cli
bitcoin-chart-cli
Special thx to `MitchTalmadge <https://github.com/MitchTalmadge>`__ for porting this package to Java! If you're a Java-guy, check it out here: `ASCIIGraph <https://github.com/MitchTalmadge/ASCIIGraph>`__.
.. |npm| image:: https://img.shields.io/npm/v/asciichart.svg
:target: https://npmjs.com/package/asciichart
.. |Travis| image:: https://travis-ci.org/kroitor/asciichart.svg?branch=master
:target: https://travis-ci.org/kroitor/asciichart
.. |Coverage Status| image:: https://coveralls.io/repos/github/kroitor/asciichart/badge.svg?branch=master
:target: https://coveralls.io/github/kroitor/asciichart?branch=master
.. |license| image:: https://img.shields.io/github/license/kroitor/asciichart.svg
:target:

View File

@@ -0,0 +1,110 @@
"use strict";
(function (exports) {
// control sequences for coloring
exports.black = "\x1b[30m"
exports.red = "\x1b[31m"
exports.green = "\x1b[32m"
exports.yellow = "\x1b[33m"
exports.blue = "\x1b[34m"
exports.magenta = "\x1b[35m"
exports.cyan = "\x1b[36m"
exports.lightgray = "\x1b[37m"
exports.default = "\x1b[39m"
exports.darkgray = "\x1b[90m"
exports.lightred = "\x1b[91m"
exports.lightgreen = "\x1b[92m"
exports.lightyellow = "\x1b[93m"
exports.lightblue = "\x1b[94m"
exports.lightmagenta = "\x1b[95m"
exports.lightcyan = "\x1b[96m"
exports.white = "\x1b[97m"
exports.reset = "\x1b[0m"
function colored (char, color) {
// do not color it if color is not specified
return (color === undefined) ? char : (color + char + exports.reset)
}
exports.colored = colored
exports.plot = function (series, cfg = undefined) {
// this function takes oth one array and array of arrays
// if an array of numbers is passed it is transfored to
// an array of exactly one array with numbers
if (typeof(series[0]) == "number"){
series = [series]
}
cfg = (typeof cfg !== 'undefined') ? cfg : {}
let min = (typeof cfg.min !== 'undefined') ? cfg.min : series[0][0]
let max = (typeof cfg.max !== 'undefined') ? cfg.max : series[0][0]
for (let j = 0; j < series.length; j++) {
for (let i = 0; i < series[j].length; i++) {
min = Math.min(min, series[j][i])
max = Math.max(max, series[j][i])
}
}
let defaultSymbols = [ '┼', '┤', '╶', '╴', '─', '╰', '╭', '╮', '╯', '│' ]
let range = Math.abs (max - min)
let offset = (typeof cfg.offset !== 'undefined') ? cfg.offset : 3
let padding = (typeof cfg.padding !== 'undefined') ? cfg.padding : ' '
let height = (typeof cfg.height !== 'undefined') ? cfg.height : range
let colors = (typeof cfg.colors !== 'undefined') ? cfg.colors : []
let ratio = range !== 0 ? height / range : 1;
let min2 = Math.round (min * ratio)
let max2 = Math.round (max * ratio)
let rows = Math.abs (max2 - min2)
let width = 0
for (let i = 0; i < series.length; i++) {
width = Math.max(width, series[i].length)
}
width = width + offset
let symbols = (typeof cfg.symbols !== 'undefined') ? cfg.symbols : defaultSymbols
let format = (typeof cfg.format !== 'undefined') ? cfg.format : function (x) {
return (padding + x.toFixed (2)).slice (-padding.length)
}
let result = new Array (rows + 1) // empty space
for (let i = 0; i <= rows; i++) {
result[i] = new Array (width)
for (let j = 0; j < width; j++) {
result[i][j] = ' '
}
}
for (let y = min2; y <= max2; ++y) { // axis + labels
let label = format (rows > 0 ? max - (y - min2) * range / rows : y, y - min2)
result[y - min2][Math.max (offset - label.length, 0)] = label
result[y - min2][offset - 1] = (y == 0) ? symbols[0] : symbols[1]
}
for (let j = 0; j < series.length; j++) {
let currentColor = colors[j % colors.length]
let y0 = Math.round (series[j][0] * ratio) - min2
result[rows - y0][offset - 1] = colored(symbols[0], currentColor) // first value
for (let x = 0; x < series[j].length - 1; x++) { // plot the line
let y0 = Math.round (series[j][x + 0] * ratio) - min2
let y1 = Math.round (series[j][x + 1] * ratio) - min2
if (y0 == y1) {
result[rows - y0][x + offset] = colored(symbols[4], currentColor)
} else {
result[rows - y1][x + offset] = colored((y0 > y1) ? symbols[5] : symbols[6], currentColor)
result[rows - y0][x + offset] = colored((y0 > y1) ? symbols[7] : symbols[8], currentColor)
let from = Math.min (y0, y1)
let to = Math.max (y0, y1)
for (let y = from + 1; y < to; y++) {
result[rows - y][x + offset] = colored(symbols[9], currentColor)
}
}
}
}
return result.map (function (x) { return x.join ('') }).join ('\n')
}
}) (typeof exports === 'undefined' ? /* istanbul ignore next */ this['asciichart'] = {} : exports);

View File

@@ -0,0 +1,28 @@
{
"folders":
[
{
"path": ".",
"folder_exclude_patterns": [
"node_modules",
"ccxt.egg-info",
"dist",
".nyc_output",
"__pycache__"
],
"file_exclude_patterns": ["*.pyc"],
"follow_symlinks": true
}
],
"settings":
{
"tab_size": 4
},
"build_systems":
[
{
"name": "List",
"shell_cmd": "ls -l"
}
]
}

View File

@@ -0,0 +1,214 @@
# -*- coding: utf-8 -*-
"""Module to generate ascii charts.
This module provides a single function `plot` that can be used to generate an
ascii chart from a series of numbers. The chart can be configured via several
options to tune the output.
"""
from __future__ import division
from math import ceil, floor, isnan
black = "\033[30m"
red = "\033[31m"
green = "\033[32m"
yellow = "\033[33m"
blue = "\033[34m"
magenta = "\033[35m"
cyan = "\033[36m"
lightgray = "\033[37m"
default = "\033[39m"
darkgray = "\033[90m"
lightred = "\033[91m"
lightgreen = "\033[92m"
lightyellow = "\033[93m"
lightblue = "\033[94m"
lightmagenta = "\033[95m"
lightcyan = "\033[96m"
white = "\033[97m"
reset = "\033[0m"
__all__ = [
'plot', 'black', 'red',
'green', 'yellow', 'blue',
'magenta', 'cyan', 'lightgray',
'default', 'darkgray', 'lightred',
'lightgreen', 'lightyellow', 'lightblue',
'lightmagenta', 'lightcyan', 'white', 'reset',
]
# Python 3.2 has math.isfinite, which could have been used, but to support older
# versions, this little helper is shorter than having to keep doing not isnan(),
# plus the double-negative of "not is not a number" is confusing, so this should
# help with readability.
def _isnum(n):
return not isnan(n)
def colored(char, color):
if not color:
return char
else:
return color + char + reset
def plot(series, cfg=None):
"""Generate an ascii chart for a series of numbers.
`series` should be a list of ints or floats. Missing data values in the
series can be specified as a NaN. In Python versions less than 3.5, use
float("nan") to specify an NaN. With 3.5 onwards, use math.nan to specify a
NaN.
>>> series = [1,2,3,4,float("nan"),4,3,2,1]
>>> print(plot(series))
4.00 ┤ ╭╴╶╮
3.00 ┤ ╭╯ ╰╮
2.00 ┤╭╯ ╰╮
1.00 ┼╯ ╰
`series` can also be a list of lists to support multiple data series.
>>> series = [[10,20,30,40,30,20,10], [40,30,20,10,20,30,40]]
>>> print(plot(series, {'height': 3}))
40.00 ┤╮ ╭╮ ╭
30.00 ┤╰╮╯╰╭╯
20.00 ┤╭╰╮╭╯╮
10.00 ┼╯ ╰╯ ╰
`cfg` is an optional dictionary of various parameters to tune the appearance
of the chart. `min` and `max` will clamp the y-axis and all values:
>>> series = [1,2,3,4,float("nan"),4,3,2,1]
>>> print(plot(series, {'min': 0}))
4.00 ┼ ╭╴╶╮
3.00 ┤ ╭╯ ╰╮
2.00 ┤╭╯ ╰╮
1.00 ┼╯ ╰
0.00 ┤
>>> print(plot(series, {'min': 2}))
4.00 ┤ ╭╴╶╮
3.00 ┤ ╭╯ ╰╮
2.00 ┼─╯ ╰─
>>> print(plot(series, {'min': 2, 'max': 3}))
3.00 ┤ ╭─╴╶─╮
2.00 ┼─╯ ╰─
`height` specifies the number of rows the graph should occupy. It can be
used to scale down a graph with large data values:
>>> series = [10,20,30,40,50,40,30,20,10]
>>> print(plot(series, {'height': 4}))
50.00 ┤ ╭╮
40.00 ┤ ╭╯╰╮
30.00 ┤ ╭╯ ╰╮
20.00 ┤╭╯ ╰╮
10.00 ┼╯ ╰
`format` specifies a Python format string used to format the labels on the
y-axis. The default value is "{:8.2f} ". This can be used to remove the
decimal point:
>>> series = [10,20,30,40,50,40,30,20,10]
>>> print(plot(series, {'height': 4, 'format':'{:8.0f}'}))
50 ┤ ╭╮
40 ┤ ╭╯╰╮
30 ┤ ╭╯ ╰╮
20 ┤╭╯ ╰╮
10 ┼╯ ╰
"""
if len(series) == 0:
return ''
if not isinstance(series[0], list):
if all(isnan(n) for n in series):
return ''
else:
series = [series]
cfg = cfg or {}
colors = cfg.get('colors', [None])
minimum = cfg.get('min', min(filter(_isnum, [j for i in series for j in i])))
maximum = cfg.get('max', max(filter(_isnum, [j for i in series for j in i])))
default_symbols = ['', '', '', '', '', '', '', '', '', '']
symbols = cfg.get('symbols', default_symbols)
if minimum > maximum:
raise ValueError('The min value cannot exceed the max value.')
interval = maximum - minimum
offset = cfg.get('offset', 3)
height = cfg.get('height', interval)
ratio = height / interval if interval > 0 else 1
min2 = int(floor(minimum * ratio))
max2 = int(ceil(maximum * ratio))
def clamp(n):
return min(max(n, minimum), maximum)
def scaled(y):
return int(round(clamp(y) * ratio) - min2)
rows = max2 - min2
width = 0
for i in range(0, len(series)):
width = max(width, len(series[i]))
width += offset
placeholder = cfg.get('format', '{:8.2f} ')
result = [[' '] * width for i in range(rows + 1)]
# axis and labels
for y in range(min2, max2 + 1):
label = placeholder.format(maximum - ((y - min2) * interval / (rows if rows else 1)))
result[y - min2][max(offset - len(label), 0)] = label
result[y - min2][offset - 1] = symbols[0] if y == 0 else symbols[1] # zero tick mark
# first value is a tick mark across the y-axis
d0 = series[0][0]
if _isnum(d0):
result[rows - scaled(d0)][offset - 1] = symbols[0]
for i in range(0, len(series)):
color = colors[i % len(colors)]
# plot the line
for x in range(0, len(series[i]) - 1):
d0 = series[i][x + 0]
d1 = series[i][x + 1]
if isnan(d0) and isnan(d1):
continue
if isnan(d0) and _isnum(d1):
result[rows - scaled(d1)][x + offset] = colored(symbols[2], color)
continue
if _isnum(d0) and isnan(d1):
result[rows - scaled(d0)][x + offset] = colored(symbols[3], color)
continue
y0 = scaled(d0)
y1 = scaled(d1)
if y0 == y1:
result[rows - y0][x + offset] = colored(symbols[4], color)
continue
result[rows - y1][x + offset] = colored(symbols[5], color) if y0 > y1 else colored(symbols[6], color)
result[rows - y0][x + offset] = colored(symbols[7], color) if y0 > y1 else colored(symbols[8], color)
start = min(y0, y1) + 1
end = max(y0, y1)
for y in range(start, end):
result[rows - y][x + offset] = colored(symbols[9], color)
return '\n'.join([''.join(row).rstrip() for row in result])

View File

@@ -0,0 +1,150 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="UTF-8">
<title>asciichart</title>
<script src="asciichart.js"></script>
<script type="text/javascript">
//-----------------------------------------------------------------------------
var s0 = new Array (120)
for (var i = 0; i < s0.length; i++)
s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciichart.plot (s0) + '\n\n')
//-----------------------------------------------------------------------------
var s1 = new Array (120)
for (var i = 0; i < s1.length; i++)
s1[i] = 15 * Math.cos (i * ((Math.PI * 8) / s1.length))
console.log (asciichart.plot (s1, { height: 6 }) + '\n\n')
//-----------------------------------------------------------------------------
var s2 = new Array (120)
s2[0] = Math.round (Math.random () * 15)
for (i = 1; i < s2.length; i++)
s2[i] = s2[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
console.log (asciichart.plot (s2) + '\n\n')
//-----------------------------------------------------------------------------
var width = 60
var line = "\n" + '='.repeat (width + 9) + "\n"
console.log ("\nbasic\n")
var s0 = new Array (width)
for (var i = 0; i < s0.length; i++)
s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciichart.plot (s0))
console.log (line)
console.log ("configuring / scale to desired height\n")
var config = {
padding: ' ', // padding string for label formatting (can be overrided)
offset: 3, // axis offset from the left (min 2)
height: 10, // any height you want
format: function (x, i) {
return (' ' + x.toFixed (2)).slice (-' '.length)
}
}
var s = []
for (var i = 0; i < width; i++)
s[i] = 15 * Math.cos (i * ((Math.PI * 8) / width)) // values range from -15 to +15
console.log (asciichart.plot (s, config)) // this rescales the graph to ±3 lines
console.log (line)
console.log ("auto-range\n")
var s2 = new Array (width)
s2[0] = Math.round (Math.random () * 15)
for (i = 1; i < s2.length; i++)
s2[i] = s2[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
console.log (asciichart.plot (s2) + "\n")
console.log (line)
console.log ("single value\n")
var s3 = new Array (width)
for (i = 0; i < width; i++)
s3[i] = 1.0
console.log (asciichart.plot (s3) + "\n")
// test multiple
console.log (line)
console.log ("multiple disjoint array test\n")
var arr1 = new Array (width)
for (var i = 0; i < arr1.length; i++)
arr1[i] = 5 * Math.sin (i * ((Math.PI * 4) / arr1.length))
var arr2 = new Array (width)
for (var i = 0; i < arr2.length; i++)
arr2[i] = arr1[i] + 2
console.log (asciichart.plot ([ arr1, arr2 ]))
// test multiple
console.log (line)
console.log ("multiple intersecting arrays test\n")
var arr1 = new Array (width)
for (var i = 0; i < arr1.length; i++)
arr1[i] = 5 * Math.sin (i * ((Math.PI * 4) / arr1.length))
var arr2 = new Array (width)
for (var i = 0; i < arr2.length; i++)
arr2[i] = 5 * Math.sin (Math.PI + i * ((Math.PI * 4) / arr2.length))
console.log (asciichart.plot ([ arr1, arr2 ]))
// test multiple colored
console.log (line)
console.log ("multiple intersecting arrays with colors test\n")
var arr1 = new Array (width)
for (var i = 0; i < arr1.length; i++)
arr1[i] = 5 * Math.sin (i * ((Math.PI * 4) / arr1.length))
var arr2 = new Array (width)
for (var i = 0; i < arr2.length; i++)
arr2[i] = 5 * Math.sin (Math.PI + i * ((Math.PI * 4) / arr2.length))
var arr3 = new Array (width)
for (var i = 0; i < arr3.length; i++)
arr3[i] = 5 - i * 0.2
var arr4 = new Array (width)
for (var i = 0; i < arr4.length; i++)
arr4[i] = 10 + 5 * Math.cos (i * ((Math.PI * 4) / arr1.length))
var config = {
colors: [
asciichart.blue,
asciichart.green,
asciichart.magenta,
asciichart.red
]
}
var series = [ arr1, arr2, arr3, arr4 ]
console.log (asciichart.plot (series, config))
</script>
</head>
<body>
</body>
</html>

View File

@@ -0,0 +1,65 @@
{
"name": "asciichart",
"version": "1.5.25",
"description": "Nice-looking lightweight console ASCII line charts ╭┈╯ with no dependencies",
"main": "asciichart.js",
"repository": {
"type": "git",
"url": "https://github.com/kroitor/asciichart.git"
},
"dependencies": {},
"devDependencies": {
"coveralls": "^3.1.0",
"esdoc-node": "^1.0.5",
"eslint": "^7.5.0",
"istanbul": "^0.4.5",
"lodash": "^4.17.19",
"marked": "^1.1.1",
"minimist": "^1.2.5",
"mocha": "^8.1.1",
"nyc": "^15.1.0"
},
"author": {
"name": "Igor Kroitor",
"email": "igor.kroitor@gmail.com",
"url": "https://github.com/kroitor"
},
"scripts": {
"test": "nyc --reporter=html --reporter=text mocha --reporter spec",
"lint": "eslint asciichart.js",
"lint-test": "eslint test.js",
"autotest": "mocha --reporter spec --watch",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/kroitor/asciichart/issues"
},
"homepage": "https://github.com/kroitor/asciichart",
"keywords": [
"asciichart",
"ascii",
"chart",
"charting",
"charts",
"console",
"terminal",
"draw",
"box-drawing",
"box drawing",
"drawing",
"stats",
"line",
"linear",
"plot",
"graph",
"ascii graphics",
"graphics",
"command line",
"commandline",
"bash",
"shell",
"sh",
"light"
]
}

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from argparse import ArgumentParser
from asciichartpy import plot
def parse_args():
parser = ArgumentParser()
parser.add_argument("series", type=float, nargs="+")
parser.add_argument("--offset", type=int)
parser.add_argument("--height", type=float)
parser.add_argument("--format", help="Format for tick numbers.")
parser.add_argument("--minimum", type=float, help="Min y value.")
parser.add_argument("--maximum", type=float, help="Max y value.")
return parser.parse_args()
if __name__ == "__main__":
args = vars(parse_args())
series = args.pop("series")
cfg = {k: v for k, v in args.items() if v is not None}
print(plot(series, cfg))

View File

@@ -0,0 +1,5 @@
#!/bin/bash
rm -rf build/*
rm -rf dist/*
python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*

View File

@@ -0,0 +1,24 @@
[bdist_wheel]
# This flag says that the code is written to work on both Python 2 and Python
# 3. If at all possible, it is good practice to do this. If you cannot, you
# will need to generate wheels for each Python version that you support.
universal=1
[flake8]
ignore = E222, E241, E261, E265, E272, E302, E303, E305, E402, E501, E701, E704, F841, F401, F405
exclude =
.ropeproject,
.tox,
.eggs,
# No need to traverse our git directory
.git,
# There's no value in checking cache directories
__pycache__,
coverage,
# Other special cases
node_modules,
.nyc_output,
build,
tmp,
# No need to check the basecode
ccxt.py

View File

@@ -0,0 +1,66 @@
# prefer setuptools over distutils
from setuptools import setup, find_packages
# use a consistent encoding
from codecs import open
from os import path
import json
import sys
here = path.abspath(path.dirname(__file__))
# long description from README file
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
# version number and all other params from package.json
with open(path.join(here, 'package.json'), encoding='utf-8') as f:
package = json.load(f)
setup(
name=package['name'] + 'py',
version=package['version'],
description=package['description'],
long_description=long_description,
long_description_content_type='text/markdown',
url=package['homepage'],
author=package['author']['name'],
author_email=package['author']['email'],
license=package['license'],
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: Financial and Insurance Industry',
'Intended Audience :: Information Technology',
'Topic :: Software Development :: Build Tools',
'Topic :: Office/Business :: Financial :: Investment',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: JavaScript',
'Programming Language :: PHP',
'Operating System :: OS Independent',
'Environment :: Console'
],
keywords=package['keywords'],
packages=find_packages(),
install_requires=['setuptools'],
extras_require={
'qa': [
'flake8'
],
}
)

View File

@@ -0,0 +1,117 @@
"use strict";
var asciichart = require ('./asciichart')
var width = 60
var line = "\n" + '='.repeat (width + 9) + "\n"
console.log ("\nbasic\n")
var s0 = new Array (width)
for (var i = 0; i < s0.length; i++)
s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciichart.plot (s0))
console.log (line)
console.log ("configuring / scale to desired height\n")
var config = {
padding: ' ', // padding string for label formatting (can be overrided)
offset: 3, // axis offset from the left (min 2)
height: 10, // any height you want
format: function (x, i) {
return (' ' + x.toFixed (2)).slice (-' '.length)
}
}
var s = []
for (var i = 0; i < width; i++)
s[i] = 15 * Math.cos (i * ((Math.PI * 8) / width)) // values range from -15 to +15
console.log (asciichart.plot (s, config)) // this rescales the graph to ±3 lines
console.log (line)
console.log ("\configuring y-axis bounds and symbols\n")
config.min = -20;
config.max = 20;
config.symbols = [ '┣', '┣', '╶', '╴', '─', '╰', '╭', '╮', '╯', '│' ];
console.log (asciichart.plot (s, config));
console.log (line)
console.log ("auto-range\n")
var s2 = new Array (width)
s2[0] = Math.round (Math.random () * 15)
for (i = 1; i < s2.length; i++)
s2[i] = s2[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
console.log (asciichart.plot (s2) + "\n")
console.log (line)
console.log ("single value\n")
var s3 = new Array (width)
for (i = 0; i < width; i++)
s3[i] = 1.0
console.log (asciichart.plot (s3) + "\n")
// test multiple
console.log (line)
console.log ("multiple disjoint array test\n")
var arr1 = new Array (width)
for (var i = 0; i < arr1.length; i++)
arr1[i] = 5 * Math.sin (i * ((Math.PI * 4) / arr1.length))
var arr2 = new Array (width)
for (var i = 0; i < arr2.length; i++)
arr2[i] = arr1[i] + 2
console.log (asciichart.plot ([ arr1, arr2 ]))
// test multiple
console.log (line)
console.log ("multiple intersecting arrays test\n")
var arr1 = new Array (width)
for (var i = 0; i < arr1.length; i++)
arr1[i] = 5 * Math.sin (i * ((Math.PI * 4) / arr1.length))
var arr2 = new Array (width)
for (var i = 0; i < arr2.length; i++)
arr2[i] = 5 * Math.sin (Math.PI + i * ((Math.PI * 4) / arr2.length))
console.log (asciichart.plot ([ arr1, arr2 ]))
// test multiple colored
console.log (line)
console.log ("multiple intersecting arrays with colors test\n")
var arr1 = new Array (width)
for (var i = 0; i < arr1.length; i++)
arr1[i] = 5 * Math.sin (i * ((Math.PI * 4) / arr1.length))
var arr2 = new Array (width)
for (var i = 0; i < arr2.length; i++)
arr2[i] = 5 * Math.sin (Math.PI + i * ((Math.PI * 4) / arr2.length))
var arr3 = new Array (width)
for (var i = 0; i < arr3.length; i++)
arr3[i] = 5 - i * 0.2
var arr4 = new Array (width)
for (var i = 0; i < arr4.length; i++)
arr4[i] = 10 + 5 * Math.cos (i * ((Math.PI * 4) / arr1.length))
var config = {
colors: [
asciichart.blue,
asciichart.green,
asciichart.magenta,
asciichart.red
]
}
var series = [ arr1, arr2, arr3, arr4 ]
console.log (asciichart.plot (series, config))

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
from math import cos
from math import pi
# ------------------------------------------------------------------------------
from asciichartpy import plot
# ------------------------------------------------------------------------------
width = 90
series = [7 * round(cos(i * ((pi * 4) / width)), 2) for i in range(width)]
print(plot(series))
series = [2.0] * width
print(plot(series))
print(plot(series, {'height':5}))
series = [0.0] * width
print(plot(series))
print(plot(series, {'height':5}))

View File

@@ -0,0 +1,14 @@
[tox]
envlist = py{27,35,36},qa
skipsdist = True
skip_missing_interpreters = True
[testenv]
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}
commands =
python test.py
[testenv:qa]
commands = flake8
deps = .[qa]