UNPKG

@springernature/nn-charts

Version:
26 lines (24 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createLegends = void 0; var createLegends = exports.createLegends = function createLegends(svgBasePanelClassNames, legend, colours) { // create legend section var baseElement = document.querySelector(".".concat(svgBasePanelClassNames)); var legendContainerEle = document.createElement("ul"); legendContainerEle.classList.add(legend.classNames, legend.legendAlignment ? legend.legendAlignment : "horizontal", legend.placement ? legend.placement : "center"); var shape = legend.swatchSymbol ? legend.swatchSymbol : "square"; legend.position === "bottom" ? baseElement.after(legendContainerEle) : baseElement.before(legendContainerEle); // create legend items legend["categories"].forEach(function (ele, i) { var li = document.createElement("li"); var span = document.createElement("span"); span.classList.add("legend-shape", "legend-shape__".concat(shape)); span.setAttribute("style", "background-color: ".concat(colours[i])); li.appendChild(span); li.appendChild(document.createTextNode(ele)); li.classList.add("legend-item", "legend-item__".concat(i)); legendContainerEle.appendChild(li); }); };