├── .gitignore
├── .hgignore
├── CHANGELOG.txt
├── pom.xml
├── base
├── src
│ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── panayotis
│ │ │ └── gnuplot
│ │ │ ├── style
│ │ │ ├── PlotColor.java
│ │ │ ├── Smooth.java
│ │ │ ├── Style.java
│ │ │ ├── RgbPlotColor.java
│ │ │ ├── NamedPlotColor.java
│ │ │ ├── FillStyle.java
│ │ │ └── PlotStyle.java
│ │ │ ├── plot
│ │ │ ├── Graph3D.java
│ │ │ ├── Plot.java
│ │ │ ├── FunctionPlot.java
│ │ │ ├── Axis.java
│ │ │ ├── AbstractPlot.java
│ │ │ ├── Page.java
│ │ │ ├── DataSetPlot.java
│ │ │ └── Graph.java
│ │ │ ├── GNUPlotException.java
│ │ │ ├── dataset
│ │ │ ├── parser
│ │ │ │ ├── DataParser.java
│ │ │ │ ├── LongDataParser.java
│ │ │ │ ├── FloatDataParser.java
│ │ │ │ ├── DoubleDataParser.java
│ │ │ │ ├── IntegerDataParser.java
│ │ │ │ └── NumericDataParser.java
│ │ │ ├── DataSet.java
│ │ │ ├── Point.java
│ │ │ ├── FileDataSet.java
│ │ │ ├── GenericDataSet.java
│ │ │ ├── ArrayDataSet.java
│ │ │ └── PointDataSet.java
│ │ │ ├── swing
│ │ │ ├── JPlot.form
│ │ │ └── JPlot.java
│ │ │ ├── layout
│ │ │ ├── ManualGraphLayout.java
│ │ │ ├── GraphLayout.java
│ │ │ ├── StripeLayout.java
│ │ │ ├── LayoutMetrics.java
│ │ │ ├── GridGraphLayout.java
│ │ │ └── AutoGraphLayout.java
│ │ │ ├── terminal
│ │ │ ├── CustomTerminal.java
│ │ │ ├── DefaultTerminal.java
│ │ │ ├── FileTerminal.java
│ │ │ ├── ImageTerminal.java
│ │ │ ├── GNUPlotTerminal.java
│ │ │ ├── PostscriptTerminal.java
│ │ │ ├── ExpandableTerminal.java
│ │ │ └── TextFileTerminal.java
│ │ │ ├── utils
│ │ │ ├── FileUtils.java
│ │ │ └── Debug.java
│ │ │ ├── PropertiesHolder.java
│ │ │ ├── GNUPlotParameters.java
│ │ │ ├── JavaPlot.java
│ │ │ ├── GNUPlotExec.java
│ │ │ └── GNUPlot.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── panayotis
│ │ └── gnuplot
│ │ └── demo
│ │ └── BaseDemo.java
└── pom.xml
├── svg
├── src
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── panayotis
│ │ │ └── gnuplot
│ │ │ └── demo
│ │ │ └── SVGDemo.java
│ └── main
│ │ └── java
│ │ └── com
│ │ └── panayotis
│ │ └── gnuplot
│ │ └── terminal
│ │ └── SVGTerminal.java
└── pom.xml
├── README.txt
└── LICENCE.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | /base/target/
2 | /svg/target/
3 |
4 | **/*.iml
5 |
--------------------------------------------------------------------------------
/.hgignore:
--------------------------------------------------------------------------------
1 | # These lines are suggested according to the svn:ignore property
2 | # Feel free to enable them by uncommenting them
3 |
4 | syntax: regexp
5 |
6 | \.gradle/
7 | \.nb-gradle/
8 | gradle.properties
9 |
--------------------------------------------------------------------------------
/CHANGELOG.txt:
--------------------------------------------------------------------------------
1 | 0.5.0
2 | Fix Windows issues: use temporary files instead of pipes.
3 |
4 | 0.4.0
5 | Basic support of Graph3D (splot). Implementation of user-defined
6 | terminals.
7 |
8 | 0.3.0
9 | Support of various data formats, i.e. date formats.
10 | Better plot layout support
11 |
12 | 0.2.0
13 | Support of multiplots
14 |
15 |
16 | 0.1.0
17 | Initial release
18 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | com.panayotis.javaplot
7 | project
8 | 0.5.0
9 | JavaPlot Project
10 | pom
11 |
12 | base
13 | svg
14 |
15 |
16 | UTF-8
17 |
18 |
19 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/style/PlotColor.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.style;
17 |
18 | /**
19 | * Interface definition of the color object to be used under gnuplot
20 | *
21 | * @author teras
22 | */
23 | public interface PlotColor {
24 |
25 | /**
26 | * Get the representation of this color
27 | *
28 | * @return The color representation as text
29 | */
30 | public String getColor();
31 | }
32 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/plot/Graph3D.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.plot;
17 |
18 | /**
19 | *
20 | * @author teras
21 | */
22 | public class Graph3D extends Graph {
23 |
24 | /**
25 | * Get the actual gnuplot command to initiate the plot.
26 | *
27 | * @return This method always returns "plot"
28 | */
29 | @Override
30 | protected String getPlotCommand() {
31 | return "splot";
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/GNUPlotException.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on 12 Οκτώβριος 2007, 4:12 μμ
17 | */
18 | package com.panayotis.gnuplot;
19 |
20 | /**
21 | * Runtime exception used whenever a recoverable error occured.
22 | *
23 | * @author teras
24 | */
25 | public class GNUPlotException extends RuntimeException {
26 |
27 | /**
28 | * Creates a new instance of GNUPlotException
29 | *
30 | * @param reason Message describing what went wrong
31 | */
32 | public GNUPlotException(String reason) {
33 | super(reason);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/dataset/parser/DataParser.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.dataset.parser;
17 |
18 | /**
19 | * Use a specific numeric parser to check if the data provided are valid or not.
20 | *
21 | * @author teras
22 | */
23 | public interface DataParser {
24 |
25 | /**
26 | * Check whether a data value with a specific index number is valid or not
27 | *
28 | * @param data The data to check
29 | * @param index The index of the specified data
30 | * @return True, if the data is valid.
31 | */
32 | public boolean isValid(String data, int index);
33 | }
34 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/swing/JPlot.form:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/style/Smooth.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 31, 2007, 2:29 AM
17 | */
18 | package com.panayotis.gnuplot.style;
19 |
20 | /**
21 | * Define how this plot should be smoothed. Please refer to the documentation of
22 | * gnuplot for specific explanation of each method
23 | *
24 | * @author teras
25 | */
26 | public enum Smooth {
27 |
28 | UNIQUE,
29 | FREQUENCY,
30 | CSPLINES,
31 | ACSPLINES,
32 | BEZIER,
33 | SBEZIER;
34 |
35 | /**
36 | * Retrieve the gnuplot argument for this smoothing mechanism
37 | *
38 | * @return the gnuplot argument
39 | */
40 | @Override
41 | public String toString() {
42 | return " smooth " + name().toLowerCase();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/layout/ManualGraphLayout.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.layout;
17 |
18 | import com.panayotis.gnuplot.plot.Page;
19 | import java.io.Serializable;
20 |
21 | /**
22 | * Position graphs in absolute coordinates. This is actually a dummy layout - no
23 | * layout information is used.
24 | *
25 | * @author teras
26 | */
27 | public class ManualGraphLayout implements GraphLayout, Serializable {
28 |
29 | /**
30 | * This is a dummy layout manager, which actually does nothing
31 | *
32 | * @param page The Page which layout we want to calculate
33 | * @param buffer The definition part of the multiplot layout
34 | */
35 | @Override
36 | public void setDefinition(Page page, StringBuilder buffer) {
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/layout/GraphLayout.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.layout;
17 |
18 | import com.panayotis.gnuplot.plot.Page;
19 |
20 | /**
21 | * This Object is used to define how graphs will be positioned on the whole page
22 | *
23 | * @author teras
24 | */
25 | public interface GraphLayout {
26 |
27 | /**
28 | * Sets the required definitions in the "set multiplot" part of gnuplot
29 | * commands. It can be also used to set various parameters, such as X/Y
30 | * position or dimension.
31 | *
32 | * @param page The Page we are referring to
33 | * @param buffer Where to send commands, just after the "set multiplot"
34 | * part. It might not be used.
35 | */
36 | public abstract void setDefinition(Page page, StringBuilder buffer);
37 | }
38 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/terminal/CustomTerminal.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.terminal;
17 |
18 | /**
19 | * This is a user specific terminal. The user in run-time defines what kind of
20 | * terminal wants. The output is not processed. If you want to process the
21 | * output, you might need to subclass this object and override
22 | * processOutput(InputStream stdout) method.
23 | *
24 | * @see GNUPlotTerminal#processOutput(java.io.InputStream)
25 | * @author teras
26 | */
27 | public class CustomTerminal extends ExpandableTerminal {
28 |
29 | private final String file;
30 |
31 | /**
32 | * Create a new custom terminal
33 | *
34 | * @param type The type of this terminal
35 | * @param file The filename to redirect output (if desired)
36 | */
37 | public CustomTerminal(String type, String file) {
38 | super(type);
39 | if (file == null)
40 | file = "";
41 | this.file = file;
42 | }
43 |
44 | /**
45 | * Retrieve the output filename
46 | *
47 | * @return The filename which this terminal will direct gnuplot output
48 | */
49 | @Override
50 | public String getOutputFile() {
51 | return file;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/dataset/parser/LongDataParser.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.dataset.parser;
17 |
18 | /**
19 | * Parser for Long data
20 | *
21 | * @author teras
22 | */
23 | public class LongDataParser extends NumericDataParser {
24 |
25 | /**
26 | * Create a new numeric data parser for Float values
27 | */
28 | public LongDataParser() {
29 | super();
30 | }
31 |
32 | /**
33 | * Create a new Long data parser, with the information that the first column
34 | * is in date format.
35 | *
36 | * @param first_column_date Whether the first column is in date format
37 | */
38 | public LongDataParser(boolean first_column_date) {
39 | super(first_column_date);
40 | }
41 |
42 | /**
43 | * Check whether this String represents a Long number
44 | *
45 | * @param format the String containing the Long number
46 | * @return True, if this is a representation of a Long number
47 | */
48 | @Override
49 | protected boolean checkNumberFormat(String format) {
50 | try {
51 | Long.parseLong(format);
52 | } catch (Exception e) {
53 | return false;
54 | }
55 | return true;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/dataset/parser/FloatDataParser.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.dataset.parser;
17 |
18 | /**
19 | * Parser for Float data
20 | *
21 | * @author teras
22 | */
23 | public class FloatDataParser extends NumericDataParser {
24 |
25 | /**
26 | * Create a new numeric data parser for Float values
27 | */
28 | public FloatDataParser() {
29 | super();
30 | }
31 |
32 | /**
33 | * Create a new Float data parser, with the information that the first
34 | * column is in date format.
35 | *
36 | * @param first_column_date Whether the first column is in date format
37 | */
38 | public FloatDataParser(boolean first_column_date) {
39 | super(first_column_date);
40 | }
41 |
42 | /**
43 | * Check whether this String represents a Float number
44 | *
45 | * @param format the String containing the Float number
46 | * @return True, if this is a representation of a Float number
47 | */
48 | @Override
49 | protected boolean checkNumberFormat(String format) {
50 | try {
51 | Float.parseFloat(format);
52 | } catch (Exception e) {
53 | return false;
54 | }
55 | return true;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/dataset/parser/DoubleDataParser.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.dataset.parser;
17 |
18 | /**
19 | * Parser for Double data
20 | *
21 | * @author teras
22 | */
23 | public class DoubleDataParser extends NumericDataParser {
24 |
25 | /**
26 | * Create a new numeric data parser for Double values
27 | */
28 | public DoubleDataParser() {
29 | super();
30 | }
31 |
32 | /**
33 | * Create a new Double data parser, with the information that the first
34 | * column is in date format.
35 | *
36 | * @param first_column_date Whether the first column is in date format
37 | */
38 | public DoubleDataParser(boolean first_column_date) {
39 | super(first_column_date);
40 | }
41 |
42 | /**
43 | * Check whether this String represents a Double number
44 | *
45 | * @param format the String containing the Double number
46 | * @return True, if this is a representation of a Double number
47 | */
48 | @Override
49 | protected boolean checkNumberFormat(String format) {
50 | try {
51 | Double.parseDouble(format);
52 | } catch (Exception e) {
53 | return false;
54 | }
55 | return true;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/dataset/parser/IntegerDataParser.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.dataset.parser;
17 |
18 | /**
19 | * Parser for Integer data
20 | *
21 | * @author teras
22 | */
23 | public class IntegerDataParser extends NumericDataParser {
24 |
25 | /**
26 | * Create a new numeric data parser for Float values
27 | */
28 | public IntegerDataParser() {
29 | super();
30 | }
31 |
32 | /**
33 | * Create a new Integer data parser, with the information that the first
34 | * column is in date format.
35 | *
36 | * @param first_column_date Whether the first column is in date format
37 | */
38 | public IntegerDataParser(boolean first_column_date) {
39 | super(first_column_date);
40 | }
41 |
42 | /**
43 | * Check whether this String represents a Integer number
44 | *
45 | * @param format the String containing the Integer number
46 | * @return True, if this is a representation of a Integer number
47 | */
48 | @Override
49 | protected boolean checkNumberFormat(String format) {
50 | try {
51 | Integer.parseInt(format);
52 | } catch (Exception e) {
53 | return false;
54 | }
55 | return true;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/plot/Plot.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 14, 2007, 1:59 PM
17 | */
18 | package com.panayotis.gnuplot.plot;
19 |
20 | /**
21 | * This interface is used by JavaPlot to handle various plot arguments. It can
22 | * be implemented to provide other entries for the plot command
23 | *
24 | * @author teras
25 | */
26 | public interface Plot {
27 |
28 | /**
29 | * Retrieve the definition part of the plot command. This is the part that
30 | * is given to the plot command, separated by commas. Commas and newlines
31 | * are automatically added
32 | *
33 | * @param buffer The buffer to store the argument of the plot command
34 | */
35 | public abstract void retrieveDefinition(StringBuilder buffer);
36 |
37 | /**
38 | * Retrieve the data set of this plot command. It is used only in data-set
39 | * plots and it is usually a set of numbers separated by space and newline
40 | * and terminated by the 'e' character. These data are appended at the end
41 | * of the actual plot command. If a plot argument does not require
42 | * additional data sets, then this method should do nothing.
43 | *
44 | * @param buffer The buffer to store the data set
45 | */
46 | public abstract void retrieveData(StringBuilder buffer);
47 | }
48 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/plot/FunctionPlot.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on 12 Οκτώβριος 2007, 5:17 μμ
17 | */
18 | package com.panayotis.gnuplot.plot;
19 |
20 | /**
21 | * This type of Plot is used to provide an interface to the functional plots of
22 | * gnuplot. For example plots like sin(x) or x**2+1
It can also be used as
23 | * a generic plot command, if the user wishes to manually provide any plot
24 | * information, without the interference of JavaPlot library.
25 | *
26 | * @author teras
27 | */
28 | public class FunctionPlot extends AbstractPlot {
29 |
30 | /**
31 | * Creates a new instance of FunctionPlot.
32 | *
33 | * @param function The function definition. It is a free text describing the
34 | * function to be plotted. The independent variable (for 2D plots) is x
35 | */
36 | public FunctionPlot(String function) {
37 | if (function == null)
38 | function = "0";
39 | set("title", "'" + function + "'");
40 | setDefinition(function);
41 | }
42 |
43 | /**
44 | * This method is unused in this object. It is here only for compatibility
45 | * reasons with Plot object.
46 | *
47 | * @param buf This parameter is not used
48 | */
49 | @Override
50 | public void retrieveData(StringBuilder buf) {
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/terminal/DefaultTerminal.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 17, 2007, 3:34 AM
17 | */
18 | package com.panayotis.gnuplot.terminal;
19 |
20 | import java.io.InputStream;
21 | import java.io.Serializable;
22 |
23 | /**
24 | * The default GNUPlot terminal. This terminal has no output file, or specific
25 | * terminal type. It is here, just in case no specific terminal type has been
26 | * provided.
27 | *
28 | * Note that in many operating systems this terminal is not really useful, or
29 | * even visible. Please use a specific terminal yourself.
30 | *
31 | * @author teras
32 | */
33 | public class DefaultTerminal implements GNUPlotTerminal, Serializable {
34 |
35 | /**
36 | * This Terminal has no type.
37 | *
38 | * @return Always returns "".
39 | */
40 | @Override
41 | public String getType() {
42 | return "";
43 | }
44 |
45 | /**
46 | * No output is defined for this terminal
47 | *
48 | * @return Always returns "".
49 | */
50 | @Override
51 | public String getOutputFile() {
52 | return "";
53 | }
54 |
55 | /**
56 | * No processing is performed. The plot is displayed in the default output.
57 | *
58 | * @param stdout The output of GNUPlot. Not processed.
59 | */
60 | @Override
61 | public String processOutput(InputStream stdout) {
62 | return null;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/dataset/DataSet.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on 15 Οκτώβριος 2007, 12:14 μμ
17 | */
18 | package com.panayotis.gnuplot.dataset;
19 |
20 | /**
21 | * This is the generic interface which every data set object should provide. By
22 | * implementing this interface the author can create his own data objects which
23 | * can be used in JavaPlot
24 | *
25 | * @author teras
26 | */
27 | public interface DataSet {
28 |
29 | /**
30 | * Retrieve how many points this data set has.
31 | *
32 | * @return the number of points
33 | */
34 | public int size();
35 |
36 | /**
37 | * Retrieve how many dimensions this dataset refers to. Typically, for every
38 | * point, this method informs JavaPlot how many "columns" of data this point
39 | * has. Make sure that every point has at least as many dimensions as what
40 | * is reported here .
41 | *
42 | * @return the number of dimensions
43 | */
44 | public int getDimensions();
45 |
46 | /**
47 | * Retrieve data information from a point. To retrieve information for each
48 | * point, a continuous call to this method will be executed, keeping the
49 | * item number constant and increasing the dimension.
50 | *
51 | * @param point The point number
52 | * @param dimension The point dimension (or "column") to request data from
53 | * @return the point data for this dimension
54 | */
55 | public String getPointValue(int point, int dimension);
56 | }
57 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/style/Style.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on 26 Οκτώβριος 2007, 3:15 μμ
17 | */
18 | package com.panayotis.gnuplot.style;
19 |
20 | /**
21 | * Possible styles to use in gnuplot
22 | *
23 | * @author teras
24 | */
25 | public enum Style {
26 |
27 | LINES(2, false),
28 | POINTS(2, false),
29 | LINESPOINTS(2, false),
30 | IMPULSES(2, false),
31 | DOTS(2, false),
32 | STEPS(2, false),
33 | FSTEPS(2, false),
34 | HISTEPS(2, false),
35 | ERRORBARS(2, false),
36 | LABELS(2, false),
37 | XERRORBARS(2, false),
38 | YERRORBARS(2, false),
39 | XYERRORBARS(2, false),
40 | ERRORLINES(2, false),
41 | XERRORLINES(2, false),
42 | YERRORLINES(2, false),
43 | XYERRORLINES(2, false),
44 | BOXES(2, true),
45 | HISTOGRAMS(2, false),
46 | FILLEDCURVES(2, false),
47 | BOXERRORBARS(2, false),
48 | BOXXYERRORBARS(2, true),
49 | FINANCEBARS(2, false),
50 | CANDLESTICKS(2, true),
51 | VECTORS(2, false),
52 | IMAGE(2, false),
53 | RGBIMAGE(2, false),
54 | PM3D(2, false);
55 | final int columns; // number of desired columns
56 | final boolean filled; // could be filled
57 |
58 | /**
59 | * Create a new Style enumeration
60 | *
61 | * @param columns how many dimensions is required
62 | * @param filled whether can be filled or not
63 | */
64 | Style(int columns, boolean filled) {
65 | this.columns = columns;
66 | this.filled = filled;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/terminal/FileTerminal.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 17, 2007, 2:51 AM
17 | */
18 | package com.panayotis.gnuplot.terminal;
19 |
20 | /**
21 | * This Terminal supports file operations. The results of the gnuplot commands
22 | * can be stored in a file, if desired.
23 | *
24 | * @author teras
25 | */
26 | public class FileTerminal extends ExpandableTerminal {
27 |
28 | private String filename;
29 |
30 | /**
31 | * Creates a new instance of FileTerminal and output to stadard out
32 | *
33 | * @param type The terminal type
34 | */
35 | public FileTerminal(String type) {
36 | this(type, "");
37 | }
38 |
39 | /**
40 | * Creates a new instance of FileTerminal and output to a specific file
41 | *
42 | * @param type The terminal type
43 | * @param filename e filename to use as an output for this terminal
44 | * @see #getOutputFile()
45 | */
46 | public FileTerminal(String type, String filename) {
47 | super(type);
48 | if (filename == null)
49 | filename = "";
50 | this.filename = filename;
51 | }
52 |
53 | /**
54 | * Retrieve the filename to use as an output for this terminal. If the
55 | * filename empty, then the output will be dumped to standard output, and
56 | * retrieved by JavaPlot
57 | *
58 | * @return If this parameter is not empty, the output filename
59 | */
60 | @Override
61 | public String getOutputFile() {
62 | return filename;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/dataset/parser/NumericDataParser.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.dataset.parser;
17 |
18 | /**
19 | * Generic data parser for numeric data
20 | *
21 | * @author teras
22 | */
23 | public abstract class NumericDataParser implements DataParser {
24 |
25 | private boolean first_column_date;
26 |
27 | /**
28 | * Create a new numeric data parser
29 | */
30 | public NumericDataParser() {
31 | this(false);
32 | }
33 |
34 | /**
35 | * Create a new numeric data parser, with the information that the first
36 | * column is in date format.
37 | *
38 | * @param first_column_date Whether the first column is in date format
39 | */
40 | public NumericDataParser(boolean first_column_date) {
41 | this.first_column_date = first_column_date;
42 | }
43 |
44 | /**
45 | * Check whether a data value with a specific index number is valid or not
46 | *
47 | * @param data The numerical data to check
48 | * @param index The index of the specified data
49 | * @return True, if the data is valid.
50 | */
51 | @Override
52 | public boolean isValid(String data, int index) {
53 | if (first_column_date && index == 0)
54 | return true;
55 | return checkNumberFormat(data);
56 | }
57 |
58 | /**
59 | * Check whether this String represents a number
60 | *
61 | * @param format the String containing the number
62 | * @return True, if this is a representation of a number
63 | */
64 | protected abstract boolean checkNumberFormat(String format);
65 | }
66 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/terminal/ImageTerminal.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 16, 2007, 1:34 AM
17 | */
18 | package com.panayotis.gnuplot.terminal;
19 |
20 | import java.awt.image.BufferedImage;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import javax.imageio.ImageIO;
24 |
25 | /**
26 | * This terminal is able to process gnuplot output as an image. The image
27 | * produced can be used by any Java object which is able to handle BufferedImage
28 | *
29 | * @author teras
30 | */
31 | public class ImageTerminal extends FileTerminal {
32 |
33 | private BufferedImage img;
34 |
35 | /**
36 | * Create a new image terminal, and use PNG as it's backend
37 | */
38 | public ImageTerminal() {
39 | super("png");
40 | }
41 |
42 | /**
43 | * Read the produced image from gnuplot standard output
44 | *
45 | * @param stdout The gnuplot output stream
46 | * @return The error definition, if any
47 | */
48 | @Override
49 | public String processOutput(InputStream stdout) {
50 | try {
51 | img = ImageIO.read(stdout);
52 | } catch (IOException ex) {
53 | return "Unable to create PNG image: " + ex.getMessage();
54 | }
55 | if (img == null)
56 | return "Unable to create image from the gnuplot output. Null image created.";
57 | return null;
58 | }
59 |
60 | /**
61 | * Get a handler of the produced image by this terminal
62 | *
63 | * @return the plot image
64 | */
65 | public BufferedImage getImage() {
66 | return img;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/terminal/GNUPlotTerminal.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 14, 2007, 2:36 PM
17 | */
18 | package com.panayotis.gnuplot.terminal;
19 |
20 | import java.io.InputStream;
21 |
22 | /**
23 | * This interface represents any GNUPlot terminal. "Terminal" by the definition
24 | * of GNUPlot is any device which will present the drawn plots.
25 | *
26 | * @author teras
27 | */
28 | public interface GNUPlotTerminal {
29 |
30 | /**
31 | * Get the terminal type / terminal name. A list of available terminal names
32 | * can be found through gnuplot if you issue the command "set term".
33 | *
34 | * @return the terminal type
35 | */
36 | public String getType();
37 |
38 | /**
39 | * Get the output filename. Use "" if not output file is desired or needed.
40 | *
41 | * @return The output filename
42 | */
43 | public String getOutputFile();
44 |
45 | /**
46 | * This method is executed bu GNUPlot, when the plot has been performed. It
47 | * actually transfers GNUPlot output to this method, if parsing is required.
48 | *
49 | * Note that if no output filename is given, then it is necessary to
50 | * "consume" this stream, or else a thread lockup might happen.
51 | *
52 | * @param stdout The output stream of GNUPlot. Note that since it is
53 | * required to read from this stream, it is given as InputStream.
54 | * @return The definition of the error, if something went wrong. If
55 | * everything is OK, it is necessary to return null.
56 | */
57 | public String processOutput(InputStream stdout);
58 | }
59 |
--------------------------------------------------------------------------------
/svg/src/test/java/com/panayotis/gnuplot/demo/SVGDemo.java:
--------------------------------------------------------------------------------
1 | package com.panayotis.gnuplot.demo;
2 |
3 | /* Copyright (c) 2007-2014 by panayotis.com
4 | *
5 | * JavaPlot is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, version 2.
8 | *
9 | * JavaPlot is free in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with CrossMobile; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 | import com.panayotis.gnuplot.JavaPlot;
19 | import com.panayotis.gnuplot.terminal.SVGTerminal;
20 | import com.panayotis.gnuplot.utils.Debug;
21 | import javax.swing.JFrame;
22 |
23 | /**
24 | * This Object is used to demonstrate JavaPlot library
25 | *
26 | * @author teras
27 | */
28 | public class SVGDemo {
29 |
30 | /**
31 | * @param args the command line arguments. First argument is the path of
32 | * gnuplot application
33 | */
34 | public static void main(String[] args) {
35 | String path = null;
36 | if (args.length > 0)
37 | path = args[0];
38 |
39 | SVGTerminal(path);
40 | }
41 |
42 | /* This demo code displays plot on screen using SVG commands (only b&w) */
43 | private static JavaPlot SVGTerminal(String gnuplotpath) {
44 | JavaPlot p = new JavaPlot();
45 | JavaPlot.getDebugger().setLevel(Debug.VERBOSE);
46 |
47 | SVGTerminal svg = new SVGTerminal();
48 | p.setTerminal(svg);
49 |
50 | p.setTitle("SVG Terminal Title");
51 | p.addPlot("x+3");
52 | p.plot();
53 |
54 | try {
55 | JFrame f = new JFrame();
56 | f.getContentPane().add(svg.getPanel());
57 | f.pack();
58 | f.setLocationRelativeTo(null);
59 | f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
60 | f.setVisible(true);
61 | } catch (ClassNotFoundException ex) {
62 | System.err.println("Error: Library SVGSalamander not properly installed?");
63 | }
64 |
65 | return p;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/dataset/Point.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 15, 2007, 1:54 AM
17 | */
18 | package com.panayotis.gnuplot.dataset;
19 |
20 | import java.io.Serializable;
21 | import java.lang.reflect.Array;
22 |
23 | /**
24 | * This object represents a N-dimensional point. It is used in PointDataSet as
25 | * the actual data object
26 | *
27 | * @param the type of this object. It should be a Number
28 | * @author teras
29 | */
30 | public class Point implements Serializable {
31 |
32 | private final N[] coords;
33 |
34 | /**
35 | * Creates a new instance of Point with given coordinates
36 | *
37 | * @param coords The coordinates given as a list of native (or boxed) type
38 | * numbers.
39 | */
40 | @SuppressWarnings("unchecked")
41 | public Point(N... coords) {
42 | this.coords = (N[]) Array.newInstance(Number.class, coords.length);
43 | System.arraycopy(coords, 0, this.coords, 0, coords.length);
44 | }
45 |
46 | /**
47 | * Retrieve the value of a specific coordinate of this point
48 | *
49 | * @param dimension the coordination dimension
50 | * @return the value of this point
51 | * @throws java.lang.ArrayIndexOutOfBoundsException The coordination
52 | * required is not present
53 | */
54 | public N get(int dimension) throws ArrayIndexOutOfBoundsException {
55 | return coords[dimension];
56 | }
57 |
58 | /**
59 | * Retrieve the actual coordinations of this point
60 | *
61 | * @return The coordinations (dimensions) of this point
62 | */
63 | public int getDimensions() {
64 | return coords.length;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/terminal/PostscriptTerminal.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 16, 2007, 1:34 AM
17 | */
18 | package com.panayotis.gnuplot.terminal;
19 |
20 | /**
21 | * This terminal uses postscript as it's backend
22 | *
23 | * @author teras
24 | */
25 | public class PostscriptTerminal extends TextFileTerminal {
26 |
27 | /**
28 | * Create a new instance of PostscriptTerminal. It is recommended to use
29 | * PostscriptTerminal(String filename) instead, since this constructor does
30 | * not produce any output file.
31 | */
32 | public PostscriptTerminal() {
33 | this("");
34 | }
35 |
36 | /**
37 | * Create a new Postscript terminal and save output to the specified file
38 | *
39 | * @param filename The filename of the output postscript file
40 | */
41 | @SuppressWarnings("OverridableMethodCallInConstructor")
42 | public PostscriptTerminal(String filename) {
43 | super("postscript", filename);
44 | setColor(true);
45 | setEPS(true);
46 | }
47 |
48 | /**
49 | * Select if the output will be in EPS format or not
50 | *
51 | * @param eps If EPS mode will be used
52 | */
53 | public void setEPS(boolean eps) {
54 | if (eps)
55 | set("eps");
56 | else
57 | unset("eps");
58 | }
59 |
60 | /**
61 | * Select if the output will be color or not (monochrome)
62 | *
63 | * @param color If the ouput will be in color
64 | */
65 | public void setColor(boolean color) {
66 | if (color) {
67 | set("color");
68 | unset("monochrome");
69 | } else {
70 | set("monochrome");
71 | unset("color");
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/dataset/FileDataSet.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 24, 2007, 2:00 AM
17 | */
18 | package com.panayotis.gnuplot.dataset;
19 |
20 | import java.io.BufferedReader;
21 | import java.io.File;
22 | import java.io.FileReader;
23 | import java.io.IOException;
24 | import java.util.ArrayList;
25 | import java.util.List;
26 | import java.util.StringTokenizer;
27 |
28 | /**
29 | * This object uses data sets already stored in files.
30 | *
31 | * @author teras
32 | */
33 | public class FileDataSet extends GenericDataSet {
34 |
35 | /**
36 | * Creates a new instance of a data set, stored in a file. When this object
37 | * is initialized, the file is read into memory.
38 | *
39 | * @param datafile The file containing the data set
40 | * @throws java.io.IOException when a I/O error is found
41 | * @throws java.lang.ArrayIndexOutOfBoundsException when the file has not
42 | * consistent number of columns
43 | * @throws java.lang.NumberFormatException when the numbers inside the file
44 | * are not parsable
45 | */
46 | public FileDataSet(File datafile) throws IOException, NumberFormatException, ArrayIndexOutOfBoundsException {
47 | super(true);
48 |
49 | BufferedReader in = new BufferedReader(new FileReader(datafile));
50 | String line;
51 | List data;
52 | while ((line = in.readLine()) != null && (!line.equals(""))) {
53 | line = line.trim();
54 | if (!line.startsWith("#")) {
55 | data = new ArrayList();
56 | StringTokenizer tk = new StringTokenizer(line);
57 | while (tk.hasMoreTokens())
58 | data.add(tk.nextToken());
59 | add(data);
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/layout/StripeLayout.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.layout;
17 |
18 | /**
19 | * Align graphs evenly on the page This Layout is based on AutoGraphLayout
20 | */
21 | public class StripeLayout extends AutoGraphLayout {
22 |
23 | /**
24 | * Information if rows or columns are added automatically
25 | */
26 | public static final boolean EXPANDROWS = true, EXPANDCOLUMNS = false;
27 |
28 | /**
29 | * Create a new Strip layout. Default behavior is EXPANDROWS.
30 | */
31 | @SuppressWarnings("OverridableMethodCallInConstructor")
32 | public StripeLayout() {
33 | setType(EXPANDROWS);
34 | }
35 |
36 | /**
37 | * Set the default behavior
38 | *
39 | * @param type Whether EXPANDROWS or EXPANDCOLUMNS is desired.
40 | * @see #EXPANDROWS #EXPANDCOLUMNS
41 | */
42 | public void setType(boolean type) {
43 | if (type == EXPANDROWS) {
44 | super.setRows(-1);
45 | super.setColumns(1);
46 | } else {
47 | super.setRows(1);
48 | super.setColumns(-1);
49 | }
50 | }
51 |
52 | /**
53 | * Set behavior, depending on the number of rows. It always creates stripes
54 | * and it might change to EXPANDCOLUMNS if rows are less than 2.
55 | *
56 | * @param rows Number of desired rows
57 | */
58 | @Override
59 | public void setRows(int rows) {
60 | if (rows > 1)
61 | setType(EXPANDROWS);
62 | else
63 | setType(EXPANDCOLUMNS);
64 | }
65 |
66 | /**
67 | * Set behaviour, depending on the number of columns. It always creates
68 | * stripes and it might change to EXPANDROWS if columns are less than 2.
69 | *
70 | * @param cols Number of desired columns
71 | */
72 | @Override
73 | public void setColumns(int cols) {
74 | if (cols > 1)
75 | setType(EXPANDCOLUMNS);
76 | else
77 | setType(EXPANDROWS);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/terminal/ExpandableTerminal.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 21, 2007, 6:58 PM
17 | */
18 | package com.panayotis.gnuplot.terminal;
19 |
20 | import com.panayotis.gnuplot.PropertiesHolder;
21 | import java.io.BufferedInputStream;
22 | import java.io.IOException;
23 | import java.io.InputStream;
24 |
25 | /**
26 | * This is the base class of all special terminals found in JavaPlot. It
27 | * provides support for terminal types and consumes unwanted gnuplot output.
28 | *
29 | * @author teras
30 | */
31 | public abstract class ExpandableTerminal extends PropertiesHolder implements GNUPlotTerminal {
32 |
33 | private final String type;
34 |
35 | /**
36 | * Create a new Terminal with a given type
37 | *
38 | * @param type The terminal to use
39 | */
40 | public ExpandableTerminal(String type) {
41 | super(" ", "");
42 | if (type == null)
43 | type = "unknown";
44 | this.type = type;
45 | }
46 |
47 | /**
48 | * Get the type of this terminal
49 | *
50 | * @return String representation of this terminal type
51 | */
52 | @Override
53 | public String getType() {
54 | StringBuilder buf = new StringBuilder();
55 | buf.append(type);
56 | appendProperties(buf);
57 | return buf.toString();
58 | }
59 |
60 | /**
61 | * This method only consumes gnuplot stdout input stream. It is performed to
62 | * prevent a possible thread lockup.
63 | *
64 | * @param stdout The output of GNUPlot. It will be consumed.
65 | */
66 | @SuppressWarnings("empty-statement")
67 | @Override
68 | public String processOutput(InputStream stdout) {
69 | byte[] buffer = new byte[1000];
70 | BufferedInputStream in = new BufferedInputStream(stdout);
71 | try {
72 | while (in.read(buffer) >= 0); // consume stream
73 | in.close();
74 | } catch (IOException ex) {
75 | return "I/O error while processing gnuplot output: " + ex.getMessage();
76 | }
77 | return null;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/style/RgbPlotColor.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.style;
17 |
18 | /**
19 | * This is an RGB (red-green-blue) color. For more information see gnuplot
20 | * documentation for linetype, colors, and
22 | * styles as well as Colorspec definition.
24 | *
25 | * @author dan
26 | * @author teras
27 | */
28 | public class RgbPlotColor implements PlotColor {
29 |
30 | private int red;
31 | private int green;
32 | private int blue;
33 |
34 | /**
35 | * Create a new color using the RGB colorspace.
36 | *
37 | * @param red value for red color, in the range of 0..255
38 | * @param green value for green color, in the range of 0..255
39 | * @param blue value for blue color, in the range of 0..255
40 | */
41 | public RgbPlotColor(int red, int green, int blue) {
42 | if (red < 0)
43 | red = 0;
44 | if (red > 255)
45 | red = 255;
46 | if (green < 0)
47 | green = 0;
48 | if (green > 255)
49 | green = 255;
50 | if (blue < 0)
51 | blue = 0;
52 | if (blue > 255)
53 | blue = 255;
54 | this.red = red;
55 | this.green = green;
56 | this.blue = blue;
57 | }
58 |
59 | /**
60 | * Create a new color using the RGB colorspace.
61 | *
62 | * @param red value for red color, in the range of 0..1
63 | * @param green value for green color, in the range of 0..1
64 | * @param blue value for blue color, in the range of 0..1
65 | */
66 | public RgbPlotColor(float red, float green, float blue) {
67 | this(Math.round(255 * red), Math.round(255 * green), Math.round(255 * blue));
68 | }
69 |
70 | /**
71 | * Get the representation of this color
72 | *
73 | * @return The color representation
74 | */
75 | @Override
76 | public String getColor() {
77 | return "rgb \"#" + String.format("%02x%02x%02x", red, green, blue) + "\"";
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/style/NamedPlotColor.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on 26 Οκτώβριος 2007, 4:32 μμ
17 | */
18 | package com.panayotis.gnuplot.style;
19 |
20 | /**
21 | * This is a list of possible colors which the user is able to use under gnuplot
22 | *
23 | * @author teras
24 | */
25 | public enum NamedPlotColor implements PlotColor {
26 |
27 | WHITE,
28 | BLACK,
29 | GRAY0,
30 | GREY0,
31 | GRAY10,
32 | GREY10,
33 | GRAY20,
34 | GREY20,
35 | GRAY30,
36 | GREY30,
37 | GRAY40,
38 | GREY40,
39 | GRAY50,
40 | GREY50,
41 | GRAY60,
42 | GREY60,
43 | GRAY70,
44 | GREY70,
45 | GRAY80,
46 | GREY80,
47 | GRAY90,
48 | GREY90,
49 | GRAY100,
50 | GREY100,
51 | GRAY,
52 | GREY,
53 | LIGHT_GRAY,
54 | LIGHT_GREY,
55 | DARK_GRAY,
56 | DARK_GREY,
57 | RED,
58 | LIGHT_RED,
59 | DARK_RED,
60 | YELLOW,
61 | LIGHT_YELLOW,
62 | DARK_YELLOW,
63 | GREEN,
64 | LIGHT_GREEN,
65 | DARK_GREEN,
66 | SPRING_GREEN,
67 | FOREST_GREEN,
68 | SEA_GREEN,
69 | BLUE,
70 | LIGHT_BLUE,
71 | DARK_BLUE,
72 | MIDNIGHT_BLUE,
73 | NAVY,
74 | MEDIUM_BLUE,
75 | ROYALBLUE,
76 | SKYBLUE,
77 | CYAN,
78 | LIGHT_CYAN,
79 | DARK_CYAN,
80 | MAGENTA,
81 | LIGHT_MAGENTA,
82 | DARK_MAGENTA,
83 | TURQUOISE,
84 | LIGHT_TURQUOISE,
85 | DARK_TURQUOISE,
86 | PINK,
87 | LIGHT_PINK,
88 | DARK_PINK,
89 | CORAL,
90 | LIGHT_CORAL,
91 | ORANGE_RED,
92 | SALMON,
93 | LIGHT_SALMON,
94 | DARK_SALMON,
95 | AQUAMARINE,
96 | KHAKI,
97 | DARK_KHAKI,
98 | GOLDENROD,
99 | LIGHT_GOLDENROD,
100 | DARK_GOLDENROD,
101 | GOLD,
102 | BEIGE,
103 | BROWN,
104 | ORANGE,
105 | DARK_ORANGE,
106 | VIOLET,
107 | DARK_VIOLET,
108 | PLUM,
109 | PURPLE;
110 |
111 | /**
112 | * Get the representation of this color
113 | *
114 | * @return The color representation
115 | */
116 | @Override
117 | public String getColor() {
118 | return "rgb '" + name().toLowerCase().replace('_', '-') + "'";
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 | JavaPlot
2 | --------
3 |
4 | A pure Java wrapper for gnuplot application.
5 |
6 |
7 | This library can be used as a way to create gnuplot plots on the fly through
8 | pure Java commands. In contrast with other common gnuplot java libraries, this
9 | library uses java structures to store the various plot parameters, including
10 | data-sets. Moreover, is flexible enough to give special parameters to gnuplot,
11 | even if the library does not support it (yet). Moreover, it uses Java's
12 | Exceptions to inform the user if something went wrong.
13 |
14 | Java 1.5 (or better) is needed for this library. The reason is the extensive
15 | usage of various 1.5 technologies, such as Generics and auto-boxing, to help
16 | manipulation of plot data. It has been tested with gnuplot 4.2. Older versions
17 | might or might not work.
18 |
19 | This library has been checked in Windows, Linux and Mac OS X. It should work on
20 | any other system, if you fine tune the special parameters needed.
21 |
22 |
23 | Usage
24 | -----
25 |
26 | A JavaPlot demo usage can be found under "demo/dist" directory. To use it type:
27 | cd demo/dist ; java -jar demo.jar
28 |
29 | Source of this demo can be found in "demo/src/demo.java" file.
30 | If you want to see javadoc, you can have a look under "dist/javadoc" directory.
31 |
32 | In order to use JavaPlot in your application, first you have to include
33 | JavaPlot.jar library in your classpath, found under "dist/JavaPlot.jar"
34 | Then the easiest way to start creating plots, is to create a new instance of
35 | JavaPlot object. Have a look at "demo/src/demo.java". Here you can find
36 | various ways to use this library.
37 |
38 |
39 | Advanced Usage
40 | --------------
41 |
42 | If you want to go deeper into the library, it is important to understand
43 | "PropertiesHolder" class, which is the base properties holder of this library.
44 | This class is able to store pairs of values (such as key-value pairs). Use the
45 | set() and unset() method of this class to add parameters which will be used when
46 | creating the gnuplot program.
47 |
48 | There are some things that are not supported yet. This is for example the splot-
49 | family commands. Still, using methods like getPreInit() and getPostInit() you
50 | might be able to simulate them.
51 |
52 | If you want to use SVG output in Java, you need a library to handle SVG files.
53 | Such a library is SVGSalamander provided with this package under directory
54 | "xtra". There is a bug in this library, though, which ignores color values. Thus
55 | all colors in SVG graphs are black.
56 |
57 |
58 | Feedback
59 | --------
60 |
61 | Any problems, suggestions, corrections, ideas e.t.c. are strongly welcome. Note
62 | that this library is still alpha quality, in the sense that the library API is
63 | not fixed yet and it will change in the next version. The reason that it is
64 | downloadable, is because I believe that it is already very useful and more or
65 | less complete already (and of course I need some feedback).
66 |
67 | To contact me, write to: panayotis (a) panayotis.com
68 |
69 | Thank you for trying this software.
70 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/terminal/TextFileTerminal.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 23, 2007, 10:46 AM
17 | */
18 | package com.panayotis.gnuplot.terminal;
19 |
20 | import java.io.BufferedReader;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import java.io.InputStreamReader;
24 |
25 | /**
26 | * Base class of all terminals with output in text format.
27 | *
28 | * @author teras
29 | */
30 | public class TextFileTerminal extends FileTerminal {
31 |
32 | /**
33 | *
34 | */
35 | protected String output = "";
36 |
37 | /**
38 | * Creates a new instance of TextFileTerminal. The output will be parsed by
39 | * JavaPlot and stored in a String, since it is expected to be a text and
40 | * not binary data.
41 | *
42 | * @param type the terminal type
43 | */
44 | public TextFileTerminal(String type) {
45 | this(type, "");
46 | }
47 |
48 | /**
49 | * Creates a new instance of TextFileTerminal and output to a specific file
50 | *
51 | * @param type the terminal type
52 | * @param filename the file to save output to
53 | */
54 | public TextFileTerminal(String type, String filename) {
55 | super(type, filename);
56 | }
57 |
58 | /**
59 | * Process output of this terminal. Since this is a text terminal, the
60 | * output will be stored in a String
61 | *
62 | * @param stdout The gnuplot output stream
63 | * @return Return the error as a String, if an error occured.
64 | */
65 | @Override
66 | public String processOutput(InputStream stdout) {
67 | StringBuilder out = new StringBuilder();
68 | BufferedReader in = new BufferedReader(new InputStreamReader(stdout));
69 | String line;
70 | try {
71 | while ((line = in.readLine()) != null)
72 | out.append(line);
73 | in.close();
74 | } catch (IOException ex) {
75 | return "I/O error while processing gnuplot output: " + ex.getMessage();
76 | }
77 | output = out.toString();
78 | return null;
79 | }
80 |
81 | /**
82 | * Retrieve the String with the output of the last gnuplot command
83 | *
84 | * @return The String with gnuplot output
85 | */
86 | public String getTextOutput() {
87 | return output;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/layout/LayoutMetrics.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.layout;
17 |
18 | import java.io.Serializable;
19 |
20 | /**
21 | * Container of the metrics for a specific graph
22 | *
23 | * @author teras
24 | */
25 | public class LayoutMetrics implements Serializable {
26 |
27 | private final static float MINSIZE = 0.001f;
28 |
29 | private float x, y, width, height;
30 |
31 | /**
32 | * Set default position, covering the whole screen
33 | */
34 | public LayoutMetrics() {
35 | this(0, 0, 1, 1);
36 | }
37 |
38 | /**
39 | * Set a specific position, in the area of 0,0-1,1 and with a minimum size
40 | *
41 | * @param x horizontal position
42 | * @param y vertical position
43 | * @param width width
44 | * @param height height
45 | */
46 | public LayoutMetrics(float x, float y, float width, float height) {
47 | if (width < 0)
48 | width = MINSIZE;
49 | if (height < 0)
50 | height = MINSIZE;
51 | if (width > 1)
52 | width = 1;
53 | if (height > 1)
54 | height = 1;
55 |
56 | if (x < 0)
57 | x = 0;
58 | if (y < 0)
59 | y = 0;
60 | if (x > 1)
61 | x = 1;
62 | if (y > 1)
63 | y = 1;
64 |
65 | float x2 = x + width;
66 | float y2 = y + height;
67 | if (x2 > 1) {
68 | x = 1 - MINSIZE;
69 | width = MINSIZE;
70 | }
71 | if (y2 > 1) {
72 | y = 1 - MINSIZE;
73 | height = MINSIZE;
74 | }
75 |
76 | this.x = x;
77 | this.y = y;
78 | this.width = width;
79 | this.height = height;
80 | }
81 |
82 | /**
83 | * Get horizontal position
84 | *
85 | * @return horizontal position
86 | */
87 | public float getX() {
88 | return x;
89 | }
90 |
91 | /**
92 | * Get vertical position
93 | *
94 | * @return vertical position
95 | */
96 | public float getY() {
97 | return y;
98 | }
99 |
100 | /**
101 | * Get width
102 | *
103 | * @return width
104 | */
105 | public float getWidth() {
106 | return width;
107 | }
108 |
109 | /**
110 | * Get height
111 | *
112 | * @return height
113 | */
114 | public float getHeight() {
115 | return height;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/utils/FileUtils.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.utils;
17 |
18 | import java.io.BufferedWriter;
19 | import java.io.File;
20 | import java.io.FileWriter;
21 | import java.io.IOException;
22 | import java.util.StringTokenizer;
23 |
24 | /**
25 | *
26 | * @author teras
27 | */
28 | public class FileUtils {
29 |
30 | /**
31 | * This method browses current path to search for a file. Typically this
32 | * should be an executable, but it is impossible under Java to check if this
33 | * file has the execution bit on. Apart from the user defined $PATH
34 | * variable, common bin-directory places are searched.
35 | *
36 | * @return The path of the specified program. If it is not found, "gnuplot"
37 | * is returned.
38 | */
39 | public static String findPathExec() {
40 | /* Check for default locations */
41 | for (String path : new String[]{
42 | "/bin/gnuplot", "/usr/bin/gnuplot", "/usr/local/bin/gnuplot",
43 | "/sbin/gnuplot", "/usr/sbin/gnuplot", "/usr/local/sbin/gnuplot",
44 | "/opt/bin/gnuplot", "/opt/local/bin/gnuplot",
45 | "/opt/sbin/gnuplot", "/opt/local/sbin/gnuplot",
46 | "/sw/bin/gnuplot",
47 | "C:\\Program Files (x86)\\gnuplot\\bin\\wgnuplot.exe",
48 | "C:\\Program Files\\gnuplot\\bin\\wgnuplot.exe",
49 | "c:\\cygwin\\bin\\gnuplot.exe"})
50 | if (new File(path).isFile())
51 | return path;
52 |
53 | /* Check for PATH-based locations */
54 | StringTokenizer st = new StringTokenizer(System.getenv("PATH"), File.pathSeparator);
55 | String dir, file;
56 | while (st.hasMoreTokens()) {
57 | dir = st.nextToken();
58 | file = dir + File.separator + "gnuplot";
59 | if (new File(file).isFile())
60 | return file;
61 | file = dir + File.separator + "wgnuplot.exe";
62 | if (new File(file).isFile())
63 | return file;
64 | file = dir + File.separator + "gnuplot.exe";
65 | if (new File(file).isFile())
66 | return file;
67 | }
68 | return "gnuplot";
69 | }
70 |
71 | public static String createTempFile(String contents) throws IOException {
72 | File file = File.createTempFile("gnuplot_", ".dat");
73 | BufferedWriter out = new BufferedWriter(new FileWriter(file));
74 | out.append(contents);
75 | out.close();
76 | return file.getAbsolutePath();
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/svg/src/main/java/com/panayotis/gnuplot/terminal/SVGTerminal.java:
--------------------------------------------------------------------------------
1 | package com.panayotis.gnuplot.terminal;
2 |
3 | /* Copyright (c) 2007-2014 by panayotis.com
4 | *
5 | * JavaPlot is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, version 2.
8 | *
9 | * JavaPlot is free in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with CrossMobile; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | *
18 | * Created on October 24, 2007, 7:47 PM
19 | */
20 |
21 |
22 | import com.kitfox.svg.SVGDiagram;
23 | import com.kitfox.svg.SVGDisplayPanel;
24 | import com.kitfox.svg.SVGUniverse;
25 | import java.io.InputStream;
26 | import java.io.StringReader;
27 | import javax.swing.JPanel;
28 |
29 | /**
30 | * This Terminal uses SVG graphics to display data on screen. It relies on the
31 | * open source project SVGSalamander (http://svgsalamander.dev.java.net/)
32 | *
33 | * @author teras
34 | */
35 | public class SVGTerminal extends TextFileTerminal {
36 |
37 | /**
38 | * Creates a new instance of SVGTerminal
39 | */
40 | public SVGTerminal() {
41 | this("");
42 | }
43 |
44 | /**
45 | * Creates a new instance of SVGTerminal and store output to a specific file
46 | *
47 | * @param filename
48 | */
49 | public SVGTerminal(String filename) {
50 | super("svg", filename);
51 | }
52 |
53 | /**
54 | * Process output of this terminal. Typically this is used to overcome a bug
55 | * in SVGSalamander
56 | *
57 | * @param stdout The gnuplot output stream
58 | * @return Return the error as a String, if an error occured.
59 | */
60 | @Override
61 | public String processOutput(InputStream stdout) {
62 | String out_status = super.processOutput(stdout);
63 | if (output != null && getOutputFile().equals(""))
64 | output = output.replace("currentColor", "black");
65 | return out_status;
66 | }
67 |
68 | /**
69 | * Retrieve a JPanel whith the provided SVG drawn on it.
70 | *
71 | * @return The JPanel with the SVG drawing
72 | * @throws java.lang.ClassNotFoundException If the SVGSalamander library
73 | * could not be found, or if any other error occurred.
74 | */
75 | public JPanel getPanel() throws ClassNotFoundException {
76 | /*
77 | * Use reflection API to create the representation in SVG format
78 | */
79 | if (output == null || output.equals(""))
80 | throw new NullPointerException("SVG output is empty; probably SVG terminal is not used or plot() not executed yet.");
81 | try {
82 | SVGUniverse universe = new SVGUniverse();
83 | universe.loadSVG(new StringReader(output), "plot");
84 | SVGDiagram diagram = universe.getDiagram(universe.getStreamBuiltURI("plot"));
85 |
86 | SVGDisplayPanel svgDisplayPanel = new SVGDisplayPanel();
87 | svgDisplayPanel.setDiagram(diagram);
88 | return svgDisplayPanel;
89 | } catch (Exception e) {
90 | throw new ClassNotFoundException(e.getMessage());
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/swing/JPlot.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 24, 2007, 7:53 PM
17 | */
18 | package com.panayotis.gnuplot.swing;
19 |
20 | import com.panayotis.gnuplot.JavaPlot;
21 | import com.panayotis.gnuplot.terminal.ImageTerminal;
22 | import java.awt.Dimension;
23 | import java.awt.Graphics;
24 | import java.awt.image.BufferedImage;
25 | import javax.swing.JPanel;
26 |
27 | /**
28 | * This Object uses an ImageTerminal as a backend, in order to draw the selected
29 | * plot
30 | *
31 | * @author teras
32 | */
33 | public class JPlot extends JPanel {
34 |
35 | private JavaPlot plot;
36 | private ImageTerminal term;
37 |
38 | /**
39 | * Creates new form JPlot with a blank JavaPlot
40 | */
41 | public JPlot() {
42 | this(new JavaPlot());
43 | }
44 |
45 | /**
46 | * Create a new form JPlot with a specified JavaPlot
47 | *
48 | * @param plot the JavaPlot to use
49 | */
50 | public JPlot(JavaPlot plot) {
51 | initComponents();
52 | term = new ImageTerminal();
53 | setJavaPlot(plot);
54 | }
55 |
56 | /**
57 | * Change the current JavaPlot
58 | *
59 | * @param javaplot the JavaPlot to use
60 | */
61 | public final void setJavaPlot(JavaPlot javaplot) {
62 | plot = javaplot;
63 | plot.setTerminal(term);
64 | }
65 |
66 | /**
67 | * Retrieve the JavaPlot of this JPlot.
68 | *
69 | * @return the JavaPlot being used
70 | */
71 | public JavaPlot getJavaPlot() {
72 | return plot;
73 | }
74 |
75 | /**
76 | * Perform a plot on this object
77 | */
78 | public void plot() {
79 | if (plot == null)
80 | return;
81 | plot.plot();
82 | BufferedImage img = term.getImage();
83 | setPreferredSize(new Dimension(img.getWidth(), img.getHeight()));
84 | }
85 |
86 | /**
87 | * Paint this component
88 | *
89 | * @param g Graphics handler for this component
90 | */
91 | @Override
92 | public void paint(Graphics g) {
93 | BufferedImage img = term.getImage();
94 | if (img == null)
95 | return;
96 | g.drawImage(img, 0, 0, null);
97 | }
98 |
99 | /**
100 | * This method is called from within the constructor to initialize the form.
101 | * WARNING: Do NOT modify this code. The content of this method is always
102 | * regenerated by the Form Editor.
103 | */
104 | // //GEN-BEGIN:initComponents
105 | private void initComponents() {
106 |
107 | }// //GEN-END:initComponents
108 | // Variables declaration - do not modify//GEN-BEGIN:variables
109 | // End of variables declaration//GEN-END:variables
110 | }
111 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/plot/Axis.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 14, 2007, 10:59 PM
17 | */
18 | package com.panayotis.gnuplot.plot;
19 |
20 | import com.panayotis.gnuplot.*;
21 |
22 | /**
23 | * This class represents the various axes of the plot. It is used to set various
24 | * axis-related parameters
25 | *
26 | * @author teras
27 | */
28 | public class Axis extends PropertiesHolder {
29 |
30 | private final String name;
31 |
32 | /**
33 | * Creates a new instance of Axis.
34 | *
35 | * @param name The name of the axis
36 | */
37 | Axis(String name) {
38 | this.name = name;
39 | }
40 |
41 | /**
42 | * Get the name of this axis as a String.
43 | *
44 | * @return The name of the axis. Usually it is "x" or "y".
45 | */
46 | public String getName() {
47 | return name;
48 | }
49 |
50 | /**
51 | * Set whether this axis is in logarithmic scale or not
52 | *
53 | * @param log Set, if this axis is in logarithmic scale
54 | */
55 | public void setLogScale(boolean log) {
56 | if (log)
57 | set("logscale", getName());
58 | else
59 | unset("logscale");
60 | }
61 |
62 | /**
63 | * Set the label of this axis.
64 | *
65 | * @param label The label of this axis
66 | * @see #setLabel(String,String,int)
67 | */
68 | public void setLabel(String label) {
69 | setLabel(label, null, -1);
70 | }
71 |
72 | /**
73 | * Set the label and the font of the current axis
74 | *
75 | * @param label The label of this axis
76 | * @param font Font name
77 | * @param size Font size
78 | */
79 | public void setLabel(String label, String font, int size) {
80 | String fontname = "";
81 | if (font != null)
82 | fontname = " font '" + font + ((size > 1) ? "," + size : "") + "'";
83 | set(getName() + "label", "'" + label + "'" + fontname);
84 | }
85 |
86 | /**
87 | * Define the area to plot.
Note that if we have chosen log scale, then
88 | * the values should be guaranteed to be larger than zero. If the axis is in
89 | * log scale, do not set a value less than zero or else a plot error will
90 | * occur.
91 | *
92 | * @param from The minimum value
93 | * @param to The maximum value
94 | */
95 | public void setBoundaries(double from, double to) {
96 | if (from == Double.POSITIVE_INFINITY || from == Double.NEGATIVE_INFINITY || from == Double.MAX_VALUE || from == Double.MIN_VALUE)
97 | return;
98 | if (to == Double.POSITIVE_INFINITY || to == Double.NEGATIVE_INFINITY || to == Double.MAX_VALUE || to == Double.MIN_VALUE)
99 | return;
100 | if (to < from) {
101 | double swap = to;
102 | to = from;
103 | from = swap;
104 | }
105 | set(getName() + "range", "[" + from + ":" + to + "]");
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/PropertiesHolder.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 19, 2007, 2:20 AM
17 | */
18 | package com.panayotis.gnuplot;
19 |
20 | import java.util.HashMap;
21 | import java.util.Map.Entry;
22 |
23 | /**
24 | * This object is a data placeholder of various text-based parameters, used in
25 | * JavaPlot graph objects.
It is possible to retrieve all it's data, as long
26 | * a valid key-value pair is present.
27 | *
28 | * @author teras
29 | */
30 | public class PropertiesHolder extends HashMap {
31 |
32 | protected static final String NL = System.getProperty("line.separator");
33 | private String prefix;
34 | private String suffix;
35 |
36 | /**
37 | * Creates a new instance of PropertiesHolder with default prefix and suffix
38 | * values.
The prefix in this case is the token "set " and the suffix is
39 | * the newline character.
40 | */
41 | public PropertiesHolder() {
42 | this("set ", NL);
43 | }
44 |
45 | /**
46 | * Creates a new instance of PropertiesHolder with given prefix and suffix
47 | * tokens.
48 | *
49 | * @param prefix The prefix to use
50 | * @param suffix The suffix to use.
51 | */
52 | public PropertiesHolder(String prefix, String suffix) {
53 | super();
54 | this.prefix = prefix;
55 | this.suffix = suffix;
56 | }
57 |
58 | /**
59 | * Add a specific key-value pair to this object.
60 | *
61 | * @param key The key to use
62 | * @param value The value of the specified parameter.
If value is null,
63 | * then this key will be removed.
64 | */
65 | public void set(String key, String value) {
66 | if (key != null)
67 | if (value == null)
68 | unset(key);
69 | else
70 | put(key, value);
71 | }
72 |
73 | /**
74 | * Set a specific key to this object, without a value
75 | *
76 | * @param key The key to add to this object
77 | */
78 | public void set(String key) {
79 | set(key, "");
80 | }
81 |
82 | /**
83 | * Remove a key from this object
84 | *
85 | * @param key The key to be removed
86 | */
87 | public void unset(String key) {
88 | remove(key);
89 | }
90 |
91 | /**
92 | * Retrieve the list of the stored key-value pairs in this object. Every
93 | * pair will be prefixed with "prefix" and suffixed with "suffix". Between
94 | * key and value will be a space character, if and only if the value is
95 | * present.
96 | *
97 | * @param bf The StringBuilder to store the representation of this object.
98 | */
99 | public void appendProperties(StringBuilder bf) {
100 | Object val;
101 | for (Entry e : entrySet()) {
102 | bf.append(prefix).append(e.getKey());
103 | val = e.getValue();
104 | if (val != null && (!val.equals("")))
105 | bf.append(' ').append(e.getValue());
106 | bf.append(suffix);
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/layout/GridGraphLayout.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | * and open the template in the editor.
16 | */
17 | package com.panayotis.gnuplot.layout;
18 |
19 | import com.panayotis.gnuplot.plot.Page;
20 | import java.io.Serializable;
21 |
22 | /**
23 | * Align graphs evenly on the page, in a grid layout.
24 | *
25 | * If you manually set metrics and use this, these metrics will be lost. Do not
26 | * use this layout, use AutoGraphLayout instead.
27 | *
28 | * @author teras
29 | * @deprecated
30 | */
31 | public class GridGraphLayout implements GraphLayout, Serializable {
32 |
33 | /**
34 | * Where the first graph will be put
35 | */
36 | public enum Start {
37 |
38 | UPLEFT, UPRIGHT, DOWNLEFT, DOWNRIGHT;
39 | }
40 | /**
41 | * Orientation of the graph layout
42 | */
43 | public static final boolean HORIZONTAL = true, VERTICAL = false;
44 | private Start start;
45 | private boolean orientation;
46 |
47 | /**
48 | * Create a new grid layout
49 | */
50 | public GridGraphLayout() {
51 | start = Start.UPLEFT;
52 | orientation = HORIZONTAL;
53 | }
54 |
55 | /**
56 | * Set where the first graph will be put
57 | *
58 | * @param start Position of the first graph
59 | */
60 | public void setStartPosition(Start start) {
61 | this.start = start;
62 | }
63 |
64 | /**
65 | * Sey the orientation of the graphs, as being put
66 | *
67 | * @param orientation Selected orientation
68 | */
69 | public void setOrientation(boolean orientation) {
70 | this.orientation = orientation;
71 | }
72 |
73 | /**
74 | * Update the capacity of this layout. This manager tries to create grid, as
75 | * much square as possible
76 | *
77 | * @param page The page with the elements we would like to position
78 | * @param buffer Where to send commands - not used.
79 | */
80 | @Override
81 | public void setDefinition(Page page, StringBuilder buffer) {
82 |
83 | int size = page.size();
84 |
85 | if (size <= 0)
86 | return;
87 |
88 | int width, height;
89 | height = (int) (Math.floor(Math.sqrt(size)));
90 | width = (int) Math.ceil((double) size / height);
91 |
92 | float dx = 1f / width;
93 | float dy = 1f / height;
94 | int col, lin;
95 | for (int index = 0; index < size; index++) {
96 | if (orientation) {
97 | col = index % width;
98 | lin = index / width;
99 | } else {
100 | lin = index % height;
101 | col = index / height;
102 | }
103 |
104 | if (start == Start.UPRIGHT || start == Start.DOWNRIGHT)
105 | col = width - col - 1;
106 | if (start == Start.UPLEFT || start == Start.UPRIGHT) // Positioning (0,0) in GNUPlot is in lower left corner
107 | lin = height - lin - 1;
108 |
109 | page.get(index).setMetrics(dx * col, dy * lin, dx, dy);
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/plot/AbstractPlot.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on 12 Οκτώβριος 2007, 4:07 μμ
17 | */
18 | package com.panayotis.gnuplot.plot;
19 |
20 | import com.panayotis.gnuplot.PropertiesHolder;
21 | import com.panayotis.gnuplot.style.PlotStyle;
22 | import com.panayotis.gnuplot.style.Smooth;
23 |
24 | /**
25 | * This is the base class of all plot objects. It is used to define the basic
26 | * characteristics of plot handling, such as definition and styles
27 | *
28 | * @author teras
29 | */
30 | public abstract class AbstractPlot extends PropertiesHolder implements Plot {
31 |
32 | private static int last_id = 0;
33 | private String definition = "";
34 | private PlotStyle style = null;
35 | private Smooth smooth = null;
36 |
37 | /**
38 | * General purpose constructor of a generic plot object
39 | */
40 | public AbstractPlot() {
41 | super(" ", "");
42 | setTitle("Datafile " + (++last_id));
43 | }
44 |
45 | /**
46 | * Set the plot definition for this plot object. It is the part that the
47 | * plot command parses.
48 | *
49 | * @param definition The string representing the plot definition.
50 | */
51 | protected void setDefinition(String definition) {
52 | this.definition = definition;
53 | }
54 |
55 | /**
56 | * Retrieve the definition of this Plot object. If styles or smoothing
57 | * engines were used, the appropriate arguments are appended
58 | *
59 | * @param buf The buffer to store the data set.
60 | */
61 | @Override
62 | public void retrieveDefinition(StringBuilder buf) {
63 | buf.append(definition);
64 | appendProperties(buf);
65 | if (smooth != null)
66 | buf.append(smooth.toString());
67 | if (style != null)
68 | style.appendProperties(buf);
69 | }
70 |
71 | /**
72 | * Set how this plot will be presented. Provide information about colors and
73 | * sizes, in accordance with the selected terminal. Give "null" if you want
74 | * to turn off this feature.
75 | *
76 | * @param style The style to use
77 | */
78 | public void setPlotStyle(PlotStyle style) {
79 | this.style = style;
80 | }
81 |
82 | /**
83 | * Retrieve the style of this Plot command
84 | *
85 | * @return The style being used
86 | */
87 | public PlotStyle getPlotStyle() {
88 | if (style == null)
89 | style = new PlotStyle();
90 | return style;
91 | }
92 |
93 | /**
94 | * Define if this plot should be smoothed.
95 | *
96 | * @param smooth The smooth definition. Give "null" if you want to turn off
97 | * this feature.
98 | */
99 | public void setSmooth(Smooth smooth) {
100 | this.smooth = smooth;
101 | }
102 |
103 | /**
104 | * A convenient method to set the title of this plot
105 | *
106 | * @param title The title to use for this plot
107 | */
108 | public final void setTitle(String title) {
109 | set("title", "\"" + title.replaceAll("[\"]", "\\\\\\\"") + "\"");
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/style/FillStyle.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on 26 Οκτώβριος 2007, 4:35 μμ
17 | */
18 | package com.panayotis.gnuplot.style;
19 |
20 | import com.panayotis.gnuplot.PropertiesHolder;
21 |
22 | /**
23 | * This object carries information on how to fill a specific graph
24 | *
25 | * @author teras
26 | */
27 | public class FillStyle extends PropertiesHolder {
28 |
29 | /**
30 | * Define the fill styles
31 | */
32 | public enum Fill {
33 |
34 | EMPTY, SOLID, PATTERN
35 | };
36 | private Fill style;
37 | private String params;
38 |
39 | /**
40 | * Create a new fill style object with default style
41 | */
42 | public FillStyle() {
43 | this(null);
44 | }
45 |
46 | /**
47 | * Create a new fill style object with a specific fill style
48 | *
49 | * @param style The style to use If it is null, then this graph will not be
50 | * filled.
51 | */
52 | @SuppressWarnings("OverridableMethodCallInConstructor")
53 | public FillStyle(Fill style) {
54 | super(" ", "");
55 | setStyle(style);
56 | }
57 |
58 | /**
59 | * Set the border type
60 | *
61 | * @param type An integer describing how the border will look like. This
62 | * parameter is terminal specific
63 | */
64 | public void setBorder(int type) {
65 | unset("noborder");
66 | set("border", String.valueOf(type));
67 | }
68 |
69 | /**
70 | * Remove the border of this graph
71 | */
72 | public void removeBorder() {
73 | unset("border");
74 | set("noborder");
75 | }
76 |
77 | /**
78 | * Set the density of this fill style
79 | *
80 | * @param density A number between 0 and 1
81 | */
82 | public void setDensity(float density) {
83 | setStyle(Fill.SOLID);
84 | params = String.valueOf(density);
85 | }
86 |
87 | /**
88 | * Set the fill pattern
89 | *
90 | * @param pattern An integer describing the fill pattern. This parameter is
91 | * terminal specific
92 | */
93 | public void setPattern(int pattern) {
94 | setStyle(Fill.PATTERN);
95 | params = String.valueOf(pattern);
96 | }
97 |
98 | /**
99 | * Set the fill style
100 | *
101 | * @param style The style to use. If it is null, then this graph will not be
102 | * filled.
103 | */
104 | public void setStyle(Fill style) {
105 | if (style == null) {
106 | style = Fill.EMPTY;
107 | params = "";
108 | }
109 | this.style = style;
110 | }
111 |
112 | /**
113 | * Retrieve information for this style. This method is used internally by
114 | * JavaPlot
115 | *
116 | * @param buf The String buffer to store information about this style
117 | */
118 | @Override
119 | public void appendProperties(StringBuilder buf) {
120 | buf.append(" fill ");
121 | buf.append(style.name().toLowerCase());
122 | if (!params.equals(""))
123 | buf.append(' ').append(params);
124 |
125 | super.appendProperties(buf);
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/utils/Debug.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 17, 2007, 3:01 PM
17 | */
18 | package com.panayotis.gnuplot.utils;
19 |
20 | import java.io.BufferedWriter;
21 | import java.io.IOException;
22 | import java.io.OutputStreamWriter;
23 | import java.io.Writer;
24 |
25 | /**
26 | * This object is responsible to display debug and/or general information on any
27 | * given Writer (by default to System.err)
28 | * .
29 | * It is possible to set another output writer, in order to redirect the errors
30 | * whenever the programmer wants.
31 | *
32 | * @author teras
33 | */
34 | public class Debug {
35 |
36 | /**
37 | * Absolutely no debug information is presented
38 | */
39 | public final static int QUIET = 0;
40 | /**
41 | * Only critical information is presented
42 | */
43 | public final static int CRITICAL = 10;
44 | /**
45 | * Only errors and critical information is presented
46 | */
47 | public final static int ERROR = 20;
48 | /**
49 | * Warnings, as well as errors and critical information is presented
50 | */
51 | public final static int WARNING = 30;
52 | /**
53 | * All messages except verbose messages are presented
54 | */
55 | public final static int INFO = 40;
56 | /**
57 | * All messages are presented
58 | */
59 | public final static int VERBOSE = 50;
60 | private static final String NL = System.getProperty("line.separator");
61 | private int level;
62 | private Writer out;
63 |
64 | /**
65 | * Creates a new instance of Debug
66 | */
67 | public Debug() {
68 | setLevel(WARNING);
69 | out = new BufferedWriter(new OutputStreamWriter(System.err));
70 | }
71 |
72 | /**
73 | * Set the level of verbosity.
74 | *
75 | * @param level Only messages at least as critical as this level are
76 | * presented.
77 | */
78 | public final void setLevel(int level) {
79 | this.level = level;
80 | }
81 |
82 | /**
83 | * Present a message on the Debug stream
84 | *
85 | * @param message Message to display. Automatically adds a newline at the
86 | * end of the string.
87 | * @param level Level of verbosity. If this level is les critical than the
88 | * desired level, the message is not displayed.
89 | */
90 | public void msg(String message, int level) {
91 | if (message == null || message.equals(""))
92 | return;
93 | if (level > QUIET && level <= this.level)
94 | try {
95 | out.write(message);
96 | if (!message.endsWith(NL))
97 | out.write(NL);
98 | out.flush();
99 | } catch (IOException ex) {
100 | System.out.println(ex.getMessage());
101 | }
102 | }
103 |
104 | /**
105 | * Set the output writer. By default this is the System.err stream.
106 | *
107 | * @param out The Debug stream writer.
108 | */
109 | public void setWriter(Writer out) {
110 | if (out == null)
111 | throw new NullPointerException("Debug: set of null output device.");
112 | this.out = out;
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/plot/Page.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.plot;
17 |
18 | import com.panayotis.gnuplot.layout.AutoGraphLayout;
19 | import com.panayotis.gnuplot.layout.GraphLayout;
20 | import com.panayotis.gnuplot.layout.LayoutMetrics;
21 | import java.util.ArrayList;
22 |
23 | /**
24 | * The data representation of a whole graph page
25 | *
26 | * @author teras
27 | */
28 | public class Page extends ArrayList {
29 |
30 | private static final long serialVersionUID = 6485013309125515984L;
31 | protected static final String NL = System.getProperty("line.separator");
32 | private String pagetitle;
33 | private GraphLayout layout;
34 |
35 | /**
36 | * Construct a new blank page with one graph inside
37 | */
38 | public Page() {
39 | this(false);
40 | }
41 |
42 | /**
43 | * Construct a new blank page with one graph inside
44 | *
45 | * @param isGraph3D true, if this graph is a 3D plot
46 | */
47 | public Page(boolean isGraph3D) {
48 | if (isGraph3D)
49 | add(new Graph3D());
50 | else
51 | add(new Graph());
52 | pagetitle = "";
53 | layout = new AutoGraphLayout();
54 | }
55 |
56 | /**
57 | * Get a reference for this page layout
58 | *
59 | * @return the layout used in this page
60 | */
61 | public GraphLayout getLayout() {
62 | return layout;
63 | }
64 |
65 | public void setLayout(GraphLayout layout) {
66 | this.layout = layout;
67 | }
68 |
69 | /**
70 | * Get the title of this page
71 | *
72 | * @return page title
73 | */
74 | public Object getTitle() {
75 | return pagetitle;
76 | }
77 |
78 | /**
79 | * Set the title of this page
80 | *
81 | * @param title the new page title
82 | */
83 | public void setTitle(String title) {
84 | if (title == null)
85 | title = "";
86 | pagetitle = title;
87 | }
88 |
89 | /**
90 | * Append the GNUPlot program which will construct this page, to a buffer.
91 | *
92 | * @param bf Buffer to store the gnuplot program
93 | */
94 | public void getGNUPlotPage(StringBuilder bf) {
95 | if (size() > 1) {
96 | /*
97 | * This is a multiplot
98 | */
99 |
100 | bf.append("set multiplot");
101 | if (!pagetitle.equals(""))
102 | bf.append(" title \"").append(pagetitle).append('"');
103 | layout.setDefinition(this, bf);
104 | bf.append(NL);
105 |
106 | LayoutMetrics metrics;
107 | for (Graph gr : this) {
108 | metrics = gr.getMetrics();
109 | if (metrics != null) {
110 | bf.append("set origin ").append(metrics.getX()).append(',').append(metrics.getY()).append(NL);
111 | bf.append("set size ").append(metrics.getWidth()).append(',').append(metrics.getHeight()).append(NL);
112 | }
113 | gr.retrieveData(bf);
114 | }
115 |
116 | bf.append("unset multiplot").append(NL);
117 | } else
118 | get(0).retrieveData(bf);
119 |
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/base/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | com.panayotis
7 | javaplot
8 | 0.5.0
9 | JavaPlot
10 | JavaPlot is a pure Java programming interface library for GNUPlot. It can be used as a way to create gnuplot plots on the fly through pure Java commands.
11 | http://javaplot.panayotis.com
12 |
13 |
14 |
15 | GNU Lesser General Public License, Version 2
16 | https://www.gnu.org/licenses/lgpl-2.0.html
17 |
18 |
19 |
20 |
21 |
22 | Panayotis Katsaloulis
23 | panayotis@panayotis.com
24 | http://www.panayotis.com
25 |
26 |
27 |
28 |
29 | scm:git:git://github.com/teras/JavaPlot.git
30 | scm:git:ssh://github.com/teras/JavaPlot.git
31 | http://github.com/teras/JavaPlot/tree/master
32 |
33 |
34 |
35 |
36 | ossrh
37 | https://oss.sonatype.org/content/repositories/snapshots
38 |
39 |
40 |
41 |
42 |
43 |
44 | org.sonatype.plugins
45 | nexus-staging-maven-plugin
46 | 1.6.7
47 | true
48 |
49 | ossrh
50 | https://oss.sonatype.org/
51 | false
52 |
53 |
54 |
55 | org.apache.maven.plugins
56 | maven-source-plugin
57 | 2.2.1
58 |
59 |
60 | attach-sources
61 |
62 | jar-no-fork
63 |
64 |
65 |
66 |
67 |
68 | org.apache.maven.plugins
69 | maven-javadoc-plugin
70 | 2.9.1
71 |
72 |
73 | attach-javadocs
74 |
75 | jar
76 |
77 |
78 |
79 |
80 |
81 | org.apache.maven.plugins
82 | maven-gpg-plugin
83 | 1.5
84 |
85 |
86 | sign-artifacts
87 | verify
88 |
89 | sign
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 | UTF-8
99 |
100 |
101 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/plot/DataSetPlot.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on 12 Οκτώβριος 2007, 4:07 μμ
17 | */
18 | package com.panayotis.gnuplot.plot;
19 |
20 | import com.panayotis.gnuplot.dataset.ArrayDataSet;
21 | import com.panayotis.gnuplot.dataset.DataSet;
22 | import com.panayotis.gnuplot.dataset.PointDataSet;
23 |
24 | /**
25 | * This plot uses data sets as coordinates of the points to e displayed. The
26 | * user can provide data either statically (through the specialized constructors
27 | * with native base types) or with the more flexible generic object
28 | * PointDataSet.
29 | *
30 | * @author teras
31 | */
32 | public class DataSetPlot extends AbstractPlot {
33 |
34 | private DataSet dataset;
35 |
36 | /**
37 | * Create a new data set with a default data set.
38 | */
39 | public DataSetPlot() {
40 | this(new PointDataSet());
41 | }
42 |
43 | /**
44 | * Create a new data set with the specified double-precision array as a data
45 | * set
46 | *
47 | * @param dataset A 2D double table with the data set
48 | */
49 | public DataSetPlot(double[][] dataset) {
50 | this(new ArrayDataSet(dataset));
51 | }
52 |
53 | /**
54 | * Create a new data set with the specified float-precision array as a data
55 | * set
56 | *
57 | * @param dataset A 2D float table with the data set
58 | */
59 | public DataSetPlot(float[][] dataset) {
60 | this(new ArrayDataSet(dataset));
61 | }
62 |
63 | /**
64 | * Create a new data set with the specified integer-precision array as a
65 | * data set
66 | *
67 | * @param dataset A 2D integer table with the data set
68 | */
69 | public DataSetPlot(int[][] dataset) {
70 | this(new ArrayDataSet(dataset));
71 | }
72 |
73 | /**
74 | * Create a new data set with the specified long-precision array as a data
75 | * set
76 | *
77 | * @param dataset A 2D long table with the data set
78 | */
79 | public DataSetPlot(long[][] dataset) {
80 | this(new ArrayDataSet(dataset));
81 | }
82 |
83 | /**
84 | * Create a new object with a specific data set
85 | *
86 | * @param dataset The data set to use
87 | */
88 | public DataSetPlot(DataSet dataset) {
89 | setDataSet(dataset);
90 | setDefinition("'-'");
91 | }
92 |
93 | /**
94 | * Retrieve the data set of this plot command. It is used internally by
95 | * JavaPlot library. Please do not use it.
96 | *
97 | * @param bf The buffer to store the data set
98 | */
99 | @Override
100 | public void retrieveData(StringBuilder bf) {
101 | int i, j;
102 | int isize, jsize;
103 |
104 | if (dataset != null) {
105 | isize = dataset.size();
106 | jsize = dataset.getDimensions();
107 | for (i = 0; i < isize; i++) {
108 | for (j = 0; j < jsize; j++)
109 | bf.append(dataset.getPointValue(i, j)).append(' ');
110 | bf.append(NL);
111 | }
112 | }
113 | bf.append("e").append(NL);
114 | }
115 |
116 | /**
117 | * Set the data set of this plot to the specified one
118 | *
119 | * @param set The data set to use
120 | */
121 | public final void setDataSet(DataSet set) {
122 | dataset = set;
123 | }
124 |
125 | /**
126 | * Retrieve the data set of this plot
127 | *
128 | * @return The data set of this plot
129 | */
130 | public DataSet getDataSet() {
131 | return dataset;
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/plot/Graph.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.plot;
17 |
18 | import com.panayotis.gnuplot.layout.LayoutMetrics;
19 | import java.util.ArrayList;
20 | import java.util.HashMap;
21 |
22 | /**
23 | * Graph objects are parts of a multi-plot drawing. Each graph contains other
24 | * plots which share the same axis. All gnuplot objects have at least one graph
25 | * object.
26 | *
27 | * For single plots, better have a look at Plot objects and GNUPlot.addPlot()
28 | * command
29 | *
30 | * @author teras
31 | */
32 | public class Graph extends ArrayList {
33 |
34 | protected static final String NL = System.getProperty("line.separator");
35 | private final HashMap axis;
36 | private LayoutMetrics metrics;
37 |
38 | /**
39 | * Create a new graph object
40 | */
41 | public Graph() {
42 | axis = new HashMap();
43 | axis.put("x", new Axis("x"));
44 | axis.put("y", new Axis("y"));
45 | axis.put("z", new Axis("z"));
46 | metrics = null;
47 | }
48 |
49 | /**
50 | * Get one of the available Axis, in order to set some parameters on it.
51 | *
52 | * @param axisname The name of the Axis. It is usually "x", "y", "z"
53 | * @return The desired Axis
54 | */
55 | public Axis getAxis(String axisname) {
56 | if (axisname == null)
57 | return null;
58 | return axis.get(axisname.toLowerCase());
59 | }
60 |
61 | /**
62 | * Add a new plot to this plot group. At least one plot is needed to produce
63 | * visual results.
64 | *
65 | * @param plot The given plot.
66 | */
67 | public void addPlot(Plot plot) {
68 | if (plot != null)
69 | add(plot);
70 | }
71 |
72 | /**
73 | * Get gnuplot commands for this graph.
74 | *
75 | * @param bf
76 | */
77 | void retrieveData(StringBuilder bf) {
78 | /*
79 | * Do not append anything, if this graph is empty
80 | */
81 | if (size() == 0)
82 | return;
83 |
84 | /*
85 | * Set various axis parameters
86 | */
87 | for (Axis ax : axis.values())
88 | ax.appendProperties(bf);
89 |
90 | /*
91 | * Create data plots
92 | */
93 | bf.append(getPlotCommand()); // Use the corresponding plot command
94 | /*
95 | * Add plot definitions
96 | */
97 | for (Plot p : this) {
98 | bf.append(' ');
99 | p.retrieveDefinition(bf);
100 | bf.append(',');
101 | }
102 | bf.deleteCharAt(bf.length() - 1).append(NL);
103 | /*
104 | * Add plot data (if any)
105 | */
106 | for (Plot p : this)
107 | p.retrieveData(bf);
108 | }
109 |
110 | /**
111 | * Set the position and size of thie graph object, relative to a 0,0-1,1
112 | * page
113 | *
114 | * @param x horizontal position
115 | * @param y vertical position
116 | * @param width width of this graph
117 | * @param height of this graph
118 | */
119 | public void setMetrics(float x, float y, float width, float height) {
120 | metrics = new LayoutMetrics(x, y, width, height);
121 | }
122 |
123 | /**
124 | * Get the positioning and size of this graph object
125 | *
126 | * @return The metrics of this object
127 | */
128 | public LayoutMetrics getMetrics() {
129 | return metrics;
130 | }
131 |
132 | /**
133 | * Get the actual gnuplot command to initiate the plot.
134 | *
135 | * @return This method always returns "plot"
136 | */
137 | protected String getPlotCommand() {
138 | return "plot";
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/svg/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | com.panayotis.javaplot
7 | svg
8 | 0.5.0
9 | JavaPlot SVG
10 | JavaPlot is a pure Java programming interface library for GNUPlot. It can be used as a way to create gnuplot plots on the fly through pure Java commands.
11 | http://javaplot.panayotis.com
12 |
13 |
14 |
15 | com.panayotis
16 | javaplot
17 | ${project.version}
18 |
19 |
20 | com.kitfox
21 | svgSalamander
22 | 1.1.2
23 |
24 |
25 |
26 |
27 |
28 | GNU Lesser General Public License, Version 2
29 | https://www.gnu.org/licenses/lgpl-2.0.html
30 |
31 |
32 |
33 |
34 |
35 | Panayotis Katsaloulis
36 | panayotis@panayotis.com
37 | http://www.panayotis.com
38 |
39 |
40 |
41 |
42 | scm:git:git://github.com/teras/JavaPlot.git
43 | scm:git:ssh://github.com/teras/JavaPlot.git
44 | http://github.com/teras/JavaPlot/tree/master
45 |
46 |
47 |
48 |
49 | ossrh
50 | https://oss.sonatype.org/content/repositories/snapshots
51 |
52 |
53 |
54 |
55 |
56 |
57 | org.sonatype.plugins
58 | nexus-staging-maven-plugin
59 | 1.6.7
60 | true
61 |
62 | ossrh
63 | https://oss.sonatype.org/
64 | false
65 |
66 |
67 |
68 | org.apache.maven.plugins
69 | maven-source-plugin
70 | 2.2.1
71 |
72 |
73 | attach-sources
74 |
75 | jar-no-fork
76 |
77 |
78 |
79 |
80 |
81 | org.apache.maven.plugins
82 | maven-javadoc-plugin
83 | 2.9.1
84 |
85 |
86 | attach-javadocs
87 |
88 | jar
89 |
90 |
91 |
92 |
93 |
94 | org.apache.maven.plugins
95 | maven-gpg-plugin
96 | 1.5
97 |
98 |
99 | sign-artifacts
100 | verify
101 |
102 | sign
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 | UTF-8
112 |
113 |
114 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/layout/AutoGraphLayout.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.layout;
17 |
18 | import com.panayotis.gnuplot.plot.Page;
19 | import java.io.Serializable;
20 |
21 | /**
22 | * Align graphs evenly on the page, in a grid layout, based on
23 | *
24 | * If you manually set metrics and use this, these metrics will be lost
25 | *
26 | * @author teras
27 | */
28 | public class AutoGraphLayout implements GraphLayout, Serializable {
29 |
30 | /**
31 | * Orientation of the graph layout
32 | */
33 | public static final boolean DOWNWARDS = true, UPWARDS = false;
34 | /**
35 | * Draw rows or columns first
36 | */
37 | public static final boolean ROWSFIRST = true, COLUMNSFIRST = false;
38 | private boolean orientation;
39 | private boolean drawfirst;
40 | private int rows, cols;
41 |
42 | /**
43 | * Create a new automatic grid layout. Default values are ROWSFIRST,
44 | * DOWNWARDS, automatic layout of components
45 | */
46 | public AutoGraphLayout() {
47 | drawfirst = ROWSFIRST;
48 | orientation = DOWNWARDS;
49 | rows = -1;
50 | cols = -1;
51 | }
52 |
53 | /**
54 | * Set where the first graph will be put
55 | *
56 | * @param drawfirst Position of the first graph
57 | * @see #ROWSFIRST
58 | * @see #COLUMNSFIRST
59 | */
60 | public void setDrawFirst(boolean drawfirst) {
61 | this.drawfirst = drawfirst;
62 | }
63 |
64 | /**
65 | * Sey the orientation of the graphs, as being put
66 | *
67 | * @param orientation Selected orientation
68 | * @see #DOWNWARDS
69 | * @see #UPWARDS
70 | */
71 | public void setOrientation(boolean orientation) {
72 | this.orientation = orientation;
73 | }
74 |
75 | /**
76 | * Manually set the number of rows. This method overrides the automatic
77 | * component layout.
78 | *
79 | * @param rows Desired number of rows. Set it to -1 to be automatically
80 | * computed.
81 | */
82 | public void setRows(int rows) {
83 | this.rows = rows;
84 | }
85 |
86 | /**
87 | * Manually set the number of columns. This method overrides the automatic
88 | * component layout.
89 | *
90 | * @param cols Desired number of columns. Set it to -1 to be automatically
91 | * computed.
92 | */
93 | public void setColumns(int cols) {
94 | this.cols = cols;
95 | }
96 |
97 | private int getOtherDimension(int size, int dim) {
98 | return (int) Math.ceil((double) size / dim);
99 | }
100 |
101 | /**
102 | * Update the capacity of this layout. This manager creates a grid, as much
103 | * square as possible, if automatic layout is wanted.
104 | *
105 | * @param page The page with the elements we would like to position
106 | * @param buffer Where to send commands, just after the "set multiplot"
107 | * part.
108 | */
109 | @Override
110 | public void setDefinition(Page page, StringBuilder buffer) {
111 | int size = page.size();
112 |
113 | if (size <= 0)
114 | return;
115 |
116 | int drawcols, drawrows;
117 | if (cols > 0 && rows > 0) {
118 | drawcols = cols;
119 | drawrows = rows;
120 | } else if (cols > 0) {
121 | drawcols = cols;
122 | drawrows = getOtherDimension(size, drawcols);
123 | } else if (rows > 0) {
124 | drawrows = rows;
125 | drawcols = getOtherDimension(size, drawrows);
126 | } else {
127 | drawrows = (int) (Math.floor(Math.sqrt(size)));
128 | drawcols = getOtherDimension(size, drawrows);
129 | }
130 |
131 | buffer.append(" layout ");
132 | buffer.append(drawrows).append(',').append(drawcols);
133 |
134 | if (drawfirst == ROWSFIRST)
135 | buffer.append(" rowsfirst");
136 | else
137 | buffer.append(" columnsfirst");
138 |
139 | if (orientation == DOWNWARDS)
140 | buffer.append(" downwards");
141 | else
142 | buffer.append(" upwards");
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/dataset/GenericDataSet.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | */
16 | package com.panayotis.gnuplot.dataset;
17 |
18 | import com.panayotis.gnuplot.dataset.parser.DataParser;
19 | import com.panayotis.gnuplot.dataset.parser.DoubleDataParser;
20 | import java.io.Serializable;
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | /**
25 | * Generic data class to store data. This class stores data as a list of
26 | * Strings, not numbers. Still, the user can check if the data are valid, by
27 | * using a specific DataParser for this object.
28 | * In this dataset one can use any type of data, while in PointDataSet the data
29 | * are stricted to numerical data only. Thus, data such as dates can be used.
30 | *
31 | * @see com.panayotis.gnuplot.dataset.parser.DataParser
32 | * @see com.panayotis.gnuplot.dataset.PointDataSet
33 | * @author teras
34 | */
35 | public class GenericDataSet implements DataSet, Serializable {
36 |
37 | private final DataParser parser;
38 | private List> data;
39 |
40 | /**
41 | * Create a new instance of GenericDataSet, with the default DataParser
42 | * (DoubleDataParser)
43 | *
44 | * @see com.panayotis.gnuplot.dataset.parser.DoubleDataParser
45 | */
46 | public GenericDataSet() {
47 | this(new DoubleDataParser());
48 | }
49 |
50 | /**
51 | * Create a new instance of GenericDataSet, with the default DataParser
52 | * (DoubleDataParser), and the information that the first column is in date
53 | * format.
54 | *
55 | * @param first_column_date Whether the first column is in date format
56 | */
57 | public GenericDataSet(boolean first_column_date) {
58 | this(new DoubleDataParser(first_column_date));
59 | }
60 |
61 | /**
62 | * Create a new instance of GenericDataSet, with a given DataParser
63 | *
64 | * @param parser The DataParser to use
65 | */
66 | public GenericDataSet(DataParser parser) {
67 | this.parser = parser;
68 | data = new ArrayList>();
69 | }
70 |
71 | @Override
72 | public int size() {
73 | return data.size();
74 | }
75 |
76 | /**
77 | * Retrieve how many dimensions this dataset refers to.
78 | *
79 | * @return the number of dimensions
80 | * @see DataSet#getDimensions()
81 | */
82 | @Override
83 | public int getDimensions() {
84 | if (size() < 1)
85 | return -1;
86 | return data.get(0).size();
87 | }
88 |
89 | /**
90 | * Retrieve data information from a point.
91 | *
92 | * @param point The point number
93 | * @param dimension The point dimension (or "column") to request data from
94 | * @return the point data for this dimension
95 | * @see DataSet#getPointValue(int,int)
96 | */
97 | @Override
98 | public String getPointValue(int point, int dimension) {
99 | return data.get(point).get(dimension);
100 | }
101 |
102 | /**
103 | * Add a new point to this DataSet
104 | *
105 | * @param point The point to add to this DataSet
106 | * @return Whether the collection changed with this call
107 | * @throws java.lang.NumberFormatException If the given collection is not in
108 | * the correct format
109 | */
110 | public boolean add(List point) throws NumberFormatException {
111 | checkData(point, getDimensions());
112 | return data.add(point);
113 | }
114 |
115 | private int checkData(List point, int old_dim) throws NumberFormatException {
116 | int new_dim = point.size();
117 | if (old_dim < 0)
118 | old_dim = new_dim; // if the array is still empty, any size is good size
119 | if (old_dim != new_dim)
120 | throw new ArrayIndexOutOfBoundsException("Point inserted differs in dimension: found " + new_dim + ", requested " + old_dim);
121 | for (int i = 0; i < point.size(); i++)
122 | if (!parser.isValid(point.get(i), i))
123 | throw new NumberFormatException("The point added with value \"" + point.get(i) + "\" and index " + i + " is not valid with parser " + parser.getClass().getName());
124 | return old_dim;
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/style/PlotStyle.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on 26 Οκτώβριος 2007, 2:58 μμ
17 | */
18 | package com.panayotis.gnuplot.style;
19 |
20 | import com.panayotis.gnuplot.PropertiesHolder;
21 |
22 | /**
23 | * This object represents the styles which can be used in gnuplot to personalize
24 | * each prot
25 | *
26 | * @author teras
27 | */
28 | public class PlotStyle extends PropertiesHolder {
29 |
30 | private Style type;
31 | private FillStyle fill;
32 |
33 | /**
34 | * Creates a new instance of PlotStyle with default parameters
35 | */
36 | public PlotStyle() {
37 | this(null);
38 | }
39 |
40 | /**
41 | * Creates a new instance of PlotStyle with a specified style
42 | *
43 | * @param style The style to use
44 | */
45 | @SuppressWarnings("OverridableMethodCallInConstructor")
46 | public PlotStyle(Style style) {
47 | super(" ", "");
48 | fill = null;
49 | setStyle(style);
50 | }
51 |
52 | /**
53 | * Set the current style to the given one
54 | *
55 | * @param style the style to use
56 | */
57 | public void setStyle(Style style) {
58 | this.type = style;
59 | }
60 |
61 | /**
62 | * Gather the properties of this style. This method is used internally by
63 | * GNUPlot
64 | *
65 | * @param buf The Srting buffer to store this object's properties.
66 | */
67 | @Override
68 | public void appendProperties(StringBuilder buf) {
69 | if (type != null) {
70 | buf.append(" with ").append(type.name().toLowerCase());
71 | super.appendProperties(buf);
72 |
73 | if (fill != null && type.filled)
74 | fill.appendProperties(buf);
75 | }
76 | }
77 |
78 | /**
79 | * Set the line width of this graph
80 | *
81 | * @param width The line width. If this number is less than zero, then the
82 | * default parameter will be used
83 | */
84 | public void setLineWidth(int width) {
85 | if (width < 0)
86 | unset("linewidth");
87 | else
88 | set("linewidth", String.valueOf(width));
89 | }
90 |
91 | /**
92 | * Set the point size of this graph
93 | *
94 | * @param width The point size. If this number is less than zero, then the
95 | * default parameter will be used
96 | */
97 | public void setPointSize(int width) {
98 | if (width < 0)
99 | unset("pointsize");
100 | else
101 | set("pointsize", String.valueOf(width));
102 | }
103 |
104 | /**
105 | * Set the line type of this graph. This option is terminal dependent.
106 | *
107 | * @param type The line type. If this number is less than zero, then the
108 | * default parameter will be used
109 | */
110 | public void setLineType(int type) {
111 | if (type < -1)
112 | unset("linetype");
113 | else
114 | set("linetype", String.valueOf(type));
115 | }
116 |
117 | /**
118 | * Set the line type of this graph to be a specific color. This option is
119 | * terminal dependent.
120 | *
121 | * @param col The color to use. If this parameter is null, then the default
122 | * parameter will be used.
123 | */
124 | public void setLineType(PlotColor col) {
125 | if (col == null)
126 | unset("linetype");
127 | else
128 | set("linetype", col.getColor());
129 | }
130 |
131 | /**
132 | * Set the point type of this graph. This option is terminal dependent.
133 | *
134 | * @param type The point type. If this number is less than zero, then the
135 | * default parameter will be used
136 | */
137 | public void setPointType(int type) {
138 | if (type < -1)
139 | unset("pointtype");
140 | else
141 | set("pointtype", String.valueOf(type));
142 | }
143 |
144 | /**
145 | * Set the fill style of this graph. If the desired style does not support
146 | * fill then this parameter will be ignored.
147 | *
148 | * @param fillstyle The fill style to use. If this parameter is null, then
149 | * the default parameter will be used.
150 | */
151 | public void setFill(FillStyle fillstyle) {
152 | this.fill = fillstyle;
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/dataset/ArrayDataSet.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on 15 Οκτώβριος 2007, 12:29 μμ
17 | */
18 | package com.panayotis.gnuplot.dataset;
19 |
20 | import java.io.Serializable;
21 |
22 | /**
23 | * Store data sets in a static primitive 2D array
24 | *
25 | * @author teras
26 | */
27 | public class ArrayDataSet implements DataSet, Serializable {
28 |
29 | private String[][] val;
30 |
31 | /**
32 | * Creates a new instance of ArrayDataSet from a double precision 2D array
33 | *
34 | * @param values the 2D array in double precision to retrieve data from
35 | */
36 | public ArrayDataSet(double[][] values) {
37 | int length = values.length;
38 | int dimension = values[0].length;
39 | int i, j;
40 |
41 | if (length == 0)
42 | throw new ArrayStoreException("Array has zero points");
43 | val = new String[length][dimension];
44 | for (i = 0; i < length; i++) {
45 | if (values[i].length != dimension)
46 | throw new ArrayStoreException("Array has not consistent size, was " + dimension + ", found " + values[i].length);
47 | for (j = 0; j < dimension; j++)
48 | val[i][j] = Double.toString(values[i][j]);
49 | }
50 | }
51 |
52 | /**
53 | * Creates a new instance of ArrayDataSet from a float precision 2D array
54 | *
55 | * @param values the 2D array in float precision to retrieve data from
56 | */
57 | public ArrayDataSet(float[][] values) {
58 | int length = values.length;
59 | int dimension = values[0].length;
60 | int i, j;
61 |
62 | if (length == 0)
63 | throw new ArrayStoreException("Array has zero points");
64 | val = new String[length][dimension];
65 | for (i = 0; i < length; i++) {
66 | if (values[i].length != dimension)
67 | throw new ArrayStoreException("Array has not consistent size, was " + dimension + ", found " + values[i].length);
68 | for (j = 0; j < dimension; j++)
69 | val[i][j] = Float.toString(values[i][j]);
70 | }
71 | }
72 |
73 | /**
74 | * Creates a new instance of ArrayDataSet from a int precision 2D array
75 | *
76 | * @param values the 2D array in int precision to retrieve data from
77 | */
78 | public ArrayDataSet(int[][] values) {
79 | int length = values.length;
80 | int dimension = values[0].length;
81 | int i, j;
82 |
83 | if (length == 0)
84 | throw new ArrayStoreException("Array has zero points");
85 | val = new String[length][dimension];
86 | for (i = 0; i < length; i++) {
87 | if (values[i].length != dimension)
88 | throw new ArrayStoreException("Array has not consistent size, was " + dimension + ", found " + values[i].length);
89 | for (j = 0; j < dimension; j++)
90 | val[i][j] = Integer.toString(values[i][j]);
91 | }
92 | }
93 |
94 | /**
95 | * Creates a new instance of ArrayDataSet from a long precision 2D array
96 | *
97 | * @param values the 2D array in long precision to retrieve data from
98 | */
99 | public ArrayDataSet(long[][] values) {
100 | int length = values.length;
101 | int dimension = values[0].length;
102 | int i, j;
103 |
104 | if (length == 0)
105 | throw new ArrayStoreException("Array has zero points");
106 | val = new String[length][dimension];
107 | for (i = 0; i < length; i++) {
108 | if (values[i].length != dimension)
109 | throw new ArrayStoreException("Array has not consistent size, was " + dimension + ", found " + values[i].length);
110 | for (j = 0; j < dimension; j++)
111 | val[i][j] = Long.toString(values[i][j]);
112 | }
113 | }
114 |
115 | /**
116 | * Creates a new instance of ArrayDataSet from a String 2D array. No check
117 | * on the data format is performed, can store any kind of value. Do not use
118 | * this method.
119 | *
120 | * @deprecated
121 | * @param values the 2D array in String format to retrieve data from
122 | */
123 | public ArrayDataSet(String[][] values) {
124 | int length = values.length;
125 | int dimension = values[0].length;
126 | int i, j;
127 |
128 | if (length == 0)
129 | throw new ArrayStoreException("Array has zero points");
130 | val = new String[length][dimension];
131 | for (i = 0; i < length; i++) {
132 | if (values[i].length != dimension)
133 | throw new ArrayStoreException("Array has not consistent size, was " + dimension + ", found " + values[i].length);
134 | System.arraycopy(values, 0, val, 0, values.length);
135 | }
136 | }
137 |
138 | /**
139 | * Retrieve how many points this data set has.
140 | *
141 | * @return the number of points
142 | */
143 | @Override
144 | public int size() {
145 | return val.length;
146 | }
147 |
148 | /**
149 | * Retrieve how many dimensions this dataset refers to.
150 | *
151 | * @return the number of dimensions
152 | * @see DataSet#getDimensions()
153 | */
154 | @Override
155 | public int getDimensions() {
156 | if (val[0] == null)
157 | return -1;
158 | return val[0].length;
159 | }
160 |
161 | /**
162 | * Retrieve data information from a point.
163 | *
164 | * @param point The point number
165 | * @param dimension The point dimension (or "column") to request data from
166 | * @return the point data for this dimension
167 | * @see DataSet#getPointValue(int,int)
168 | */
169 | @Override
170 | public String getPointValue(int point, int dimension) {
171 | return val[point][dimension];
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/base/src/test/java/com/panayotis/gnuplot/demo/BaseDemo.java:
--------------------------------------------------------------------------------
1 | package com.panayotis.gnuplot.demo;
2 |
3 | /* Copyright (c) 2007-2014 by panayotis.com
4 | *
5 | * JavaPlot is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, version 2.
8 | *
9 | * JavaPlot is free in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with CrossMobile; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 | import com.panayotis.gnuplot.GNUPlotParameters;
19 | import com.panayotis.gnuplot.JavaPlot;
20 | import com.panayotis.gnuplot.dataset.FileDataSet;
21 | import com.panayotis.gnuplot.layout.StripeLayout;
22 | import com.panayotis.gnuplot.plot.AbstractPlot;
23 | import com.panayotis.gnuplot.plot.DataSetPlot;
24 | import com.panayotis.gnuplot.style.NamedPlotColor;
25 | import com.panayotis.gnuplot.style.PlotStyle;
26 | import com.panayotis.gnuplot.style.Style;
27 | import com.panayotis.gnuplot.swing.JPlot;
28 | import com.panayotis.gnuplot.terminal.PostscriptTerminal;
29 | import com.panayotis.gnuplot.utils.Debug;
30 | import java.io.File;
31 | import java.io.FileInputStream;
32 | import java.io.FileOutputStream;
33 | import java.io.IOException;
34 | import java.io.ObjectInputStream;
35 | import java.io.ObjectOutputStream;
36 | import javax.swing.JFrame;
37 |
38 | /**
39 | * This Object is used to demonstrate JavaPlot library
40 | *
41 | * @author teras
42 | */
43 | public class BaseDemo {
44 |
45 | /**
46 | * @param args the command line arguments. First argument is the path of
47 | * gnuplot application
48 | */
49 | public static void main(String[] args) {
50 | String path = null;
51 | if (args.length > 0)
52 | path = args[0];
53 |
54 | //simple();
55 | //simple3D();
56 | // defaultTerminal(path);
57 | // EPSTerminal(path);
58 | // SVGTerminal(path);
59 | JPlotTerminal(path);
60 | //serialization(defaultTerminal(path));
61 | //file();
62 |
63 | }
64 |
65 | /* This is a very simple plot to demonstrate JavaPlot graphs */
66 | private static void simple() {
67 | JavaPlot p = new JavaPlot();
68 | p.addPlot("sin(x)");
69 | p.plot();
70 | }
71 |
72 | /* This is a very simple plot to demonstrate JavaPlot 3d graphs */
73 | private static void simple3D() {
74 | JavaPlot p = new JavaPlot(true);
75 | p.addPlot("sin(x)*y");
76 | p.plot();
77 | }
78 |
79 | /* This demo code uses default terminal. Use it as reference for other javaplot arguments */
80 | private static JavaPlot defaultTerminal(String gnuplotpath) {
81 | JavaPlot p = new JavaPlot(gnuplotpath);
82 | JavaPlot.getDebugger().setLevel(Debug.VERBOSE);
83 |
84 | p.setTitle("Default \"Terminal Title\"");
85 | p.getAxis("x").setLabel("X axis", "Arial", 20);
86 | p.getAxis("y").setLabel("Y axis");
87 |
88 | p.getAxis("x").setBoundaries(-30, 20);
89 | p.setKey(JavaPlot.Key.TOP_RIGHT);
90 |
91 | double[][] plot = {{1, 1.1}, {2, 2.2}, {3, 3.3}, {4, 4.3}};
92 | DataSetPlot s = new DataSetPlot(plot);
93 | p.addPlot(s);
94 | p.addPlot("besj0(x)*0.12e1");
95 | PlotStyle stl = ((AbstractPlot) p.getPlots().get(1)).getPlotStyle();
96 | stl.setStyle(Style.POINTS);
97 | stl.setLineType(NamedPlotColor.GOLDENROD);
98 | stl.setPointType(5);
99 | stl.setPointSize(8);
100 | p.addPlot("sin(x)");
101 |
102 | p.newGraph();
103 | p.addPlot("sin(x)");
104 |
105 | p.newGraph3D();
106 | double[][] plot3d = {{1, 1.1, 3}, {2, 2.2, 3}, {3, 3.3, 3.4}, {4, 4.3, 5}};
107 | p.addPlot(plot3d);
108 |
109 | p.newGraph3D();
110 | p.addPlot("sin(x)*sin(y)");
111 |
112 | p.setMultiTitle("Global test title");
113 | StripeLayout lo = new StripeLayout();
114 | lo.setColumns(9999);
115 | p.getPage().setLayout(lo);
116 | p.plot();
117 |
118 | return p;
119 | }
120 |
121 | /* This demo code creates a EPS file on home directory */
122 | private static JavaPlot EPSTerminal(String gnuplotpath) {
123 | JavaPlot p = new JavaPlot();
124 |
125 | PostscriptTerminal epsf = new PostscriptTerminal(System.getProperty("user.home")
126 | + System.getProperty("file.separator") + "output.eps");
127 | epsf.setColor(true);
128 | p.setTerminal(epsf);
129 |
130 | p.setTitle("Postscript Terminal Title");
131 | p.addPlot("sin (x)");
132 | p.addPlot("sin(x)*cos(x)");
133 | p.newGraph();
134 | p.addPlot("cos(x)");
135 | p.setTitle("Trigonometric functions -1");
136 | p.setMultiTitle("Trigonometric functions");
137 | p.plot();
138 | return p;
139 | }
140 |
141 | /* This demo code displays plot on screen using image terminal */
142 | private static JavaPlot JPlotTerminal(String gnuplotpath) {
143 | JPlot plot = new JPlot();
144 | plot.getJavaPlot().addPlot("sqrt(x)/x");
145 | plot.getJavaPlot().addPlot("x*sin(x)");
146 | plot.plot();
147 |
148 | JFrame f = new JFrame();
149 | f.getContentPane().add(plot);
150 | f.pack();
151 | f.setLocationRelativeTo(null);
152 | f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
153 | f.setVisible(true);
154 |
155 | return plot.getJavaPlot();
156 | }
157 |
158 | private static void serialization(JavaPlot p) {
159 | ObjectOutputStream out = null;
160 | ObjectInputStream in = null;
161 | try {
162 | out = new ObjectOutputStream(new FileOutputStream("koko.lala"));
163 | out.writeObject(p.getParameters());
164 |
165 | in = new ObjectInputStream(new FileInputStream("koko.lala"));
166 | JavaPlot q = new JavaPlot((GNUPlotParameters) in.readObject());
167 | q.plot();
168 | } catch (ClassNotFoundException ex) {
169 | ex.printStackTrace();
170 | } catch (IOException ex) {
171 | ex.printStackTrace();
172 | } finally {
173 | try {
174 | out.close();
175 | } catch (IOException ex) {
176 | ex.printStackTrace();
177 | }
178 | }
179 | }
180 |
181 |
182 | /* This is a simple plot to demonstrate file datasets */
183 | private static void file() {
184 | try {
185 | JavaPlot p = new JavaPlot();
186 | p.addPlot(new FileDataSet(new File("lala")));
187 | p.plot();
188 | } catch (IOException ex) {
189 | ex.printStackTrace();
190 | }
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/GNUPlotParameters.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 13, 2007, 4:02 PM
17 | */
18 | package com.panayotis.gnuplot;
19 |
20 | import com.panayotis.gnuplot.layout.GraphLayout;
21 | import com.panayotis.gnuplot.plot.Axis;
22 | import com.panayotis.gnuplot.plot.Graph;
23 | import com.panayotis.gnuplot.plot.Graph3D;
24 | import com.panayotis.gnuplot.plot.Page;
25 | import com.panayotis.gnuplot.plot.Plot;
26 | import com.panayotis.gnuplot.terminal.GNUPlotTerminal;
27 | import java.io.Serializable;
28 | import java.util.ArrayList;
29 | import java.util.List;
30 |
31 | /**
32 | * This is a placeholder for the parameters used to create the actual plot.
33 | *
34 | * @author teras
35 | */
36 | public class GNUPlotParameters extends PropertiesHolder implements Serializable {
37 |
38 | private Page page;
39 | private int defaultgraph;
40 | private List preinit;
41 | private List postinit;
42 |
43 | /**
44 | * Create a new plot with the default parameters
45 | */
46 | public GNUPlotParameters() {
47 | }
48 |
49 | /**
50 | * Create a new plot with the default parameters
51 | *
52 | * @param isGraph3D Whether this plot is a Graph3D
53 | */
54 | public GNUPlotParameters(boolean isGraph3D) {
55 | page = new Page(isGraph3D);
56 | defaultgraph = 0;
57 |
58 | preinit = new ArrayList();
59 | postinit = new ArrayList();
60 | }
61 |
62 | /**
63 | * Get one of the available Axis from default Graph, in order to set some
64 | * parameters on it.
65 | *
66 | * @param axisname The name of the Axis. It is usually "x", "y", "z"
67 | * @return The desired Axis
68 | */
69 | public Axis getAxis(String axisname) {
70 | return page.get(defaultgraph).getAxis(axisname);
71 | }
72 |
73 | /**
74 | * This list is used to add special commands to gnuplot, before the
75 | * automatically generated from this library. It is a convenient method to
76 | * send unsupported commands to gnuplot at the beginning of the program.
77 | *
78 | * @return The list of the initialization commands
79 | */
80 | public List getPreInit() {
81 | return preinit;
82 | }
83 |
84 | /**
85 | * This list is used to add special commands to gnuplot, after the
86 | * automatically generated from this library. It is a convenient method to
87 | * send unsupported commands to gnuplot at the end of the program, just
88 | * before the final plot command.
89 | *
90 | * @return he list of the post initialization commands
91 | */
92 | public List getPostInit() {
93 | return postinit;
94 | }
95 |
96 | /**
97 | * Add a new plot to the default plot group. At least one plot is needed to
98 | * produce visual results.
99 | *
100 | * @param plot The given plot.
101 | */
102 | public void addPlot(Plot plot) {
103 | page.get(defaultgraph).add(plot);
104 | }
105 |
106 | /**
107 | * Add a new Graph object. This method is used to create a multiplot graph.
108 | * Every "plot" command corresponds to a different Graph object. In order to
109 | * draw to a new plot gnuplot object, create a new page.
110 | *
111 | * @see #newGraph3D()
112 | */
113 | public void newGraph() {
114 | addGraph(new Graph());
115 | }
116 |
117 | /**
118 | * Add a new Graph3D object. This method is used to create a multiplot
119 | * graph. Every "splot" command corresponds to a different Graph object. In
120 | * order to draw to a new plot gnuplot object, create a new page.
121 | *
122 | * @see #newGraph()
123 | */
124 | public void newGraph3D() {
125 | addGraph(new Graph3D());
126 | }
127 |
128 | /**
129 | * Add a defined graph.
130 | *
131 | * @param gr Graph object to be added
132 | * @see #newGraph()
133 | */
134 | public void addGraph(Graph gr) {
135 | page.add(gr);
136 | defaultgraph = page.size() - 1;
137 | }
138 |
139 | /**
140 | * Set the title of all graph objects, in multiplot environment.
141 | *
142 | * @param title The title to use
143 | */
144 | public void setMultiTitle(String title) {
145 | page.setTitle(title);
146 | }
147 |
148 | /**
149 | * Get the current layout of this plot object
150 | *
151 | * @return The used layout
152 | */
153 | GraphLayout getLayout() {
154 | return page.getLayout();
155 | }
156 |
157 | /**
158 | * Retrieve the whole page object, defining the various graph plots
159 | *
160 | * @return the Page object which holds all plots
161 | */
162 | public Page getPage() {
163 | return page;
164 | }
165 |
166 | /**
167 | * Get the list of the stored plots from default graph
168 | *
169 | * @return List of Plot objects
170 | */
171 | public List getPlots() {
172 | return page.get(defaultgraph);
173 | }
174 |
175 | /**
176 | * Get the actual GNUPlot commands. This method is used to construct the
177 | * gnuplot program
178 | *
179 | * @param term The terminal to use
180 | * @return The GNUPlot program
181 | */
182 | String getPlotCommands(GNUPlotTerminal term) {
183 | StringBuilder bf = new StringBuilder();
184 |
185 | /*
186 | * First execute pre-init commands
187 | */
188 | for (String com : preinit)
189 | bf.append(com).append(NL);
190 |
191 | /*
192 | * Gather various "set" parameters
193 | */
194 | appendProperties(bf);
195 |
196 | /*
197 | * Set Terminal (and it's parameters)
198 | */
199 | if (!term.getType().equals(""))
200 | bf.append("set term ").append(term.getType()).append(NL);
201 | if (!term.getOutputFile().equals(""))
202 | bf.append("set output \'").append(term.getOutputFile()).append("\'").append(NL);
203 |
204 |
205 | /*
206 | * We are almost ready. Before executing the actual plot command, issue
207 | * the post-init commands
208 | */
209 | for (String com : postinit)
210 | bf.append(com).append(NL);
211 |
212 | /*
213 | * Append various plots
214 | */
215 | page.getGNUPlotPage(bf);
216 |
217 | /*
218 | * Finish!
219 | */
220 | bf.append("quit").append(NL);
221 |
222 | return bf.toString();
223 | }
224 | }
225 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/JavaPlot.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 19, 2007, 1:11 AM
17 | */
18 | package com.panayotis.gnuplot;
19 |
20 | import com.panayotis.gnuplot.dataset.DataSet;
21 | import com.panayotis.gnuplot.plot.DataSetPlot;
22 | import com.panayotis.gnuplot.plot.FunctionPlot;
23 | import com.panayotis.gnuplot.terminal.GNUPlotTerminal;
24 |
25 | /**
26 | * A friendly wrapper of GNUPlot, able to set common plot parameters. If easy of
27 | * use is required, it is recommended to use this class instead of GNUPlot.
28 | *
29 | *
30 | * This object is not serializable, use GNUPlotParameters instead.
31 | *
32 | * @author teras
33 | */
34 | public class JavaPlot extends GNUPlot {
35 |
36 | /**
37 | * Create a new instance of JavaPlot, with the default parameters
38 | *
39 | * @throws com.panayotis.gnuplot.GNUPlotException If the gnuplot executable
40 | * is not found, this exception is thrown. Typically at this case there is
41 | * need to use a constructor which defines the gnuplot path.
42 | * @see GNUPlot#GNUPlot()
43 | */
44 | public JavaPlot() throws GNUPlotException {
45 | super();
46 | }
47 |
48 | /**
49 | * Create a new instance of JavaPlot, using the default parameters. Use this
50 | * method if you want to specifically define that the default plot is
51 | * Graph3D
52 | *
53 | * @throws com.panayotis.gnuplot.GNUPlotException If the gnuplot executable
54 | * is not found, this exception is thrown. Typically at this case there is
55 | * need to use a constructor which defines the gnuplot path.
56 | * @param isGraph3D true if the default plot is Graph3D
57 | * @see GNUPlot#GNUPlot(boolean)
58 | */
59 | public JavaPlot(boolean isGraph3D) throws GNUPlotException {
60 | super(isGraph3D);
61 | }
62 |
63 | /**
64 | * Create a new JavaPlot object with a given gnuplot path
65 | *
66 | * @param gnuplotpath
67 | * @throws com.panayotis.gnuplot.GNUPlotException If the gnuplot executable
68 | * is not found, this exception is thrown. It means that the provided path
69 | * for gnuplot is not valid.
70 | * @see GNUPlot#GNUPlot(String)
71 | */
72 | public JavaPlot(String gnuplotpath) throws GNUPlotException {
73 | super(gnuplotpath);
74 | }
75 |
76 | /**
77 | * Create a new instance of gnuplot, with a given path for gnuplot. This
78 | * constructor is useful if the automatic path search for gnuplot is not
79 | * fruitful, or the user wants to point to a specific gnuplot executable.
80 | *
81 | * @param gnuplotpath The pathname of the gnuplot executable. If this
82 | * parameter is set to null, use the default path.
83 | * @param isGraph3D true if the default plot is Graph3D
84 | * @throws com.panayotis.gnuplot.GNUPlotException If the gnuplot executable
85 | * is not found, this exception is thrown. It means that the provided path
86 | * for gnuplot is not valid.
87 | * @see GNUPlot#GNUPlot(String,boolean)
88 | */
89 | public JavaPlot(String gnuplotpath, boolean isGraph3D) throws GNUPlotException {
90 | super(gnuplotpath, isGraph3D);
91 | }
92 |
93 | /**
94 | * Create a new JavaPlot object with given parameters
95 | *
96 | * @param par
97 | * @throws com.panayotis.gnuplot.GNUPlotException
98 | * @see GNUPlot#GNUPlot(GNUPlotParameters)
99 | */
100 | public JavaPlot(GNUPlotParameters par) throws GNUPlotException {
101 | super(par);
102 | }
103 |
104 | /**
105 | * Create a new JavaPlot object with given parameters, gnuplot path and
106 | * terminal
107 | *
108 | * @param par
109 | * @param gnuplotpath
110 | * @param term
111 | * @throws com.panayotis.gnuplot.GNUPlotException
112 | * @see GNUPlot#GNUPlot(GNUPlotParameters,String,GNUPlotTerminal)
113 | */
114 | public JavaPlot(GNUPlotParameters par, String gnuplotpath, GNUPlotTerminal term) throws GNUPlotException {
115 | super(par, gnuplotpath, term);
116 | }
117 |
118 | /**
119 | * Create a new JavaPlot object with given parameters, gnuplot path terminal
120 | * ans isGraph3D
121 | *
122 | * @param par
123 | * @param gnuplotpath
124 | * @param term
125 | * @param isGraph3D
126 | * @throws com.panayotis.gnuplot.GNUPlotException
127 | * @see GNUPlot#GNUPlot(GNUPlotParameters,String,GNUPlotTerminal,boolean)
128 | */
129 | public JavaPlot(GNUPlotParameters par, String gnuplotpath, GNUPlotTerminal term, boolean isGraph3D) throws GNUPlotException {
130 | super(par, gnuplotpath, term, isGraph3D);
131 | }
132 |
133 | /**
134 | * Set the graph Title
135 | *
136 | * @param title Title of the graph
137 | */
138 | public void setTitle(String title) {
139 | setTitle(title, null, -1);
140 | }
141 |
142 | /**
143 | * Set the graph title and the title font
144 | *
145 | * @param title Title of the graph
146 | * @param font Font name of this title text
147 | * @param size Font size of this title text
148 | */
149 | public void setTitle(String title, String font, int size) {
150 | String fontname = "";
151 | if (font != null)
152 | fontname = " font '" + font + ((size > 1) ? "," + size : "") + "'";
153 | set("title", "'" + title + "'" + fontname);
154 | }
155 |
156 | /**
157 | *
158 | */
159 | public static enum Key {
160 |
161 | OFF, TOP_RIGHT, BOTTOM_RIGHT, TOP_LEFT, BOTTOM_LEFT, BELOW, OUTSIDE
162 | };
163 |
164 | /**
165 | *
166 | * @param position
167 | */
168 | public void setKey(Key position) {
169 | if (position == null)
170 | set("key", null);
171 | else
172 | set("key", position.name().replace('_', ' ').toLowerCase());
173 | }
174 |
175 | /**
176 | *
177 | * @param points
178 | */
179 | public void addPlot(double[][] points) {
180 | addPlot(new DataSetPlot(points));
181 | }
182 |
183 | /**
184 | *
185 | * @param points
186 | */
187 | public void addPlot(float[][] points) {
188 | addPlot(new DataSetPlot(points));
189 | }
190 |
191 | /**
192 | *
193 | * @param points
194 | */
195 | public void addPlot(int[][] points) {
196 | addPlot(new DataSetPlot(points));
197 | }
198 |
199 | /**
200 | *
201 | * @param points
202 | */
203 | public void addPlot(long[][] points) {
204 | addPlot(new DataSetPlot(points));
205 | }
206 |
207 | /**
208 | *
209 | * @param function
210 | */
211 | public void addPlot(String function) {
212 | addPlot(new FunctionPlot(function));
213 | }
214 |
215 | /**
216 | *
217 | * @param set
218 | */
219 | public void addPlot(DataSet set) {
220 | addPlot(new DataSetPlot(set));
221 | }
222 | }
223 |
--------------------------------------------------------------------------------
/LICENCE.txt:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/GNUPlotExec.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 14, 2007, 1:42 PM
17 | */
18 | package com.panayotis.gnuplot;
19 |
20 | import com.panayotis.gnuplot.terminal.GNUPlotTerminal;
21 | import com.panayotis.gnuplot.utils.Debug;
22 | import com.panayotis.gnuplot.utils.FileUtils;
23 | import java.io.BufferedReader;
24 | import java.io.File;
25 | import java.io.IOException;
26 | import java.io.InputStreamReader;
27 | import java.io.PrintStream;
28 |
29 | /**
30 | * Object representing the low level gnuplot executable. This object is used in
31 | * the plot() method of GNUPlot.
32 | *
33 | * @author teras
34 | */
35 | class GNUPlotExec {
36 |
37 | private static final transient String DEFAULT_PATH = FileUtils.findPathExec();
38 | private transient String gnuplotexec;
39 | private boolean ispersist;
40 | private final static String[] persistcommand = {"path", "file", "-persist"};
41 | private final static String[] nopersist = {"path", "file"};
42 |
43 | /**
44 | * Create a new GNUPlotExec object with defaultΩ gnuplot path. Under POSIX
45 | * environment, it is able to automatically find gnuplot executable in the
46 | * $PATH
47 | *
48 | * @throws java.io.IOException if something went wrong and it is impossible
49 | * to continue without further notice
50 | */
51 | GNUPlotExec() throws IOException {
52 | this(null);
53 | }
54 |
55 | /**
56 | * Create a new GNUPlotExec object with a specific gnuplot path.
57 | *
58 | * @param path Path of gnuplot executable
59 | * @throws java.io.IOException if the gnuplot executable is not found
60 | */
61 | GNUPlotExec(String path) throws IOException {
62 | if (path == null)
63 | path = DEFAULT_PATH;
64 | setGNUPlotPath(path);
65 | ispersist = true;
66 | }
67 |
68 | /**
69 | * Set the desired path for gnuplot executable.
70 | *
71 | * @param path Filename of gnuplot executable
72 | * @throws java.io.IOException gnuplot is not found, or not valid
73 | */
74 | final void setGNUPlotPath(String path) throws IOException {
75 | if (new File(path).isFile())
76 | gnuplotexec = path;
77 | else
78 | throw new IOException("GnuPlot executable \"" + path + "\" not found.");
79 | }
80 |
81 | /**
82 | * Retrieve the file path of gnuplot
83 | *
84 | * @return The gnuplot file path
85 | */
86 | String getGNUPlotPath() {
87 | return gnuplotexec;
88 | }
89 |
90 | /**
91 | * Retrieves the command which will actually send to gnuplot, if we perform
92 | * a plot with the given parameters to the selected terminal.
This
93 | * method is used for debugging purposes.
94 | *
95 | * @return The commands to send to the gnuplot executable
96 | */
97 | public String getCommands(GNUPlotParameters par, GNUPlotTerminal terminal) {
98 | // Could cache these commands..
99 | return par.getPlotCommands(terminal);
100 | }
101 |
102 | /**
103 | * Plot using specific parameters and selected terminal.
104 | *
105 | * @param par The parameters to use
106 | * @param terminal The terminal to use
107 | * @throws com.panayotis.gnuplot.GNUPlotException throw if something goes
108 | * wrong
109 | */
110 | void plot(GNUPlotParameters par, GNUPlotTerminal terminal) throws GNUPlotException {
111 | try {
112 | final GNUPlotTerminal term = terminal; // Use this thread-aware variable instead of "terminal"
113 | final String comms = getCommands(par, term); // Get the commands to send to gnuplot
114 | final Messages msg = new Messages(); // Where to store messages from output threads
115 |
116 | /*
117 | * Display plot commands to send to gnuplot
118 | */
119 | GNUPlot.getDebugger().msg("** Start of plot commands **", Debug.INFO);
120 | GNUPlot.getDebugger().msg(comms, Debug.INFO);
121 | GNUPlot.getDebugger().msg("** End of plot commands **", Debug.INFO);
122 |
123 | /*
124 | * It's time now to start the actual gnuplot application
125 | */
126 | String[] command;
127 | if (ispersist)
128 | command = persistcommand;
129 | else
130 | command = nopersist;
131 | command[0] = getGNUPlotPath();
132 | command[1] = FileUtils.createTempFile(comms);
133 |
134 | {
135 | String cmdStr = "";
136 | for (String cmd : command)
137 | cmdStr += cmd + " ";
138 | GNUPlot.getDebugger().msg("exec(" + cmdStr + ")", Debug.INFO);
139 | }
140 | final Process proc = Runtime.getRuntime().exec(command);
141 |
142 | /*
143 | * Windows buffers DEMAND asynchronus read & write
144 | */
145 |
146 | /*
147 | * Thread to process the STDERR of gnuplot
148 | */
149 | Thread err_thread = new Thread() {
150 |
151 | @Override
152 | public void run() {
153 | BufferedReader err = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
154 | StringBuilder buf = new StringBuilder();
155 | String line;
156 | try {
157 | while ((line = err.readLine()) != null)
158 | if (!line.trim().equals(""))
159 | buf.append(line).append('\n');
160 | err.close();
161 | msg.output = buf.toString(); // Store output stream
162 | } catch (IOException ex) {
163 | ex.printStackTrace(new PrintStream(System.out));
164 | }
165 | }
166 | };
167 | /*
168 | * Thread to process the STDOUT of gnuplot
169 | */
170 | err_thread.start();
171 | Thread out_thread = new Thread() {
172 |
173 | @Override
174 | public void run() {
175 | msg.process = term.processOutput(proc.getInputStream()); // Execute terminal specific output parsing
176 | }
177 | };
178 | out_thread.start();
179 |
180 | try {
181 | proc.waitFor(); // wait for process to finish
182 | out_thread.join(); // wait for output (terminal related) thread to finish
183 | err_thread.join(); // wait for error (messages) output to finish
184 | } catch (InterruptedException ex) {
185 | throw new GNUPlotException("Interrupted execution of gnuplot");
186 | }
187 | new File(command[1]).delete();
188 |
189 | /*
190 | * Find the error message, if any, with precendence to the error
191 | * thread
192 | */
193 | String message = msg.error != null ? msg.error : msg.process;
194 |
195 | /*
196 | * Determine if error stream should be dumbed or not
197 | */
198 | int level = Debug.VERBOSE;
199 | if (message != null)
200 | level = Debug.ERROR;
201 | GNUPlot.getDebugger().msg("** Start of error stream **", level);
202 | GNUPlot.getDebugger().msg(msg.output, level);
203 | GNUPlot.getDebugger().msg("** End of error stream **", level);
204 |
205 | /*
206 | * Throw an exception if an error occured
207 | */
208 | if (message != null)
209 | throw new GNUPlotException(message);
210 |
211 | } catch (IOException ex) {
212 | throw new GNUPlotException("IOException while executing \"" + getGNUPlotPath() + "\":" + ex.getLocalizedMessage());
213 | }
214 |
215 | }
216 |
217 | void setPersist(boolean persist) {
218 | ispersist = persist;
219 | }
220 |
221 | private class Messages {
222 |
223 | String output = "";
224 | String error = null;
225 | String process = null;
226 | }
227 | }
228 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/dataset/PointDataSet.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on October 15, 2007, 2:10 AM
17 | */
18 | package com.panayotis.gnuplot.dataset;
19 |
20 | import java.lang.reflect.Array;
21 | import java.util.ArrayList;
22 | import java.util.Collection;
23 |
24 | /**
25 | * Store data sets in a dynamic Generics List of Points. Prefer this object
26 | * instead of ArrayDataSet if you plan to alter the points of this data sets
27 | * afterwards its creation.
28 | * If your data are not only numerical, consider using a GenericDataSet instead.
29 | *
30 | * @param The precision of each point
31 | * @see com.panayotis.gnuplot.dataset.GenericDataSet
32 | * @author teras
33 | */
34 | public class PointDataSet extends ArrayList> implements DataSet {
35 |
36 | /**
37 | * Create an empty PointDataSet
38 | */
39 | public PointDataSet() {
40 | super();
41 | }
42 |
43 | /**
44 | * Create an empty PointDataSet with a specified initial capacity
45 | *
46 | * @param initial The initial capacity of this PointDataSet
47 | */
48 | public PointDataSet(int initial) {
49 | super(initial);
50 | }
51 |
52 | /**
53 | * Create a new PointDataSet from a previous collection of Points
54 | *
55 | * @param pts The collection of Points to use as a model
56 | * @throws java.lang.NumberFormatException If the given collection is not in
57 | * the correct format
58 | */
59 | public PointDataSet(Collection extends Point> pts) throws NumberFormatException {
60 | super(pts);
61 | if (pts != null) {
62 | int lastDimension = -1;
63 | for (Point p : pts)
64 | if (lastDimension < 0)
65 | lastDimension = p.getDimensions();
66 | else
67 | checkDimension(p, lastDimension);
68 | }
69 | }
70 |
71 | private int checkDimension(Point point, int old_dim) throws ArrayIndexOutOfBoundsException {
72 | int new_dim = point.getDimensions();
73 | if (old_dim < 0)
74 | old_dim = new_dim; // if the array is still empty, any size is good size
75 | if (old_dim != new_dim)
76 | throw new ArrayIndexOutOfBoundsException("Point inserted differs in dimension: found " + new_dim + ", requested " + old_dim);
77 | return old_dim;
78 | }
79 |
80 | /**
81 | * Add a new point to this DataSet
82 | *
83 | * @param point The point to add to this DataSet
84 | * @return Whether the collection changed with this call
85 | * @throws java.lang.NumberFormatException If the given collection is not in
86 | * the correct format
87 | */
88 | @Override
89 | public boolean add(Point point) throws NumberFormatException {
90 | checkDimension(point, getDimensions());
91 | return super.add(point);
92 | }
93 |
94 | /**
95 | * Add a new point to this DataSet at a specified position
96 | *
97 | * @param index Where to add this point
98 | * @param point The point to add to this DataSet
99 | * @throws java.lang.NumberFormatException If the given collection is not in
100 | * the correct format
101 | */
102 | @Override
103 | public void add(int index, Point point) throws NumberFormatException {
104 | checkDimension(point, getDimensions());
105 | super.add(index, point);
106 | }
107 |
108 | /**
109 | * Add a collection of points to this DataSet
110 | *
111 | * @param pts The points colelction
112 | * @return Whether the collection changed with this call
113 | * @throws java.lang.NumberFormatException If the given collection is not in
114 | * the correct format
115 | */
116 | @Override
117 | public boolean addAll(Collection extends Point> pts) throws NumberFormatException {
118 | int old_dim = getDimensions();
119 | for (Point p : pts)
120 | old_dim = checkDimension(p, old_dim);
121 | return super.addAll(pts);
122 | }
123 |
124 | /**
125 | * Add a collection of points to this DataSet starting at a specified
126 | * position if there are data at the specified position, these will be
127 | * shifted
128 | *
129 | * @param index Where to start adding point data.
130 | * @param pts The point collection to add
131 | * @return Whether the collection changed with this call
132 | * @throws java.lang.NumberFormatException If the given collection is not in
133 | * the correct format
134 | */
135 | @Override
136 | public boolean addAll(int index, Collection extends Point> pts) throws NumberFormatException {
137 | int old_dim = getDimensions();
138 | for (Point p : pts)
139 | old_dim = checkDimension(p, old_dim);
140 | return super.addAll(index, pts);
141 | }
142 |
143 | /**
144 | * Replace the Point at the specified position with the provided one
145 | *
146 | * @param index The position of the point to be altered
147 | * @param point The point to use
148 | * @return The Point previously found in the specified position
149 | * @throws java.lang.NumberFormatException If the given collection is not in
150 | * the correct format
151 | */
152 | @Override
153 | public Point set(int index, Point point) throws NumberFormatException {
154 | checkDimension(point, getDimensions());
155 | return super.set(index, point);
156 | }
157 |
158 | /**
159 | * Add a new point to the data set, given the values for each dimension.
160 | *
161 | * @param coords a list of primitive data of the same type of this
162 | * collection. Could also be boxed variables too.
163 | */
164 | public void addPoint(N... coords) {
165 | add(new Point(coords));
166 | }
167 |
168 | /**
169 | * Retrieve how many dimensions this dataset refers to.
170 | *
171 | * @return the number of dimensions
172 | * @see DataSet#getDimensions()
173 | */
174 | @Override
175 | public int getDimensions() {
176 | if (size() == 0)
177 | return -1;
178 | return get(0).getDimensions();
179 | }
180 |
181 | /**
182 | * Retrieve data information from a point.
183 | *
184 | * @param point The point number
185 | * @param dimension The point dimension (or "column") to request data from
186 | * @return the point data for this dimension
187 | * @see DataSet#getPointValue(int,int)
188 | */
189 | @Override
190 | public String getPointValue(int point, int dimension) {
191 | return get(point).get(dimension).toString();
192 | }
193 |
194 | /**
195 | * This is a convinient method to transform a statically defined primitive
196 | * array to PointDataSet object. Use this method if your oroginal data is in
197 | * a static primitive array but you want to take advantage of the
198 | * flexibility of PointDataSet, instead od ArrayDataSet.
199 | *
200 | * @param The precision of each point
201 | * @param objclass The class of this PointDataSet. For example for Double
202 | * precision numbers, this parameter should be Double.class
203 | * @param array The array containing the primitive data
204 | * @return The produced PointDataSet of class objclass
205 | * @throws java.lang.ArrayStoreException If some misconfiguration is
206 | * performed on the provided array object
207 | */
208 | @SuppressWarnings("unchecked")
209 | public static final PointDataSet constructDataSet(Class objclass, Object array) throws ArrayStoreException {
210 | int length, dim, cdim;
211 | int i, j;
212 | Object row, value;
213 |
214 | if (!array.getClass().isArray())
215 | throw new ArrayStoreException("The second argument of constructDataSet should be a two dimensional array.");
216 |
217 | length = Array.getLength(array);
218 | dim = -1;
219 | PointDataSet points = new PointDataSet(length);
220 | N[] buffer = null;
221 |
222 | for (i = 0; i < length; i++) {
223 | row = Array.get(array, i);
224 | if (!row.getClass().isArray())
225 | throw new ArrayStoreException("The second argument of constructDataSet is a one dimensional, instead of two dimensional, array.");
226 | cdim = Array.getLength(row);
227 | if (dim < 0) {
228 | dim = cdim;
229 | buffer = (N[]) Array.newInstance(Number.class, dim);
230 | }
231 | if (dim != cdim)
232 | throw new ArrayStoreException("Array has not consistent size, was " + dim + ", found " + cdim);
233 | for (j = 0; j < dim; j++) {
234 | value = Array.get(row, j);
235 | if (!value.getClass().equals(objclass))
236 | throw new ArrayStoreException("Array item " + value + " is " + value.getClass().getName() + " and not " + objclass.getName());
237 | buffer[j] = (N) value;
238 | }
239 | points.quickadd(new Point(buffer));
240 | }
241 | return points;
242 | }
243 |
244 | /**
245 | * Use this to override the check mechanism
246 | * @param point The point to add
247 | */
248 | private void quickadd(Point point) {
249 | super.add(point);
250 | }
251 | }
252 |
--------------------------------------------------------------------------------
/base/src/main/java/com/panayotis/gnuplot/GNUPlot.java:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007-2014 by panayotis.com
2 | *
3 | * JavaPlot is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU Lesser General Public License as published by
5 | * the Free Software Foundation, version 2.
6 | *
7 | * JavaPlot is free in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with CrossMobile; if not, write to the Free Software
14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 | *
16 | * Created on 12 Οκτώβριος 2007, 3:07 μμ
17 | */
18 | package com.panayotis.gnuplot;
19 |
20 | import com.panayotis.gnuplot.layout.GraphLayout;
21 | import com.panayotis.gnuplot.plot.Axis;
22 | import com.panayotis.gnuplot.plot.Graph;
23 | import com.panayotis.gnuplot.plot.Page;
24 | import com.panayotis.gnuplot.plot.Plot;
25 | import com.panayotis.gnuplot.terminal.DefaultTerminal;
26 | import com.panayotis.gnuplot.terminal.GNUPlotTerminal;
27 | import com.panayotis.gnuplot.utils.Debug;
28 | import java.io.IOException;
29 | import java.util.List;
30 |
31 | /**
32 | * This is the main class of JavaPlot. It is the cental point to create a
33 | * gnuplot. Typically the user needs to create a new instance of this object and
34 | * add the desired plots.
35 | * It also provides some convenient methods in order to set various parameters.
36 | *
37 | * This object is not serializable, use GNUPlotParameters instead.
38 | *
39 | * @author teras
40 | * @see com.panayotis.gnuplot.JavaPlot
41 | * @see #addPlot(Plot)
42 | */
43 | public class GNUPlot {
44 |
45 | private static final long serialVersionUID = GNUPlot.serialVersionUID;
46 | /**
47 | * GNUPlot parameters. Here we store all gnuplot information.
48 | */
49 | private GNUPlotParameters param;
50 | /**
51 | * The GNUPlot parameter to use
52 | */
53 | private transient GNUPlotTerminal term;
54 | /**
55 | * The GNUPlotExec to use.
56 | */
57 | private transient GNUPlotExec exec;
58 | private static transient Debug dbg = new Debug();
59 |
60 | /**
61 | * Create a new instance of gnuplot, using the default parameters
62 | *
63 | * @throws com.panayotis.gnuplot.GNUPlotException If the gnuplot executable
64 | * is not found, this exception is thrown. Typically at this case there is
65 | * need to use a constructor which defines the gnuplot path.
66 | * @see #GNUPlot(String)
67 | * @see #GNUPlot(GNUPlotParameters,String,GNUPlotTerminal,boolean)
68 | */
69 | public GNUPlot() throws GNUPlotException {
70 | this(null, null, null, false);
71 | }
72 |
73 | /**
74 | * Create a new instance of gnuplot, using the default parameters. Use this
75 | * method if you want to specifically define that the default plot is
76 | * Graph3D
77 | *
78 | * @throws com.panayotis.gnuplot.GNUPlotException If the gnuplot executable
79 | * is not found, this exception is thrown. Typically at this case there is
80 | * need to use a constructor which defines the gnuplot path.
81 | * @param isGraph3D true if the default plot is Graph3D
82 | * @see #GNUPlot(String)
83 | * @see #GNUPlot(GNUPlotParameters,String,GNUPlotTerminal,boolean)
84 | */
85 | public GNUPlot(boolean isGraph3D) throws GNUPlotException {
86 | this(null, null, null, isGraph3D);
87 | }
88 |
89 | /**
90 | * Create a new instance of gnuplot, with a given set of parameters.
91 | *
92 | * @see #GNUPlot(String)
93 | * @see #GNUPlot(GNUPlotParameters,String,GNUPlotTerminal,boolean)
94 | * @param par Use this set of parameters, instead of a default one.
95 | * @throws com.panayotis.gnuplot.GNUPlotException If the gnuplot executable
96 | * is not found, this exception is thrown. Typically at this case there is
97 | * need to use a constructor which defines the gnuplot path.
98 | */
99 | public GNUPlot(GNUPlotParameters par) throws GNUPlotException {
100 | this(par, null, null, false);
101 | }
102 |
103 | /**
104 | * Create a new instance of gnuplot, with a given path for gnuplot. This
105 | * constructor is useful if the automatic path search for gnuplot is not
106 | * fruitful, or the user wants to point to a specific gnuplot executable.
107 | *
108 | * @param gnuplotpath The pathname of the gnuplot executable. If this
109 | * parameter is set to null, use the default path.
110 | * @throws com.panayotis.gnuplot.GNUPlotException If the gnuplot executable
111 | * is not found, this exception is thrown. It means that the provided path
112 | * for gnuplot is not valid.
113 | */
114 | public GNUPlot(String gnuplotpath) throws GNUPlotException {
115 | this(null, gnuplotpath, null, false);
116 | }
117 |
118 | /**
119 | * Create a new instance of gnuplot, with a given path for gnuplot. This
120 | * constructor is useful if the automatic path search for gnuplot is not
121 | * fruitful, or the user wants to point to a specific gnuplot executable.
122 | *
123 | * @param gnuplotpath The pathname of the gnuplot executable. If this
124 | * parameter is set to null, use the default path.
125 | * @param isGraph3D true if the default plot is Graph3D
126 | * @throws com.panayotis.gnuplot.GNUPlotException If the gnuplot executable
127 | * is not found, this exception is thrown. It means that the provided path
128 | * for gnuplot is not valid.
129 | */
130 | public GNUPlot(String gnuplotpath, boolean isGraph3D) throws GNUPlotException {
131 | this(null, gnuplotpath, null, isGraph3D);
132 | }
133 |
134 | /**
135 | * Create a new instance of gnuplot, with given parameters and given path
136 | * for gnuplot.
137 | *
138 | * This constructor is useful if the user wants to fine tune eny aspect of
139 | * GNUPlot object, and especially if there is need to define a priori the
140 | * output terminal.
141 | *
142 | * Any parameters set to null, produce the default parameters.
143 | *
144 | * @param par GNUPlot parameters to use. These parameters encapsulate the
145 | * whole gnuplot variables, including data sets.
146 | * @param gnuplotpath The pathname of the gnuplot executable. If this
147 | * parameter is set to null, use the default path.
148 | * @param term The gnuplot terminal to use
149 | * @throws com.panayotis.gnuplot.GNUPlotException If the gnuplot executable
150 | * is not found, this exception is thrown. It means that the provided path
151 | * for gnuplot is not valid.
152 | */
153 | public GNUPlot(GNUPlotParameters par, String gnuplotpath, GNUPlotTerminal term) throws GNUPlotException {
154 | this(par, gnuplotpath, term, false);
155 | }
156 |
157 | /**
158 | * Create a new instance of gnuplot, with given parameters and given path
159 | * for gnuplot.
160 | *
161 | * This constructor is useful if the user wants to fine tune eny aspect of
162 | * GNUPlot object, and especially if there is need to define a priori the
163 | * output terminal.
164 | *
165 | * Any parameters set to null, produce the default parameters.
166 | *
167 | * @param par GNUPlot parameters to use. These parameters encapsulate the
168 | * whole gnuplot variables, including data sets.
169 | * @param gnuplotpath The pathname of the gnuplot executable. If this
170 | * parameter is set to null, use the default path.
171 | * @param term The gnuplot terminal to use
172 | * @param isGraph3D true, if this is a Graph3D object
173 | * @throws com.panayotis.gnuplot.GNUPlotException If the gnuplot executable
174 | * is not found, this exception is thrown. It means that the provided path
175 | * for gnuplot is not valid.
176 | */
177 | public GNUPlot(GNUPlotParameters par, String gnuplotpath, GNUPlotTerminal term, boolean isGraph3D) throws GNUPlotException {
178 | if (par == null)
179 | par = new GNUPlotParameters(isGraph3D);
180 | this.param = par;
181 |
182 | if (term == null)
183 | term = new DefaultTerminal();
184 | this.term = term;
185 |
186 | try {
187 | exec = new GNUPlotExec(gnuplotpath);
188 | } catch (IOException e) {
189 | String msg = e.getMessage();
190 | if (gnuplotpath == null)
191 | msg += " Please provide gnuplot path to the constructor of GNUPlot.";
192 | throw new GNUPlotException(msg);
193 | }
194 | }
195 |
196 | /**
197 | * Set various GNUPlot parameters. All parameters added here will be used in
198 | * the form of "set key value"
199 | *
200 | * @param key The key to use for this gnuplot
201 | * @param value The value of this key
202 | */
203 | public void set(String key, String value) {
204 | param.set(key, value);
205 | }
206 |
207 | /**
208 | * Use this method to get a reference to the plot axis, in order to set
209 | * various parameters.
210 | *
211 | * @param axisname The name of the axis. This typically is "x", "y", "z".
212 | * @return The requested Axis, or null if axis is not found
213 | */
214 | public Axis getAxis(String axisname) {
215 | return param.getAxis(axisname);
216 | }
217 |
218 | /**
219 | * Add a new Plot
220 | *
221 | * @param plot The plot to add to the list of plots.
222 | * @see com.panayotis.gnuplot.plot.Plot
223 | */
224 | public void addPlot(Plot plot) {
225 | if (plot == null)
226 | return;
227 | param.addPlot(plot);
228 | }
229 |
230 | /**
231 | * Add a defined graph to this GNUPlot object.
232 | *
233 | * @param gr Graph object to be added
234 | * @see #newGraph()
235 | */
236 | public void addGraph(Graph gr) {
237 | param.addGraph(gr);
238 | }
239 |
240 | /**
241 | * Add a new Graph object. This method is used to create a multiplot graph.
242 | * Every "plot" command corresponds to a different Graph object. In order to
243 | * draw to a new plot gnuplot object, create a new page.
244 | *
245 | * @see #newGraph3D()
246 | */
247 | public void newGraph() {
248 | param.newGraph();
249 | }
250 |
251 | /**
252 | * Add a new Graph3D object. This method is used to create a multiplot
253 | * graph. Every "splot" command corresponds to a different Graph object. In
254 | * order to draw to a new plot gnuplot object, create a new page.
255 | *
256 | * @see #newGraph()
257 | */
258 | public void newGraph3D() {
259 | param.newGraph3D();
260 | }
261 |
262 | /**
263 | * Set the title of all graph objects, in multiplot environment.
264 | *
265 | * @param title The title to use
266 | */
267 | public void setMultiTitle(String title) {
268 | param.setMultiTitle(title);
269 | }
270 |
271 | /**
272 | * Get a list of the (default) plots used in this set. This method is a way
273 | * to enumerate the plots already inserted, epspecially if a plot is added
274 | * on the fly.
275 | *
276 | * @return An array of stored plots.
277 | */
278 | public List getPlots() {
279 | return param.getPlots();
280 | }
281 |
282 | /**
283 | * Get a Page containing all Graphs. This method is used for example in
284 | * order to get a list of graphs already inserted, especially if a graph is
285 | * automatically added
286 | *
287 | * @return An array of stored Graphs
288 | */
289 | public Page getPage() {
290 | return param.getPage();
291 | }
292 |
293 | /**
294 | * Get the current layout of this plot object
295 | *
296 | * @return The used layout
297 | */
298 | public GraphLayout getLayout() {
299 | return param.getLayout();
300 | }
301 |
302 | /**
303 | * Perform the actual action of plotting. Use the current parameters and
304 | * terminal, and perform a plot. If an error occured, an exception is thrown
305 | *
306 | * @throws com.panayotis.gnuplot.GNUPlotException This exception is thrown
307 | * if an error occured. Use the Debug object to dump information about this
308 | * error.
309 | */
310 | public void plot() throws GNUPlotException {
311 | exec.plot(param, term);
312 | }
313 |
314 | /**
315 | * Retrieves the command which will actually send to gnuplot, if we perform
316 | * a plot with the already defined parameters to the selected terminal.
317 | * This method is used for debugging purposes.
318 | *
319 | * @return The commands to send to the gnuplot executable
320 | */
321 | public String getCommands() {
322 | return exec.getCommands(param, term);
323 | }
324 |
325 | // public void splot() throws GNUPlotException {
326 | // exec.splot(param, term);
327 | // }
328 | /**
329 | * Set the desired path for gnuplot executable.
330 | *
331 | * @param path Filename of gnuplot executable
332 | * @throws java.io.IOException gnuplot is not found, or not valid
333 | */
334 | public void setGNUPlotPath(String path) throws IOException {
335 | exec.setGNUPlotPath(path);
336 | }
337 |
338 | /**
339 | * Retrieve the file path of gnuplot
340 | *
341 | * @return The gnuplot file path
342 | */
343 | public String getGNUPlotPath() {
344 | return exec.getGNUPlotPath();
345 | }
346 |
347 | /**
348 | * Set all terminals to be persistent. Thus, after executing plot command,
349 | * the graph window stays open and does not disappear automatically.
350 | *
351 | * @param ispersist whether the terminal window should be persistent
352 | */
353 | public void setPersist(boolean ispersist) {
354 | exec.setPersist(ispersist);
355 | }
356 |
357 | /**
358 | * Set gnuplot parameters to another set of parameters.
359 | *
360 | * @param parameters The new GNUPlot parameters.
361 | */
362 | public void setParameters(GNUPlotParameters parameters) {
363 | if (param == null)
364 | return;
365 | param = parameters;
366 | }
367 |
368 | /**
369 | * Ge the actual gnuplot parameters. This method is useful if the developer
370 | * wants to have access to lower level GNUPlotparameter methods.
371 | *
372 | * @return Object having all information on how to make the plot.
373 | */
374 | public GNUPlotParameters getParameters() {
375 | return param;
376 | }
377 |
378 | /**
379 | * Change gnuplot terminal. Use this method to make gnuplot draw to another
380 | * terminal than the default
381 | *
382 | * @param term The terminal to use
383 | */
384 | public void setTerminal(GNUPlotTerminal term) {
385 | if (term == null)
386 | return;
387 | this.term = term;
388 | }
389 |
390 | /**
391 | * Get the current used terminal
392 | *
393 | * @return The used terminal
394 | */
395 | public GNUPlotTerminal getTerminal() {
396 | return term;
397 | }
398 |
399 | /**
400 | * Get the specific GNUPlot Debug object
401 | *
402 | * @return The Debug object
403 | */
404 | public static Debug getDebugger() {
405 | return dbg;
406 | }
407 |
408 | /**
409 | * Execute gnuplot commands before any kind of initialization. This method
410 | * together with getPostInit() is useful to add basic commands to gnuplot
411 | * exetutable, if the library does not support the desired functionality
412 | *
413 | * @return Array of pre-init commands
414 | */
415 | public List getPreInit() {
416 | return param.getPreInit();
417 | }
418 |
419 | /**
420 | * Execute gnuplot commands before any kind of initialization. This method
421 | * together with getPostInit() is useful to add basic commands to gnuplot
422 | * exetutable, if the library does not support the desired functionality
423 | *
424 | * @return Array of pre-init commands
425 | */
426 | public List getPostInit() {
427 | return param.getPostInit();
428 | }
429 | }
430 |
--------------------------------------------------------------------------------