Skip to content

Commit

Permalink
2.9.3 improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bmschmidt committed Apr 11, 2023
1 parent 0ac141c commit a117356
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 58 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2022 Nomic, Inc.
Copyright 2022-23 Nomic, Inc.

===========================

Expand Down
95 changes: 75 additions & 20 deletions dist/deepscatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5583,9 +5583,20 @@ class Zoom {
});
}
zoom_to_bbox(corners, duration = 4e3, buffer = 1.111) {
console.log("ZOOOOM");
const scales2 = this.scales();
const [x02, x12] = corners.x.map(scales2.x);
const [y02, y12] = corners.y.map(scales2.y);
let [x02, x12] = corners.x.map(scales2.x);
let [y02, y12] = corners.y.map(scales2.y);
console.log(this.scatterplot.prefs.zoom_align, "AAH");
if (this.scatterplot.prefs.zoom_align === "right") {
const aspect_ratio = this.width / this.height;
const data_aspect_ratio = (x12 - x02) / (y12 - y02);
if (data_aspect_ratio < aspect_ratio) {
const extension = data_aspect_ratio / aspect_ratio;
console.log(extension, { x0: x02 });
x02 = x02 - (x12 - x02) * extension;
}
}
const { svg_element_selection: canvas, zoomer, width, height } = this;
const t = identity$3.translate(width / 2, height / 2).scale(1 / buffer / Math.max((x12 - x02) / width, (y12 - y02) / height)).translate(-(x02 + x12) / 2, -(y02 + y12) / 2);
canvas.transition().duration(duration).call(zoomer.transform, t);
Expand Down Expand Up @@ -17290,6 +17301,12 @@ function isLambdaChannel(input) {
function isConstantChannel(input) {
return input.constant !== void 0;
}
function isURLLabels(labels) {
return labels !== null && labels.url !== void 0;
}
function isLabelset(labels) {
return labels !== null && labels.labels !== void 0;
}
var lodash = { exports: {} };
/**
* @license
Expand Down Expand Up @@ -23103,6 +23120,9 @@ class BooleanAesthetic extends Aesthetic {
if (input.op === "within") {
return [4, input.a, input.b];
}
if (input.op === "between") {
return [4, (input.b - input.a) / 2, (input.b + input.a) / 2];
}
const val = [
[null, "lt", "gt", "eq"].indexOf(input.op),
input.a,
Expand Down Expand Up @@ -34097,8 +34117,7 @@ class QuadTile extends Tile {
url = url.replace("/public", "");
}
const request = {
method: "GET",
credentials: "include"
method: "GET"
};
this._download = fetch(url, request).then(async (response) => {
const buffer = await response.arrayBuffer();
Expand Down Expand Up @@ -35501,6 +35520,7 @@ class LabelMaker extends Renderer {
d.data.y = y_.invert(event.y);
});
handler.on("end", (event, d) => {
console.log({ text: d.data.text, x: d.data.x, y: d.data.y });
});
bboxes.call(handler);
}
Expand Down Expand Up @@ -35597,7 +35617,7 @@ class DepthTree extends dist.RBush3D {
throw "Missing Aspect Ratio" + JSON.stringify(point);
return p;
}
insert_point(point, mindepth = 1) {
insert_point(point, mindepth = 1 / 4) {
if (point.text === void 0 || point.text === "") {
return;
}
Expand Down Expand Up @@ -35660,7 +35680,8 @@ const default_API_call = {
encoding: {},
point_size: 1,
alpha: 40,
background_options: default_background_options
background_options: default_background_options,
zoom_align: "center"
};
const base_elements = [
{
Expand Down Expand Up @@ -35754,6 +35775,26 @@ class Scatterplot {
this.secondary_renderers[name] = labels;
this.secondary_renderers[name].start();
}
add_api_label(labelset) {
const geojson = {
type: "FeatureCollection",
features: labelset.labels.map((label) => {
return {
type: "Feature",
geometry: {
type: "Point",
coordinates: [label.x, label.y]
},
properties: {
text: label.text,
size: label.size || void 0
}
};
})
};
console.log("OPTIONS", labelset.options);
this.add_labels(geojson, labelset.name, "text", "size", labelset.options || {});
}
async reinitialize() {
const { prefs } = this;
if (prefs.source_url !== void 0) {
Expand Down Expand Up @@ -35915,6 +35956,7 @@ class Scatterplot {
delete this.hooks[name];
}
stop_labellers() {
console.log("Stopping labels");
for (const [k, v] of Object.entries(this.secondary_renderers)) {
if (v && v["label_key"] !== void 0) {
this.secondary_renderers[k].stop();
Expand Down Expand Up @@ -36014,6 +36056,7 @@ class Scatterplot {
});
}
async unsafe_plotAPI(prefs) {
var _a2;
if (prefs === null) {
return;
}
Expand All @@ -36031,19 +36074,6 @@ class Scatterplot {
prefs.background_options.size = [prefs.background_options.size, 1];
}
}
if (prefs.labels) {
const { url, label_field, size_field } = prefs.labels;
const name = prefs.labels.name || url;
if (!this.secondary_renderers[name]) {
this.stop_labellers();
this.add_labels_from_url(url, name, label_field, size_field).catch(
(error) => {
console.error("Label addition failed.");
console.error(error);
}
);
}
}
this.update_prefs(prefs);
if (this._root === void 0) {
await this.reinitialize();
Expand All @@ -36059,7 +36089,7 @@ class Scatterplot {
if (prefs.zoom === null) {
this._zoom.zoom_to(1, width / 2, height / 2);
prefs.zoom = void 0;
} else if (prefs.zoom.bbox) {
} else if ((_a2 = prefs.zoom) == null ? void 0 : _a2.bbox) {
this._zoom.zoom_to_bbox(prefs.zoom.bbox, prefs.duration);
}
}
Expand All @@ -36075,6 +36105,31 @@ class Scatterplot {
this._renderer.reglframe = this._renderer.regl.frame(() => {
this._renderer.tick("Basic");
});
if (prefs.labels !== void 0) {
if (isURLLabels(prefs.labels)) {
const { url, label_field, size_field } = prefs.labels;
const name = prefs.labels.name || url;
if (!this.secondary_renderers[name]) {
this.stop_labellers();
this.add_labels_from_url(url, name, label_field, size_field).catch(
(error) => {
console.error("Label addition failed.");
console.error(error);
}
);
}
} else if (isLabelset(prefs.labels)) {
if (!prefs.labels.name) {
throw new Error("API field `labels` must have a name.");
}
this.stop_labellers();
this.add_api_label(prefs.labels);
} else if (prefs.labels === null) {
this.stop_labellers();
} else {
throw new Error("API field `labels` format not recognized.");
}
}
this._zoom.restart_timer(6e4);
}
async root_table() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "deepscatter",
"type": "module",
"version": "2.9.3",
"version": "2.10.0",
"description": "Fast, animated zoomable scatterplots scaling to billions of points",
"files": [
"dist"
Expand Down
6 changes: 6 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

# 2.10.0

- Fully supported 'between' as alternative to 'within' for filter operations.
- Allow passing labels through API directly.

# 2.9.2

- Fix bug in manually-assigned categorical color schemes involving the first color always being gray.
Expand Down
3 changes: 3 additions & 0 deletions src/Aesthetic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ abstract class BooleanAesthetic extends Aesthetic<
if (input.op === 'within') {
return [4, input.a, input.b];
}
if (input.op === 'between') {
return [4, (input.b - input.a) / 2, (input.b + input.a) / 2];
}
const val: OpArray = [
// Encoding of op as number.
[null, 'lt', 'gt', 'eq'].indexOf(input.op),
Expand Down
71 changes: 54 additions & 17 deletions src/deepscatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { LabelMaker, LabelOptions } from './label_rendering';
import { Renderer } from './rendering';
import { ArrowTile, QuadTile, Tile } from './tile';
import type { ConcreteAesthetic } from './StatefulAesthetic';

import { isURLLabels, isLabelset } from './typing';

// DOM elements that deepscatter uses.
const base_elements = [
Expand Down Expand Up @@ -209,7 +209,28 @@ export default class Scatterplot<T extends Tile> {
this.secondary_renderers[name] = labels;
this.secondary_renderers[name].start();
}

add_api_label(
labelset: Labelset
) {
const geojson : FeatureCollection = {
type: 'FeatureCollection',
features: labelset.labels.map((label : Label) => {
return {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [label.x, label.y],
},
properties: {
text: label.text,
size: label.size || undefined,
},
};
})
};
console.log("OPTIONS", labelset.options)
this.add_labels(geojson, labelset.name, 'text', 'size', labelset.options || {});
}
async reinitialize() {
const { prefs } = this;
if (prefs.source_url !== undefined) {
Expand Down Expand Up @@ -451,6 +472,7 @@ export default class Scatterplot<T extends Tile> {
}

public stop_labellers() {
console.log("Stopping labels")
for (const [k, v] of Object.entries(this.secondary_renderers)) {
// Stop any existing labels
if (v && v['label_key'] !== undefined) {
Expand Down Expand Up @@ -621,19 +643,7 @@ export default class Scatterplot<T extends Tile> {
prefs.background_options.size = [prefs.background_options.size, 1]
}
}
if (prefs.labels) {
const { url, label_field, size_field } = prefs.labels;
const name = (prefs.labels.name || url) as string;
if (!this.secondary_renderers[name]) {
this.stop_labellers();
this.add_labels_from_url(url, name, label_field, size_field).catch(
(error) => {
console.error('Label addition failed.');
console.error(error);
}
);
}
}

this.update_prefs(prefs);

// Some things have to be done *before* we can actually run this;
Expand All @@ -644,7 +654,7 @@ export default class Scatterplot<T extends Tile> {
if (this._root === undefined) {
await this.reinitialize();
}

// Doesn't block.
/*
if (prefs.basemap_geojson) {
Expand Down Expand Up @@ -676,7 +686,7 @@ export default class Scatterplot<T extends Tile> {
if (prefs.zoom === null) {
this._zoom.zoom_to(1, width / 2, height / 2);
prefs.zoom = undefined;
} else if (prefs.zoom.bbox) {
} else if (prefs.zoom?.bbox) {
this._zoom.zoom_to_bbox(prefs.zoom.bbox, prefs.duration);
}
}
Expand All @@ -696,6 +706,33 @@ export default class Scatterplot<T extends Tile> {
this._renderer.tick('Basic');
});

if (prefs.labels !== undefined) {
if (isURLLabels(prefs.labels)) {
const { url, label_field, size_field } = prefs.labels;
const name = (prefs.labels.name || url) as string;
if (!this.secondary_renderers[name]) {
this.stop_labellers();
this.add_labels_from_url(url, name, label_field, size_field).catch(
(error) => {
console.error('Label addition failed.');
console.error(error);
}
);
}
} else if (isLabelset(prefs.labels)) {
if (!prefs.labels.name) {
throw new Error('API field `labels` must have a name.');
}
this.stop_labellers();
this.add_api_label(prefs.labels);
} else if (prefs.labels === null) {
this.stop_labellers()
} else {
throw new Error('API field `labels` format not recognized.');
}

}

this._zoom.restart_timer(60_000);
}

Expand Down
1 change: 1 addition & 0 deletions src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export const default_API_call: APICall = {
point_size: 1, // base size before aes modifications.
alpha: 40, // Default screen saturation target.
background_options: default_background_options,
zoom_align: 'center'
} as const;
Loading

0 comments on commit a117356

Please sign in to comment.