index.html 27 KB
Newer Older
jhoogenboom's avatar
jhoogenboom committed
1 2 3
<!DOCTYPE html>
<html>
<head>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
    <!--
    # Copyright (C) 2016 Jerry Hoogenboom
    #
    # This file is part of FDSTools, data analysis tools for Next
    # Generation Sequencing of forensic DNA markers.
    #
    # FDSTools is free software: you can redistribute it and/or modify it
    # under the terms of the GNU General Public License as published by the
    # Free Software Foundation, either version 3 of the License, or (at
    # your option) any later version.
    #
    # FDSTools is distributed in the hope that it will be useful, but
    # WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    # General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with FDSTools.  If not, see <http://www.gnu.org/licenses/>.
    -->
23
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
24
    <meta name="viewport" content="width=device-width, initial-scale=1">
jhoogenboom's avatar
jhoogenboom committed
25
    <meta charset="UTF-8">
26
    <title>Background Noise Visualisation - FDSTools</title>
27
    <!-- VERSION 2.0.1 -->
jhoogenboom's avatar
jhoogenboom committed
28
    <!-- BEGIN_LIBRARIES -->
29 30
    <script src="https://vega.github.io/vega-editor/vendor/d3.min.js"></script>
    <script src="https://vega.github.io/vega/vega.min.js"></script>
jhoogenboom's avatar
jhoogenboom committed
31 32
    <!-- END_LIBRARIES -->
    <style>
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    input {
        font-family: inherit;
        font-size: 1em;
    }
    .icon {
        padding: 1em;
        margin-right: .25em;
        background-size: contain;
        background-position: center;
        background-repeat: no-repeat;
    }
    @media screen {
        html, body {
            /* First the UI fonts of WinVista+, OSX10.11, OSX10.10, OSX10.9-, WinXP-, Ubuntu. Then some fallbacks. */
            font-family: Segoe UI, San Francisco, Helvetica Neue, Lucida Grande, Tahoma, Ubuntu, Helvetica, Arial, sans-serif;
jhoogenboom's avatar
jhoogenboom committed
48
            font-size: 10pt;
jhoogenboom's avatar
jhoogenboom committed
49 50
        }
        body {
51
            margin: 0rem;
jhoogenboom's avatar
jhoogenboom committed
52
        }
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        a {
            color: inherit;
            text-decoration: inherit;
            border-bottom: 1px dotted;
        }
        a:hover {
            border-bottom: 1px solid;
        }
        a.disabled {
            color: hsl(220, 20%, 53%);
        }
        a.disabled:hover {
            color: hsl(220, 20%, 53%);
            border-bottom: 1px dotted;
            cursor: default;
        }
        #outer {
            display: flex;
            flex-flow: column nowrap;
            height: 100vh;
            overflow: hidden;
        }
        #inner {
            display: flex;
            flex-flow: row nowrap;
            flex: 1 1 auto;
            overflow: hidden;
