Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow setting label font #174

Open
wants to merge 1 commit into
base: 11-11-refactor_manifests_to_be_lazier
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
d3.ContainerElement,
Record<string, BaseType>,
HTMLElement,
any

Check failure on line 44 in src/interaction.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

Unexpected any. Specify a different type
>;
public width: number;
public height: number;
Expand Down Expand Up @@ -172,7 +172,7 @@
if (event.sourceEvent) {
(event.sourceEvent as Event).stopPropagation();
}
});
})

canvas.call(zoomer);

Expand Down Expand Up @@ -285,7 +285,7 @@
this._timer.stop();
}

const t = timer(this.tick.bind(this));

Check failure on line 288 in src/interaction.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

Unsafe argument of type `any` assigned to a parameter of type `(elapsed: number) => void`

this._timer = t;
this.stopTimerAt = stop_at;
Expand Down Expand Up @@ -385,7 +385,7 @@
return scales;
}

webgl_scale(flatten = true) {

Check failure on line 388 in src/interaction.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

'flatten' is assigned a value but never used
const { x, y } = this.scales();
const transform = window_transform(x, y).flat();
return transform;
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 @@
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 @@
) {
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 @@
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 @@
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 @@ -307,9 +314,9 @@
return (d.data.properties.__display as string) || 'inline';
})
.on('mouseover', (event, d: P3d) => {
select(event.target).style('opacity', RECT_DEFAULT_OPACITY);

Check failure on line 317 in src/label_rendering.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

Unsafe member access .target on an `any` value
this.hovered = '' + d.minZ + d.minX;
event.stopPropagation();

Check failure on line 319 in src/label_rendering.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

Unsafe call of an `any` typed value

Check failure on line 319 in src/label_rendering.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

Unsafe member access .stopPropagation on an `any` value
})
.on('mousemove', function (event: MouseEvent) {
event.stopPropagation();
Expand All @@ -319,7 +326,7 @@
})
.on('mouseout', (event) => {
this.hovered = undefined;
event.stopPropagation();

Check failure on line 329 in src/label_rendering.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

Unsafe call of an `any` typed value

Check failure on line 329 in src/label_rendering.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

Unsafe member access .stopPropagation on an `any` value
return;
});

Expand Down Expand Up @@ -380,13 +387,13 @@
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 @@
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 @@
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 @@
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 Expand Up @@ -555,7 +565,7 @@
// it's guaranteed that their *data*
// will not. And it means we can avoid unnecessary trees.

const blocked_until = this.max_collision_depth(p3d.data, overlapper.data);

Check failure on line 568 in src/label_rendering.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

Unsafe argument of type `any` assigned to a parameter of type `Point`

if (blocked_until > hidden_until) {
hidden_until = blocked_until;
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ 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?
font?: string // Font. Default verdana.
};

export type Labelset = {
Expand Down
Loading