agentscape
Version:
Agentscape is a library for creating agent-based simulations. It provides a simple API for defining agents and their behavior, and for defining the environment in which the agents interact. Agentscape is designed to be flexible and extensible, allowing
40 lines • 1.8 kB
JavaScript
export default class Inspector {
constructor(opts) {
const { title = 'Inspector', id = 'inspector_0', height = 600 } = opts;
this.title = title;
this.id = id;
const inspectorPane = document.createElement('drag-pane');
inspectorPane.setAttribute('heading', title);
inspectorPane.setAttribute('key', id);
inspectorPane.style.display = 'none';
const inspectorContainer = document.createElement('div');
inspectorContainer.style.overflow = 'scroll';
inspectorContainer.style.height = (height - 40) + 'px';
const inspectorContent = document.createElement('pre');
inspectorContent.style.width = '300px';
inspectorContent.style.height = (height - 40) + 'px';
inspectorContent.style.padding = '10px';
inspectorContent.style.whiteSpace = 'pre-wrap';
inspectorContent.style.textAlign = 'justify';
this.contentRef = inspectorContent;
window.addEventListener('inspectClick', (event) => {
const customEvent = event;
const clickedCellPosition = customEvent.detail;
const clickedCell = opts.fetchCell(clickedCellPosition);
this.contentRef.innerHTML = JSON.stringify(clickedCell, null, 2);
});
window.addEventListener('toggleInspectorPane', (event) => {
const customEvent = event;
if (customEvent.detail) {
inspectorPane.style.display = 'block';
}
else {
inspectorPane.style.display = 'none';
}
});
inspectorContainer.appendChild(inspectorContent);
inspectorPane.appendChild(inspectorContainer);
opts.root.appendChild(inspectorPane);
}
}
//# sourceMappingURL=Inspector.js.map