jhoogenboom's avatar
jhoogenboom committed
80
        }
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
        #optscrollbox {
            display: flex;
            flex-flow: column nowrap;
            flex: 0 0 auto;
            width: 22.5em;
            order: -1;
            overflow: auto;
            background-color: hsl(220, 20%, 77%);
            border-right: 1px solid hsl(220, 20%, 3%);
            border-bottom: none;
            cursor: default;
        }
        #visscrollbox {
            flex: 1 1 auto;
            overflow: auto;
            background-color: hsl(220, 20%, 97%); /* eef8ff */
            text-align: right;
        }
        .optiongroup {
            flex: 0 0 auto;
            padding: .2rem .2rem 1rem;
        }
        .optiongroup:last-child {
            padding: .2rem;
        }
        .optiongroup > table {
            margin: 0rem;
            border-spacing: 0rem;
            border: none;
        }
        .optiongroup > .optionheader {
            text-align: left;
            font-weight: bold;
            text-transform: uppercase;
        }
        .optiongroup > .optionheader:first-letter {
            font-size: 1.25em;
        }
        .optiongroup > table td {
            white-space: nowrap;
        }
        .optiongroup > table td:not(:last-child) {
            padding-right: .4rem;
        }
        .optiongroup > table tr.fileselectrow, .optiongroup > table tr.fileselect2row, .optiongroup > table tr.filenamedisplayrow {
            display: none;
        }
        .optiongroup > table tr.filenamedisplayrow #filenamedisplay {
            max-width: 20em;
            width: auto;
        }
        .optiongroup > table td.footnote {
            font-style: italic;
            white-space: wrap;
        }
        .optiongroup > table select {
            font-size: inherit;
            font-family: inherit;
        }
        .help {
141 142
            cursor: help;
            font-weight: bold;
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
            border-bottom: 1px dotted hsl(220, 20%, 3%);
        }
        .hidden {
            display: none;
        }
        .special-option {
            font-style: italic;
        }
        #vis {
            direction: rtl;
            display: inline-block;
        }
        #vis div {
            direction: ltr;
        }
        #vis div:nth-child(2n+3) {
            border-top: 1px solid hsl(220, 20%, 3%);
            padding-top: .8rem;
            margin-top: .8rem;
        }
        #vis div:last-child {
            padding-bottom: .8rem;
        }
        td.num {
            text-align: right;
        }
        td.wrap {
            white-space: normal !important;
            width: 1em;
        }
    }
    /*
    portrait, height >= 55:

      small collapsed   large collapsed   small top    large top
    |-----------------|-----------------|------------|------------>  width
    0                 45                60           68


    portrait, height < 55:

      small collapsed   large collapsed
    |-----------------|------------------------------------------->  width
    0                 45


    landscape:

      small collapsed   large collapsed   small left   large left
    |-----------------|-----------------|------------|------------>  width
    0                 45                60           68
    */
    @media only screen and (min-aspect-ratio: 40000/30000) and (min-width: 60em) and (max-width: 68em), /* Full menu is at the side, but viewport is not very wide */
           only screen and (max-aspect-ratio: 40000/30000) and (min-height: 55em) and (min-width: 60em) and (max-width: 68em), /* Full menus at the top, but viewport not wide enough */
           only screen and (max-width: 45em) { /* Very narrow; menu names don't fit anymore */
        /* Limited width: make menu smaller */
        #optscrollbox {
            font-size: .85em;
        }
    }
    @media only screen and (max-aspect-ratio: 40000/30000), only screen and (max-width: 60em) {
        /* Portrait or near-portrait, or rather narrow: menu at the top */
        #inner {
            flex-direction: column;
        }
        #optscrollbox {
            flex: 0 0 auto;
            flex-flow: row nowrap;
            width: 100%;
            border-right: none;
            border-bottom: 1px solid hsl(220, 20%, 3%);
        }
        #visscrollbox {
            flex: 1 1 auto;
        }
        .optiongroup {
            flex: 1 0 auto;
            padding: .2rem 1rem .2rem .2rem;
        }
    }
    @media only screen and (max-aspect-ratio: 40000/30000) and (max-height: 55em), only screen and (max-width: 60em) {
        /* Portrait or near-portrait combined with very limited height, or rather narrow: collapse menu */
        #optscrollbox {
            overflow: visible;
            z-index: 100;
            border-bottom: 1px solid hsl(220, 20%, 3%);
        }
        .optiongroup {
            position: relative;
        }
        .optiongroup > table {
            display: none;
            position: absolute;
            top: 100%;
            background-color: hsl(220, 20%, 77%);
            border: 1px solid hsl(220, 20%, 3%);
            border-top: none;
        }
        .optiongroup:last-child > table {
            left: auto;
            right: .2rem;
        }
        .optiongroup:hover > .optionheader {
            color: hsl(220, 20%, 97%);
        }
        .optiongroup:hover > table {
            display: table;
        }
    }

    @media print {
        html, body {
            font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
            font-size: 10pt;
        }
        .noprint, .help, .hidden {
            display: none;
        }
        #optscrollbox {
            display: flex;
            box-sizing: border-box;
            flex-flow: row wrap;
            align-items: stretch;
            width: 100%;
            border-top: 1pt solid black;
            border-right: 1pt solid black;
            font-size: 7pt;
        }
        .optiongroup {
            flex-grow: 1;
            padding: 5pt;
            border-left: 1pt solid black;
            border-bottom: 1pt solid black;
276
        }
