我有一个 GraphML 文件,我必须在网页上显示它并使用 JavaScript 更改显示属性(例如更改节点、边缘等的颜色)。
可能吗?
如果有任何 JavaScript 库可以在网页上加载、解析和绘制 GraphML,请告诉我。
我有一个 GraphML 文件,我必须在网页上显示它并使用 JavaScript 更改显示属性(例如更改节点、边缘等的颜色)。
可能吗?
如果有任何 JavaScript 库可以在网页上加载、解析和绘制 GraphML,请告诉我。
可以使用 JavaScript XSLT API 调用将 GraphML 作为输入并输出 SVG 的 XSLT 样式表。例如:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/2000/svg">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="graph">
<!-- when finding a 'graph' element, create the 'svg' root and its 'defs' section -->
<svg>
<defs>
<marker id="arrow" refX="5" refY="5" markerUnits="userSpaceOnUse" markerWidth="10" markerHeight="10" orient="auto">
<path fill="black" d="M0 0 10 5 0 10z"/>
</marker>
</defs>
<!-- for each 'node' create a 'g' element with its contents -->
<xsl:for-each select="node">
<g>
<rect width="100" height="100" fill="silver"/>
<text style="font-size:24;font-weight:bold">
<xsl:value-of select="@id"/>
</text>
</g>
</xsl:for-each>
<!-- for each 'edge' create a 'line' with the arrow if it is a 'directed' edge -->
<xsl:for-each select="edge">
<line>
<xsl:if test="not(@directed='false')">
<xsl:attribute name="style">marker-end:url(#arrow)</xsl:attribute>
</xsl:if>
</line>
</xsl:for-each>
</svg>
</xsl:template>
</xsl:stylesheet>
参考
这项任务的重要竞争者(至少在商业环境中)将是yFiles for HTML Javascript Graph Drawing Library:
全面披露:我为创建该库的公司工作,但我不代表我的雇主在 SO