Now I understand,All this while I was thinking of a template as some skeleton structure for SVG code which will remain same every time user makes an export
like in R export,I didn't think of reading an inbuilt .svg file and using it as a skeleton for export.
it's much easier than you assume. The attached *.svg was a demo
template. Proceed as follows:
A) Create keywords for the X and Y axis, for the axis tics as well
as for the legend:
%PLACEHOLDER X-AXIS%, %PLACEHOLDER Y-AXIS%, X01, X02, ... Y01, Y02,
%SERIES A%, %SERIES B%, ...
B) Create a template using Inkscape for Line-, Scatter- and BarChart
exports.
C) Store the templates in the swtchart.export bundle in a directory,
e.g. called "templates".
D) When running an export, use a FileReader to read the template.
E) Modify the template keywords according to the data selection that
shall be exported, e.g. replace:
%PLACEHOLDER X-AXIS% -> Minutes, %PLACEHOLDER Y-AXIS% ->
Intensity, X01 -> 5.02, X02 -> 7.09, ...
F) Add the series (Line, Bar or Scatter) in the data field (my
template contained two series as an example) - the real template
wouldn't contain such series, because the X and Y scale defines,
where the data shall be plotted. Additionally, an element could be
added in the SVG, which is marked as the data area. Play with
Inkscape and explore how to best support the three chart types.
Colors of the series are given by the chart series.
G) Create the legend.
H) Done
All that is needed is a FileReader, some calculations to get the
values of the data and the tics, probably some Regex to replace the
keywords and a PrintWriter to export the chart as *.svg.
Best,
Philip
Am 28.02.20 um 19:32 schrieb Yash
Bharatiya:
Hi,
I saw the sample templates that you have shared, seeing
that they are Inkscape generated
I'm assuming that we'll have to print our own svg code
using tags like-
<g>,<line>(for linechart) and <circle>
(for scatter charts) etc.
to create the internal template which will be modified when
exporting.
Yep, using a template allows people to export the data
in different styles, see attached and example template.
This approach doesn't require to use Apache Batik and so on.
It can be implemented by just using a FileReader for the
template and a PrintWriter to export the data. The XY bar
and line series data can be fetched dynamically from the
BaseChart, see R export.
Best,
Philip
Am 27.02.20 um 14:58 schrieb Yash Bharatiya:
Okay,
So does that mean the basic features of the .svg
file like font,color and styling will remain the same
every time the user makes an export,
and only the data series for different axes being
exported will change?
I would recommend to create a simple *.svg
template in Inkscape for each type, which could be
used internally, see attached very rough demo file.
The template *.svg files could be modified in a way,
that certain keywords for the X and Y axis are used
and a data area is defined. This would enable a
system, that a user could use its own *.svg
templates in step 2 to export the data.
Do you know what I mean?
Best,
Philip
Am 27.02.20 um 14:07 schrieb Yash Bharatiya:
Hi,
Yes, I meant using this SVG code generated
by batik as a reference to create the template
for different charts
For e.g-
PrintWriter printWriter = null;
/*
USE PRINTWRITER TO PRINT SVG CODE TO A FILE HERE
*/
printWriter=new PrintWriter(new File(filename));
/*
printWriter.println(); // SVG code to print to the file goes inside this print statement.
the current SVG export is fine and uses
Apache Batik and other dependencies to
export the data.
I would like to have a second solution
without using these dependencies, via a
template. The template for Bar-, Line- and
Scatter-Charts shall define one x and one y
axis, which is populated by the export
script. The line series shall be exported as
"one" connected line instead of separate
elements.
Best,
Philip
Am 26.02.20 um 15:18 schrieb Yash
Bharatiya:
Hi,
I looked into how Graphics2D
generated the .svg export for
different charts and found
that it consists of three sections
of code-
1) General declaration of xml
document and SVG object,this will be
common to all templates.
--
~~~~~~~~~~~~~~~~~~~~~~~~
OpenChrom - the open source alternative for chromatography / mass spectrometry
Dr. Philip Wenig » Founder » philip.wenig@xxxxxxxxxxxxx » http://www.openchrom.net
~~~~~~~~~~~~~~~~~~~~~~~~
--
~~~~~~~~~~~~~~~~~~~~~~~~
OpenChrom - the open source alternative for chromatography / mass spectrometry
Dr. Philip Wenig » Founder » philip.wenig@xxxxxxxxxxxxx » http://www.openchrom.net
~~~~~~~~~~~~~~~~~~~~~~~~
--
~~~~~~~~~~~~~~~~~~~~~~~~
OpenChrom - the open source alternative for chromatography / mass spectrometry
Dr. Philip Wenig » Founder » philip.wenig@xxxxxxxxxxxxx » http://www.openchrom.net
~~~~~~~~~~~~~~~~~~~~~~~~
--
~~~~~~~~~~~~~~~~~~~~~~~~
OpenChrom - the open source alternative for chromatography / mass spectrometry
Dr. Philip Wenig » Founder » philip.wenig@xxxxxxxxxxxxx » http://www.openchrom.net
~~~~~~~~~~~~~~~~~~~~~~~~