277 278
        .optiongroup > table {
            padding: 0px;
jhoogenboom's avatar
jhoogenboom committed
279 280 281 282
            margin: 0px;
            border-spacing: 0px;
            border: none;
        }
283
        .optiongroup > .optionheader {
jhoogenboom's avatar
jhoogenboom committed
284 285
            text-align: left;
            font-weight: bold;
286
            text-transform: uppercase;
jhoogenboom's avatar
jhoogenboom committed
287
        }
288 289
        .optiongroup > .optionheader:first-letter {
            font-size: 1.25em;
jhoogenboom's avatar
jhoogenboom committed
290
        }
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
        .optiongroup > table td {
            white-space: nowrap;
        }
        .optiongroup > table td:not(:last-child) {
            padding-right: 5pt;
        }
        .optiongroup > table td.footnote {
            font-style: italic;
            white-space: wrap;
        }
        .optiongroup > table input {
            border: none;
        }
        .optiongroup > table select {
            /* No dropdow box arrow on FF and Webkit-based browsers */
            -webkit-appearance: none;
            -moz-appearance: none;
            appearance: none;
            font-size: inherit;
            border: none;
        }
        select::-ms-expand {
            /* No dropdown box arrow on IE10+ */
            display: none;
        }
        .optiongroup > table input[type=checkbox] {
            height: 1em;
            width: 1em;
        }
        #vis {
            width: 100%;
        }
        #vis > div {
            width: 100%;
            direction: rtl;
jhoogenboom's avatar
jhoogenboom committed
326 327
            text-align: right;
        }
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
        #vis > div > * {
            direction: ltr;
        }
        .vega, canvas {
            max-width: 100%;
            height: auto;
            overflow: visible;
        }
        svg {
            /* Using slightly smaller width to prevent clipping in Chrome */
            max-width: 98%;
            height: auto;
            overflow: visible;
        }
        canvas {
            object-fit: scale-down;
        }
        .num {
            text-align: right;
        }
        td.wrap {
            white-space: normal !important;
        }
    }
jhoogenboom's avatar
jhoogenboom committed
352 353 354
    </style>
</head>
<body>
355 356 357 358 359 360 361 362
<div id="outer">
<div id="inner">
    <div id="optscrollbox">
        <div class="optiongroup noprint">
            <div class="optionheader">Input &amp; output</div>
            <table>
                <tr class="fileselectrow filenamedisplayrow">
                    <td>Background noise data file:</td>
jhoogenboom's avatar
jhoogenboom committed
363
                </tr>
364
                <tr class="fileselectrow">
jhoogenboom's avatar
jhoogenboom committed
365 366
                    <td><input id="fileselect" type="file"></td>
                </tr>
367
                <tr class="fileselectrow">
jhoogenboom's avatar
jhoogenboom committed
368 369
                    <td>(or drag a file onto this page)</td>
                </tr>
370 371 372
                <tr class="filenamedisplayrow">
                    <td id="filenamedisplay" class="wrap"></td>
                </tr>
jhoogenboom's avatar
jhoogenboom committed
373
                <tr>
374 375 376
                    <td>
                        <a id="saveImageLink" href="javascript:void(saveImage())" class="disabled">Save image</a>
                    </td>
jhoogenboom's avatar
jhoogenboom committed
377
                </tr>
378 379 380 381 382
            </table>
        </div>
        <div class="optiongroup">
            <div class="optionheader">Filtering options</div>
            <table>
jhoogenboom's avatar
jhoogenboom committed
383
                <tr>
384 385
                    <td><label for="minN">Require at least</label></td>
                    <td><label><input type="text" value="5" id="minN" size="3"> reads</label></td>
jhoogenboom's avatar
jhoogenboom committed
386 387
                </tr>
                <tr>
388 389
                    <td><label for="minP">Minimum noise ratio</label></td>
                    <td><label><input type="text" value="0.5" id="minP" size="3">%</label></td>
jhoogenboom's avatar
jhoogenboom committed
390 391
                </tr>
                <tr>
392
                    <td rowspan="2"><label for="markerSelect">Marker name</label></td>
