asciigraph

package module
v0.0.0-...-49259cc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2018 License: BSD-3-Clause Imports: 4 Imported by: 0

README

.. -*-restructuredtext-*-

asciigraph
===========

.. image:: https://travis-ci.org/guptarohit/asciigraph.svg?branch=master
    :target: https://travis-ci.org/guptarohit/asciigraph
    :alt: Build status

.. image:: https://goreportcard.com/badge/github.com/guptarohit/asciigraph
    :target: https://goreportcard.com/report/github.com/guptarohit/asciigraph
    :alt: Go Report Card

.. image:: https://coveralls.io/repos/github/guptarohit/asciigraph/badge.svg?branch=master
    :target: https://coveralls.io/github/guptarohit/asciigraph?branch=master
    :alt: Coverage Status

.. image:: https://godoc.org/github.com/guptarohit/asciigraph?status.svg
    :target: https://godoc.org/github.com/guptarohit/asciigraph
    :alt: GoDoc

.. image:: https://img.shields.io/badge/licence-BSD-blue.svg
    :target: https://github.com/guptarohit/asciigraph/blob/master/LICENSE
    :alt: License

|

Go package to make lightweight ASCII line graphs ╭┈╯.

.. image:: https://user-images.githubusercontent.com/7895001/41509956-b1b2b3d0-7279-11e8-9d19-d7dea17d5e44.png


Installation
------------

::

    go get github.com/guptarohit/asciigraph


Usage
-----

Basic graph
^^^^^^^^^^^

.. code:: go

    package main

    import (
        "fmt"
        "github.com/guptarohit/asciigraph"
    )

    func main() {
        data := []float64{3, 4, 9, 6, 2, 4, 5, 8, 5, 10, 2, 7, 2, 5, 6}
        graph := asciigraph.Plot(data)

        fmt.Println(graph)
    }

Running this example would render the following graph:

::

 10.00 ┤        ╭╮
  9.00 ┤ ╭╮     ││
  8.00 ┤ ││   ╭╮││
  7.00 ┤ ││   ││││╭╮
  6.00 ┤ │╰╮  ││││││ ╭
  5.00 ┤ │ │ ╭╯╰╯│││╭╯
  4.00 ┤╭╯ │╭╯   ││││
  3.00 ┼╯  ││    ││││
  2.00 ┤   ╰╯    ╰╯╰╯
..

Command line interface
----------------------

This package also brings a small utility for command line usage. Assuming
`$GOPATH/bin` is in yout `$PATH`, simply `go get` it, and feed it data
points via stdin:

::

 $ go install github.com/guptarohit/asciigraph/cmd/asciigraph
 $ seq 1 72 | asciigraph -h 10 -c "plot data from stdin"
 72.00 ┼
 65.55 ┤                                                                  ╭────
 59.09 ┤                                                           ╭──────╯
 52.64 ┤                                                    ╭──────╯
 46.18 ┤                                             ╭──────╯
 39.73 ┤                                      ╭──────╯
 33.27 ┤                              ╭───────╯
 26.82 ┤                       ╭──────╯
 20.36 ┤                ╭──────╯
 13.91 ┤         ╭──────╯
  7.45 ┤  ╭──────╯
  1.00 ┼──╯
          plot data from stdin
..


Acknowledgement
----------------
This package is golang port of library `asciichart <https://github.com/kroitor/asciichart>`_ written by `@kroitor <https://github.com/kroitor>`_.

Contributing
------------

Feel free to make a pull request! :octocat:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Plot

func Plot(series []float64, options ...Option) string

Plot returns ascii graph for a series.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option represents a configuration setting.

func Caption

func Caption(caption string) Option

Caption sets the graphs caption.

func Height

func Height(h int) Option

Height sets the graphs height.

func Offset

func Offset(o int) Option

Offset sets the graphs offset.

func Width

func Width(w int) Option

Width sets the graphs width. By default, the width of the graph is determined by the number of data points. If the value given is a positive number, the data points are interpolated on the x axis. Values <= 0 reset the width to the default value.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL