-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vis-type: scatter): improve rendering of scatter plot (#530)
Co-authored-by: Michael Puehringer <[email protected]> Co-authored-by: Christian Bors <[email protected]> Co-authored-by: oltionchampari <[email protected]> Co-authored-by: Holger Stitz <[email protected]> Co-authored-by: Michael Pühringer <[email protected]>
- Loading branch information
1 parent
77e5a0a
commit 913d5ea
Showing
23 changed files
with
1,653 additions
and
858 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* No @types/jstat exist yet, this is a temporary workaround. | ||
*/ | ||
declare module 'jstat' { | ||
export function corrcoeff(a: number[], b: number[]): number; | ||
export function spearmancoeff(a: number[], b: number[]): number; | ||
export function tukeyhsd(a: number[][]): number; | ||
export function ftest(a: number, b: number, c: number): number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Class that can measure text for a given font very efficiently (about ~1000 times faster than canvas measuretext). | ||
* It uses a precomputed table of character widths for a given font and size. | ||
* | ||
* Also supports utility functions like ellipsis. | ||
*/ | ||
export class FastTextMeasure { | ||
table = new Float32Array(127); | ||
|
||
meanWidth = 0; | ||
|
||
constructor(private font: string) { | ||
this.computeTable(); | ||
} | ||
|
||
// Computes the whole size table | ||
computeTable() { | ||
const textWidthCanvas = document.createElement('canvas'); | ||
const textWidthContext = textWidthCanvas.getContext('2d'); | ||
|
||
if (!textWidthContext) { | ||
throw new Error('Could not get 2d context'); | ||
} | ||
|
||
textWidthContext.font = this.font; | ||
|
||
for (let i = 1; i < 127; i++) { | ||
this.table[i] = textWidthContext.measureText(String.fromCharCode(i)).width; | ||
this.meanWidth += this.table[i]!; | ||
} | ||
|
||
this.meanWidth /= 127; | ||
} | ||
|
||
// Measures the width of a given text | ||
fastMeasureText(text: string) { | ||
let width = 0; | ||
|
||
for (let i = 0; i < text.length; i++) { | ||
const ascii = text.charCodeAt(i); | ||
if (ascii < 127) { | ||
width += this.table[ascii]!; | ||
} else { | ||
width += this.meanWidth; | ||
} | ||
} | ||
|
||
return width; | ||
} | ||
|
||
// Cuts off text and adds ellipsis if it exceeds the given width | ||
textEllipsis(text: string, maxWidth: number) { | ||
let width = this.fastMeasureText(text); | ||
|
||
if (width <= maxWidth) { | ||
return text; | ||
} | ||
|
||
const ellipsisWidth = this.fastMeasureText('...'); | ||
let ellipsisCount = 0; | ||
|
||
while (width + ellipsisWidth > maxWidth) { | ||
ellipsisCount++; | ||
width -= this.table[text.charCodeAt(text.length - ellipsisCount)]!; | ||
} | ||
|
||
return `${text.slice(0, text.length - ellipsisCount)}...`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.