393
                    <td>
394 395 396 397
                        <select id="markerSelect">
                            <option value="" class="special-option" selected>Show all</option>
                            <option value="CUSTOM" class="special-option">Custom filter</option>
                        </select>
398
                    </td>
jhoogenboom's avatar
jhoogenboom committed
399 400
                </tr>
                <tr>
401 402 403 404 405 406
                    <td id="markerFilterRow" class="hidden">
                        <label>
                            <input type="text" id="markerFilter" size="15">
                            <span class="help" title="Type xyz to show all markers with 'xyz' in their names. Type =xyz to show only the marker 'xyz'. Separate multiple values with spaces.">?</span>
                        </label>
                    </td>
jhoogenboom's avatar
jhoogenboom committed
407
                </tr>
408 409 410 411 412
            </table>
        </div>
        <div class="optiongroup noprint">
            <div class="optionheader">Display options</div>
            <table>
jhoogenboom's avatar
jhoogenboom committed
413
                <tr>
414 415
                    <td><label for="graphwidth">Graph width</label></td>
                    <td colspan="2"><label><input type="text" value="600" id="graphwidth" size="3"> px</label></td>
jhoogenboom's avatar
jhoogenboom committed
416 417
                </tr>
                <tr>
418 419
                    <td><label for="barwidth">Bar width</label></td>
                    <td colspan="2"><label><input type="text" value="15" id="barwidth" size="3"> px</label></td>
jhoogenboom's avatar
jhoogenboom committed
420 421
                </tr>
                <tr>
422 423
                    <td><label for="subgraphoffset">Subgraph spacing</label></td>
                    <td colspan="2"><label><input type="text" value="70" id="subgraphoffset" size="3"> px</label></td>
jhoogenboom's avatar
jhoogenboom committed
424 425 426
                </tr>
                <tr>
                    <td>Axis scale</td>
427 428
                    <td><label><input type="radio" name="scale" value="linear" id="scaleLinear" checked> Linear</label></td>
                    <td><label><input type="radio" name="scale" value="log" id="scaleLog"> Logarithmic</label></td>
jhoogenboom's avatar
jhoogenboom committed
429 430
                </tr>
                <tr>
jhoogenboom's avatar
jhoogenboom committed
431
                    <td>Renderer</td>
432 433
                    <td><label><input type="radio" name="renderer" value="svg" id="renderSVG" checked> SVG</label></td>
                    <td><label><input type="radio" name="renderer" value="canvas" id="renderCanvas"> Canvas</label></td>
jhoogenboom's avatar
jhoogenboom committed
434 435
                </tr>
            </table>
jhoogenboom's avatar
jhoogenboom committed
436 437
        </div>
    </div>
438 439 440 441 442 443 444 445 446
    <div id="visscrollbox">
        <div id="vis"></div>
    </div>
</div>
</div>
<script type="text/javascript">
var graph = false;
var data_format = {};
var data_values = [];
447
var fileName = "bgprofiles-raw";
448 449 450 451 452 453 454 455 456 457 458 459
var stamp = 0;
function parse(){
    var this_stamp = ++stamp;
    var visdiv = document.getElementById("vis");
    var scrolldiv = document.getElementById("visscrollbox");
    var rendererName = document.querySelector("input[name=renderer]:checked").value;
    removeChildren(visdiv);
    document.getElementById("saveImageLink").setAttribute("class", "disabled");
    vg.parse.spec(graph_spec, function(chart){
        //Cancel rendering if a new parse() call was made.
        if(this_stamp != stamp)
            return;
460

461 462 463 464
        //Add new visualisation divs.
        var newvis = document.createElement("div");
        newvis.setAttribute("id", "vis0");
        visdiv.appendChild(newvis);
jhoogenboom's avatar
jhoogenboom committed
465

466 467 468 469 470
        graph = chart({el: newvis, renderer: rendererName});
        graph.update();
        if(rendererName == "svg")
            updateViewBox(graph._el.childNodes[0]);
        document.getElementById("saveImageLink").setAttribute("class", "");
jhoogenboom's avatar
jhoogenboom committed
471

472 473 474 475
        //Scroll to the right; the graph is more interesting than the long labels.
        scrolldiv.scrollLeft = scrolldiv.scrollWidth;
    });
}
476

