Skip to content

Commit

Permalink
Working ES Module build
Browse files Browse the repository at this point in the history
  • Loading branch information
bmschmidt committed Jun 24, 2021
1 parent 848a31d commit 2805052
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 30 deletions.
29 changes: 29 additions & 0 deletions dist/deepscatter.es.js

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions dist/deepscatter.umd.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ <h1>Welcome to a demo/test page.</h1>
import { select } from 'd3-selection';
window.select = select; // For the click function below.
const prefs = {
"source_url" : "/tiles",
"max_points" : 25000, // a full cap.
"alpha" : .7, // Target saturation for the full page.
"source_url" : "//localhost:3000/tiles",
"max_points" : 10000, // a full cap.
"alpha" : .9, // Target saturation for the full page.
"zoom_balance" : 0.09, // Rate at which points increase size. https://observablehq.com/@bmschmidt/zoom-strategies-for-huge-scatterplots-with-three-js
"point_size": 10, // Default point size before application of size scaling
"point_size": 7, // Default point size before application of size scaling
"background_color": "#EEEDDE",
"click_function": "select('#ident').html(JSON.stringify(datum, undefined, 2))",
"encoding": {
Expand Down
90 changes: 90 additions & 0 deletions index_prod.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<style>
.ttooltip {
z-index: 99
}
</style>

<body>
<h1>Welcome to a demo/test page.</h1>
<div id="deepscatter" style="position:fixed;top:0;left:0">
</div>
<button id="flip" style="z-index:99;position:fixed;">Change encoding</button>
<pre id="ident" style="z-index:99;position:fixed;"></pre>

</body>
<script src="https://d3js.org/d3.v7.min.js"></script>

<script type = "module">
import Scatterplot from './dist/deepscatter.es.js';
const select = d3.select
// import { select } from 'd3-selection';
window.select = select; // For the click function below.
const prefs = {
"source_url" : "/dist/tiles",
"max_points" : 25000, // a full cap.
"alpha" : .7, // Target saturation for the full page.
"zoom_balance" : 0.09, // Rate at which points increase size. https://observablehq.com/@bmschmidt/zoom-strategies-for-huge-scatterplots-with-three-js
"point_size": 10, // Default point size before application of size scaling
"background_color": "#EEEDDE",
"click_function": "select('#ident').html(JSON.stringify(datum, undefined, 2))",
"encoding": {
"color": {
"field": "class",
"range": "category10",
"domain": [-2047, 2047]
},
"x": {
field: "x",
transform: "literal"
},
"y": {
field: "y",
transform: "literal"
},
"size": {
"field": "quantity",
"transform": "sqrt",
"domain": [0, 3],
"range": [0, 4]
}
}
};


const colors = [
JSON.parse(JSON.stringify(prefs.encoding.color)),
{
"field": "quantity",
"range": "viridis",
"domain": [0, 1]
},
{
"field": "x",
"range": "viridis",
"domain": [-3, 3]
}
]

const plot = new Scatterplot("#deepscatter")
plot.plotAPI(prefs);
window.plot = plot; // For debugging


// Simple animation demonstration.

let cycle = 0;

select("#flip").on("click", () => {
cycle += 1
const new_coding = {
"encoding": {
"x": {"field": cycle % 2 == 0 ? "x": "y"},
"y": {"field": cycle % 2 == 0 ? "y": "x"},
"color": colors[cycle % colors.length]
}
}
console.log(new_coding)
plot.plotAPI(new_coding)
})

</script>
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"homepage": "https://github.com/CreatingData/deepscatter#readme",
"dependencies": {
"@apache-arrow/es2015-esm": "^4.0.1",
"@apache-arrow/es5-esm": "^3.0.0",
"@babel/runtime": "^7.9.6",
"comlink": "^4.3.0",
"d3-array": "^3.0.1",
Expand Down Expand Up @@ -80,6 +81,7 @@
"regenerator-runtime": "^0.13.5",
"rollup-plugin-glslify": "^1.2.0",
"rollup-plugin-web-worker-loader": "^1.6.1",
"vite": "^2.3.8"
"vite": "^2.3.8",
"vite-plugin-legacy": "^2.1.0"
}
}
23 changes: 20 additions & 3 deletions src/glsl/general.frag
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifdef GL_OES_standard_derivatives
#extension GL_OES_standard_derivatives : enable
#endif

precision mediump float;

varying float pic_mode;
Expand All @@ -8,17 +12,20 @@ uniform float u_only_color;
uniform float u_color_picker_mode;
uniform sampler2D u_sprites;

float delta = 0.0, alpha = 1.0;


bool out_of_circle(in vec2 coord) {
vec2 cxy = 2.0 * coord - 1.0;
float r_sq = dot(cxy, cxy);
if (r_sq > 1.0) {return true;}
if (r_sq > 1.03) {return true;}
return false;
}

bool out_of_hollow_circle(in vec2 coord) {
vec2 cxy = 2.0 * coord - 1.0;
float r_sq = dot(cxy, cxy);
if (r_sq > 1.0) {return true;}
if (r_sq > 1.01) {return true;}
float distance_from_edge = (1.0 - r_sq) * point_size;
if (distance_from_edge > 4.0) {return true;}
return false;
Expand All @@ -33,6 +40,8 @@ bool out_of_triangle(in vec2 coord) {

void main() {



if (u_only_color >= -1.5) {
gl_FragColor = vec4(0., 0., 0., 1./255.);
return;
Expand All @@ -44,10 +53,18 @@ void main() {
discard;
return;
}
float alpha = fill.a;
vec2 cxy = 2.0 * gl_PointCoord - 1.0;
float r = dot(cxy, cxy);
#ifdef GL_OES_standard_derivatives
delta = fwidth(r);
alpha *= (1.0 - smoothstep(1.0 - delta, 1.0 + delta, r));
#endif

if (u_color_picker_mode > 0.5) {
gl_FragColor = fill;
} else {
// Pre-blend the alpha channel.
gl_FragColor = vec4(fill.rgb * fill.a, fill.a);
gl_FragColor = vec4(fill.rgb * alpha, alpha);
}
}
1 change: 1 addition & 0 deletions src/regl_rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class ReglRenderer extends Renderer {
{
// extensions: 'angle_instanced_arrays',
optionalExtensions: [
'OES_standard_derivatives',
'OES_element_index_uint',
'OES_texture_float',
'OES_texture_half_float',
Expand Down
17 changes: 12 additions & 5 deletions src/tile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

import { extent, range, min, max, bisectLeft } from 'd3-array';
import { Table } from '@apache-arrow/es2015-esm';
import { Table } from '@apache-arrow/es5-esm';
import * as Comlink from 'comlink';
import Counter from './Counter';
//import TileWorker from './tileworker.worker.js?worker&inline';

import TileWorker from './tileworker.worker.js?worker&inline';

class BaseTile {
// Can this usefully do anything?
Expand Down Expand Up @@ -274,6 +275,7 @@ class Tile extends BaseTile {
if (this._table) { return this._table; }
// Constitute table if there's a present buffer.
if (this._table_buffer && this._table_buffer.byteLength > 0) {
console.log("BYTES", this._table_buffer.byteLength)
return this._table = Table.from(this._table_buffer);
}
return undefined;
Expand All @@ -298,7 +300,9 @@ class Tile extends BaseTile {
}
this._already_called = true;

const url = `${window.location.origin}/${this.url}/${this.key}.feather`;
const url = this.url.match("//") ?
`${this.url}/${this.key}.feather` :
`${window.location.origin}/${this.url}/${this.key}.feather`;

this.download_state = 'In progress';

Expand All @@ -315,6 +319,9 @@ class Tile extends BaseTile {
// how to fix it on the table in javascript, just python.
this._current_mutations = JSON.parse(JSON.stringify(this.needed_mutations));
this._table_buffer = buffer;
console.log("Got buffer")
this._table = Table.from(buffer)
console.log("Into table")
this._extent = JSON.parse(metadata.get('extent'));
this.child_locations = JSON.parse(metadata.get('children'));
this._min_ix = this.table.getColumn('ix').get(0);
Expand Down Expand Up @@ -705,8 +712,8 @@ export default class RootTile extends Tile {
for (const i of range(NUM_WORKERS)) {
console.log(`Allocating worker ${i}`);
this._tileWorkers.push(
Comlink.wrap(new Worker(this.url + '/../worker.js')),
// Comlink.wrap(new TileWorker()),
// Comlink.wrap(new Worker(this.url + '/../worker.js')),
Comlink.wrap(new TileWorker()),
);
}

Expand Down
5 changes: 1 addition & 4 deletions src/tileworker.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import { transfer, expose } from 'comlink';
import {
Table, Column, Vector, Utf8, Float32,
Uint32, Int32, Int64, Dictionary,
} from '@apache-arrow/es5-cjs';
} from '@apache-arrow/es5-esm';

const {Table, Column, Vector, Utf8, Float32,
Uint32, Int32, Int64, Dictionary} = window.Arrow;
const { transfer, expose } = window.comlink;
function compose_functions(val) {

function compose_singleton_function(val) {
Expand Down
16 changes: 5 additions & 11 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import glslify from 'rollup-plugin-glslify';
import worker from 'rollup-plugin-web-worker-loader';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export default {
build: {
target: "esnext",
lib: {
entry: path.resolve(__dirname, 'src/deepscatter.js'),
name: 'deepscatter',
formats: [/*'es', */'umd'],
},
},
rollupOptions: {
output: {
inlineDynamicImports: true,
manualChunks: {},
name: 'Deepscatter',
formats: ['es', 'umd'],
},
},
plugins: [
glslify({ compress: false }),
worker({
/* worker({
targetPlatform: 'browser',
pattern: /(.+)\?worker/,
// extensions: supportedExts,
preserveSource: true, // somehow results in slightly smaller bundle
}),
}), */
],
};

0 comments on commit 2805052

Please sign in to comment.