Bokeh Collapsing

Adapting 'SlickGrid example 5: Collapsing' to Bokeh

by Jan Burgy

HTML

<!DOCTYPE html>
<!--suppress HtmlUnknownTarget, SpellCheckingInspection, JSUnresolvedLibraryURL, CssUnusedSymbol -->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Collapsing DataTable</title>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bokeh/0.12.16/bokeh.min.css" />
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bokeh/0.12.16/bokeh-tables.min.css" />

    <style>
        .toggle {
            height: 9px;
            width: 9px;
            display: inline-block;
        }
        .toggle.expand:before {
            content: "⊞";
        }
        .toggle.collapse:before {
            content: "⊟";
        }
    </style>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/bokeh/0.12.16/bokeh.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bokeh/0.12.16/bokeh-api.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bokeh/0.12.16/bokeh-tables.min.js"></script>
</head>
<body>

<div class="bk-root" id="bokeh-root"></div>

<script>
    const
        {span} = Bokeh.require('core/dom'),
        DataTable = Bokeh.require('models/widgets/tables/data_table');

    function rollup(objects, dimensions, measures) {
        const
            path = [],
            parents = [],
            result = {indent: [], parent: [], dimension: []};

        for (const measure of Object.keys(measures)) {
            result[measure] = []
        }

        for (const object of objects) {
            // Determine parent by comparing my dimensions
            const
                overlap = dimensions.findIndex((dimension, j) => object[dimension] !== path[j]);

            parents.splice(overlap);

            // Update sub-totals
            for (const parent of parents) {
                if (parent !== null) {
                    for (const [measure, aggregate] of Object.entries(measures)) {
                       ...