477 478 479
function compileFilter(filter){
    return new RegExp('(?:' + filter.replace(/(^| )=(.*?)(?= |$)/g, '$1^$2$$').replace(/ +/g, ')|(?:') + ')')
}
jhoogenboom's avatar
jhoogenboom committed
480

481 482 483 484 485
function updateViewBox(svg){
    //Setting the viewBox enables shrink-to-fit behaviour when printing.
    svg.setAttribute("viewBox",
        "0 0 " + svg.getAttribute("width") + " " + svg.getAttribute("height"));
}
jhoogenboom's avatar
jhoogenboom committed
486

487 488 489 490 491
function removeChildren(el){
    while(el.lastChild){
      el.removeChild(el.lastChild);
    }
}
jhoogenboom's avatar
jhoogenboom committed
492

493 494 495 496 497 498 499 500 501
function setScale(value){
    if(!graph_spec)
        return;
    for(i in graph_spec.marks)
        if(graph_spec.marks[i].scales)
            for(j in graph_spec.marks[i].scales)
                if(graph_spec.marks[i].scales[j].name == "x")
                    graph_spec.marks[i].scales[j].type = value;
    //setSignalValue("low", value == "log"? 0.001 : 0);  //Need this for profile bars.
jhoogenboom's avatar
jhoogenboom committed
502

503 504 505
    if(graph)
        parse();
}
jhoogenboom's avatar
jhoogenboom committed
506

507 508 509 510 511 512 513 514 515 516
function getScale(){
    if(!graph_spec)
        return "linear";
    for(i in graph_spec.marks)
        if(graph_spec.marks[i].scales)
            for(j in graph_spec.marks[i].scales)
                if(graph_spec.marks[i].scales[j].name == "x")
                    return graph_spec.marks[i].scales[j].type;
    return "linear";
}
jhoogenboom's avatar
jhoogenboom committed
517

518 519 520 521 522 523 524 525 526 527 528
function setSignalValue(signalname, value){
    if(!graph_spec)
        return;
    var scrolldiv = document.getElementById("visscrollbox");
    var scrollRight = (scrolldiv.scrollLeft >= scrolldiv.scrollWidth - scrolldiv.clientWidth);
    if(signalname == "width")
        graph_spec.width = value;
    for(i in graph_spec.signals){
        if(graph_spec.signals[i].name == signalname){
            graph_spec.signals[i].init = value;
            break;
529
        }
530 531 532 533 534 535 536 537 538 539
    }
    if(graph){
        graph.signal(signalname, value).padding("auto").update();
        if(document.getElementById("renderSVG").checked)
            updateViewBox(graph._el.childNodes[0]);
    }
    if(scrollRight)
        scrolldiv.scrollLeft = scrolldiv.scrollWidth;
    return;
}
540

541 542 543 544 545 546 547 548 549 550
function getSignalValue(signalname){
    if(!graph_spec)
        return false;
    if(signalname == "width")
        return graph_spec.width;
    for(i in graph_spec.signals)
        if(graph_spec.signals[i].name == signalname)
            return graph_spec.signals[i].init;
    return false;
}
jhoogenboom's avatar
jhoogenboom committed
551

552 553 554 555 556 557 558 559 560 561
function setRenderer(value){
    if(graph){
        graph.renderer(value).update();
        if(value == "svg")
            updateViewBox(graph._el.childNodes[0]);
    }
}

function setFileName(value){
    if(!value)
562
        value = "bgprofiles-raw";
563
    fileName = value;
564
    if(value == "bgprofiles-raw")
565 566 567 568 569 570 571 572 573 574 575 576 577 578
        document.title = "Background Noise Visualisation - FDSTools";
    else
        document.title = value + " - Background Noise Visualisation - FDSTools";
}

