Pushing D3.js output through fabric.js for IE8 support?

血红的双手。 提交于 2019-12-05 05:56:07

Disclaimer: I'm the author of Fabric.js

Very interesting question. To address your points:

Are there any existing projects that allow D3 output to be rendered using fabric.js, similar to D34Raphael?

Not that I know of. But from what I can see, D3.js has SVG output. And Fabric has SVG parser, so it seems pretty straightforward to feed D3's markup to Fabric for rendering.

Is there anything about how D3 works with SVG that simply couldn't be piped through Fabric's SVG to Canvas conversion and object model?

I'm not really familiar with D3, but looking at one of the examples you linked to, I see some compatibility issues indeed. I copied entire SVG markup of "force directed graphs" and loaded it in kitchensink

Circles are rendered properly-ish, but something is off with lines. Curiously, all the lines are parsed and loaded onto canvas correctly. But they're not visible. Why? Because their styles in D3.js are defined via ".line" class and we don't support stylesheet parsing in Fabric.

.link {
  stroke: #999;
  stroke-opacity: .6;
}

If we were to "unroll" those styles unto each line (either via "stroke" and "stroke-opacity" attributes or style="stroke: ...; stroke-opacity: ...;") it would work as expected.

I imagine the problem with white outlines around circles has the same roots.

Is there any simpler way to push D3 output through Fabric than the D34Raphael approach of forking the D3 project and adapting its output?

Can't think of anything really.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!