简体   繁体   English

KonvaJS 中的线、路径和形状类有什么区别?

[英]What's the differences with the line, path, and shape classes in KonvaJS?

I'm a big fan of PaperJS, however, the library doesn't see much activity so we're looking at other tools, like KonvaJS, Fabric, and Pixi.我是 PaperJS 的忠实粉丝,但是,该库没有看到太多活动,因此我们正在寻找其他工具,如 KonvaJS、Fabric 和 Pixi。 We'd like to replicate the example here:我们想在这里复制这个例子:

http://paperjs.org/examples/path-simplification/ http://paperjs.org/examples/path-simplification/

in KonvaJS but we're not sure which class is the most appropriate?在 KonvaJS 中,但我们不确定哪个 class 最合适? Should we use the line, which is described as a collection of points with tension, the path tool which is what we use in Paper, or the shape class?我们应该使用被描述为具有张力的点的集合的线,我们在 Paper 中使用的路径工具,还是形状 class? Does KonvaJS offer the same type of access to the bezier curve tools and shape border, blue line, found in the above-mentioned paper example? KonvaJS 是否提供与上述论文示例中相同类型的贝塞尔曲线工具和形状边框、蓝线的访问权限?

Konva.Line requires a list of x & y passed into its points property as a simple array, then draws straight lines connecting those points. Konva.Line 需要将 x 和 y 列表作为简单数组传递到其点属性中,然后绘制连接这些点的直线。 The tension property can be used to make the straight line joins more curvy.张力属性可用于使直线连接更弯曲。

Konva.Path expects you to provide a data property that is more like a list of SVG drawing instructions, so move, l.neto, arc, etc. (See supported instructions list in Konva docs for Konva.Path.data here ) Konva.Path 希望您提供一个更像是 SVG 绘图指令列表的数据属性,例如 move、l.neto、arc 等。(请参阅 Konva 文档中支持的指令列表以获取 Konva.Path.data here

There is no built-in equivalent path-editing features to those in the demo you linked to - so no automatic anchors on the path control points and no Bezier handles.没有与您链接到的演示中的功能等效的内置路径编辑功能 - 因此路径控制点上没有自动锚点,也没有贝塞尔曲线图柄。 You would have to DIY those.你将不得不自己动手做那些。 Having said that, it would all be achievable - what I mean is the drawing of the control anchors and lines, the listening for mouse and drag events, and the final passing back of the SVG drawing data to the Konva.Path shape when the path's edit mode ends are all well supported in Konva.话虽如此,这一切都是可以实现的——我的意思是绘制控件锚点和线条,监听鼠标和拖动事件,最后将 SVG 绘图数据传回 Konva.Path 形状,当路径是Konva 很好地支持编辑模式结束。

As at May 2022, the Konva lib is well supported, with appropriately frequent (as Goldilocks would want - not too many and not too few), no ill-thought-out breaking changes, issues are responded to, SO posts replied to, and there is a busy Discord channel.截至 2022 年 5 月,Konva 库得到了很好的支持,频率适当(正如 Goldilocks 所希望的那样——不要太多也不要太少),没有经过深思熟虑的重大更改,问题得到了回应,SO 帖子得到了回复,并且Discord 频道忙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM