Skip to content

Commit

Permalink
circuit sim: load units from JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
clbarnes committed Aug 18, 2021
1 parent 562cbb2 commit 6685da4
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@
var CS = this;
var tabs = CATMAID.DOM.addTabGroup(controls, CS.widgetID, ['Main', 'Export']);

const fileButton = controls.appendChild(CATMAID.DOM.createFileButton(
'load-json-dialog-' + this.widgetID, false, (event) => CS.loadJson(event.target.files)
));
const openButton = document.createElement('input');
openButton.setAttribute('type', 'button');
openButton.setAttribute('value', 'Load JSON');
openButton.onclick = () => fileButton.click();
CATMAID.DOM.appendToTab(tabs['Main'],
[[document.createTextNode('From')],
[CATMAID.skeletonListSources.createSelect(CS)],
['Append', CS.loadSource.bind(CS)],
['Clear', CS.clear.bind(CS)],
['Show/Hide parameters', CS.toggleParametersUI.bind(CS)],
['Run', CS.run.bind(CS)],
[openButton],
[CATMAID.DOM.createNumericField('cs_time' + CS.widgetID, 'Time:', 'Amount of simulated time, in arbitrary units', '10000', '(a.u.)', CS.run.bind(CS), 6)],
]);

Expand All @@ -66,6 +74,16 @@
};
};

CircuitSimulation.prototype.loadJson = function (files) {
if (!CATMAID.containsSingleValidFile(files, 'json')) {
return;
}

const reader = new FileReader();
reader.onload = (event) => { this.units = JSON.parse(event.target.result); };
reader.readAsText(files[0]);
};

CircuitSimulation.prototype.clear = function() {
this.units = [];
this.redraw();
Expand Down

0 comments on commit 6685da4

Please sign in to comment.