Skip to content

Commit

Permalink
New: graphOptions is now flattened into each datum
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciopoppe committed Oct 23, 2015
1 parent d3752f7 commit e0108c9
Show file tree
Hide file tree
Showing 21 changed files with 7,162 additions and 993 deletions.
119 changes: 68 additions & 51 deletions README.md
@@ -1,4 +1,4 @@
# function-plot
# function-plot

[![NPM][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
Expand All @@ -15,7 +15,7 @@ utility: [y = x * x](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&
The library currently supports interactive line charts and scatterplots, whenever the graph scale is modified the function
is evaluated again with the new bounds, result: infinite graphs!

Have a look at [the homepage](http://maurizzzio.github.io/function-plot/)
[**homepage**](http://maurizzzio.github.io/function-plot/)

## Install

Expand Down Expand Up @@ -50,9 +50,9 @@ var functionPlot = require('function-plot');
* `options`
* `options.target` {string} the selector of the parent element to render the graph to
* `options.title` {string} If set the chart will have it as a title on the top
* `options.xDomain` {array} domain of the linear scale (used in the x axis)
* `options.xDomain` {array} domain of the linear scale (used in the x axis)
* `options.yDomain` {array} domain of the linear scale (used in the y axis)
* `options.xLabel` {string} x axis label
* `options.xLabel` {string} x axis label
* `options.yLabel` {string} y axis label
* `options.disableZoom` {boolean} true to disable drag and zoom on the graph
* `options.grid` {boolean} true to show a grid
Expand All @@ -65,69 +65,86 @@ var functionPlot = require('function-plot');
* `options.annotations` {array} An array defining parallel lines to the y-axis or the x-axis
* `options.annotations[i].x` {number} x-coordinate of the line parallel to the y-axis
* `options.annotations[i].y` {number} y-coordinate of the line parallel to the x-axis
* `options.annotations[i].text` {string} text shown next to the parallel line
* `options.annotations[i].text` {string} text shown next to the parallel line
* `options.data` {array} *required* An array defining the functions to be rendered
* `options.data[i].title` {string} title of the function
* `options.data[i].color` {string} color of the function
* `options.data[i].skipTip` {boolean} true to avoid this function from being a target of the tip
* `options.data[i].fn` *required* {string} the function that represents the curve, this function is evaluated
with values which are in `range` limiting the values to the screen min/max coordinates for `x`, i.e.
at any given time the graph min/max x coordinates will limit the range of values to be plotted
* `options.data[i].range` {number[]} if given the function will only be evaluated with multiple values from this range
* `options.data[i].samples` {number} the fixed number of samples to be computed within the current domain ends
* `options.data[i].implicit` {boolean} true to creates samples for the function considering it implicit, it assumes
that the function depends on the variables *x* and *y*
* `options.data[i].secants` {Object[]} Secants of `options.data[i].fn`
* `options.data[i].secants[j].x0` {number} The abscissa of the first point
* `options.data[i].secants[j].x1` {number} (optional if `updateOnMouseMove` is set) The abscissa of the second point
* `options.data[i].secants[j].updateOnMouseMove` {boolean} (optional) True to update the secant line by evaluating
`options.data[i].fn` with the current mouse position (`x0` is the fixed point and `x1` is computed
dynamically based on the current mouse position)
* `options.data[i].derivative` {Object} Info of the instantaneous rate of change of y with respect to x
* `options.data[i].derivative.fn` {string} The derivative of `options.data[i].fn`
* `options.data[i].derivative.x0` {number} The abscissa of the point which belongs to the curve
represented by `options.data[i].fn` whose tangent will be computed (i.e. the tangent line to the point
`x0, fn(x0)`)
* `options.data[i].derivative.updateOnMouseMove` {boolean} True to compute the tangent line by evaluating
`options.data[i].derivative.fn` with the current mouse position (i.e. let `x0` be the abscissa of the
mouse position transformed to local coordinates, the tangent line to the point `x0, fn(x0)`)
* `options.data[i].graphOptions` {Object} options passed to the the files located in `lib/type/` which plot the data
generated by the library, the most useful property of this object is `type` which is used to determine the type of
graph to be rendered for a function
* `options.plugins` {array} An array describing plugins to be run when the graph is initialized, check out the
examples on the main page

### `options.data[i].graphOptions` {Object}

* `type` {string} type of graph, currently `line`, `scatter` and `interval` are supported, `interval` is the default option
* `sampler` {string} the sampler to use, currently `interval` and `builtIn` are supported (`interval` should
be used with `type: 'interval'` and `builtIn` with `type: 'line'` or `type: 'scatter'`)
### `options.data` {Array}

Depending on the type option:
An array of objects, each object contains info of a function to render and can have the following options

* `options.closed` {boolean} (only if `type: 'interval'` or `type: 'line'`) True to close the path, for any segment of the closed area graph
`y0` will be 0 and `y1` will be `f(x)`

#### if `options.data[i].parametric = true`
* `title` {string} title of the function
* `skipTip` {boolean=false} true to make the tip ignore this function
* `range` {number[]=[-Infinity, Infinity]} an array with two numbers, the function will only be evaluated with values that belong to this interval
* `nSamples` {number} The number of values to be taken from `range` to evaluate the function, note that if interval-arithmetic is used the function
will be evaluated with intervals instead of single values
* `graphType` {string='interval'} The type of graph to render, available values are `interval|polyline|scatter`
* `fnType` {string='linear'} The type of function to render, available values are `linear|parametric|implicit|polar|points|vector`
* `sampler` {string='interval'} The sampler to take samples from `range`, available values are `interval|builtIn`
* **NOTE: `builtIn` should only be used when `graphType` is `polyline|scatter`**
* **NOTE: when math.js is included in the webpage it will be used instead of the bundled sampler**

Additional style related options

* `color` {string} color of the function to render
* `closed` {boolean=false} (only if `graphType: 'polyline'` or `graphType: 'scatter'`) True to close the path, for any segment of the closed area graph
`y0` will be 0 and `y1` will be `f(x)`

When `derivative` {Object} is present on a datum

* `derivative.fn` {string} The derivative of `fn`
* `derivative.x0` {number} The abscissa of the point which belongs to the curve
represented by `fn` whose tangent will be computed (i.e. the tangent line to the point
`x0, fn(x0)`)
* `derivative.updateOnMouseMove` {boolean} True to compute the tangent line by evaluating
`derivative.fn` with the current mouse position (i.e. let `x0` be the abscissa of the
mouse position transformed to local coordinates, the tangent line to the point `x0, fn(x0)`)

When `secants` {Array} is present on a datum

* `secants[i].x0` {number} The abscissa of the first point
* `secants[i].x1` {number} (optional if `updateOnMouseMove` is set) The abscissa of the second point
* `secants[i].updateOnMouseMove` {boolean} (optional) True to update the secant line by evaluating
`fn` with the current mouse position (`x0` is the fixed point and `x1` is computed dynamically based on the current mouse position)

#### if `fnType: 'linear'` (default)

* `fn` {string} the function that represents the curve, this function is evaluated with values which are inside `range`

#### if `fnType: 'parametric'`

- `x` the x-coordinate of a point to be sampled with a parameter `t`
- `y` the y-coordinate of a point to be sampled with a parameter `t`
- `range = [0, 2 * Math.PI]` the `range` property in parametric equations is used
to determine the possible values of `t`, remember that the number of samples is
set in the property `samples`

#### if `options.data[i].polar = true`
#### if `fnType: 'polar'`

- `r` a polar equation in terms of `theta`
- `range = [-Math.PI, Math.PI]` the `range` property in polar equations is used
to determine the possible values of `theta`, remember that the number of samples is
set in the property `samples`
#### if `options.data[i].implicit = true`

#### if `fnType: 'implicit'`

- `fn` a function which needs to be expressed in terms of `x` and `y`

### `instance`
**NOTE: implicit functions can only be rendered using interval-arithmetic**

#### if `fnType: 'points'`

- `points` an array of 2-number array which hold the coordinates of the points to render

**NOTE: make sure your type of graph is either `scatter` or `polyline`**

#### if `fnType: 'vector'`

- `vector` {Array} an 2-number array which has the ends of the vector
- `offset` {Array=[0, 0]} (optional) vector's offset

### `instance`

* `instance.id` {string} a random generated id made out of letters and numbers
* `instance.linkedGraphs` {array} array of function-plot instances linked to the events of this instance,
Expand All @@ -154,8 +171,8 @@ events can be triggered by doing `instance.emit([eventName][, params])`
* `mousemove` fired whenever the mouse is moved inside the canvas, callback params `x`, `y` (in canvas space
coordinates)
* `mouseout` fired whenever the mouse is moved outside the canvas
* `before:draw` fired before drawing all the graphs
* `after:draw` fired after drawing all the graphs
* `before:draw` fired before drawing all the graphs
* `after:draw` fired after drawing all the graphs
* `zoom:scaleUpdate` fired whenever the scale of another graph is updated, callback params `xScale`, `yScale`
(x-scale and y-scale of another graph whose scales were updated)
* `tip:update` fired whenever the tip position is updated, callback params `x`, `y`, `index` (in canvas
Expand Down Expand Up @@ -184,7 +201,7 @@ When the `definite-integral` plugin is included the instance will fire the follo
## Recipes

### Evaluate a function at some value `x`

```javascript
var y = functionPlot.eval.builtIn(datum, fnProperty, scope)
```
Expand Down Expand Up @@ -306,7 +323,7 @@ Selectors (sass)
// d attribute defines the graph bounds
}
}

.y.axis {
.tick {
line {
Expand Down Expand Up @@ -334,7 +351,7 @@ npm start
Open `127.0.0.1:5555` and that's it! Local development server powered [beefy](https://www.npmjs.com/package/beefy)
Plain demo: `127.0.0.1:5555/demo.html`
Development page: `127.0.0.1:5555/playground.html`
## License
Expand Down
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "function-plot",
"main": "site/js/function-plot.js",
"main": "dist/function-plot.js",
"homepage": "https://github.com/maurizzzio/function-plot",
"authors": [
"Mauricio Poppe <me@maurizzzio.com>"
Expand Down

0 comments on commit e0108c9

Please sign in to comment.