Skip to content

Commit a02d3f3

Browse files
committed
Merge branch 'master' of github.com:flekschas/regl-scatterplot
2 parents 2e0e261 + 37441f9 commit a02d3f3

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ _FYI, regl-scatterplot doesn't bundle regl and pub-sub-es, which is why you have
5555

5656
## Getting started
5757

58-
#### Basic Example
58+
### Basic Example
5959

6060
```javascript
6161
import createScatterplot from 'regl-scatterplot';
@@ -78,7 +78,9 @@ const points = new Array(10000)
7878
scatterplot.draw(points);
7979
```
8080

81-
#### Color, Opacity, and Size Encoding
81+
**IMPORTANT:** Your points positions need to be normalized to `[-1, 1]` (normalized device coordinates). Why? Regl-scatterplot is designed to be a lower-level library, whose primary purpose is speed. As such it expects you to normalize the data upfront.
82+
83+
### Color, Opacity, and Size Encoding
8284

8385
In regl-scatterplot, points can be associated with two data values. These two values are defined as the third and forth component of the point quadruples (`[x, y, value, value]`). For instance:
8486

@@ -122,7 +124,7 @@ You can encode a point data value in multiple ways. For instance, as you can see
122124

123125
For a complete example see [example/index.js](example/index.js) and [example/size-encoding.js](example/size-encoding.js).
124126

125-
#### Connecting points
127+
### Connecting points
126128

127129
You can connect points visually using spline curves by adding a 5th component to your point data and setting `showPointConnections: true`.
128130

@@ -170,7 +172,7 @@ Note, to visualize the point connections, make sure `scatterplot.set({ showPoint
170172

171173
For an example see [example/connected-points.js](example/connected-points.js).
172174

173-
#### Synchronize D3 x and y scales with the scatterplot view
175+
### Synchronize D3 x and y scales with the scatterplot view
174176

175177
Under the hood regl-scatterplot uses a [2D camera](https://github.com/flekschas/dom-2d-camera), which you can either get via `scatterplot.get('camera')` or `scatterplot.subscribe('view', ({ camera }) => {})`. You can use the camera's `view` matrix to compute the x and y scale domains. However, since this is tedious, regl-scatterplot allows you to specify D3 x and y scales that will automatically be synchronized. For example:
176178

@@ -190,7 +192,7 @@ Now whenever you pan or zoom, the domains of `xScale` and `yScale` will be updat
190192

191193
For a complete example with D3 axes see [example/axes.js](example/axes.js).
192194

193-
#### Translating Point Coordinates to Screen Coordinates
195+
### Translating Point Coordinates to Screen Coordinates
194196

195197
Imagine you want to render additional features on top of points points, for which you need to know where on the canvas points are drawn. To determine the screen coordinates of points you can use [D3 scales](#synchronize-d3-x-and-y-scales-with-the-scatterplot-view) and `scatterplot.get('pointsInView')` as follows:
196198

@@ -245,7 +247,9 @@ _DEPRECATED! Use [`scatterplot.createTextureFromUrl()`](#scatterplot.createTextu
245247

246248
<a name="scatterplot.draw" href="#scatterplot.draw">#</a> scatterplot.<b>draw</b>(<i>points</i>, <i>options</i>)
247249

248-
Sets and draws `points`. Note that repeatedly calling this method without specifying `points` will not clear previously set points. To clear points use [`scatterplot.clear()`](#scatterplot.clear)
250+
Sets and draws `points`. Importantly, the `points`' x and y coordinates need to have been normalized to `[-1, 1]` (normalized device coordinates). The two additional values (`valueA` and `valueB`) need to be normalized to `[0, 1]` (if they represent continuous data) or `[0, >1]` (if they represent categorical data).
251+
252+
Note that repeatedly calling this method without specifying `points` will not clear previously set points. To clear points use [`scatterplot.clear()`](#scatterplot.clear).
249253

250254
**Arguments:**
251255

@@ -265,9 +269,9 @@ Sets and draws `points`. Note that repeatedly calling this method without specif
265269
```javascript
266270
const points = [
267271
[
268-
// The relative X position in normalized device coordinates
272+
// The relative X position in [-1,1] (normalized device coordinates)
269273
0.9,
270-
// The relative Y position in normalized device coordinates
274+
// The relative Y position in [-1,1] (normalized device coordinates)
271275
0.3,
272276
// The category, which defaults to `0` if `undefined`
273277
0,

0 commit comments

Comments
 (0)