Skip to content

Commit

Permalink
nt scale for selection box
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacfink21 committed Jul 6, 2021
1 parent 111e877 commit a5867c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 70 deletions.
12 changes: 0 additions & 12 deletions anvio/data/interactive/css/genomeview.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,6 @@ g.scale rect.background{
pointer-events: all;
}

.brush .extent {
stroke: black;
fill-opacity: .125;
shape-rendering: crispEdges;
}

rect.background {
fill: rgba(0,0,0,0.1);
visibility: visible !important;
pointer-events: all;
}

#tooltip-body{
height: 300px;
width: 300px;
Expand Down
69 changes: 11 additions & 58 deletions anvio/data/interactive/js/genomeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@

// Settings vars
// TODO migrate below variables to kvp in state
var stateData = {};
var calculatedSpacing; // like spacing, but calculated ;)
var state = {};
var spacing = 30; // vertical spacing between genomes
var showLabels = true; // show genome labels?
var genomeLabelSize = 15; // font size of genome labels
Expand All @@ -39,7 +38,7 @@
var showScale = true; // show nt scale?
var scaleInterval = 100; // nt scale intervals
var scaleFactor = 1; // widths of all objects are scaled by this value to zoom in/out

var alignToGC = null;

var arrowStyle = 1; // gene arrow cosmetics. 1 (default) = 'inspect-page', 2 = thicker arrows, 3 = pentagon
Expand All @@ -54,7 +53,7 @@ var genomeData;
$(document).ready(function() {
initData();
// loadState();
processState('default', stateData) // lifted here until loadState is hooked in from backend
processState('default', {}) // lifted here until loadState is hooked in from backend
loadAll();
});

Expand Down Expand Up @@ -148,26 +147,6 @@ function processState(stateName, stateData){
'ordering' : 'beaks to tails'
}
]
stateData['additional-data-layers'] = []

calculateMaxGenomeLength()

for(let i = 0; i < genomeData.genomes.length; i++){ // generate mock additional data layer content
let gcContent = []
let coverage = []

for(let j = 0; j < genomeMax; j++){
gcContent.push(Math.floor(Math.random() * 25))
coverage.push(Math.floor(Math.random() * 25))
}
let genomeLabel = Object.keys(genomeData.genomes[i][1]['contigs']['info'])[0];
let additionalDataObject = {
'genome' : genomeLabel,
'coverage' : coverage,
'gcContent' : gcContent
}
stateData['additional-data-layers'].push(additionalDataObject)
}

if(stateData['genome-order-method']){
stateData['genome-order-method'].forEach(orderMethod => {
Expand All @@ -189,8 +168,11 @@ function loadAll() {
canvas.setWidth(VIEWER_WIDTH * 0.85);

// Find max length genome
calculateMaxGenomeLength()
calculatedSpacing = calculateSpacingForGroups()
for(genome of genomeData.genomes) {
genome = genome[1].genes.gene_calls;
let genomeEnd = genome[Object.keys(genome).length-1].stop;
if(genomeEnd > genomeMax) genomeMax = genomeEnd;
}

var scaleWidth = canvas.getWidth();
var scaleHeight = 200;
Expand All @@ -211,12 +193,13 @@ function loadAll() {
.x(xScale)
.on("brushend", onBrush);

$("#scaleSvg").attr("width", scaleWidth);
$("#scaleSvg").attr("width", scaleWidth + 10);

var scaleBox = d3.select("#scaleSvg").append("g")
.attr("id", "scaleBox")
.attr("class","scale")
.attr("y", 230); // rather than 80 from 50?
.attr("y", 230) // rather than 80 from 50?
.attr("transform", "translate(5,0)");

scaleBox.append("g")
.attr("class", "x axis top noselect")
Expand All @@ -234,7 +217,6 @@ function loadAll() {
$('#brush_end').val(Math.floor(scaleWidth));

function onBrush(){
console.log("onBrush() called!");
var b = brush.empty() ? xScale.domain() : brush.extent();

if (brush.empty()) {
Expand Down Expand Up @@ -461,7 +443,6 @@ function draw(scaleX=scaleFactor) {
for(genome of genomeData.genomes) {
let label = genome[1].genes.gene_calls[0].contig;
addGenome(label, genome[1].genes.gene_calls, genome[0], y, scaleX=scaleX)
addLayers(label, genome[1], genome[0])
labelSpacing += 30
y++;
}
Expand Down Expand Up @@ -701,17 +682,6 @@ function addGenome(label, gene_list, genomeID, y, scaleX=1) {
//geneGroup.destroy();
}

function addLayers(label, genome, genomeID){ // this will work alongside addGenome to render out any additional data layers associated with each group (genome)

let additionalDataLayers = stateData['additional-data-layers'].find(group => group.genome = label)
if(additionalDataLayers['coverage']){
// process for rendering coverage
}
if(additionalDataLayers['gcContent']){
//process for rendering GC content
}
}

function geneArrow(gene, geneID, functions, y, genomeID, style, scaleX=1) {
var cag = null;
var color = 'gray';
Expand Down Expand Up @@ -855,23 +825,6 @@ function changeGenomeOrder(updatedOrder){
draw()
}

function calculateMaxGenomeLength(){
for(genome of genomeData.genomes) {
genome = genome[1].genes.gene_calls;
let genomeEnd = genome[Object.keys(genome).length-1].stop;
if(genomeEnd > genomeMax) genomeMax = genomeEnd;
}
}

function calculateSpacingForGroups(){ // to be used for setting vertical spacing
let maxGroupSize = 1; // default, as each group will always have at minimum a 'genome' layer
stateData['additional-data-layers'].map(group => {
Object.keys(group).length > maxGroupSize ? maxGroupSize = Object.keys(group).length : null
})
let spacing = 500 / [maxGroupSize * genomeData.genomes.length] // 500 is hardcoded main canvas height
return spacing
}

var fixHelperModified = function(e, tr) { // ripped from utils.js instead of importing the whole file
var $originals = tr.children();
var $helper = tr.clone();
Expand Down

0 comments on commit a5867c9

Please sign in to comment.