XChart
XChart copied to clipboard
TeX formulas in chart elements
Hello Tim, I guess this is more of a comment/proposal than an issue... Something I always wanted is a plotting package that supports the use of professionally-looking mathematical elements for plot axes, legends etc. Since I could not find anything suitable (even professional tools do not offer this), I started out about 2 weeks ago to marry forks of XChart and JLatexMath to get this working. The main features I had in mind are
- the possibility to replace axis labels, legends, and chart titles by TeX-formated math elements ("$...$"),
- the use of proper minus signs in numerical values (turned out to be easy),
- the use of standard TeX fonts (Computer Modern) for axis tick labels.
I am attaching an example below. I also added PDF output with iText (which I regularly use). What was originally intended for personal use only ended up in quite some coding work, so I decided to put a preliminary version online (http://sourceforge.net/projects/jtexxchart/). However, if you like the idea and there is interest to merge this into the main XChart distribution, I'd be happy to contribute. Please let me know what you think about this.
--Wilhelm
Example output:
I love the idea!
XChart already uses a different lib for PDF export that also exports SVG and EPS. So ideally that would just continue to work.
Great! Let me know how you would like to proceed.
Actually the choice of the PDF exporter is no real issue as long as it provides an AWT-compatible Graphic2D. I looked at VectorGraphics2D initially and liked its simplicity very much but also noticed two problems with its EPS and PDF output:
- Font embedding does not seem to work properly and causes viewers to throw errors. This is not an issue as long as text is rendered as shape outlines. (I thus proposed to the JLatexMath developers to adopt my changes for rendering outline text only.)
- Apparently VectorGraphics2D does not specifiy a default color profile for viewing. This creates problems with Acrobat X+ by rendering wrong colors. The same happens when converting a VectorGraphics2D-created EPS to PDF with Adobe Distiller.
Those are the primary reasons for continuing with iText, which is very mature. However it is not free for commercial applications.
--Wilhelm
Awesome! How to proceed... I'm working on 3.0.0, which is a pretty major refactor and the code is a bit of a mess. On the one hand, it'd be good for you to work off of that branch (I can commit it if you prefer this option). Or you could just add to the current develop branch. Then later I'll need to manually merge your code into 3.0.0. How big are the changes?
I think it's important to keep this and all dependencies commercial-friendly. We could always submit a feature request at VectorGraphics2D or even submit a PR with a fix if it's easy.
This is not an issue as long as text is rendered as shape outlines.
That's the way to go. Hopefully they accept your changes. What license does JLatexMath have?
Most of the changes to XChart relate to the drawing of text, calculating dimensions and render positions. I am attaching a screenshot below that lists all modified and new files. All (OK, most) modifications in the code are marked "wilbur" and there is also a new package with that name which contains all new files. Please just browse the code (which I just cleaned up) in http://sourceforge.net/p/jtexxchart/code/HEAD/tree/trunk/xchart/src/main/java/imagingbook/other/xchart/ to see the scope of the modifications. Generally I suggest to add this functionality to version 3.0.0 once it is close to being finished, but perhaps some of the anticipated changes could be considered right away. I'd be happy to edit and commit myself -- if you permit ;-).
One more comment regarding vector output: I agree that outline text rendering solves many - if not all - font-related problems. However, some people (including myself if required) still use the old-fashioned DVI-PS-PDF LaTeX workflow in combination with the popular 'psfrag' literal text replacement in EPS files. There is no working substitute for PDF's yet and (e.g.) EPS output by recent Mathematica releases has become completely useless for this purpose -- a real nightmare! Thus I think it would be quite helpful to (at least optionally) have standard font inclusion and rendering too. And it should not be too hard to do either.
--Wilhelm
XChart modifications by "wilbur":
I took a quick look and the changes seem pretty minimal, which is nice! I'll push the new 3.0.0 branch in a few days from now. I suggest doing it in two stages 1) just integrate jlatexmath and get it rendering on screen. 2) Get VectorGraphics2D working (or other options you've mentioned).
Note that jlatexmath 1.0.2 is available on Maven Central but not the newest version: http://mvnrepository.com/artifact/org.scilab.forge/jlatexmath
A PR is preferred as it is a wonderful way to do a changes review and comment back and forth on specifics. It's the path of least resistance and saves the most time.
Actually this is kind of a big issue: https://www.apache.org/licenses/GPL-compatibility.html
We avoid GPLv3 software because merely linking to it is considered by the GPLv3 authors to create a derivative work. We want to honor their license. Unless GPLv3 licensors relax this interpretation of their own license regarding linking, our licensing philosophies are fundamentally incompatible. This is an identical issue for both GPLv2 and GPLv3.
What are your thoughts?
The plan is perfectly fine with me, and VectorGraphics2D does work with the current setup.
I had downloaded (and modified) JLatexMath 1.0.3 from https://forge.scilab.org/index.php/p/jlatexmath/ . Unfortunately I am quite ignorant about licensing issues (should take a course maybe?). Is this of any help?: https://forge.scilab.org/index.php/p/jlatexmath/issues/1566/
OK, we can do this, but there is some ground work to be taken care of first.
- They need to add the part about "GPL with classpath exception" to their LICENSE: https://github.com/opencollab/jlatexmath/blob/master/LICENSE, as mentioned here. Until that exists, the license is incompatible with XChart's. Here's what theya re talking about: https://en.wikipedia.org/wiki/GPL_linking_exception
- They need to incorporate your changes into their code.
- Once that is done, we need a jar on Maven Central. They have an open issue for that here:https://forge.scilab.org/index.php/p/jlatexmath/issues/1293/
After that, we're good to go and add your code into XChart. Since you have already made contact with them, it'd be great if you could follow up with them on the above issues. I'd love to see this work out!
OK, I will contact the JLatexMath people again to clarify these issues. I wonder how other projects incorporating JLatexMath (e.g., SciLab, Geogebra ...) handle this problem.
Looks like those two are GPL licensed, so no problem.
The main problem people/companies have with GPL is that if their proprietary app uses GPL libs, then they must also provide their app under the same license. That means they'd have to give the source code to their app if asked for. That's a major issue for companies making software, and why I chose Apache 2.0 for XChart. Companies can use XChart in their apps and not need to also open source their projects. For XChart that means potentially more contributors compared to similar libs licensed under a more restrictive license.
I'm not against GPL by any means, and think it's the right choice for a lot of projects.
Also, a fun side note is that if I wanted to change the license of XChart, I couldn't without the consent of all the people who contributed to XChart, because we all share copyright to the project and only the copyright holder(s) can change the license.
Just a quick update: To keep things simple I reverted the vector export in my code to 'VectorGraphics2D' so there is no more dependency on 'iText'. As mentioned, the problem with the missing PDF output profile remains and I have not idea how to fix this in VectorGraphics2D. An example is given below. SVG and EPS seem to render OK.
PNG Output with VectorGraphics2D (OK):
PDF export with VectorGraphics2D when viewed with Adobe Acrobat X (and exported to PNG again):
Excellent! OK, so what's the problem with PDF exactly? Just the colors or something else as well?
If we can clearly show the problems with PDF vs. EPS and SVG, then we can post an issue on: https://github.com/eseifert/vectorgraphics2d
How's the progress on the licensing issue? Are there any threads I could help "poke" and move the issue forward?
Apart from the color problem (missing viewer profile) I suspect that PDF font embedding does not work properly (throws "bad character box" errors in Acrobat). It can be avoided if outline-only text rendering is used.
I had no time to follow-up the licensing issue yet. Will check...