@antv/t8
Version:
T8 is a text visualization solution for unstructured data within the AntV technology stack, and it is a declarative T8 markdown syntax that can be used to describe the content of data interpretation reports.
69 lines (65 loc) • 2.15 kB
JavaScript
;
var tslib = require('tslib');
/**
* Selection API for DOM manipulation
* Provides D3-like selection interface for SVG elements
*/
var Selection = /** @class */ (function () {
function Selection(elements) {
this.elements = Array.isArray(elements) ? elements : [elements];
}
Selection.select = function (selector) {
var element = document.querySelector(selector);
return new Selection(element || []);
};
Selection.selectAll = function (selector) {
var elements = document.querySelectorAll(selector);
return new Selection(Array.from(elements));
};
Selection.prototype.attr = function (name, value) {
this.elements.forEach(function (el) {
if (el instanceof Element) {
el.setAttribute(name, String(value));
}
});
return this;
};
Selection.prototype.style = function (name, value) {
this.elements.forEach(function (el) {
if (el instanceof Element) {
el.style.setProperty(name, value);
}
});
return this;
};
Selection.prototype.append = function (tagName) {
var newElements = [];
this.elements.forEach(function (el) {
var newEl = document.createElementNS('http://www.w3.org/2000/svg', tagName);
el.appendChild(newEl);
newElements.push(newEl);
});
return new Selection(newElements);
};
Selection.prototype.text = function (content) {
this.elements.forEach(function (el) {
el.textContent = content;
});
return this;
};
Selection.prototype.on = function (event, handler) {
this.elements.forEach(function (el) {
el.addEventListener(event, handler);
});
return this;
};
Selection.prototype.node = function () {
return this.elements[0] || null;
};
Selection.prototype.nodes = function () {
return tslib.__spreadArray([], this.elements, true);
};
return Selection;
}());
exports.Selection = Selection;
//# sourceMappingURL=selection.js.map