Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph/Chart plotting library #100

Open
maximecb opened this issue Apr 24, 2014 · 1 comment
Open

Graph/Chart plotting library #100

maximecb opened this issue Apr 24, 2014 · 1 comment

Comments

@maximecb
Copy link
Contributor

Minimalist graph and bar chart plotting library based on lib/draw (X11 drawing library, already implemented). This could be loosely inspired from Python's matplotlib. Should allow updating/redrawing the graphs dynamically as new data is added. This could be used, for example, to chart mathematical functions, or stock prices over time.

Example usage:

plot = require('lib/plot')

// Draws a graph linking points by line segments
// values is an array of y values
// yMin and yMax are the range of the y axis
// xMin, xMax and xDelta determine x values corresponding to point indices
plot.graph(canvas, values, yMin, yMax, xMin, xMax, xDelta)

// Draws a bar graph with labeled bars
plot.barChart(/* TODO: determine argument format */)

I would strongly advise not trying to cover every possible use case for the first version of this library, as this may increase the difficulty and complexity significantly. Comments/feedback welcome.

@maximecb
Copy link
Contributor Author

A discussion with drbell in the chat prompted me to realize that it may be best if we could create reusable objects representing graphs. The API would then be more like this:

plot = require('lib/plot')

var plot = new plot.Graph(yValues);
plot.setTitle('Graph of Y values in function of X values');
plot.setYLabel('Y values');
plot.setXLabel('X values');
plot.setYRange(0, 100);

plot.draw(canvas);

In this way, parameters could be set on a plot object. All parameters would be optional, so that only an array of y values is required to produce a graph in the most minimal case. The graph would automatically update on the next draw() call if the y values in the array change.

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

No branches or pull requests

1 participant