Skip to content

Commit 8d1e449

Browse files
committed
Close #14
1 parent 8338ef2 commit 8d1e449

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ npm -i regl-scatterplot
3434

3535
## Getting started
3636

37+
#### Basic Example
38+
3739
```javascript
3840
import createScatterplot from 'regl-scatterplot';
3941

@@ -55,7 +57,34 @@ const points = new Array(10000)
5557
scatterplot.draw(points);
5658
```
5759

58-
See a complete example at [example/index.js](example/index.js).
60+
#### Color by value or category
61+
62+
Regl-scatterplot supports two color modes: coloring by value or coloring by category. To support those, each point can be associated to a categorical and continuous value. To specify those values simply append two additional values to a point quadruples: e.g., `[x, y, category, value]`.
63+
64+
```javascript
65+
scatterplot.draw([
66+
// x, y, category, value
67+
0.2, -0.1, 0, 0.1337,
68+
0.3, 0.1, 0, 0.3371,
69+
-0.9, 0.8, 1, 0.3713,
70+
]);
71+
```
72+
73+
To color points by category, set `pointColor` to a list of colors. For performance reasons, regl-scatterplot assumes that the category `0` refers to the first color, `1` refers to the second color, etc. Mathematically, regl-scatterplot maps categories to colors as follows: `category => category % colors.length`.
74+
75+
```javascript
76+
const colorsCat = ['#3a78aa', '#aa3a99'];
77+
scatterplot.set({ colorBy: 'category', pointColor: colorsCat });
78+
```
79+
80+
To apply a continuous colormap use `colorBy: 'value'` and set `pointColor` to a list of colors representing the colormap. For performance reasons, regl-scatterplot assumes that the values are in `[0,1]` . Mathematically, the maping functions is as follows: `value => Math.min(1, Math.max(0, value))`.
81+
82+
```javascript
83+
const blackToWhite = ['#000000', ..., '#ffffff'];
84+
scatterplot.set({ colorBy: 'value', pointColor: blackToWhite });
85+
```
86+
87+
For a complete example see [example/index.js](example/index.js).
5988

6089
## API
6190

0 commit comments

Comments
 (0)