Skip to content

Commit

Permalink
hoist out plasmid cache and remove unused canvases
Browse files Browse the repository at this point in the history
  • Loading branch information
chgibb committed Nov 20, 2019
1 parent b12883f commit e2d977c
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 81 deletions.
85 changes: 85 additions & 0 deletions src/req/renderer/containers/circularGenome/cachedPlasmid.ts
@@ -0,0 +1,85 @@
import { Plasmid } from '../../../ngplasmid/lib/plasmid';
import { CircularFigure, buildBaseFigureTemplate, assembleCompilableTemplates, assembleCompilableCoverageTrack } from '../../circularFigure/circularFigure';
import {Node, loadFromString } from '../../../ngplasmid/lib/html';

export interface CachedPlasmid
{
uuid : string;
plasmid : Plasmid
}

let plasmidCache = new Array<CachedPlasmid>();

export async function loadPlasmid(target : string,figure : CircularFigure) : Promise<CachedPlasmid| undefined>
{
let scope = {genome : figure};
if(target == figure.uuid)
{
console.log("Loading base figure");
console.log(figure.name);

let plasmid : Plasmid = new Plasmid();
plasmid.$scope = scope;

let nodes : Array<Node> = await loadFromString(
assembleCompilableTemplates(figure,
buildBaseFigureTemplate(figure)
)
);

for(let i = 0; i != nodes.length; ++i)
{
if(nodes[i].name == "div")
{
for(let k = 0; k != nodes[i].children.length; ++k)
{
if(nodes[i].children[k].name == "plasmid")
{
plasmid.fromNode(nodes[i].children[k]);
return {
uuid : figure.uuid,
plasmid : plasmid
};
}
}
}
}
}

else
{
let coverageTrack = figure.renderedCoverageTracks.find((x) => x.uuid == target);
if(coverageTrack)
{
let plasmid : Plasmid = new Plasmid();
plasmid.$scope = scope;

let nodes : Array<Node> = await loadFromString(assembleCompilableCoverageTrack(figure,coverageTrack));

for(let i = 0; i != nodes.length; ++i)
{
if(nodes[i].name == "div")
{
for(let k = 0; k != nodes[i].children.length; ++k)
{
if(nodes[i].children[k].name == "plasmid")
{
plasmid.fromNode(nodes[i].children[k]);
plasmidCache = [
...plasmidCache,
{
uuid : target,
plasmid : plasmid
}
];

return {uuid:target,plasmid:plasmid};
}
}
}
}
}
}

return undefined;
}
97 changes: 16 additions & 81 deletions src/req/renderer/containers/circularGenome/circularGenome.tsx
@@ -1,8 +1,8 @@
import * as React from "react";

import {CircularFigure, assembleCompilableTemplates, buildBaseFigureTemplate, assembleCompilableCoverageTrack, renderSVGToCanvas} from "../../circularFigure/circularFigure";
import {CircularFigure, renderSVGToCanvas} from "../../circularFigure/circularFigure";
import {Plasmid} from "../../../ngplasmid/lib/plasmid";
import {Node, loadFromString} from "../../../ngplasmid/lib/html";
import { loadPlasmid } from './cachedPlasmid';

export interface CircularGenomeState
{
Expand Down Expand Up @@ -33,86 +33,11 @@ export class CircularGenome extends React.Component<CircularGenomeProps,Circular

this.plasmidCache = [];

this.loadPlasmid = this.loadPlasmid.bind(this);
this.updateCanvas = this.updateCanvas.bind(this);
this.componentDidMount = this.componentDidMount.bind(this);
this.componentDidUpdate = this.componentDidUpdate.bind(this);
}

public async loadPlasmid(target : string) : Promise<{uuid : string,plasmid : Plasmid} | undefined>
{
let scope = {genome : this.props.figure};
if(target == this.props.figure.uuid)
{
console.log("Loading base figure");
console.log(this.props.figure.name);

let plasmid : Plasmid = new Plasmid();
plasmid.$scope = scope;

let nodes : Array<Node> = await loadFromString(
assembleCompilableTemplates(this.props.figure,
buildBaseFigureTemplate(this.props.figure)
)
);

for(let i = 0; i != nodes.length; ++i)
{
if(nodes[i].name == "div")
{
for(let k = 0; k != nodes[i].children.length; ++k)
{
if(nodes[i].children[k].name == "plasmid")
{
plasmid.fromNode(nodes[i].children[k]);
return {
uuid : this.props.figure.uuid,
plasmid : plasmid
};
}
}
}
}
}

else
{
let coverageTrack = this.props.figure.renderedCoverageTracks.find((x) => x.uuid == target);
if(coverageTrack)
{
let plasmid : Plasmid = new Plasmid();
plasmid.$scope = scope;

let nodes : Array<Node> = await loadFromString(assembleCompilableCoverageTrack(this.props.figure,coverageTrack));

for(let i = 0; i != nodes.length; ++i)
{
if(nodes[i].name == "div")
{
for(let k = 0; k != nodes[i].children.length; ++k)
{
if(nodes[i].children[k].name == "plasmid")
{
plasmid.fromNode(nodes[i].children[k]);
this.plasmidCache = [
...this.plasmidCache,
{
uuid : target,
plasmid : plasmid
}
];

return {uuid:target,plasmid:plasmid};
}
}
}
}
}
}

return undefined;
}

public async updateCanvas()
{
for (let i = 0; i != this.props.figure.visibleLayers.length; ++i)
Expand Down Expand Up @@ -140,7 +65,7 @@ export class CircularGenome extends React.Component<CircularGenomeProps,Circular

if (!plasmid)
{
plasmid = await this.loadPlasmid(layer);
plasmid = await loadPlasmid(layer,this.props.figure);
}

if (plasmid && canvas)
Expand Down Expand Up @@ -209,15 +134,25 @@ export class CircularGenome extends React.Component<CircularGenomeProps,Circular
if(prevProps.y != this.props.y)
canvas.style.top = `${this.props.y}px`;
}
}

if(this.props.shouldUpateCanvas)
if(this.props.shouldUpateCanvas)
{
shouldUpdateCanvasDueToResize = true;

while(canvasArr.length > this.props.figure.visibleLayers.length){
if(this.ref.current.lastChild){
this.ref.current.lastChild.remove();
}
canvasArr = this.ref.current.getElementsByTagName("canvas");
}
}

if(shouldUpdateCanvasDueToResize || this.props.shouldUpateCanvas)
{
await this.updateCanvas();
}
}



}

Expand Down

0 comments on commit e2d977c

Please sign in to comment.