-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: How can I reduce the "size" of the generated SVG? #26
Comments
At least we know the character encoding isn't the reason, as that function writes to UTF-8 vs. UTF-16. Do you pre-filter the chart's data? In one of my applications, I have a collection of overlapping IFFT's (at different impulse measurement distances from the point source) with up to 30 million overall data points, but the relevant time window for any given measurement is usually only a small portion of that, so I choose some heuristics for a reasonable epsilon and throw out the "noise" so that there are fewer overall line segments in the rendered data. |
No, I don't do any prefiltering. I could try to decimate the data. Let's say take every second data point as first try then tune it to know how many data points are producing an SVG with an acceptable size without losing visual data on the picture. I make some filtering experiment and then I'll comment again. |
Well, best of luck, and I look forward to seeing what you find out. I can see how you wouldn't have the luxury of pre-filtering the data even with a reasonable epsilon for redundancies or noise. In my own context, the measurements are domain-specific and thus have known bounds and dynamic range of possible values. That makes a big difference. |
So, I tried it, a decimation of 27 (resulting in 10k data points) is producing a small-enough image, but now the data shown is different as I'm really decimating and not rescaling/resampling. It would be much much bettern if there would be some setting in the library to "compress" the created image. |
I may have dealt with this issue previously. I'm in the midst of pulling archived code to add to my BasicGraphics2D library that I am preparing as a general purpose utilities library so that it isn't part of my EpsGraphics2D library when it doesn't need to be. I was using UC Berkeley's PtPlot for years before switching to JavaFX, and may have had to do data rescaling there as well -- I definitely have to do it in FX Charts due to the Scene Graph having significant limits on Node count. I may find this older code a bit later tonight; at the very least, I think I already had it in place for the AWT context when exporting to Excel (CSV at the time; I now use Apache POI for XLSX export). There's no guarantee the archive has copies of the older code; we'll see. |
I found the AWT version of my resampling algorithm just now, and am copying it verbatim below, hoping that the code, variable and function and class names, and comments, are clear enough in isolation from the overall library context, to be understandable and potentially usable with JFreeChart or whatever. You may not have enough discardable noise in your data; in my prior case the data domain was fixed, specific, and known in its bounds. Be aware that this particular IFFT is normalized to { -1, +1 } as the actual units aren't terribly useful in the context I was addressing. Finding the Peak Impulse Time was the more critical factor. But even so, one of the techniques in this algorithm may help you, if you're not already doing it, and that is to combine each data set plot into a single Polyline. This especially made a big difference in producing EPS output, so likely would have a similar impact on your SVG size.
Of course I check data vector size first, and do three versions for int, float, and double. AWT doesn't have a Polyline shape, whereas JavaFX does. For purposes of legibility, I am attaching the data reduction code snippet in a separate post. I have now refactored it into a reusable utility function, stripped of specifics to the class I implemented it on (e.g. pass parameters for tolerance and dynamic range vs. built-in assumptions of the data domain). I also eliminated dependencies on EpsGraphics2D and have now tested this code with both OrsonPDF and jFreeSVG, as I abstracted my EPS support to cover all three formats generically. If your context is a scene graph with data points as nodes, rather than a canvas with graphics primitives drawn in the repaint loop, I can also copy/paste my JavaFX data reduction solution, which has some differences with this AWT algorithm. |
|
Here is a typical usage context within a chart panel that derived ultimately from a JPanel, though the critical factor is just having an available Graphics2D canvas at hand.
|
@mhschmieder : Thanks a lot for the effort! I really appreciate it! I will give it a try soon - I'm just working on some proof-of-concept thing which has a higher prio for the management at the moment. I will give you feedback soon. Thanks again! |
Cool; no problem. I just finalized my final code review and API documentation revisions for five open source libraries that hopefully I will get published tomorrow (finally), one of which contains a lot of utilities that are useful for different vector graphics export targets, such as the data reduction algorithm above. Although it's a super-skeletal library at the moment (and I haven't yet had time to learn how to publish artifacts and Javadocs freely to Maven Central), I did make a placeholder project for it on my GitHub page, after restructuring the code a bit more to be as generic as possible (the original code was specific to the needs of a particular application and problem domain). https://github.com/mhschmieder/charttoolkit My other GitHub-posted toolkits are graphics oriented as well, and are growing rather quickly, beyond just supporting my just-published EPS vector graphics export library. Even though I got mostly away from AWT/Swing (after two painful years of dealing with multi-threading in hybrid code) towards JavaFX, I'm still seeing more Swing in the job market (although very little Java front-end desktop work at all anymore), so I'm trying to package up all of my legacy code into more generic nuggets that might help others, as that also gets me back into the "swing" of things with those toolkits (which I only retained for a few legacy needs, these past few years). |
Hi,
I am using JFreeSVG in combination with JFreeChart to produce SVG images to be embedded later on in HTML.
My problem is that the generated SVG file is huge (as example: plotting a single measurement where the sampling rate is 1ms, the time (X) is 270 seconds long (270k data points) produces an SVG file of 180MB. The picture is perfect but it simpy kills any browser I try to open with.
Question: How can I reduce (drastically) the generated SVG size?
The code generating the SVG (Kotlin):
I also tried using
SVGHints
with no luck.Thanks a lot,
David
The text was updated successfully, but these errors were encountered: