Skip to content

Commit 2977219

Browse files
committed
Added option to set first line as header in Scatterplot
1 parent e6f820a commit 2977219

4 files changed

Lines changed: 84 additions & 12 deletions

File tree

Source/Charts/src/ca/uqac/lif/spreadsheet/chart/Scatterplot.java

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/*
2-
MTNP: Manipulate Tables N'Plots
3-
Copyright (C) 2017 Sylvain Hallé
2+
A provenance-aware spreadsheet library
3+
Copyright (C) 2021-2023 Sylvain Hallé
44
5-
This program is free software: you can redistribute it and/or modify
6-
it under the terms of the GNU General Public License as published by
7-
the Free Software Foundation, either version 3 of the License, or
8-
(at your option) any later version.
5+
This program 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, either version 3 of the License, or
8+
(at your option) any later version.
99
10-
This program is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
GNU General Public License for more details.
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
1414
15-
You should have received a copy of the GNU General Public License
16-
along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
You should have received a copy of the GNU Lesser General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818
package ca.uqac.lif.spreadsheet.chart;
1919

@@ -54,4 +54,19 @@ public interface Scatterplot extends Chart
5454
* @return This plot
5555
*/
5656
public Scatterplot withLines();
57+
58+
/**
59+
* Tells the plot whether the first line of the spreadsheet contains the name
60+
* of each data series, and is not a line of numerical data.
61+
* @param b True if first line is a header, false otherwise
62+
* @return This plot
63+
*/
64+
public Scatterplot hasHeaders(boolean b);
65+
66+
/**
67+
* Tells the plot that the first line of the spreadsheet contains the name
68+
* of each data series, and is not a line of numerical data.
69+
* @return This plot
70+
*/
71+
public Scatterplot hasHeaders();
5772
}

Source/Charts/src/ca/uqac/lif/spreadsheet/chart/UnsupportedPlotFormatException.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
A provenance-aware spreadsheet library
3+
Copyright (C) 2021-2022 Sylvain Hallé
4+
5+
This program 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, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
118
package ca.uqac.lif.spreadsheet.chart;
219

320
/**

Source/Gnuplot/src/ca/uqac/lif/spreadsheet/chart/gnuplot/GnuplotScatterplot.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public class GnuplotScatterplot extends Gnuplot implements Scatterplot
6363
* Whether to draw each data series with marks for each data point
6464
*/
6565
protected boolean m_withPoints = true;
66+
67+
/**
68+
* Whether the first line of the spreadsheet is a header
69+
*/
70+
protected boolean m_hasHeaders = true;
6671

6772
/**
6873
* Creates an empty scatterplot
@@ -97,6 +102,19 @@ public GnuplotScatterplot withPoints(boolean b)
97102
m_withPoints = b;
98103
return this;
99104
}
105+
106+
@Override
107+
public GnuplotScatterplot hasHeaders(boolean b)
108+
{
109+
m_hasHeaders = b;
110+
return this;
111+
}
112+
113+
@Override
114+
public GnuplotScatterplot hasHeaders()
115+
{
116+
return hasHeaders(true);
117+
}
100118

101119
@Override
102120
public GnuplotScatterplot setTitle(String title)
@@ -137,6 +155,10 @@ public void toGnuplot(PrintStream out, Spreadsheet table, ChartFormat term, Stri
137155
PrintStream p_baos = new PrintStream(baos);
138156
s_printer.print(table, p_baos);
139157
String csv_values = baos.toString();
158+
if (m_hasHeaders)
159+
{
160+
csv_values = csv_values.substring(csv_values.indexOf(System.getProperty("line.separator")));
161+
}
140162
String point_string = " with points";
141163
if (m_withLines)
142164
{

Source/Gral/src/ca/uqac/lif/spreadsheet/chart/gral/GralScatterplot.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public class GralScatterplot extends GralPlot implements Scatterplot
5252
* Whether to draw each data series with marks for each data point
5353
*/
5454
protected boolean m_withPoints = true;
55+
56+
/**
57+
* Whether the first line of the spreadsheet is a header
58+
*/
59+
protected boolean m_hasHeaders = false;
5560

5661
/**
5762
* Creates an empty scatterplot with default settings
@@ -89,6 +94,19 @@ public GralScatterplot withPoints()
8994
return this;
9095
}
9196

97+
@Override
98+
public GralScatterplot hasHeaders(boolean b)
99+
{
100+
m_hasHeaders = b;
101+
return this;
102+
}
103+
104+
@Override
105+
public GralScatterplot hasHeaders()
106+
{
107+
return hasHeaders(true);
108+
}
109+
92110
@Override
93111
public GralScatterplot setTitle(String title)
94112
{

0 commit comments

Comments
 (0)