UNPKG

@future-grid/fgp-graph

Version:

fgp-graph is a chart lib based on Dygraphs

43 lines (30 loc) 1.3 kB
import {GraphCollection, ViewConfig} from "../../../metadata/configurations"; export default class View { constructor(public parentElement: Element, public viewConfigs: Array<ViewConfig>, public viewChangeListener: (view: ViewConfig) => void) { this.initDom(); } private initDom = () => { // dropdown container let dropdownContainer: HTMLDivElement = document.createElement('div'); dropdownContainer.setAttribute("class", "fgp-views-dropdown"); // create select const select = document.createElement("select"); // create options this.viewConfigs.forEach(config => { const option = document.createElement('option'); option.text = config.name; option.value = config.name; option.selected = config.show; select.add(option); }); select.addEventListener("change", (e:Event)=>{ this.viewConfigs.map((_config, _index) => { _config.show = _index === select.selectedIndex; }); // call listener this.viewChangeListener(this.viewConfigs[select.selectedIndex]); }); dropdownContainer.appendChild(select); this.parentElement.appendChild(dropdownContainer); }; }