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

fix: improve within link performance by reducing the number of event points #828

Merged
merged 2 commits into from
Nov 26, 2022
Merged
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
11 changes: 5 additions & 6 deletions src/core/mark/area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ import type { Tile } from '../../gosling-track/gosling-track';
/**
* Draw area marks
*/
export function drawArea(HGC: import('@higlass/types').HGC, trackInfo: any, tile: Tile, model: GoslingTrackModel) {
export function drawArea(HGC: import('@higlass/types').HGC, track: any, tile: Tile, model: GoslingTrackModel) {
/* track spec */
const spec = model.spec();

/* data */
const data = model.data();

/* track size */
const [trackWidth, trackHeight] = trackInfo.dimensions;
const tileSize = trackInfo.tilesetInfo.tile_size;
const { tileX } = trackInfo.getTilePosAndDimensions(tile.tileData.zoomLevel, tile.tileData.tilePos, tileSize);
const [trackWidth, trackHeight] = track.dimensions;

/* circular parameters */
const circular = spec.layout === 'circular';
Expand All @@ -32,7 +30,7 @@ export function drawArea(HGC: import('@higlass/types').HGC, trackInfo: any, tile
const trackCenterY = trackHeight / 2.0;

/* genomic scale */
const xScale = trackInfo._xScale;
const xScale = track._xScale;

/* row separation */
const rowCategories = (model.getChannelDomainArray('row') as string[]) ?? ['___SINGLE_ROW___'];
Expand Down Expand Up @@ -202,6 +200,7 @@ export function drawArea(HGC: import('@higlass/types').HGC, trackInfo: any, tile
const baselinePoints: number[][] = [];
const areaPoints: number[] = [];
const baselineR = trackOuterRadius - ((rowPosition + rowHeight) / trackHeight) * trackRingSize;
let startX = 0;

data.filter(
d =>
Expand Down Expand Up @@ -273,13 +272,13 @@ export function drawArea(HGC: import('@higlass/types').HGC, trackInfo: any, tile
if (i === 0) {
// start position of the polygon
areaPoints.push(cx, rowPosition + rowHeight);
startX = cx;
}

areaPoints.push(cx, rowPosition + rowHeight - cy);

if (i === array.length - 1) {
// close the polygon with a point at the start
const startX = xScale(tileX);
areaPoints.push(cx, rowPosition + rowHeight);
areaPoints.push(startX, rowPosition + rowHeight);
}
Expand Down
21 changes: 12 additions & 9 deletions src/core/mark/bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { cartesianToPolar, valueToRadian } from '../utils/polar';
import colorToHex from '../utils/color-to-hex';
import type { Tile } from '../../gosling-track/gosling-track';

export function drawBar(trackInfo: any, tile: Tile, model: GoslingTrackModel) {
export function drawBar(track: any, tile: Tile, model: GoslingTrackModel) {
/* track spec */
const spec = model.spec();

Expand All @@ -20,13 +20,8 @@ export function drawBar(trackInfo: any, tile: Tile, model: GoslingTrackModel) {
const data = model.data();

/* track size */
const [trackWidth, trackHeight] = trackInfo.dimensions;
const tileSize = trackInfo.tilesetInfo.tile_size;
const { tileX, tileWidth } = trackInfo.getTilePosAndDimensions(
tile.tileData.zoomLevel,
tile.tileData.tilePos,
tileSize
);
const [trackWidth, trackHeight] = track.dimensions;
const tileSize = track.tilesetInfo.tile_size;
const zoomLevel =
(model.getChannelScale('x') as any).invert(trackWidth) - (model.getChannelScale('x') as any).invert(0);

Expand All @@ -42,7 +37,15 @@ export function drawBar(trackInfo: any, tile: Tile, model: GoslingTrackModel) {

/* genomic scale */
const xScale = model.getChannelScale('x');
const tileUnitWidth = xScale(tileX + tileWidth / tileSize) - xScale(tileX);
let tileUnitWidth: number;
if (tile.tileData.tilePos) {
const { tileX, tileWidth } = track.getTilePosAndDimensions(
tile.tileData.zoomLevel,
tile.tileData.tilePos,
tileSize
);
tileUnitWidth = xScale(tileX + tileWidth / tileSize) - xScale(tileX);
}

/* row separation */
const rowCategories = (model.getChannelDomainArray('row') as string[]) ?? ['___SINGLE_ROW___'];
Expand Down
4 changes: 2 additions & 2 deletions src/core/mark/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import colorToHex from '../utils/color-to-hex';
import { cartesianToPolar } from '../utils/polar';
import type { PIXIVisualProperty } from '../visual-property.schema';

export function drawPoint(trackInfo: any, g: PIXI.Graphics, model: GoslingTrackModel) {
export function drawPoint(track: any, g: PIXI.Graphics, model: GoslingTrackModel) {
/* track spec */
const spec = model.spec();

Expand All @@ -19,7 +19,7 @@ export function drawPoint(trackInfo: any, g: PIXI.Graphics, model: GoslingTrackM
const data = model.data();

/* track size */
const [trackWidth, trackHeight] = trackInfo.dimensions;
const [trackWidth, trackHeight] = track.dimensions;
const zoomLevel =
(model.getChannelScale('x') as any).invert(trackWidth) - (model.getChannelScale('x') as any).invert(0);

Expand Down
13 changes: 5 additions & 8 deletions src/core/mark/withinLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function drawWithinLink(g: PIXI.Graphics, trackInfo: any, model: GoslingT

/* defaults */
const MIN_HEIGHT = spec.style?.linkMinHeight ?? 0.5;
const NUM_STEPS = spec.experimental?.performanceMode ? 200 : 1000; // https:/gosling-lang/gosling.js/issues/634
const NUM_STEPS = spec.experimental?.performanceMode ? 10 : 50; // https:/gosling-lang/gosling.js/issues/634

// TODO: Can row be actually used for circular layouts?
/* render */
Expand Down Expand Up @@ -324,13 +324,10 @@ export function drawWithinLink(g: PIXI.Graphics, trackInfo: any, model: GoslingT
: Math.min(xe - x + trackWidth * MIN_HEIGHT, trackWidth) / trackWidth) *
(flipY ? -1 : 1);

if (step % 20 === 0 || step === NUM_STEPS) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unnecessary.

// we draw less points than the hidden points that captures mouse events
if (step === 0) {
g.moveTo(mx, my);
} else {
g.lineTo(mx, my);
}
if (step === 0) {
g.moveTo(mx, my);
} else {
g.lineTo(mx, my);
}
morePoints.push({ x: mx, y: my });
}
Expand Down