index.html 29.1 KB
Newer Older
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">
25
    <meta charset="UTF-8">
26
    <title>Background Noise Profile Visualisation - FDSTools</title>
27
    <!-- VERSION 2.0.1 -->
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>
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;
49 50
        }
        body {
51
            margin: 0rem;
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 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
        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;
        }
        #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;
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
        .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.fileselect3row, .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
            border-bottom: 1px dotted hsl(220, 20%, 3%);
        }
        .hidden {
            display: none;
        }
        .special-option {
            font-style: italic;
        }
        #vis {
            direction: rtl;
            display: inline-block;
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 276 277 278
        #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;
        }
        .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;
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;
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;
        }
    }
352 353 354
    </style>
</head>
<body>
355 356 357 358 359 360 361
<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">
jhoogenboom's avatar
jhoogenboom committed
362 363
                    <td>Background noise profiles file:</td>
                </tr>
364
                <tr class="fileselectrow">
jhoogenboom's avatar
jhoogenboom committed
365 366
                    <td><input id="fileselect" type="file"></td>
                </tr>
367 368 369 370 371 372 373 374 375 376
                <tr class="filenamedisplayrow">
                    <td id="filenamedisplay" class="wrap"></td>
                </tr>
                <tr class="fileselect2row">
                    <td>Raw per-sample background noise file:</td>
                </tr>
                <tr class="fileselect2row">
                    <td><input id="fileselect2" type="file"></td>
                </tr>
                <tr class="fileselect3row">
jhoogenboom's avatar
jhoogenboom committed
377 378
                    <td>(or drag a file onto this page)</td>
                </tr>
379 380 381 382 383
                <tr>
                    <td>
                        <a id="saveImageLink" href="javascript:void(saveImage())" class="disabled">Save image</a>
                    </td>
                </tr>
jhoogenboom's avatar
jhoogenboom committed
384
            </table>
385 386 387 388
        </div>
        <div class="optiongroup">
            <div class="optionheader">Filtering options</div>
            <table>
jhoogenboom's avatar
jhoogenboom committed
389
                <tr>
390 391 392 393 394 395 396
                    <td><label for="minN">Require at least</label></td>
                    <td>
                        <label>
                            <input type="text" value="5" id="minN" size="3"> reads
                            <span class="help" title="This option applies only to raw per-sample data points.">?</span>
                        </label>
                    </td>
jhoogenboom's avatar
jhoogenboom committed
397 398
                </tr>
                <tr>
399 400
                    <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
401 402
                </tr>
                <tr>
403
                    <td rowspan="2"><label for="markerSelect">Marker name</label></td>
404
                    <td>
405 406 407 408
                        <select id="markerSelect">
                            <option value="" class="special-option" selected>Show all</option>
                            <option value="CUSTOM" class="special-option">Custom filter</option>
                        </select>
409
                    </td>
jhoogenboom's avatar
jhoogenboom committed
410 411
                </tr>
                <tr>
412 413 414 415 416 417
                    <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
418
                </tr>
419 420 421 422 423
            </table>
        </div>
        <div class="optiongroup noprint">
            <div class="optionheader">Display options</div>
            <table>
jhoogenboom's avatar
jhoogenboom committed
424
                <tr>
425 426
                    <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
427 428
                </tr>
                <tr>
429 430
                    <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
431 432
                </tr>
                <tr>
433 434
                    <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
435 436 437
                </tr>
                <tr>
                    <td>Axis scale</td>
438 439
                    <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
440 441
                </tr>
                <tr>
jhoogenboom's avatar
jhoogenboom committed
442
                    <td>Renderer</td>
443 444
                    <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
445 446
                </tr>
            </table>
447 448
        </div>
    </div>
449 450 451 452 453 454 455 456 457
    <div id="visscrollbox">
        <div id="vis"></div>
    </div>
</div>
</div>
<script type="text/javascript">
var graph = false;
var data_format = {};
var data_values = [];
458
var fileName = "bgprofiles";
459 460 461 462 463 464 465 466 467 468 469 470
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;
471

472 473 474 475
        //Add new visualisation divs.
        var newvis = document.createElement("div");
        newvis.setAttribute("id", "vis0");
        visdiv.appendChild(newvis);
476

477 478 479 480 481
        graph = chart({el: newvis, renderer: rendererName});
        graph.update();
        if(rendererName == "svg")
            updateViewBox(graph._el.childNodes[0]);
        document.getElementById("saveImageLink").setAttribute("class", "");
482

483 484 485 486
        //Scroll to the right; the graph is more interesting than the long labels.
        scrolldiv.scrollLeft = scrolldiv.scrollWidth;
    });
}
487

488 489 490
function compileFilter(filter){
    return new RegExp('(?:' + filter.replace(/(^| )=(.*?)(?= |$)/g, '$1^$2$$').replace(/ +/g, ')|(?:') + ')')
}
491

492 493 494 495 496
function updateViewBox(svg){
    //Setting the viewBox enables shrink-to-fit behaviour when printing.
    svg.setAttribute("viewBox",
        "0 0 " + svg.getAttribute("width") + " " + svg.getAttribute("height"));
}
497

