@@ -32,6 +32,7 @@ export class LabelMaker extends Renderer {
32
32
public label_key ?: string ;
33
33
public labelgroup : SVGGElement ;
34
34
private hovered : undefined | string ;
35
+ private font : string = 'verdana' ;
35
36
public options : DS . LabelOptions = { } ;
36
37
/**
37
38
*
@@ -46,6 +47,11 @@ export class LabelMaker extends Renderer {
46
47
) {
47
48
super ( scatterplot . div ! . node ( ) as HTMLDivElement , scatterplot ) ;
48
49
this . options = options ;
50
+ if ( options . font ) {
51
+ this . font = options . font ;
52
+ // else verdana
53
+ }
54
+
49
55
this . canvas = scatterplot
50
56
. elements ! [ 2 ] . selectAll ( 'canvas' )
51
57
. node ( ) as HTMLCanvasElement ;
@@ -74,6 +80,7 @@ export class LabelMaker extends Renderer {
74
80
0.5 ,
75
81
[ 0.5 , 1e6 ] ,
76
82
options . margin === undefined ? 30 : options . margin ,
83
+ this . font
77
84
) ;
78
85
79
86
/* this.tree.accessor = (x, y) => {
@@ -264,7 +271,7 @@ export class LabelMaker extends Renderer {
264
271
if ( this . hovered === '' + d . minZ + d . minX ) {
265
272
emphasize += 2 ;
266
273
}
267
- context . font = `${ datum . height * size_adjust + emphasize } pt verdana ` ;
274
+ context . font = `${ datum . height * size_adjust + emphasize } pt ${ this . font } ` ;
268
275
269
276
context . shadowBlur = 12 + emphasize * 3 ;
270
277
context . lineWidth = 3 + emphasize ;
@@ -380,13 +387,13 @@ function getContext(): CanvasRenderingContext2D {
380
387
return context ;
381
388
}
382
389
383
- function measure_text ( d : RawPoint , pixel_ratio : number , margin : number ) {
390
+ function measure_text ( d : RawPoint , pixel_ratio : number , margin : number , font : string ) {
384
391
// Uses a global context that it calls into existence for measuring;
385
392
// using the deepscatter
386
393
// canvas gets too confused with state information.
387
394
const context = getContext ( ) ;
388
395
// Called for the side-effect of setting `d.aspect_ratio` on the passed item.
389
- context . font = `${ d . height } pt verdana ` ;
396
+ context . font = `${ d . height } pt ${ font } ` ;
390
397
if ( d . text === '' ) {
391
398
return null ;
392
399
}
@@ -427,6 +434,7 @@ class DepthTree extends RBush3D {
427
434
public pixel_ratio : number ;
428
435
public rectangle_buffer : number ;
429
436
public margin : number ;
437
+ public font : string ;
430
438
// public insertion_log = [];
431
439
private _accessor : ( p : Point ) => [ number , number ] = ( p ) => [ p . x , p . y ] ;
432
440
@@ -440,12 +448,14 @@ class DepthTree extends RBush3D {
440
448
scale_factor = 0.5 ,
441
449
zoom = [ 0.1 , 1000 ] ,
442
450
margin = 10 , // in screen pixels
451
+ font = 'verdana' ,
443
452
) {
444
453
// scale factor used to determine how quickly points scale.
445
454
// Not implemented.
446
455
// size = exp(log(k) * scale_factor);
447
456
448
457
super ( ) ;
458
+ this . font = font ;
449
459
this . scale_factor = scale_factor ;
450
460
this . mindepth = zoom [ 0 ] ;
451
461
this . maxdepth = zoom [ 1 ] ;
@@ -520,7 +530,7 @@ class DepthTree extends RBush3D {
520
530
if ( point [ 'pixel_width' ] === undefined ) {
521
531
measured = {
522
532
...point ,
523
- ...measure_text ( point , this . pixel_ratio , this . margin ) ,
533
+ ...measure_text ( point , this . pixel_ratio , this . margin , this . font ) ,
524
534
} ;
525
535
} else {
526
536
measured = point as Point ;
0 commit comments