英文:
Converting between pixels and graphviz sizes/coordinates
问题
我如何将PNG渲染的图形的坐标转换为从-Tjson或-Tjson0获得的坐标?例如,我有一个大小为167 x 251的PNG,但.json文件中的边界框(bb)为117 x 180。我需要能够显示一个图形,在图形上的某处单击,然后让Python响应所单击的节点,但我无法弄清楚这个转换。
英文:
How can I translate the coordinates of a PNG render of a graph, to the coordinates I get from -Tjson or -Tjson0? For example, I have a PNG that's 167 x 251, but the .json file says the bounding box (bb) is 117 x 180. I need to be able to display a graph, click somewhere on the graph, and have Python respond with the node clicked, but I can't figure out this conversion.
答案1
得分: 1
Graphviz使用“points”(pts)作为位置和bb值的单位(在此页面的某个地方 - https://graphviz.org/doc/info/attrs.html - 您会找到此信息:目前,大多数设备无关的单位要么是英寸,要么是点,我们将其视为每英寸72点。
)
此外,默认的输出设置为96 dpi(https://graphviz.org/docs/attrs/dpi/)
因此,bb尺寸/72应该等于png尺寸/96。
几乎,但不完全相等!
猜测最后需要匹配这两组尺寸的部分是考虑pad(https://graphviz.org/docs/attrs/pad/)。将4点(4/72英寸)添加到每个Graphviz pos值中,将8点(8/72)添加到bb总宽度和高度中。
英文:
Graphviz uses "points" (pts) - 72/inch as the unit for pos and bb values (somewhere on this page -https://graphviz.org/doc/info/attrs.html- you will find this:
At present, most device-independent units are either inches or points, which we take as 72 points per inch.
)
Furthermore the default for output is set to 96 dpi (https://graphviz.org/docs/attrs/dpi/)
So bb dimensions /72 should equal png dimensions /96.
Almost, but not quite!
As a guess, the last bit needed to match the two sets of dimensions, is to factor in pad (https://graphviz.org/docs/attrs/pad/). Add 4 points (4/72 inches) to every Graphviz pos value and 8 points (8/72 to the bb total width & height)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论