Team Ai
Apppublic

exbert-project/exbert

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
185likes
SVGplus.ts45 linesDownload Raw Back to etc
1import * as d3 from "d3"2import 'd3-selection-multi'3import { D3Sel } from '../etc/Util'4 5/**6 * Created by hen on 5/15/17.7 * Modified by hoo on 4/16/19.8 */9export class SVG {10    static translate({x, y}):string {11        return "translate(" + x + "," + y + ")"12    }13 14    static rotate(deg):string {15        return `rotate(${deg})`16    }17 18    static group(parent, classes, pos = {x: 0, y: 0}) {19        return parent.append('g').attrs({20            class: classes,21            "transform": SVG.translate(pos)22        })23    }24 25}26 27export class SVGMeasurements {28 29    private measureElement: d3.Selection<any, any, any, any>;30 31    constructor(baseElement, classes = '') {32        this.measureElement = baseElement.append('text')33            .attrs({x: 0, y: -20, class: classes})34 35    }36 37    textLength(text, style = null) {38        this.measureElement.attr('style', style);39        this.measureElement.text(text);40        const tl = (<SVGTextElement> this.measureElement.node()).getComputedTextLength();41        this.measureElement.text('');42 43        return tl;44    }45}