|
1 |
| -gl-error-bars |
| 1 | +gl-error3d |
2 | 2 | =============
|
3 |
| - |
4 |
| -Draws error bars around scatter points. |
| 3 | +Draws error bars around data points |
5 | 4 |
|
6 | 5 | # Example
|
7 | 6 |
|
8 | 7 | ```javascript
|
9 |
| -var shell = require('gl-now')({ clearColor: [0,0,0,0] }) |
10 |
| -var camera = require('game-shell-orbit-camera')(shell) |
11 |
| -var createAxes = require('gl-axes') |
12 |
| -var createErrorBars = require('gl-error-bars') |
13 |
| -var mat4 = require('gl-mat4') |
14 |
| - |
15 |
| -var bounds = [[-5,-5,-5], [5,5,5]] |
16 |
| -var errorbars, axes |
17 |
| - |
18 |
| -shell.on('gl-init', function() { |
19 |
| - var gl = shell.gl |
20 |
| - |
21 |
| - camera.lookAt(bounds[1], [0,0,0], [0, 1, 0]) |
22 |
| - |
23 |
| - axes = createAxes(gl, { |
24 |
| - bounds: bounds |
25 |
| - }) |
26 |
| - |
27 |
| - errorbars = createErrorBars(gl, { |
28 |
| - position: [ |
29 |
| - [0,0,0], |
30 |
| - [0,2,0], |
31 |
| - [-2,-3,0] |
32 |
| - ], |
33 |
| - |
34 |
| - error: [ |
35 |
| - [[-0.5,-0.5,-0.1], [0.5,0.5,0.5]], |
36 |
| - [[0,0,0], [0.5,0.5,0.5]], |
37 |
| - [[-0.5,-0.5,0], [0,0,0]] |
38 |
| - ], |
39 |
| - |
40 |
| - color: [ |
41 |
| - [1,0,0], |
42 |
| - [0,1,0], |
43 |
| - [0,0,1] |
44 |
| - ] |
45 |
| - }) |
| 8 | +var createScene = require('gl-plot3d') |
| 9 | +var createScatter = require('gl-scatter3d') |
| 10 | +var createErrorBars = require('gl-error3d') |
| 11 | + |
| 12 | +var points = [ [0,0,0], [1,1,1], [-1, 2, -3] ] |
| 13 | +var errors = [ |
| 14 | + [[-0.5,-0.5,-0.5],[0.5,0.5,0.5]], |
| 15 | + [[-0.1,-1,-2],[0,0,0]], |
| 16 | + [[-0.1,-0.1,-0.1],[0.1,0.1,0.1]] |
| 17 | +] |
| 18 | + |
| 19 | +var scene = createScene() |
| 20 | + |
| 21 | +var scatter = createScatter({ |
| 22 | + gl: scene.gl, |
| 23 | + position: points, |
| 24 | + size: 20, |
| 25 | + orthographic: true, |
| 26 | + lineColor: [0,0,0], |
| 27 | + color: [0.7,0.8,0.4], |
| 28 | + lineWidth: 1 |
46 | 29 | })
|
| 30 | +scene.add(scatter) |
47 | 31 |
|
48 |
| -shell.on('gl-render', function() { |
49 |
| - var gl = shell.gl |
50 |
| - gl.enable(gl.DEPTH_TEST) |
51 |
| - |
52 |
| - var cameraParameters = { |
53 |
| - view: camera.view(), |
54 |
| - projection: mat4.perspective( |
55 |
| - mat4.create(), |
56 |
| - Math.PI/4.0, |
57 |
| - shell.width/shell.height, |
58 |
| - 0.1, |
59 |
| - 1000.0) |
60 |
| - } |
61 | 32 |
|
62 |
| - axes.draw(cameraParameters) |
63 |
| - errorbars.draw(cameraParameters) |
| 33 | +var errorBars = createErrorBars({ |
| 34 | + gl: scene.gl, |
| 35 | + position: points, |
| 36 | + error: errors, |
| 37 | + color: [0.9, 0.3, 0.3] |
64 | 38 | })
|
| 39 | +scene.add(errorBars) |
65 | 40 | ```
|
66 | 41 |
|
67 | 42 | # API
|
68 | 43 |
|
69 | 44 | ## Constructor
|
70 | 45 |
|
71 |
| -#### `var errorBars = require('gl-error-bars')(gl, options)` |
| 46 | +#### `var errorBars = require('gl-error3d')(options)` |
72 | 47 | Creates a new error bar object.
|
73 | 48 |
|
74 | 49 | * `gl` is a WebGL context
|
75 |
| -* `object` is a collection of properties which are used to initialize the object |
76 |
| - |
77 |
| -**Returns** A new error bar object |
78 |
| - |
79 |
| -## Methods |
80 |
| - |
81 |
| -#### `errorBars.draw(camera)` |
82 |
| -Draws the error bars |
83 |
| - |
84 |
| -* `camera` is an object storing the parameters to draw |
85 |
| - |
86 |
| - + `camera.model` is the model matrix |
87 |
| - + `camera.view` is the view matrix |
88 |
| - + `camera.projection` is the projection matrix |
89 |
| - |
90 |
| -#### `errorBars.update(options)` |
91 |
| -Updates the error bar object |
92 |
| - |
93 | 50 | * `position` is the position of each point in the plot
|
94 | 51 | * `error` is an array of error bounds represented as `[lo,hi]` for each point
|
95 | 52 | * `color` a length 3 array of arrays giving the color of the error bars along each axis.
|
96 | 53 | * `lineWidth` is the width of the error bar lines in pixels
|
97 | 54 | * `capSize` is the size of the cap for error bars
|
98 | 55 | * `clipBounds` is a box to which all error bars will be clipped
|
99 | 56 |
|
| 57 | +**Returns** A new error bar object |
| 58 | + |
| 59 | +#### `errorBars.update(options)` |
| 60 | +Updates the error bar object |
| 61 | + |
100 | 62 | #### `errorBars.dispose()`
|
101 | 63 | Destroy the error bars and release all associated resources
|
102 | 64 |
|
103 |
| -#### `errorBars.bounds` |
104 |
| -Bounds on the error bar object for display purposes |
105 |
| - |
106 | 65 | # Credits
|
107 |
| -(c) 2014 Mikola Lysenko. MIT License |
| 66 | +(c) 2014-2015 Mikola Lysenko. MIT License |
0 commit comments