DWV display example #1.1

Simplest DWV DICOM image display example with 2 views.

by Fahd Murtaza

HTML

<script src="https://github.com/ivmartel/dwv/releases/download/v0.30.4/dwv-0.30.4.min.js"></script>
<div class="tab">
    <button class="tablinks" onclick="openTab(event, 'DWV1')">DWV App 1</button>
    <button class="tablinks" onclick="openTab(event, 'DWV2')">DWV App 2</button>
</div>

<!-- Tab content -->
<div id="DWV1" class="tabcontent">
    <div id="dwv">
        <div id="layerGroup0"></div>
    </div>
</div>

<div id="DWV2" class="tabcontent">
    <div id="dwv2">
        <div id="layerGroup1"></div>
    </div>
</div>

CSS

.tab {
            overflow: hidden;
            border: 1px solid #ccc;
            background-color: #f1f1f1;
        }

        /* Style the buttons inside the tab */
        .tab button {
            background-color: inherit;
            float: left;
            border: none;
            outline: none;
            cursor: pointer;
            padding: 14px 16px;
            transition: 0.3s;
        }

        /* Change background color of buttons on hover */
        .tab button:hover {
            background-color: #ddd;
        }

        /* Create an active/current tablink class */
        .tab button.active {
            background-color: #ccc;
        }

        /* Style the tab content */
        .tabcontent {
            display: none;
            padding: 6px 12px;
            border: 1px solid #ccc;
            border-top: none;
        }

JavaScript

// Initialize DWV apps outside of any function to have them in the global scope
var app, app2;

function initDwv() {
    // create the first dwv app
    app = new dwv.App();
    app.init({
      containerDivId: "dwv",
      tools: ["Scroll", "ZoomAndPan", "WindowLevel"],
      dataViewConfigs: {
        '*': [{
          divId: 'layerGroup0'
        }]
      }
    });
    app.loadURLs(['https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm']);

    // create the second dwv app
    app2 = new dwv.App();
    app2.init({
      containerDivId: "dwv2",
      tools: ["Scroll", "ZoomAndPan", "WindowLevel"],
      dataViewConfigs: {
        '*': [{
          divId: 'layerGroup1'
        }]
      }
    });
    app2.loadURLs(['https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323707.dcm']);
}

function openTab(evt, tabName) {
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById(tabName).style.display = "block";
    evt.currentTarget.className += " active";

    // Reinitialize or refresh the DWV app depending on the selected tab
    if (tabName === 'DWV1') {
        if (app) app.reset();
        else initDwv();
    } else if (tabName === 'DWV2') {
        if (app2) app2.reset();
        else initDwv();
    }
}

// Initialize the DWV apps once the page content is fully loaded
document.addEventListener("DOMContentLoaded", function() {
    initDwv();
    // Default open tab
    document.getElementsByClassName("tablinks")[0].click();
});