D3 Graphviz Theme Component

The D3 Graphviz Theme Component allows you to add animated Graphviz graphs to your post using the DOT language. Based on d3-graphviz.

Repository: GitHub - magjac/discourse-d3-graphviz: Discourse theme component for rendering animated Graphviz graphs using DOT source code

Installation

See How do I install a Theme or Theme Component?

Usage

Static graphs

This is just a brief introduction. You may want to read the detailed Render Graphviz graphs directly in your posts - Announcements - Graphviz which shows the theme component in action or join the Graphviz fourm where you can use it yourself.

To render a graph inline in your post, wrap the graph definition in dot tags like this:

[dot] digraph {a -> b} [/dot]

The block form is also supported:

[dot]
digraph {
  a -> b
}
[/dot]

Animated transitions between graphs

An animated transition between multiple graphs is shown when more than one graph is added to the same paragraph of a post and there is only whitespace between them:

[dot] digraph {bgcolor=lightblue a -> b} [/dot]
[dot] digraph {bgcolor=lightblue a -> b; a -> c} [/dot]
[dot] digraph {bgcolor=lightblue a -> b; a -> c; b -> c} [/dot]

or

[dot]
digraph {
  a -> b
}
[/dot]
[dot]
digraph {
  a -> b
  a -> c
}
[/dot]
[dot]
digraph {
  a -> b
  a -> c
  b -> c
}
[/dot]

Paragraphs are separated by blank lines, so this will generate three separate graphs:

[dot] digraph {bgcolor=lightblue a -> b} [/dot]

[dot] digraph {bgcolor=lightblue a -> b; a -> c} [/dot]

[dot] digraph {bgcolor=lightblue a -> b; a -> c; b -> c} [/dot]

Options

The graphs and the animated transitions are highly customizable by options that you can add to the dot tag. See Render Graphviz graphs directly in your posts - Announcements - Graphviz.

8 个赞

A client yesterday reported that all of the content of their posts was missing. I disabled this theme to resolve the problem.

I think this should be moved to #theme:broken-theme , but wondered if anyone else has had trouble.

3 个赞

Yes there are a bunch of edge cases with this approach, recommend anyone wanting graphviz use:

3 个赞

@pfaffman 抱歉这么晚才看到这篇帖子并采取行动。我一定是误关闭了通知。我以前自己也注意到了这个问题,但当时没有时间处理,也不记得我发过这个帖子,也不知道还有其他人在使用它。

我很高兴地宣布 d3-graphviz 主题组件现在又能正常工作了。您可以在 Render Graphviz graphs directly in your posts - Announcements - Graphviz 看到它的实际效果。

@sam 您现在可以移除 broken 标签了吗?

4 个赞

我已经安装了这个组件(Discourse 3.2.1)
将上面的示例复制到一个新帖子中,它没有渲染成图表
能否有人确认一下,这个现在是否可以工作了,谢谢……

这是由“内容安全策略”引起的……
不确定要在“内容安全策略脚本源”设置中添加什么才能使其工作……能否有人帮忙,谢谢……

您试过插件了吗?它似乎更稳定。

您可能需要允许这些链接:

2 个赞

谢谢 @Arkshine
我们托管的实例不包含该计划的 graphviz 插件 :frowning:
尝试将这 3 个文件添加到“内容安全策略脚本 src”设置中,但无效……

2 个赞

您能试试这个组件吗?

这是集成第三方库以避免 CSP 问题的更好方法。

注意:包装器不同;它不是 bbcode。

2 个赞

谢谢,@Arkshine
它奏效了!

2 个赞

如果您对单个静态图满意,那么 discourse-graphviz-theme-component 可能就足够了,但如果您想在图之间使用动画过渡并能够控制图渲染的各个方面,您可能想尝试 D3 Graphviz 主题组件。您可以在以下位置看到它的实际效果:

不需要白名单。这是我们的设置:

1 个赞

嘿,@magjac
我想试试 D3 动画,但我遇到了上面提到的内容安全策略问题,有什么设置可以更改以使其正常工作吗?
我们的实例现在是 3.2.1。谢谢…

不幸的是,他正在使用使用严格动态 CSP 的新设置,而您的 3.2.1 版本中没有该设置。

1 个赞