@devexperts/dxcharts-lite
Version:
40 lines (39 loc) • 1.6 kB
JavaScript
/*
* Copyright (C) 2019 - 2025 Devexperts Solutions IE Limited
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { validateChartElements } from './chart-elements';
import generateNewCanvasChartHTML from './canvas-chart-html';
/**
* Creates a default layout template for a canvas chart.
* @function
* @returns {HTMLTemplateElement} - The default layout template for a canvas chart.
*/
export function createDefaultLayoutTemplate(config) {
const template = document.createElement('template');
template.innerHTML = generateNewCanvasChartHTML(config.devexpertsPromoLink);
return template;
}
/**
* Extracts chart elements from a given container and returns them as a validated object.
* @param {Element} container - The container element to search for chart elements.
* @returns {ValidatedChartElements} - An object containing the chart elements as properties.
* @throws {Error} - If some chart elements are missing.
*/
export function extractElements(container) {
const result = {};
const elements = Array.from(container.querySelectorAll('[data-element]'));
if (elements.length !== 0) {
elements.forEach(el => {
var _a;
result[(_a = el.getAttribute('data-element')) !== null && _a !== void 0 ? _a : ''] = el;
});
}
if (validateChartElements(result)) {
return result;
}
else {
throw new Error('Some chart elements are missing');
}
}