Earlier quoted context omitted.
SVG could never be as fast as canvas.
SVG is a series of drawing commands (with transformations, filters, and so on). Which is exactly what canvas is. With appropriate layer caching of course it can be 100% as fast if the rudiments are similar and in the same context[1], and on many platforms it is. Chromium derivatives have a particularly slow implementation of SVG and it has tainted the whole realm. [1] Obviously if you're zooming and transforming and…
Easy SVG sparklines
61–70 of 106 posts
Re: Easy SVG sparklines
#62For context, here's the 22 lines of code it took to create a simple svg graph: https://github.com/jjcm/soci-frontend/blob/master/components...
And here's the final output: https://non.io/Animation-example
Re: Easy SVG sparklines
#63Re: Easy SVG sparklines
#64Earlier quoted context omitted.
This is only an issue on chrome-based browsers; performance in Firefox is much closer to what you would expect. You can/could (late 2022) reliably crash chrome by displaying 1000+ unique SVG files on one page, with each SVG simply displaying a single line of text. My current workaround is rendering the SVGs to png serverside if the client is chrome-based, as canvas feels like the wrong solution.
Since the vast majority of users are a chromium based browser, doesn't this put the burden on your server pretty much all of the time? why even bother with code to do 2 different things when the other thing is such a niche segment of users?
Re: Easy SVG sparklines
#65Maybe it's just because I have so much experience with design and visual art, but I think SVG is one of the most, if not the most underutilized web format. It's great for the self-contained static vector graphics that it's most commonly used for, but it can do so much more. SMIL animations can be a little clunky, but having an alternative to gif and video that doesn't require JS is pretty rad-- especially for throbbe…
Re: Easy SVG sparklines
#66Earlier quoted context omitted.
Of course SVG is slower than Canvas. SVG is fundamentally much more powerful. Canvas is just a pixel buffer. You know what's even faster than Canvas? JPEG. Of course these tools have different use cases. Handling scaling events and interactivity with Canvas is far, far more laborious. The great thing about SVG (and to a lesser extent JPEGs) is that you can produce them anywhere, not just in a browser with a JavaScrip…
> You know what's even faster than Canvas? JPEG Is that true? Isn't canvas a bitmap whereas JPEG requires decoding?
Re: Easy SVG sparklines
#67Earlier quoted context omitted.
It would be nice if you consider to put it in a jsfiddle, or something.
Good point, updated that to a jsfiddle.
Main function: https://www.val.town/v/stevekrouse.sparklineSVG
Rendered example: https://www.val.town/v/stevekrouse.sparklineEx2
Re: Easy SVG sparklines
#68First I did the opposite of this post and used all the libraries (react, htm, and react-sparkline): https://www.val.town/v/stevekrouse.sparklineEx
Then I found a comment below that does it in vanilla js, so I ported that over to Val Town as well: https://www.val.town/v/stevekrouse.sparklineEx2
Re: Easy SVG sparklines
#69this works well when you have a few sparklines with a dozen datapoints each, but less well when you have many sparklines with hundreds of datapoints.
I'd bet an SVG can easily handle hundreds, if not thousands, of datapoints.
a sparkline with 100 datapoints is very realistic. and having a couple columns in a table with 100 rows filled with these svg sparklines will have ui lag that you'll definitely feel.
sadly, svg is not a great performer in these 1k+ datapoints cases and you gotta switch to canvas.
Re: Easy SVG sparklines
#70Earlier quoted context omitted.
SVG is a series of drawing commands (with transformations, filters, and so on). Which is exactly what canvas is. With appropriate layer caching of course it can be 100% as fast if the rudiments are similar and in the same context[1], and on many platforms it is. Chromium derivatives have a particularly slow implementation of SVG and it has tainted the whole realm. [1] Obviously if you're zooming and transforming and…
Canvas is just a pixel buffer. Even with sufficient caching SVG would be slower because there’s more work to do with parsing, etc.
SVG is a pixel buffer and a set of drawing rudiments to imperatively or declaratively actually make that pixel buffer useful.
The distinction you are drawing between these is sophistry.