客户端要求缩小绘图,所以我将宽度/高度和viewBox添加到SVG元素 . 问题是某些元素的缩放比例不同 . svg的结构是这样的:

<svg width="100%" height="100%" viewBox="0 50 700 200"> <defs>...</defs> <g id="group-ab"> Here are the boxes (drawn with polyline) that are scaled correctly, both in their own group (group-a, group-b) </g> <g id="group-a-id"> <text>A</text> <circle id="group-a-id-bg-circle"></circle> </g> <g id="group-B-id"> <text>B</text> <circle id="group-b-id-bg-circle"></circle> </g> <path id="group-a-pattern" d="..."></path> <path id="group-b-pattern" d="..."></path> </svg>

路径是碎片的图案 . 似乎不在“group-ab”组下的所有内容都没有正确缩放,请参见下图 . 通常(当不使用viewBox时)图案填满方框,A / B以方框为中心(对它们进行相同的翻译) .

enter image description here

为什么会这样?如果svg被缩放,人们会认为元素是否在组内是无关紧要的 .