498 499 500 501 502
function removeChildren(el){
    while(el.lastChild){
      el.removeChild(el.lastChild);
    }
}
jhoogenboom's avatar
jhoogenboom committed
503

504 505 506 507 508 509 510 511 512
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.
513

514 515 516
    if(graph)
        parse();
}
517

518 519 520 521 522 523 524 525 526 527
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";
}
528

529 530 531 532 533 534 535 536 537 538 539
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;
540
        }
541 542 543 544 545 546 547 548 549 550
    }
    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;
}
551

552 553 554 555 556 557 558 559 560 561
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;
}
562

563 564 565 566 567 568 569
function setRenderer(value){
    if(graph){
        graph.renderer(value).update();
        if(value == "svg")
            updateViewBox(graph._el.childNodes[0]);
    }
}
570

571 572
function setFileName(value){
    if(!value)
573
        value = "bgprofiles";
574
    fileName = value;
575
    if(value == "bgprofiles")
576 577 578 579
        document.title = "Background Noise Profile Visualisation - FDSTools";
    else
        document.title = value + " - Background Noise Profile Visualisation - FDSTools";
}
580

581 582 583 584 585 586 587 588 589
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);
590

591 592 593 594 595 596 597 598 599 600 601 602 603 604 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 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 658 659 660 661
    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", "");
    }
}

var currentlyLoadedProfilesFile = "no/file/loaded";
function loadProfiles(filename, data){
    if(filename == currentlyLoadedProfilesFile)
        return false;
    currentlyLoadedProfilesFile = 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;
}
var currentlyLoadedRawDataFile = "no/file/loaded";
function loadRawData(filename, data){
    if(filename == currentlyLoadedRawDataFile)
        return false;
    currentlyLoadedRawDataFile = filename;
    graph_spec.data[1].values = data;
    return !!graph;
}
function setSelectedFiles(input, fileList){
    //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.
    input.value = "";
    input.files = fileList;
}

//Input is a fileList object; only the first file is loaded.
var embeddedFiles = 0;
function loadFile(fileList, setInput){
    if(!graph_spec || !fileList || !fileList.length)
        return;
    var reader = new FileReader();
    reader.onload = function(e){
        var success;
        var cols = reader.result.substr(0, reader.result.indexOf("\n")).split("\t");
        if(Math.min(cols.indexOf("fnoise"), cols.indexOf("rnoise"), cols.indexOf("tnoise")) == -1){
            //This is a file with background noise profiles.
            if((embeddedFiles & 1) == 0){
                success = loadProfiles(fileList[0].name, reader.result);
                if(setInput)
                    setSelectedFiles(document.getElementById("fileselect"), fileList);
662
            }
663 664 665 666 667 668 669 670 671 672 673 674
        }
        else if((embeddedFiles & 2) == 0){
            //This is a file with raw data points.
            success = loadRawData(fileList[0].name, reader.result);
            if(setInput)
                setSelectedFiles(document.getElementById("fileselect2"), fileList);
        }
        if(success)
            parse();
    };
    reader.readAsText(fileList[0]);
}
675

676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
//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;
}
702

703
function onLoadSpec(has_data, has_rawdata){
704 705 706
    data_format = graph_spec.data[0].format;
    graph_spec.data[0].format = null;

707 708 709 710 711 712 713 714 715
    if(!has_data){
        //Handle files from the file input.
        document.getElementById("fileselect").addEventListener('change', function(){
            loadFile(document.getElementById("fileselect").files);
        }, false);
        var rows = document.querySelectorAll(".fileselectrow");
        for (var i = 0; i < rows.length; i++)
            rows[i].style.display = "table-row";
    }
716 717 718 719 720 721 722 723 724 725 726
    else{
        loadProfiles(fileName, graph_spec.data[0].values);
        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);
        }
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
    }
    if(!has_rawdata){
        //Handle files from the file input.
        document.getElementById("fileselect2").addEventListener('change', function(){
            loadFile(document.getElementById("fileselect2").files);
        }, false);
        var rows = document.querySelectorAll(".fileselect2row");
        for (var i = 0; i < rows.length; i++)
            rows[i].style.display = "table-row";
    }
    if(!has_data || !has_rawdata){
        //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();
            loadFile(evt.dataTransfer.files, true);
        }, false);
        var rows = document.querySelectorAll(".fileselect3row");
        for (var i = 0; i < rows.length; i++)
            rows[i].style.display = "table-row";
    }
    embeddedFiles = (has_data? 1:0) + (has_rawdata? 2:0);
753

754 755 756 757 758 759 760 761 762 763 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 800 801 802 803 804 805 806 807 808 809
    //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());
810
        }
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851
        catch(e){
            value = "=";
        }
        setSignalValue("filter_marker", value);
    }, false);

    //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: "profilevis.json"}, function(err, result){
    graph_spec = JSON.parse(result);
    onLoadSpec(false, false);
});
</script>
<!-- END_LOAD_SCRIPT -->
852 853
</body>
</html>