svg.js icon indicating copy to clipboard operation
svg.js copied to clipboard

2.7 update to 3.0, Why I use new SVG.List([rect]) in the project will prompt me not to find the current List

Open mengbo-ji opened this issue 4 years ago • 11 comments

image

mengbo-ji avatar Dec 04 '20 06:12 mengbo-ji

This seems to be a typescript issue. Maybe it's fixed it master. You can give it a try by replacing the d.ts file with the current one

Fuzzyma avatar Dec 05 '20 13:12 Fuzzyma

image

With respect to my stupidity, how can I use list instead of set? Is there something wrong with my writing

mengbo-ji avatar Dec 06 '20 14:12 mengbo-ji

I write according to the document on the official website. Did I make a mistake? My code prompts me to report an error. import SVG, { SVG as A } from '@svgdotjs/svg.js'; const list = new A.List(); // It's not right const list = new SVG.List(); // It's not right

// 2.7 create a set and add the elements var set = draw.set() set.add(rect).add(circle)

// change the fill of all elements in the set at once set.fill('#ff0')

// 3.0c reate a set and add the elements var list = new SVG.List([rect]) list.push(circle)

// list[0] == rect // list[1] == circle

// change the fill of all elements in the set at once list.fill('#ff0')

mengbo-ji avatar Dec 06 '20 14:12 mengbo-ji

import {List} from '@svgdotjs/svg.js';

Fuzzyma avatar Dec 06 '20 17:12 Fuzzyma

image

  • I did not see the List method in your source code, I only saw an interface!
  • Did I make a mistake? I read the documentation and it says to use list instead of set, but now I don't know how to create a list. image

mengbo-ji avatar Dec 07 '20 02:12 mengbo-ji

3.0: image 2.7: image

  • After I added additional text, my node position was automatically moved downward, which is not possible in 2.7. The used dy How can I use it now so that it will not push my node down?

mengbo-ji avatar Dec 07 '20 08:12 mengbo-ji

Use stackoverflow to get these questions answered or try around a little bit. version 3 has breaking changes which are documented in the changelog. So not everything works as before

Fuzzyma avatar Dec 07 '20 08:12 Fuzzyma

Anyway, thank you for your reply, I will take a closer look at the changes in 3.0 and 2.7

mengbo-ji avatar Dec 07 '20 08:12 mengbo-ji

Use stackoverflow to get these questions answered or try around a little bit. version 3 has breaking changes which are documented in the changelog. So not everything works as before

I have a lot of nodes. There are 4000 when there are more than 500+. At this time, the page will be very lagging. I want to ask whether svg.js can be rendered into canvas or any good suggestions? Can improve performance. Our project is considering replacing svg.js with g6, but this is a huge project!

mengbo-ji avatar Dec 08 '20 12:12 mengbo-ji

The dom is not particularly fast. If you overload it with nodes it becomes slower and slower. It doesn't matter how this nodes are created or which library does that. You can get around that by minimizing the changes you do in the dom and by avoiding repaints as much as possible. In one of my applications, I e.g. used css zoom instead of viewbox zoom because css is way faster. You can render any svg into a canvas by using a data string and setting it as source for the canvas. However, that doesn't necessarily make it any faster. The advantages of svg is that it handles all mouse interaction for you. Rendering on a canvas can be faster (especially if you don't have to rerender) but you have to implement all mouse interactions on your own.

Fuzzyma avatar Dec 08 '20 13:12 Fuzzyma

The dom is not particularly fast. If you overload it with nodes it becomes slower and slower. It doesn't matter how this nodes are created or which library does that. You can get around that by minimizing the changes you do in the dom and by avoiding repaints as much as possible. In one of my applications, I e.g. used css zoom instead of viewbox zoom because css is way faster. You can render any svg into a canvas by using a data string and setting it as source for the canvas. However, that doesn't necessarily make it any faster. The advantages of svg is that it handles all mouse interaction for you. Rendering on a canvas can be faster (especially if you don't have to rerender) but you have to implement all mouse interactions on your own.

This problem has troubled me for a long time. When there are many nodes, the interaction performance is very bad. I saw an issue two days ago(https://github.com/antvis/G6/issues/1643), the plan inside, I don't know if it is. If the technology stack is changed to g6, it will be very time-consuming.

mengbo-ji avatar Dec 09 '20 08:12 mengbo-ji