function makeMarkerSelectionOptions(data){
    var sel = document.getElementById("markerSelect");
    var val = sel.value;
    removeChildren(sel);
    var opt = document.createElement("option");
    opt.setAttribute("value", "");
    opt.setAttribute("class", "special-option");
    opt.innerText = "Show all";
    sel.appendChild(opt);
jhoogenboom's avatar
jhoogenboom committed
579

580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
    var markerNames = {}
    var validValue = (val == "CUSTOM");
    data.forEach(function(datum){
        markerNames[datum.marker] = true;
    });
    Object.keys(markerNames).sort().forEach(function(marker){
        opt = document.createElement("option");
        opt.setAttribute("value", "=" + marker);
        opt.innerText = marker;
        sel.appendChild(opt);
        if(val == "=" + marker)
            validValue = true;
    });
    opt = document.createElement("option");
    opt.setAttribute("value", "CUSTOM");
    opt.setAttribute("class", "special-option");
    opt.innerText = "Custom filter";
    sel.appendChild(opt);
    sel.value = validValue? val : "";
    if(!validValue){
        document.getElementById("markerFilter").value = "";
        if(graph)  // Don't overwrite the filter_marker on initial data load.
            setSignalValue("filter_marker", "");
    }
}
605

606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
//Load the data (input is a fileList object; only the first file is loaded).
var currentlyLoadedFile = "no/file/loaded";
function loadProfiles(filename, data){
    if(filename == currentlyLoadedFile)
        return false;
    currentlyLoadedFile = filename;
    if(filename)
        setFileName(filename.substr(0, filename.lastIndexOf(".")));
    else
        setFileName(false);
    data_values = vg.util.read(data, data_format);
    graph_spec.data[0].values = data_values;
    makeMarkerSelectionOptions(data_values);
    return true;
}
function loadDataset(fileList){
    if(!graph_spec || !fileList || !fileList.length)
        return;
    var reader = new FileReader();
    reader.onload = function(e){
        if(loadProfiles(fileList[0].name, reader.result))
            parse();
    };
    reader.readAsText(fileList[0]);
}
631

632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
//Save image function.
function saveImage(){
    var link = document.getElementById("saveImageLink");
    if(link.getAttribute("class") == "disabled")
        return false;
    var imageType = document.getElementById("renderSVG").checked? "svg": "png";
    if(window.navigator.msSaveOrOpenBlob){
        //Internet Explorer has its own ways of doing things.
        var b;
        if(imageType == "svg")
            b = new Blob([graph._el.innerHTML], {type: "image/svg+xml;charset=utf-8"});
        else
            b = graph._el.firstChild.msToBlob();
        window.navigator.msSaveOrOpenBlob(b, fileName + "." + imageType);
        if(b.msClose)
            b.msClose();
    }
    else{
        link.setAttribute("href", graph.toImageURL(imageType));
        link.setAttribute("download", fileName + "." + imageType);
        link.click();
        link.setAttribute("href", "javascript:void(saveImage())");
        link.removeAttribute("download");
    }
    return false;
}
jhoogenboom's avatar
jhoogenboom committed
658

