diff --git a/src/bonsai/bonsai/bim/data/webui/sioserver.py b/src/bonsai/bonsai/bim/data/webui/sioserver.py index 117505d2c0..8d88f05aa5 100644 --- a/src/bonsai/bonsai/bim/data/webui/sioserver.py +++ b/src/bonsai/bonsai/bim/data/webui/sioserver.py @@ -38,9 +38,9 @@ class WebNamespace(socketio.AsyncNamespace): async def on_connect(self, sid, environ): print(f"Web client connected: {sid}") + await sio.emit("theme_data", blender_theme, namespace="/web", room=sid) if blender_messages: await sio.emit("connected_clients", list(blender_messages.keys()), namespace="/web", room=sid) - await sio.emit("theme_data", blender_theme, namespace="/web", room=sid) await self.send_cached_messages(sid) async def on_disconnect(self, sid): @@ -55,7 +55,6 @@ class WebNamespace(socketio.AsyncNamespace): ) async def on_get_svg(self, sid, data): - print("hello world!") file_path = data["path"] with open(file_path, "r") as file: svg_data = file.read() @@ -71,6 +70,7 @@ class WebNamespace(socketio.AsyncNamespace): if "demo_data" in messages: await self.emit("demo_data", {"blenderId": blenderId, "data": messages["demo_data"]}, room=sid) + # Blender namespace class BlenderNamespace(socketio.AsyncNamespace): def __init__(self, namespace): @@ -115,7 +115,7 @@ class BlenderNamespace(socketio.AsyncNamespace): blender_theme = data await sio.emit("theme_data", data, namespace="/web") - # this function will be called when the event demo_data is emitted + # this function will be called when the event demo_data is emitted async def on_demo_data(self, sid, data): print(f"Demo data from Blender client {sid}") blender_messages[sid]["demo_data"] = data diff --git a/src/bonsai/bonsai/bim/data/webui/static/css/demo.css b/src/bonsai/bonsai/bim/data/webui/static/css/demo.css index 9a2460c90f..975bb318d1 100644 --- a/src/bonsai/bonsai/bim/data/webui/static/css/demo.css +++ b/src/bonsai/bonsai/bim/data/webui/static/css/demo.css @@ -54,10 +54,7 @@ body { #container { flex: 1; - margin-top: var(--margin-medium); - margin-left: var(--margin-small); - margin-right: var(--margin-small); - margin-bottom: var(--margin-medium); + padding: var(--margin-small); } h3 { diff --git a/src/bonsai/bonsai/bim/data/webui/static/css/drawings.css b/src/bonsai/bonsai/bim/data/webui/static/css/drawings.css index c2779d7e9e..17485412d3 100644 --- a/src/bonsai/bonsai/bim/data/webui/static/css/drawings.css +++ b/src/bonsai/bonsai/bim/data/webui/static/css/drawings.css @@ -55,10 +55,7 @@ body { } #container { - margin-top: var(--margin-medium); - margin-left: var(--margin-tiny); - margin-right: var(--margin-tiny); - margin-bottom: var(--margin-medium); + padding: var(--margin-small); height: calc(100vh - var(--nav-height)); box-sizing: border-box; display: flex; diff --git a/src/bonsai/bonsai/bim/data/webui/static/css/gantt.css b/src/bonsai/bonsai/bim/data/webui/static/css/gantt.css index cd575af2bb..035fd68f0b 100644 --- a/src/bonsai/bonsai/bim/data/webui/static/css/gantt.css +++ b/src/bonsai/bonsai/bim/data/webui/static/css/gantt.css @@ -74,10 +74,7 @@ body { #container { flex: 1; - margin-top: var(--margin-medium); - margin-left: var(--margin-small); - margin-right: var(--margin-small); - margin-bottom: var(--margin-medium); + padding: var(--margin-small); } h3 { diff --git a/src/bonsai/bonsai/bim/data/webui/static/css/index.css b/src/bonsai/bonsai/bim/data/webui/static/css/index.css index 02cb6cf3e4..510354f2bd 100644 --- a/src/bonsai/bonsai/bim/data/webui/static/css/index.css +++ b/src/bonsai/bonsai/bim/data/webui/static/css/index.css @@ -202,11 +202,10 @@ footer p { } .table-container { - position: absolute; display: block; - height: calc(100% - var(--margin-small) * 2); - width: calc(100% - var(--margin-small) * 2); - overflow-x: scroll; + height: calc(100vh - var(--margin-small)); + width: 100%; + margin-bottom: var(--margin-medium); } .csv-table { @@ -281,22 +280,29 @@ button:hover { -:root.blender .tabulator-selected .tabulator-cell { +:root.blender .tabulator-selected .tabulator-cell, +:root.blender .tabulator-row.tabulator-selected { background-color: var(--blender-active-highlight) !important; color: var(--blender-active-text-highlight) !important; } -:root.blender .tabulator-selected:hover .tabulator-cell { +:root.blender .tabulator-selected:hover .tabulator-cell, +:root.blender .tabulator-row.tabulator-selected:hover { filter: brightness(1.2) } -.tabulator-menu-item { +:root.blender .tabulator-popup-container { + background: var(--blender-panel-background); + border: var(--blender-tab-outline); +} + +:root.blender .tabulator-menu-item { color: var(--blender-text) !important; background-color: var(--blender-panel-background) !important; transition: filter 0.1s ease; } -.tabulator-menu-item:hover { +:root.blender .tabulator-menu-item:hover { filter: brightness(1.4); -} +} \ No newline at end of file diff --git a/src/bonsai/bonsai/bim/data/webui/static/js/index.js b/src/bonsai/bonsai/bim/data/webui/static/js/index.js index 3fac376f28..d4b6d7fb73 100644 --- a/src/bonsai/bonsai/bim/data/webui/static/js/index.js +++ b/src/bonsai/bonsai/bim/data/webui/static/js/index.js @@ -207,8 +207,35 @@ function addTableElement(blenderId, csvData, filename) { return menu; } - var containerHeight=$('.table-container').height(); - var h3Height=$('.table-container>h3').height(); + // create right click context menu for choosing column top calculation + function createColumnContextMenu(column) { + const field = column.field; + const calculations = ["sum", "avg", "max", "min"]; + + // label is the item label in the menu + // update column defination on clicking an item + // specifically the topCalc and pass calc type to the topCalcFormatter function + // uisng the topCalcFormatterParams field + return calculations.map((calc) => ({ + label: `Show ${ + calc.charAt(0).toUpperCase() + calc.slice(1) + } for ${field}`, + action: (e, cell) => + cell + .getColumn() + .updateDefinition({ topCalc: calc, topCalcFormatterParams: calc }), + })); + } + + function calcFormatter(cell, formatterParams, onRendered) { + // formatterParams is anything in the topCalcFormatterParams field in the column definition + // so we pass the calculation type to display what the calculation type is + return `${formatterParams}: ${cell.getValue()}`; + } + + var containerHeight = $(".table-container").height(); + var h3Height = $(".table-container>h3").height(); + var table = new Tabulator("#table-" + blenderId, { placeholder: "No data to display", resizableColumnGuide: true, @@ -222,14 +249,21 @@ function addTableElement(blenderId, csvData, filename) { movableColumns: true, // Our fields are never nested, and we use the "." character in queries nestedFieldSeparator: false, + // defines column defualts that are applied to all columns + columnDefaults: { + visible: true, + headerFilter: true, + topCalc: "sum", + topCalcFormatter: calcFormatter, + topCalcFormatterParams: "sum", + }, + // defines a callback to edit the column definition generated by autoColumns + // that cannot be set as default autoColumnsDefinitions: function (definitions) { - menu = createHeaderMenu(definitions, table); + headerMenu = createHeaderMenu(definitions, table); definitions.forEach((column) => { - column.visible = true; - column.headerFilter = true; - column.headerMenu = menu; - // TODO: more user control to choose function, style at bottomCalc - column.topCalc = 'sum'; + column.headerMenu = headerMenu; + column.contextMenu = createColumnContextMenu(column); }); return definitions; }, @@ -239,7 +273,9 @@ function addTableElement(blenderId, csvData, filename) { .css("margin-left", "10px") .css("cursor", "pointer"); tableTitle.append(downloadCsv); - downloadCsv.on('click', function() { table.download("csv", "data.csv"); }) + downloadCsv.on("click", function () { + table.download("csv", "data.csv"); + }); table.on("rowSelected", function (row) { var index = row.getIndex(); // the guid of the object diff --git a/src/bonsai/bonsai/bim/data/webui/templates/demo.html b/src/bonsai/bonsai/bim/data/webui/templates/demo.html index 151a7948e8..da67d65d5c 100644 --- a/src/bonsai/bonsai/bim/data/webui/templates/demo.html +++ b/src/bonsai/bonsai/bim/data/webui/templates/demo.html @@ -5,6 +5,11 @@