Skip to content

Commit 5aa217c

Browse files
committed
fix: add test page for point size alpha variables, allow plotting one point.
1 parent f095ca6 commit 5aa217c

File tree

6 files changed

+36
-72
lines changed

6 files changed

+36
-72
lines changed

dev/Main.svelte

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,16 @@
11
<script>
2-
import { Scatterplot } from '../src/deepscatter';
3-
import { onMount } from 'svelte';
4-
import SwitchPositions from './svelte/SwitchPositions.svelte';
5-
import ColorChange from './svelte/ColorChange.svelte';
6-
import SizeSlider from './svelte/SizeSlider.svelte';
7-
8-
const startSize = 2;
9-
const prefs = {
10-
source_url: '/tiles',
11-
max_points: 1000000,
12-
alpha: 35, // Target saturation for the full page.
13-
zoom_balance: 0.22, // Rate at which points increase size. https://observablehq.com/@bmschmidt/zoom-strategies-for-huge-scatterplots-with-three-js
14-
point_size: startSize, // Default point size before application of size scaling
15-
background_color: '#EEEDDE',
16-
encoding: {
17-
color: {
18-
field: 'class',
19-
range: 'category10',
20-
},
21-
x: {
22-
field: 'x',
23-
transform: 'literal',
24-
},
25-
y: {
26-
field: 'y',
27-
transform: 'literal',
28-
},
29-
},
2+
import FourClasses from './FourClasses.svelte';
3+
import SinglePoint from './SinglePoint.svelte';
4+
const modes = {
5+
FourClasses: FourClasses,
6+
SinglePoint: SinglePoint,
307
};
318
32-
let scatterplot = null;
33-
onMount(() => {
34-
scatterplot = new Scatterplot('#deepscatter');
35-
window.scatterplot = scatterplot;
36-
scatterplot.plotAPI(prefs);
37-
});
9+
$: mode = 'SinglePoint';
3810
</script>
3911

40-
<div id="overlay">
41-
<SwitchPositions {scatterplot}></SwitchPositions>
42-
<ColorChange {scatterplot}></ColorChange>
43-
<SizeSlider size={startSize} {scatterplot}></SizeSlider>
44-
</div>
45-
46-
<div id="deepscatter"></div>
47-
48-
<style>
49-
#overlay {
50-
position: fixed;
51-
z-index: 10;
52-
left: 40px;
53-
top: 40px;
54-
}
55-
#deepscatter {
56-
z-index: 0;
57-
width: 100vw;
58-
height: 100vh;
59-
}
60-
</style>
12+
{#if mode in modes}
13+
<svelte:component this={modes[mode]} />
14+
{:else}
15+
<h1>Mode not found</h1>
16+
{/if}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "deepscatter",
33
"type": "module",
4-
"version": "3.0.0-next.0",
4+
"version": "3.0.0-next.1",
55
"description": "Fast, animated zoomable scatterplots scaling to billions of points",
66
"files": [
77
"dist"

src/glsl/general.vert

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ uniform vec2 u_wrap_colors_after;
99
uniform float u_jitter;
1010
uniform float u_last_jitter;
1111

12-
1312
// Whether to plot only a single category.
1413
uniform float u_only_color;
1514
uniform float u_grid_mode;
@@ -595,13 +594,16 @@ float texture_float_lookup(in vec2 domain,
595594
// Literal transforms aren't looked up, just returned as is.
596595
return attr;
597596
}
597+
598598
float inrange = domainify(domain, transform, attr, 0.);
599599
if (texture_position > 0.5) {
600600
float y_pos = texture_position / 32. - 0.5 / 32.;
601601
vec4 encoded = texture2D(u_one_d_aesthetic_map, vec2(y_pos, inrange));
602602
return encoded.a;
603603
} else {
604-
return mix(range.x, range.y, inrange);
604+
// return 0.25;
605+
// return inrange;
606+
return mix(domain.x, domain.y, inrange);
605607
}
606608
}
607609

@@ -1257,7 +1259,8 @@ void main() {
12571259
float size_multiplier = texture_float_lookup(
12581260
u_size_domain,
12591261
u_size_range,
1260-
u_size_transform, a_size,
1262+
u_size_transform,
1263+
a_size,
12611264
u_size_map_position);
12621265

12631266
float last_size_multiplier = texture_float_lookup(
@@ -1267,11 +1270,10 @@ void main() {
12671270
size_multiplier = u_base_size *
12681271
mix(last_size_multiplier, size_multiplier, ease);
12691272

1270-
float depth_size_adjust = (1.0 - ix / (u_maxix));
1271-
1273+
// float depth_size_adjust = (1.0 - ix / (u_maxix));
12721274

12731275
point_size_adjust = exp(log(u_k) * u_zoom_balance) ;// * depth_size_adjust;
1274-
// point_size_adjust = exp(log(u_k) * u_zoom_balance);
1276+
12751277
gl_PointSize = point_size_adjust * size_multiplier;
12761278

12771279
if (gl_PointSize <= 5.1) {
@@ -1341,6 +1343,7 @@ void main() {
13411343
fill = packFloat(ix_in_tile + 1.);
13421344
} else {
13431345
run_color_fill(ease);
1346+
// fill = packFloat(ix + 1.);
13441347
}
13451348

13461349
// Are we in a mode where we need to plot foreground and background?
@@ -1383,7 +1386,6 @@ void main() {
13831386
}
13841387

13851388
point_size = gl_PointSize;
1386-
13871389
/* if (u_use_glyphset > 0. && point_size > 5.0) {
13881390
float random_letter = floor(64. * ix_to_random(ix, 1.3));
13891391
letter_pos = vec2(

src/regl_rendering.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export class ReglRenderer extends Renderer {
200200
number,
201201
],
202202
};
203+
// console.log(props.alpha, 'alpha');
203204

204205
// Clone.
205206
return JSON.parse(JSON.stringify(props)) as DS.GlobalDrawProps;
@@ -896,7 +897,10 @@ export class ReglRenderer extends Renderer {
896897
u_zoom_balance: regl.prop('zoom_balance'),
897898
u_base_size: (_: C, { point_size }: P) => point_size,
898899
u_maxix: (_: C, { max_ix }: P) => max_ix,
899-
u_alpha: (_: C, { alpha }: P) => alpha,
900+
u_alpha: (_: C, { alpha }: P) => {
901+
//console.log(alpha);
902+
return alpha;
903+
},
900904
u_foreground_number: (_: C, { foreground }: P) => foreground as number,
901905
u_foreground_alpha: () => this.render_props.foreground_opacity,
902906
u_background_rgba: () => {
@@ -914,6 +918,9 @@ export class ReglRenderer extends Renderer {
914918
u_background_size: () => this.render_props.background_size,
915919
u_foreground_size: () => this.render_props.foreground_size,
916920
u_k: (_: DefaultContext, props: P) => {
921+
if (Math.random() < 0.01) {
922+
//console.log(props.transform.k);
923+
}
917924
return props.transform.k;
918925
},
919926
// Allow interpolation between different coordinate systems.
@@ -1234,9 +1241,6 @@ export class TileBufferManager {
12341241

12351242
async create_buffer_data(key: string): Promise<Float32Array> {
12361243
const { tile } = this;
1237-
if (tile.key === '4/4/9') {
1238-
console.log('MAKING', key, tile.key);
1239-
}
12401244
type ColumnType = Vector<Dictionary<Utf8> | Float | Bool | Int | Timestamp>;
12411245

12421246
if (!tile.hasLoadedColumn(key)) {

src/rendering.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class RenderProps {
104104
return this.targetOpacity.value;
105105
}
106106
get point_size() {
107+
// console.log('GETTING POINT SIZE', this.pointSize.value);
107108
return this.pointSize.value;
108109
}
109110
get foreground_opacity() {
@@ -185,15 +186,16 @@ export class Renderer {
185186
const k = this.zoom?.transform?.k ?? 1;
186187
const target_share = alpha / 100;
187188
const fraction_of_total_visible = 1 / k ** 2;
188-
const pixelRatio = window.devicePixelRatio || 1;
189+
const pixelRatio = window?.devicePixelRatio || 1;
189190

190191
const pixel_area = (width * height) / pixelRatio;
191192
const total_intended_points = min([
192193
max_ix,
193194
this.dataset.highest_known_ix || 1e10,
194195
]) as number;
195-
const total_points = total_intended_points * (1 - discard_share);
196196

197+
const total_points = total_intended_points * (1 - discard_share);
198+
//console.log({ total_points });
197199
const size_adjust = Math.exp(Math.log(k) * zoom_balance);
198200
const area_of_point =
199201
Math.PI * ((size_adjust * point_size) / pixelRatio / 2) ** 2;
@@ -214,11 +216,11 @@ export class Renderer {
214216
const { prefs } = this;
215217
const { max_points } = this.render_props;
216218
if (!this._use_scale_to_download_tiles) {
217-
return max_points;
219+
return max_points + 1;
218220
}
219221
const k = this.zoom.transform!.k;
220222
const point_size_adjust = Math.exp(Math.log(k) * prefs.zoom_balance);
221-
return (max_points * k * k) / point_size_adjust / point_size_adjust;
223+
return (max_points * k * k) / point_size_adjust / point_size_adjust + 0.5;
222224
}
223225

224226
visible_tiles(): Array<Tile> {

src/tile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ export class Tile {
545545
manifest.max_ix = manifest.min_ix + 1e5;
546546
manifest.min_ix = 0;
547547
}
548-
this.highest_known_ix = this.max_ix;
548+
this.highest_known_ix = manifest.max_ix;
549549
this.manifest = {
550550
key: this.key,
551551
children: manifest.children,

0 commit comments

Comments
 (0)