Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"glsl-read-float": "^1.1.0",
"lodash.merge": "^4.6.2",
"rbush-3d": "^0.0.4",
"regl": "^2.1.0"
"regl": "^2.1.0",
"webgpu-utils": "^1.9.3"
},
"devDependencies": {
"@playwright/test": "^1.46.1",
Expand All @@ -78,6 +79,7 @@
"@types/lodash.merge": "^4.6.9",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"@webgpu/types": "^0.1.51",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-formatter-summary-chart": "^0.3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

export class Zoom {
public prefs: DS.APICall;
public svg_element_selection: d3.Selection<

Check failure on line 40 in src/interaction.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

Cannot find namespace 'd3'.
d3.ContainerElement,

Check failure on line 41 in src/interaction.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

Cannot find namespace 'd3'.
Record<string, BaseType>,
HTMLElement,
any
Expand All @@ -47,10 +47,10 @@
public height: number;
public renderers: Map<string, Renderer>;
public deeptable?: Deeptable;
public _timer?: d3.Timer;

Check failure on line 50 in src/interaction.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

Cannot find namespace 'd3'.
public _scales?: ScaleSet;
public zoomer?: d3.ZoomBehavior<Element, unknown>;

Check failure on line 52 in src/interaction.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

Cannot find namespace 'd3'.
public transform?: d3.ZoomTransform;

Check failure on line 53 in src/interaction.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

Cannot find namespace 'd3'.
public _start?: number;
public scatterplot: Scatterplot;
private stopTimerAt?: number;
Expand Down Expand Up @@ -172,7 +172,7 @@
if (event.sourceEvent) {
(event.sourceEvent as Event).stopPropagation();
}
});
})

canvas.call(zoomer);

Expand Down
18 changes: 14 additions & 4 deletions src/label_rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class LabelMaker extends Renderer {
public label_key?: string;
public labelgroup: SVGGElement;
private hovered: undefined | string;
private font: string = 'verdana';
public options: DS.LabelOptions = {};
/**
*
Expand All @@ -46,6 +47,11 @@ export class LabelMaker extends Renderer {
) {
super(scatterplot.div!.node() as HTMLDivElement, scatterplot);
this.options = options;
if (options.font) {
this.font = options.font;
// else verdana
}

this.canvas = scatterplot
.elements![2].selectAll('canvas')
.node() as HTMLCanvasElement;
Expand Down Expand Up @@ -74,6 +80,7 @@ export class LabelMaker extends Renderer {
0.5,
[0.5, 1e6],
options.margin === undefined ? 30 : options.margin,
this.font
);

/* this.tree.accessor = (x, y) => {
Expand Down Expand Up @@ -264,7 +271,7 @@ export class LabelMaker extends Renderer {
if (this.hovered === '' + d.minZ + d.minX) {
emphasize += 2;
}
context.font = `${datum.height * size_adjust + emphasize}pt verdana`;
context.font = `${datum.height * size_adjust + emphasize}pt ${this.font}`;

context.shadowBlur = 12 + emphasize * 3;
context.lineWidth = 3 + emphasize;
Expand Down Expand Up @@ -380,13 +387,13 @@ function getContext(): CanvasRenderingContext2D {
return context;
}

function measure_text(d: RawPoint, pixel_ratio: number, margin: number) {
function measure_text(d: RawPoint, pixel_ratio: number, margin: number, font: string) {
// Uses a global context that it calls into existence for measuring;
// using the deepscatter
// canvas gets too confused with state information.
const context = getContext();
// Called for the side-effect of setting `d.aspect_ratio` on the passed item.
context.font = `${d.height}pt verdana`;
context.font = `${d.height}pt ${font}`;
if (d.text === '') {
return null;
}
Expand Down Expand Up @@ -427,6 +434,7 @@ class DepthTree extends RBush3D {
public pixel_ratio: number;
public rectangle_buffer: number;
public margin: number;
public font: string;
// public insertion_log = [];
private _accessor: (p: Point) => [number, number] = (p) => [p.x, p.y];

Expand All @@ -440,12 +448,14 @@ class DepthTree extends RBush3D {
scale_factor = 0.5,
zoom = [0.1, 1000],
margin = 10, // in screen pixels
font = 'verdana',
) {
// scale factor used to determine how quickly points scale.
// Not implemented.
// size = exp(log(k) * scale_factor);

super();
this.font = font;
this.scale_factor = scale_factor;
this.mindepth = zoom[0];
this.maxdepth = zoom[1];
Expand Down Expand Up @@ -520,7 +530,7 @@ class DepthTree extends RBush3D {
if (point['pixel_width'] === undefined) {
measured = {
...point,
...measure_text(point, this.pixel_ratio, this.margin),
...measure_text(point, this.pixel_ratio, this.margin, this.font),
};
} else {
measured = point as Point;
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
* zoom events & recieve the zoom transform. For example, a consumer
* might update annotations on zoom events to keep them in sync.
*/
export type onZoomCallback = (transform: d3.ZoomTransform) => null;

Check failure on line 501 in src/types.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

Cannot find namespace 'd3'.

export type Label = {
x: number; // in data space.
Expand All @@ -516,6 +516,7 @@
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?
font?: string // Font. Default verdana.
};

export type Labelset = {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"outDir": "./dist",
"rootDir": "./src",
"lib": ["DOM"],
"types": ["@webgpu/types"],
"noEmitOnError": true,
"emitDeclarationOnly": true
},
Expand Down
Loading