Revision 1042

tmp/org.txm.specificities.core/src/org/txm/specificities/core/functions/SpecificitiesSelection.java (revision 1042)
4 4
package org.txm.specificities.core.functions;
5 5

  
6 6
import java.io.File;
7
import java.util.ArrayList;
8
import java.util.Arrays;
9
import java.util.HashSet;
10
import java.util.List;
7 11

  
8 12
import org.apache.commons.lang.StringUtils;
9 13
import org.txm.chartsengine.core.results.ChartResult;
......
21 25
 */
22 26
public class SpecificitiesSelection extends ChartResult {
23 27

  
24
	
25 28
	/**
26
	 * The selected type names to focus on.
29
	 * Banality threshold.
27 30
	 */
28
	protected String[] selectedTypeNames;
31
	@Parameter(key=SpecificitiesPreferences.CHART_BANALITY, type=Parameter.RENDERING)
32
	protected Float pBanality;
29 33

  
30 34
	/**
31
	 * The selected specificities indices to focus on.
35
	 * To draw bars or not.
32 36
	 */
33
	protected double[][] selectedSpecificitiesIndex;
37
	@Parameter(key=SpecificitiesPreferences.CHART_DRAW_BARS, type=Parameter.RENDERING)
38
	protected Boolean pDrawBars;
34 39

  
40
	/**
41
	 * To draw lines or not.
42
	 */
43
	@Parameter(key=SpecificitiesPreferences.CHART_DRAW_LINES, type=Parameter.RENDERING)
44
	protected Boolean pDrawLines;
35 45

  
36
	
37
	
38 46
	/**
39 47
	 * Group by lines / transpose matrix.
40 48
	 */
41 49
	@Parameter(key=SpecificitiesPreferences.CHART_GROUP_BY_LINES, type=Parameter.RENDERING)
42
	protected boolean groupByLines;
43
	
44
	/**
45
	 * Banality threshold.
46
	 */
47
	@Parameter(key=SpecificitiesPreferences.CHART_BANALITY, type=Parameter.RENDERING)
48
	protected float banality;
50
	protected Boolean pGroupByLines;
49 51

  
50 52
	/**
51
	 * To draw bars or not.
53
	 * The selected specificities indices to focus on.
52 54
	 */
53
	@Parameter(key=SpecificitiesPreferences.CHART_DRAW_BARS, type=Parameter.RENDERING)
54
	protected boolean drawBars;
55
	protected double[][] selectedSpecificitiesIndex;
55 56

  
57

  
58

  
56 59
	/**
57
	 * To draw lines or not.
60
	 * The selected type names to focus on.
58 61
	 */
59
	@Parameter(key=SpecificitiesPreferences.CHART_DRAW_LINES, type=Parameter.RENDERING)
60
	protected boolean drawLines;
62
	@Parameter(key=SpecificitiesPreferences.VALUES, type=Parameter.RENDERING)
63
	protected List<String> pSelectedTypeNames;
61 64

  
62
	
63
	
64

  
65
	
66 65
	/**
67 66
	 * Creates an empty SpecificitiesSelection.
68 67
	 * @param parent
......
71 70
		super(parent);
72 71
	}
73 72

  
74

  
75
	
76 73
	public SpecificitiesSelection(String uuid)	{
77 74
		this(uuid, null);
78 75
	}
79
	
76

  
80 77
	public SpecificitiesSelection(String uuid, Specificities parent)	{
81 78
		super(uuid, parent);
82 79
	}
83 80

  
84
	
85
	
86
	
81
	public Specificities getParent() {
82
		return (Specificities)super.getParent();
83
	}
87 84

  
88 85
	@Override
89
	public boolean loadParameters() {
90
		// nothing to do
91
		return true;
86
	protected boolean _compute() throws Exception {
87
		Specificities specificities = getParent();
88
		double[][] tableLines = specificities.getSpecificitesIndex();
89
		String[] partNames = specificities.getPartShortNames();
90
		String[] rowNames = specificities.getTypeNames();
91

  
92
		selectedSpecificitiesIndex = new double[pSelectedTypeNames.size()][partNames.length];
93
		int n = 0;
94
		for (int i = 0; i < rowNames.length; i++) {
95
			double[] line = tableLines[i];
96
			String rowName = rowNames[i];
97
			if (pSelectedTypeNames.contains(rowName)) {
98
				selectedSpecificitiesIndex[n++] = line;
99
			}
100
		}
101

  
102
		return selectedSpecificitiesIndex.length > 0;
92 103
	}
93 104

  
94 105
	@Override
95
	public boolean saveParameters() {
96
		// nothing to do
97
		return true;
106
	public boolean canCompute() throws Exception {
107
		return this.parent != null;
98 108
	}
99
	
100
	
101
	/**
102
	 * @return the selectedTypeNames
103
	 */
104
	public String[] getSelectedTypeNames() {
105
		return selectedTypeNames;
109

  
110
	@Override
111
	public void clean() {
112
		//does nothing
106 113
	}
107 114

  
108 115
	/**
109
	 * @param selectedTypeNames the selectedTypeNames to set
116
	 * @return the banality
110 117
	 */
111
	public void setSelectedTypeNames(String[] selectedTypeNames) {
112
		this.selectedTypeNames = selectedTypeNames;
118
	public float getBanality() {
119
		return pBanality;
113 120
	}
114 121

  
122
	@Override
123
	public String getDetails() {
124
		StringBuilder sb = new StringBuilder();
125
		sb.append(this.getName());
126

  
127
		if (pBanality != null) {
128
			sb.append("\n\t"+"banality: "+this.pBanality);
129
		}
130
		if (pDrawBars != null) {
131
			sb.append("\n\t"+"draw bars: "+this.pDrawBars);
132
		}
133
		if (pDrawLines != null) {
134
			sb.append("\n\t"+"draw lines: "+this.pDrawLines);
135
		}
136
		if (pGroupByLines != null) {
137
			sb.append("\n\t"+"group lines: "+this.pGroupByLines);
138
		}
139
		return sb.toString();
140
	}
141

  
142
	@Override
143
	public String getName() {
144
		String name = "[" + StringUtils.join(this.pSelectedTypeNames, ", ") + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
145
		if (name.length() > 80) {
146
			name = name.substring(0, 79) + "...";
147
		}
148
		return name;
149
	}
150

  
151
	@Override
152
	public String getResultype() {
153
		return SpecificitiesCoreMessages.SELECTION_RESULT_TYPE;
154
	}
155

  
156

  
115 157
	/**
116 158
	 * @return the selectedPartNames
117 159
	 */
......
134 176
	}
135 177

  
136 178
	/**
137
	 * @param selectedSpecificitiesIndex the selectedSpecificitiesIndex to set
179
	 * @return the selectedTypeNames
138 180
	 */
139
	public void setSelectedSpecificitiesIndex(double[][] selectedSpecificitiesIndex) {
140
		this.selectedSpecificitiesIndex = selectedSpecificitiesIndex;
181
	public List<String> getSelectedTypeNames() {
182
		return pSelectedTypeNames;
141 183
	}
142 184

  
143

  
144 185
	@Override
145
	public String getName() {
146
		String name = "[" + StringUtils.join(this.selectedTypeNames, ", ") + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
147
		if (name.length() > 80) {
148
			name = name.substring(0, 79) + "...";
149
		}
150
		return name;
151
	}
152

  
153
	@Override
154 186
	public String getSimpleName() {
155
		// TODO Auto-generated method stub
156 187
		return this.getName();
157 188
	}
158 189

  
159
	@Override
160
	public String getDetails() {
161
		// TODO Auto-generated method stub
162
		return this.getName();
190
	/**
191
	 * @return the drawBars
192
	 */
193
	public boolean isDrawingBars() {
194
		return pDrawBars;
163 195
	}
164 196

  
165
	@Override
166
	public void clean() {
167
		//does nothing
197
	/**
198
	 * @return the drawLines
199
	 */
200
	public boolean isDrawingLines() {
201
		return pDrawLines;
168 202
	}
169 203

  
170
	@Override
171
	public boolean canCompute() throws Exception {
172
		return this.parent != null;
204
	/**
205
	 * @return the groupByLines
206
	 */
207
	public boolean isGroupingByLines() {
208
		return pGroupByLines;
173 209
	}
174 210

  
175 211
	@Override
176
	protected boolean _compute() throws Exception {
177
		// does nothing
212
	public boolean loadParameters() {
213
		String str = this.getStringParameterValue(SpecificitiesPreferences.VALUES);
214
		if (!str.isEmpty()) {
215
			pSelectedTypeNames = Arrays.asList(str.split("\t"));
216
		}
178 217
		return true;
179 218
	}
180 219

  
181 220
	@Override
182
	public boolean setParameters(TXMParameters parameters) {
183
		// TODO Auto-generated method stub
184
		System.err.println("SpecificitiesSelection.setParameters(): not yet implemented.");
221
	public boolean saveParameters() {
222
		if (pSelectedTypeNames != null) {
223
			this.saveParameter(SpecificitiesPreferences.VALUES, StringUtils.join(pSelectedTypeNames, "\t"));
224
		}
185 225
		return true;
186 226
	}
187 227

  
188
	@Override
189
	public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception {
190
		// TODO Auto-generated method stub
191
		return false;
192
	}
193

  
194

  
195 228
	/**
196
	 * @return the groupByLines
229
	 * @param banality the banality to set
197 230
	 */
198
	public boolean isGroupingByLines() {
199
		return groupByLines;
231
	public void setBanality(float banality) {
232
		this.pBanality = banality;
200 233
	}
201 234

  
202

  
203

  
204 235
	/**
205 236
	 * @param groupByLines the groupByLines to set
206 237
	 */
207 238
	public void setGroupByLines(boolean groupByLines) {
208
		this.groupByLines = groupByLines;
239
		this.pGroupByLines = groupByLines;
209 240
	}
210 241

  
211

  
212

  
213
	/**
214
	 * @return the banality
215
	 */
216
	public float getBanality() {
217
		return banality;
242
	@Override
243
	public void setHasBeenComputedOnce(boolean hasBeenComputedOnce) {
244
		// redefined to not reset the chart
218 245
	}
219 246

  
220

  
221

  
222
	/**
223
	 * @param banality the banality to set
224
	 */
225
	public void setBanality(float banality) {
226
		this.banality = banality;
247
	@Override
248
	public boolean setParameters(TXMParameters parameters) {
249
		// TODO Auto-generated method stub
250
		System.err.println("SpecificitiesSelection.setParameters(): not yet implemented.");
251
		return true;
227 252
	}
228 253

  
229

  
230

  
231 254
	/**
232
	 * @return the drawBars
255
	 * @param selectedTypeNames the selectedTypeNames to set
233 256
	 */
234
	public boolean isDrawingBars() {
235
		return drawBars;
257
	public void setSelectedTypeNames(List<String> selectedTypeNames) {
258
		this.pSelectedTypeNames = selectedTypeNames;
236 259
	}
237 260

  
238

  
239

  
240
	/**
241
	 * @return the drawLines
242
	 */
243
	public boolean isDrawingLines() {
244
		return drawLines;
245
	}
246
	
247 261
	@Override
248
	public void setHasBeenComputedOnce(boolean hasBeenComputedOnce) {
249
		// redefined to not reset the chart
262
	public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception {
263
		// TODO Auto-generated method stub
264
		return false;
250 265
	}
251 266

  
252

  
253

  
254
	@Override
255
	public String getResultype() {
256
		return SpecificitiesCoreMessages.SELECTION_RESULT_TYPE;
257
	}
258

  
259 267
}
tmp/org.txm.specificities.core/src/org/txm/specificities/core/chartsengine/jfreechart/JFCSpecificitiesBarChartCreator.java (revision 1042)
1 1
package org.txm.specificities.core.chartsengine.jfreechart;
2 2

  
3 3
import java.awt.Color;
4
import java.util.List;
4 5

  
5 6
import org.jfree.chart.JFreeChart;
6 7
import org.jfree.chart.axis.NumberAxis;
......
100 101
			String[] xAxisSymbols;
101 102
	
102 103
			// Transpose the data set
103
			if(specificitiesSelection.isGroupingByLines())	{
104
		        xAxisSymbols = new String[specificitiesSelection.getSelectedTypeNames().length];
104
			List<String> types = specificitiesSelection.getSelectedTypeNames();
105
			String[] parts = specificitiesSelection.getSelectedPartNames();
106
			if (specificitiesSelection.isGroupingByLines())	{
107
		        xAxisSymbols = new String[types.size()];
105 108
	
106
				for(int i = 0; i < specificitiesSelection.getSelectedPartNames().length; i++) {
107
					XYSeries series = new XYSeries(specificitiesSelection.getSelectedPartNames()[i]);
109
				for(int i = 0; i < parts.length; i++) {
110
					XYSeries series = new XYSeries(parts[i]);
108 111
					dataset.addSeries(series);
109 112
	
110
					for(int j = 0; j < specificitiesSelection.getSelectedTypeNames().length; j++) {
113
					for(int j = 0; j < types.size(); j++) {
111 114
						series.add(j, specificitiesSelection.getSelectedSpecificitiesIndex()[j][i]);
112 115
						// Add X axis symbol
113
						xAxisSymbols[j] = specificitiesSelection.getSelectedTypeNames()[j];
116
						xAxisSymbols[j] = types.get(j);
114 117
					}
115 118
				}
116 119
	
117 120
			}
118 121
			else {
119
		        xAxisSymbols = new String[specificitiesSelection.getSelectedPartNames().length];
122
		        xAxisSymbols = new String[parts.length];
120 123
	
121
				for(int i = 0; i < specificitiesSelection.getSelectedTypeNames().length; i++) {
124
				for(int i = 0; i < types.size(); i++) {
122 125
	
123
					XYSeries series = new XYSeries(specificitiesSelection.getSelectedTypeNames()[i]);
126
					XYSeries series = new XYSeries(types.get(i));
124 127
					dataset.addSeries(series);
125 128
	
126
					for(int j = 0; j < specificitiesSelection.getSelectedPartNames().length; j++) {
129
					for(int j = 0; j < parts.length; j++) {
127 130
						series.add(j, specificitiesSelection.getSelectedSpecificitiesIndex()[i][j]);
128 131
						// Add X axis symbol
129
						xAxisSymbols[j] = specificitiesSelection.getSelectedPartNames()[j];
132
						xAxisSymbols[j] = parts[j];
130 133
					}
131 134
				}
132 135
			}
133
			
134 136
	
135 137
	        
136 138
	        // Custom range axis for ticks drawing options
tmp/org.txm.specificities.core/src/org/txm/specificities/core/chartsengine/r/RSpecificitiesBarChartCreator.java (revision 1042)
83 83
			}
84 84
			// to put one color per word
85 85
			else	{
86
				itemsCount = specificitiesSelection.getSelectedTypeNames().length;				
86
				itemsCount = specificitiesSelection.getSelectedTypeNames().size();				
87 87
			}
88 88

  
89 89
			String[] colors = new String[itemsCount];
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/data/VectorImpl.java (revision 1042)
87 87
	}
88 88
	
89 89
	/**
90
	 * Instantiates a new vector impl.
91
	 *
92
	 * @param data the data
93
	 * @throws RWorkspaceException the r workspace exception
94
	 */
95
	public VectorImpl(List<String> data) throws RWorkspaceException {
96
		super();
97
		rw.addVectorToWorkspace(symbol, data.toArray(new String[data.size()]));
98
		length = data.size();
99
	}
100
	
101
	/**
90 102
	 * Instantiates a new vector.
91 103
	 *
92 104
	 * @param data the data
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/handlers/ComputeSpecifictiesSelectionChart.java (revision 1042)
1 1
package org.txm.specificities.rcp.handlers;
2 2

  
3
import java.util.Arrays;
4

  
3 5
import org.eclipse.core.commands.ExecutionEvent;
4 6
import org.eclipse.core.commands.ExecutionException;
5 7
import org.eclipse.jface.viewers.IStructuredSelection;
......
69 71
				specificitiesSelection = new SpecificitiesSelection(specificities);
70 72
				
71 73
				// Set the data to focus on
72
				specificitiesSelection.setSelectedTypeNames(selectedTypeNames);
73
				specificitiesSelection.setSelectedSpecificitiesIndex(selectedSpecificitiesIndices);
74
				specificitiesSelection.setSelectedTypeNames(Arrays.asList(selectedTypeNames));
74 75
				
75 76
			} catch (Exception e) {
76 77
				System.out.println("Error while computing specificities bar chart: " + e.getLocalizedMessage());

Also available in: Unified diff