将SVG文本剪切到D3树形图中的矩形的宽度 [英] Clip SVG text to width of rectangle in a D3 treemap

查看:747
本文介绍了将SVG文本剪切到D3树形图中的矩形的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一个更简单的方法来限制文本标签的宽度,而不是使用剪辑路径。



这里是一个例子寻找有关标签:隐藏在内部< svg> 元素。


I'm wondering if there is a simpler way to restrict the width of a text label than using a clip path.

Here's an example of what I'm looking for with regard to labeling: treemap:

Notice that the labels get truncated by the boundaries of the containing tiles.

That particular example is implemented using <div> tags, which have this behaviour by default. But I'm using SVG <rect> and I'm hoping there is a more straight-forward way of doing this than a separate clip path defining another rect shape.

解决方案

You could wrap each <rect> element in an <svg> element of the same width/height. By default overflow is hidden on inner <svg> elements.

这篇关于将SVG文本剪切到D3树形图中的矩形的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