659
function onLoadSpec(has_data){
660 661 662
    data_format = graph_spec.data[0].format;
    graph_spec.data[0].format = null;

663 664 665 666 667 668 669 670
    if(!has_data){
        //Handle files from the file input.
        document.getElementById("fileselect").addEventListener('change', function(){
            loadDataset(document.getElementById("fileselect").files);
        }, false);
        var rows = document.querySelectorAll(".fileselectrow");
        for (var i = 0; i < rows.length; i++)
            rows[i].style.display = "table-row";
jhoogenboom's avatar
jhoogenboom committed
671

672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
        //Allow files to be dragged onto the page.
        document.addEventListener('dragover', function(evt){
            evt.stopPropagation();
            evt.preventDefault();
        }, false);
        document.addEventListener('drop', function(evt){
            evt.stopPropagation();
            evt.preventDefault();

            //Try to clear the currently displayed file, then try to set
            //the drag-'n-dropped file as the selected one on the file input.
            //Both actions are not supported in all major browsers.
            document.getElementById("fileselect").value = "";
            document.getElementById("fileselect").files = evt.dataTransfer.files;
            loadDataset(evt.dataTransfer.files);
        }, false);
    }
689
    else{
690
        loadProfiles(fileName, graph_spec.data[0].values);
691 692 693 694 695 696 697 698 699 700
        if(graph_spec.data[0].fdstools_filename){
            var rows = document.querySelectorAll(".filenamedisplayrow");
            for (var i = 0; i < rows.length; i++)
                rows[i].style.display = "table-row";
            var cell = document.getElementById("filenamedisplay");
            removeChildren(cell);
            cell.appendChild(document.createTextNode(graph_spec.data[0].fdstools_filename));
            setFileName(graph_spec.data[0].fdstools_filename);
        }
    }
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763

    //Update graph when rendering mode or axis scale is changed.
    document.getElementById("renderCanvas").addEventListener('change', function(){
        setRenderer(this.value);
    }, false);
    document.getElementById("renderSVG").addEventListener('change', function(){
        setRenderer(this.value);
    }, false);
    document.getElementById("scaleLinear").addEventListener('change', function(){
        setScale(this.value);
    }, false);
    document.getElementById("scaleLog").addEventListener('change', function(){
        setScale(this.value);
    }, false);
    document.getElementById("graphwidth").addEventListener('change', function(){
        var value = parseFloat(this.value);
        if(isNaN(value))
            return;
        setSignalValue("width", value);
    }, false);
    document.getElementById("barwidth").addEventListener('change', function(){
        var value = parseFloat(this.value);
        if(isNaN(value))
            return;
        setSignalValue("barwidth", value);
    }, false);
    document.getElementById("subgraphoffset").addEventListener('change', function(){
        var value = parseFloat(this.value);
        if(isNaN(value))
            return;
        setSignalValue("subgraphoffset", value);
    }, false);
    document.getElementById("minN").addEventListener('change', function(){
        var value = parseFloat(this.value);
        if(isNaN(value))
            return;
        setSignalValue("amplitude_threshold", value);
    }, false);
    document.getElementById("minP").addEventListener('change', function(){
        var value = parseFloat(this.value);
        if(isNaN(value))
            return;
        setSignalValue("amplitude_pct_threshold", value);
    }, false);
    document.getElementById("markerSelect").addEventListener('change', function(){
        if(this.value == "CUSTOM")
            document.getElementById("markerFilterRow").setAttribute("class", "");
        else{
            document.getElementById("markerFilterRow").setAttribute("class", "hidden");
            document.getElementById("markerFilter").value = this.value;
            setSignalValue("filter_marker", this.value);
        }
    }, false);
    document.getElementById("markerFilter").addEventListener('change', function(){
        var value = this.value;
        try{
            compileFilter(value.trim());
        }
        catch(e){
            value = "=";
        }
        setSignalValue("filter_marker", value);
    }, false);
jhoogenboom's avatar
jhoogenboom committed
764

765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799
    //Sync graph_spec and display.
    if(getScale() == "linear"){
        document.getElementById("scaleLinear").checked = true;
        document.getElementById("scaleLog").checked = false;
    }
    else{
        document.getElementById("scaleLinear").checked = false;
        document.getElementById("scaleLog").checked = true;
    }
    var mf = getSignalValue("filter_marker");
    document.getElementById("markerFilter").value = mf;
    var ms = document.getElementById("markerSelect");
    ms.value = "CUSTOM";
    for(i = 0; i < ms.options.length; i++)
        if(mf == ms.options.item(i).value)
            ms.value = mf;
    document.getElementById("markerFilterRow").setAttribute("class", ms.value == "CUSTOM"? "" : "hidden");
    document.getElementById("graphwidth").value = getSignalValue("width");
    document.getElementById("barwidth").value = getSignalValue("barwidth");
    document.getElementById("subgraphoffset").value = getSignalValue("subgraphoffset");
    document.getElementById("minN").value = getSignalValue("amplitude_threshold");
    document.getElementById("minP").value = getSignalValue("amplitude_pct_threshold");
    if(has_data)
        parse();
}
</script>
<!-- BEGIN_LOAD_SCRIPT -->
<script type="text/javascript">
var graph_spec = false;
vg.util.load({url: "bgrawvis.json"}, function(err, result){
    graph_spec = JSON.parse(result);
    onLoadSpec(false);
});
</script>
<!-- END_LOAD_SCRIPT -->
jhoogenboom's avatar
jhoogenboom committed
800 801
</body>
</html>