Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
Cómo ajustar el texto con una longitud específica proporcionada por getComputedTextLength a la longitud especificada en SVG

Soy nuevo en mecanografiado y svg y d3, así que tengo este código

 this.main .selectAll(this.appCssConstants.sliceLabel.selectorName) .data(root) .enter() .append("text") .style("fill", "blue") .classed(this.appCssConstants.sliceLabel.className, true) // font size + slice padding .attr("dy", (d, i) => { return labelshift - d.depth * labelshiftmulti; }) .append("textPath") .attr("startOffset", "50%") .attr("xlink:href", (d, i) => "#sliceLabel_" + i) .text(dataPoint => dataPoint.data.name) .attr("textLength") .each(this.wrapPathText(labelPadding));

...

 private wrapPathText(padding?: number): (slice: HierarchyRectangularNode<SunburstDataPoint>, index: number) => void { const self = this; return function () { const selection: Selection<BaseType, any, BaseType, any> = d3Select(this); const width = (<SVGPathElement>d3Select(selection.attr("xlink:href")).node()).getTotalLength(); self.wrapText(selection, padding, width); }; } private wrapText(selection: Selection<BaseType, any, BaseType, any>, padding?: number, width?: number): void { let node: SVGTextElement = <SVGTextElement>selection.node(), textLength: number = node.getComputedTextLength(), text: string = selection.text(); width = width || 0; padding = padding || 0; while (textLength > (width - 2 * padding) && text.length > 0) { text = text.slice(0, -1); selection.text(text + "\u2026"); textLength = node.getComputedTextLength(); } if (textLength > (width - 2 * padding)) { selection.text(""); } }

Tengo un bucle ".each" en la primera parte del código que llama al método wrapPathText y wrapPathText tiene un bucle for que lleva mucho tiempo en el bucle para cortar texto

Mi pregunta es: ¿hay alguna forma de optimizar este bucle? Por ejemplo, ¿quitar más de una letra en cada bucle para que quepa en la cadena? Otra pregunta: ¿hay alguna manera de ajustar una cadena con una longitud específica (en mi caso, 'ancho - 2 * relleno'), por ejemplo, con la ayuda de un atributo específico sin usar el bucle for no optimizado?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda