Skip to content

Commit

Permalink
make labels not draggable by default
Browse files Browse the repository at this point in the history
  • Loading branch information
bmschmidt committed Feb 8, 2023
1 parent baaa270 commit 0cfc706
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
18 changes: 10 additions & 8 deletions dist/deepscatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36157,14 +36157,16 @@ class LabelMaker extends Renderer {
event.stopPropagation();
return;
});
handler.on("drag", (event, d) => {
d.data.x = x_.invert(event.x);
d.data.y = y_.invert(event.y);
});
handler.on("end", (event, d) => {
console.log(`${d.data.x} ${d.data.y} ${d.data.text}`);
});
bboxes.call(handler);
if (this.options.draggable_labels) {
handler.on("drag", (event, d) => {
d.data.x = x_.invert(event.x);
d.data.y = y_.invert(event.y);
});
handler.on("end", (event, d) => {
console.log(`${d.data.x} ${d.data.y} ${d.data.text}`);
});
bboxes.call(handler);
}
context2.shadowColor = "black";
context2.strokeStyle = "black";
}
Expand Down
2 changes: 1 addition & 1 deletion integers.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
arrow_table: table,
point_size: 4,
max_points: num_batches * 65536,
alpha: 100,
alpha: 25,
background_color: '#EEEDDE',
zoom_balance: 0.75,
duration: 500,
Expand Down
23 changes: 20 additions & 3 deletions src/label_rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { RBush3D } from 'rbush-3d';
import Scatterplot from './deepscatter';
import { Timer, timer } from 'd3-timer';
import { select } from 'd3-selection';
//import { Data } from 'apache-arrow';
import { drag } from 'd3-drag';

const handler = drag();

export type LabelOptions = {
useColorScale?: boolean; // Whether the colors of text should inherit from the active color scale.
margin?: number; // The number of pixels around each box. Default 30.
draggable_labels?: boolean; // Should labels be draggable in place?
};

function pixel_ratio(scatterplot: Scatterplot): number {
Expand Down Expand Up @@ -79,6 +82,7 @@ export class LabelMaker extends Renderer {
if (this.timer) {
this.timer.stop();
}

select(this.labelgroup).attr('display', 'inline');

this.timer = timer(() => {
Expand Down Expand Up @@ -156,11 +160,13 @@ export class LabelMaker extends Renderer {
maxY: corners.y[1],
maxZ: transform.k,
});

// context.fillStyle = "rgba(0, 0, 0, 0)";
context.clearRect(0, 0, 4096, 4096);
const dim = this.scatterplot.dim('color');
const bboxes = select(this.labelgroup)
.selectAll('rect.labelbbox')
// Keyed by the coordinates.
.data(overlaps, (d) => '' + d.minZ + d.minX)
.join((enter) =>
enter
Expand All @@ -173,6 +179,7 @@ export class LabelMaker extends Renderer {
const labeler = this;
const Y_BUFFER = 5;

// Go through and draw the canvas events.
for (const d of overlaps) {
const datum = d.data as RawPoint;
const x = x_(datum.x) as number;
Expand Down Expand Up @@ -300,6 +307,16 @@ export class LabelMaker extends Renderer {
console.log({ event, d });
});

if (this.options.draggable_labels) {
handler.on('drag', (event, d) => {
d.data.x = x_.invert(event.x);
d.data.y = y_.invert(event.y);
});
handler.on('end', (event, d) => {
console.log(`${d.data.x}\t${d.data.y}\t${d.data.text}`);
});
bboxes.call(handler);
}
context.shadowColor = 'black';
context.strokeStyle = 'black';
}
Expand Down Expand Up @@ -465,9 +482,9 @@ class DepthTree extends RBush3D {
maxY: y + pixel_height / zoom / 2,
minZ: zoom,
maxZ: maxZ || this.maxdepth,
data: {
data: point /*{
...point,
},
},*/,
};

if (Number.isNaN(x) || Number.isNaN(y))
Expand Down

0 comments on commit 0cfc706

Please sign in to comment.