Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #148 from cBioPortal/draw-arrays-instanced
Browse files Browse the repository at this point in the history
Optimizations
  • Loading branch information
adamabeshouse authored Jun 11, 2021
2 parents 4ce3c91 + 73d732a commit 306a521
Show file tree
Hide file tree
Showing 17 changed files with 767 additions and 468 deletions.
8 changes: 4 additions & 4 deletions src/js/bucketsort.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {extendArray, sgndiff} from "./utils";
import {extendArray, fastParseInt10, sgndiff} from "./utils";

const string_type = typeof "";

Expand Down Expand Up @@ -107,7 +107,7 @@ export function stringToVector(string:string) {
// character is not numeric
if (numberStartIncl > -1) {
// if we're in a number, then we need to add the number to the vector
vector.push(parseInt(string.substring(numberStartIncl, i), 10));
vector.push(fastParseInt10(string, numberStartIncl, i));
// and record no longer in a number
numberStartIncl = -1;
}
Expand All @@ -117,7 +117,7 @@ export function stringToVector(string:string) {
}
if (numberStartIncl > -1) {
// if we're in a number at the end of the string, add it to vector
vector.push(parseInt(string.substring(numberStartIncl), 10));
vector.push(fastParseInt10(string, numberStartIncl));
// no need to reset numberStartIncl because the algorithm is done
}
return vector;
Expand Down Expand Up @@ -202,8 +202,8 @@ export function bucketSortHelper<T>(
key = vector[vector_index];
if (!(key in buckets)) {
keys.push(key);
buckets[key] = [];
}
buckets[key] = buckets[key] || [];
buckets[key].push(array[i]);
} else {
// if the vector has no entry at this index, sort earlier, in line w string sorting convention of shorter strings first
Expand Down
38 changes: 30 additions & 8 deletions src/js/extractrgba.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
export default function extractrgba(str:string) {
let ret = [0, 0, 0, 1];
import { fastParseInt16 } from "./utils";
import {RGBAColor} from "./oncoprintruleset";

export default function extractrgba(str:string):RGBAColor {
if (str[0] === "#") {
// hex, convert to rgba
const r = parseInt(str[1] + str[2], 16);
const g = parseInt(str[3] + str[4], 16);
const b = parseInt(str[5] + str[6], 16);
str = 'rgba('+r+','+g+','+b+',1)';
return hexToRGBA(str);
}
const match = str.match(/^[\s]*rgba\([\s]*([0-9.]+)[\s]*,[\s]*([0-9.]+)[\s]*,[\s]*([0-9.]+)[\s]*,[\s]*([0-9.]+)[\s]*\)[\s]*$/);
if (match && match.length === 5) {
ret = [parseFloat(match[1]) / 255,
return [parseFloat(match[1]) / 255,
parseFloat(match[2]) / 255,
parseFloat(match[3]) / 255,
parseFloat(match[4])];
}
return ret;
throw `could not extract rgba from ${str}`;
};

export function hexToRGBA(str:string):RGBAColor {
const r = fastParseInt16(str[1] + str[2]);
const g = fastParseInt16(str[3] + str[4]);
const b = fastParseInt16(str[5] + str[6]);
return [r,g,b,1];
}

export function rgbaToHex(rgba:RGBAColor):string {
let hexR = rgba[0].toString(16);
let hexG = rgba[1].toString(16);
let hexB = rgba[2].toString(16);
if (hexR.length === 1) {
hexR = '0' + hexR;
}
if (hexG.length === 1) {
hexG = '0' + hexG;
}
if (hexB.length === 1) {
hexB = '0' + hexB;
}
return `#${hexR}${hexG}${hexB}`;
}
2 changes: 1 addition & 1 deletion src/js/makesvgelement.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function makesvgelement(tag:string, attrs:any) {
const el = document.createElementNS('http://www.w3.org/2000/svg', tag);
for (const k in attrs) {
if (attrs.hasOwnProperty(k)) {
if (k in attrs) {
el.setAttribute(k, attrs[k]);
}
}
Expand Down
63 changes: 30 additions & 33 deletions src/js/oncoprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export default class Oncoprint {
public label_view: OncoprintLabelView;
public legend_view: OncoprintLegendView;

private keep_sorted:boolean;
private keep_horz_zoomed_to_fit:boolean;
private keep_horz_zoomed_to_fit_ids:ColumnId[];
private pending_resize_and_organize:boolean;
Expand Down Expand Up @@ -341,8 +340,6 @@ export default class Oncoprint {

this.legend_view = new OncoprintLegendView($legend_div, 10, 20);

this.keep_sorted = false;

this.keep_horz_zoomed_to_fit = false;
this.keep_horz_zoomed_to_fit_ids = [];

Expand Down Expand Up @@ -525,7 +522,7 @@ export default class Oncoprint {
this.track_info_view.moveTrack(this.model, this.getCellViewHeight);
this.minimap_view.moveTrack(this.model, this.cell_view);

if (this.keep_sorted && this.model.isSortAffected([target_track, new_previous_track], "track")) {
if (this.model.keep_sorted && this.model.isSortAffected([target_track, new_previous_track], "track")) {
this.sort();
}

Expand All @@ -542,7 +539,7 @@ export default class Oncoprint {
this.track_options_view.setTrackGroupOrder(this.model);
this.track_info_view.setTrackGroupOrder(this.model, this.getCellViewHeight);

if (!dont_sort && this.keep_sorted && this.model.isSortAffected(index, "group")) {
if (!dont_sort && this.model.keep_sorted && this.model.isSortAffected(index, "group")) {
this.sort();
}

Expand All @@ -558,12 +555,13 @@ export default class Oncoprint {
this.resizeAndOrganizeAfterTimeout();
}

public keepSorted(keep_sorted:boolean) {
public keepSorted(keep_sorted?:boolean) {
if(this.webgl_unavailable || this.destroyed) {
return;
}
this.keep_sorted = (typeof keep_sorted === 'undefined' ? true : keep_sorted);
if (this.keep_sorted) {
const oldValue = this.model.keep_sorted;
this.model.keep_sorted = typeof keep_sorted === 'undefined' ? true : keep_sorted;
if (this.model.keep_sorted && this.model.keep_sorted !== oldValue) {
this.sort();
}
}
Expand Down Expand Up @@ -591,7 +589,7 @@ export default class Oncoprint {
this.legend_view.addTracks(this.model);
this.minimap_view.addTracks(this.model, this.cell_view);

if (this.keep_sorted && this.model.isSortAffected(track_ids, "track")) {
if (this.model.keep_sorted && this.model.isSortAffected(track_ids, "track")) {
this.sort();
}
this.resizeAndOrganizeAfterTimeout();
Expand All @@ -613,7 +611,7 @@ export default class Oncoprint {
this.legend_view.removeTrack(this.model);
this.minimap_view.removeTrack(this.model, this.cell_view);

if (this.keep_sorted && this.model.isSortAffected(track_id, "track")) {
if (this.model.keep_sorted && this.model.isSortAffected(track_id, "track")) {
this.sort();
}
this.resizeAndOrganizeAfterTimeout();
Expand All @@ -623,13 +621,9 @@ export default class Oncoprint {
if(this.webgl_unavailable || this.destroyed) {
return;
}
this.keepSorted(false);
this.suppressRendering();
for (let i=0; i<track_ids.length; i++) {
this.removeTrack(track_ids[i]);
}
this.keepSorted(true);
this.releaseRendering();
}

public getTracks() {
Expand Down Expand Up @@ -934,7 +928,7 @@ export default class Oncoprint {
this.legend_view.setTrackData(this.model);
this.minimap_view.setTrackData(this.model, this.cell_view);

if (this.keep_sorted && this.model.isSortAffected(track_id, "track")) {
if (this.model.keep_sorted && this.model.isSortAffected(track_id, "track")) {
this.sort();
}
this.resizeAndOrganizeAfterTimeout();
Expand All @@ -957,7 +951,7 @@ export default class Oncoprint {
this.model.setTrackGroupSortPriority(priority);
this.cell_view.setTrackGroupSortPriority(this.model);

if (this.keep_sorted) {
if (this.model.keep_sorted) {
this.sort();
}
this.resizeAndOrganizeAfterTimeout();
Expand All @@ -969,7 +963,7 @@ export default class Oncoprint {
}
this.model.resetSortableTracksSortDirection(true);

if (this.keep_sorted) {
if (this.model.keep_sorted) {
this.sort();
}
}
Expand All @@ -981,7 +975,7 @@ export default class Oncoprint {
if (this.model.isTrackSortDirectionChangeable(track_id)) {
this.model.setTrackSortDirection(track_id, dir);

if (this.keep_sorted && this.model.isSortAffected(track_id, "track")) {
if (this.model.keep_sorted && this.model.isSortAffected(track_id, "track")) {
this.sort();
}

Expand All @@ -999,7 +993,7 @@ export default class Oncoprint {
return;
}
this.model.setTrackSortComparator(track_id, sortCmpFn);
if (this.keep_sorted && this.model.isSortAffected(track_id, "track")) {
if (this.model.keep_sorted && this.model.isSortAffected(track_id, "track")) {
this.sort();
}
}
Expand Down Expand Up @@ -1104,7 +1098,7 @@ export default class Oncoprint {
this.cell_view.setSortConfig(this.model);
this.track_options_view.setSortConfig(this.model);

if (this.keep_sorted) {
if (this.model.keep_sorted) {
this.sort();
}
}
Expand All @@ -1118,7 +1112,7 @@ export default class Oncoprint {
this.cell_view.setIdOrder(this.model, ids);
this.minimap_view.setIdOrder(this.model, this.cell_view);

if (this.keep_sorted) {
if (this.model.keep_sorted) {
this.sort();
}
}
Expand Down Expand Up @@ -1175,17 +1169,20 @@ export default class Oncoprint {
if(this.webgl_unavailable || this.destroyed) {
return;
}
this.model.rendering_suppressed_depth -= 1;
this.model.rendering_suppressed_depth = Math.max(0, this.model.rendering_suppressed_depth);
if (this.model.rendering_suppressed_depth === 0) {
this.label_view.releaseRendering(this.model, this.getCellViewHeight);
this.header_view.releaseRendering(this.model);
this.cell_view.releaseRendering(this.model);
this.track_options_view.releaseRendering(this.model, this.getCellViewHeight);
this.track_info_view.releaseRendering(this.model, this.getCellViewHeight);
this.legend_view.releaseRendering(this.model);
this.minimap_view.releaseRendering(this.model, this.cell_view);
this.resizeAndOrganizeAfterTimeout(onComplete);
if (this.model.rendering_suppressed_depth > 0) {
this.model.rendering_suppressed_depth -= 1;
this.model.rendering_suppressed_depth = Math.max(0, this.model.rendering_suppressed_depth);
if (this.model.rendering_suppressed_depth === 0) {
this.model.releaseRendering();
this.label_view.releaseRendering(this.model, this.getCellViewHeight);
this.header_view.releaseRendering(this.model);
this.cell_view.releaseRendering(this.model);
this.track_options_view.releaseRendering(this.model, this.getCellViewHeight);
this.track_info_view.releaseRendering(this.model, this.getCellViewHeight);
this.legend_view.releaseRendering(this.model);
this.minimap_view.releaseRendering(this.model, this.cell_view);
this.resizeAndOrganizeAfterTimeout(onComplete);
}
}
}

Expand Down Expand Up @@ -1287,7 +1284,7 @@ export default class Oncoprint {
const everything_group = svgfactory.group(0,0);
root.appendChild(everything_group);

const bgrect = svgfactory.bgrect(10,10,'#ffffff');
const bgrect = svgfactory.bgrect(10,10,[255,255,255,1]);

if (with_background) {
everything_group.appendChild(bgrect);
Expand Down
7 changes: 5 additions & 2 deletions src/js/oncoprintlegendrenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ export default class OncoprintLegendView {
const concrete_shapes = rule.apply(config.target, model.getCellWidth(true), this.base_height);
if (rule.legend_base_color) {
// generate backgrounds
const baseRect = svgfactory.rect(0, 0, model.getCellWidth(true), this.base_height, rule.legend_base_color);
const baseRect = svgfactory.rect(0, 0, model.getCellWidth(true), this.base_height, {
type: "rgba",
value: rule.legend_base_color
});
root.appendChild(baseRect);
}
// generate shapes
Expand Down Expand Up @@ -223,7 +226,7 @@ export default class OncoprintLegendView {
target_defs.appendChild(gradient);
root.appendChild(svgfactory.text(display_range[0].toString(), 0, 0, 12, 'Arial', 'normal'));
root.appendChild(svgfactory.text(display_range[1].toString(), 120, 0, 12, 'Arial', 'normal'));
root.appendChild(svgfactory.rect(30,0,60,20,"url(#"+gradient_id+")"));
root.appendChild(svgfactory.rect(30,0,60,20,{type:"gradientId", value: gradient_id}));
}
return root;
}
Expand Down
Loading

0 comments on commit 306a521

Please sign in to comment.