You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-8Lines changed: 12 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ _FYI, regl-scatterplot doesn't bundle regl and pub-sub-es, which is why you have
55
55
56
56
## Getting started
57
57
58
-
####Basic Example
58
+
### Basic Example
59
59
60
60
```javascript
61
61
importcreateScatterplotfrom'regl-scatterplot';
@@ -78,7 +78,9 @@ const points = new Array(10000)
78
78
scatterplot.draw(points);
79
79
```
80
80
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
82
84
83
85
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:
84
86
@@ -122,7 +124,7 @@ You can encode a point data value in multiple ways. For instance, as you can see
122
124
123
125
For a complete example see [example/index.js](example/index.js) and [example/size-encoding.js](example/size-encoding.js).
124
126
125
-
####Connecting points
127
+
### Connecting points
126
128
127
129
You can connect points visually using spline curves by adding a 5th component to your point data and setting `showPointConnections: true`.
128
130
@@ -170,7 +172,7 @@ Note, to visualize the point connections, make sure `scatterplot.set({ showPoint
170
172
171
173
For an example see [example/connected-points.js](example/connected-points.js).
172
174
173
-
####Synchronize D3 x and y scales with the scatterplot view
175
+
### Synchronize D3 x and y scales with the scatterplot view
174
176
175
177
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:
176
178
@@ -190,7 +192,7 @@ Now whenever you pan or zoom, the domains of `xScale` and `yScale` will be updat
190
192
191
193
For a complete example with D3 axes see [example/axes.js](example/axes.js).
192
194
193
-
####Translating Point Coordinates to Screen Coordinates
195
+
### Translating Point Coordinates to Screen Coordinates
194
196
195
197
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:
196
198
@@ -245,7 +247,9 @@ _DEPRECATED! Use [`scatterplot.createTextureFromUrl()`](#scatterplot.createTextu
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).
249
253
250
254
**Arguments:**
251
255
@@ -265,9 +269,9 @@ Sets and draws `points`. Note that repeatedly calling this method without specif
265
269
```javascript
266
270
constpoints= [
267
271
[
268
-
// The relative X position in normalized device coordinates
272
+
// The relative X position in [-1,1] (normalized device coordinates)
269
273
0.9,
270
-
// The relative Y position in normalized device coordinates
274
+
// The relative Y position in [-1,1] (normalized device coordinates)
271
275
0.3,
272
276
// The category, which defaults to `0` if `undefined`
0 commit comments