1 |
|
package org.txm.chartsengine.core;
|
2 |
|
|
3 |
|
import java.io.File;
|
4 |
|
import java.io.IOException;
|
5 |
|
import java.util.ArrayList;
|
6 |
|
import java.util.HashMap;
|
7 |
|
import java.util.Map;
|
8 |
|
import java.util.Properties;
|
9 |
|
|
10 |
|
import org.txm.chartsengine.core.messages.ChartsEngineCoreMessages;
|
11 |
|
import org.txm.utils.logger.Log;
|
12 |
|
|
13 |
|
|
14 |
|
/**
|
15 |
|
* Common charts engine. This is the superclass of all chart engine implementations.
|
16 |
|
* This class provides methods to create charts from variable data such as CA, CAH, Singular values, etc. results.
|
17 |
|
* @author Sebastien Jacquot
|
18 |
|
*
|
19 |
|
*/
|
20 |
|
public abstract class ___ChartsEngine {
|
21 |
|
|
22 |
|
/**
|
23 |
|
* Chart type constants.
|
24 |
|
*/
|
25 |
|
public final static int CHART_TYPE_PARTITION_DIMENSIONS = 0, CHART_TYPE_SPECIFICITIES = 1, CHART_TYPE_PROGRESSION = 2, CHART_TYPE_CA_FACTORIAL_MAP = 3, CHART_TYPE_CA_SINGULAR_VALUES = 4,
|
26 |
|
CHART_TYPE_CAH_2D = 5, CHART_TYPE_CAH_3D = 6;
|
27 |
|
|
28 |
|
/**
|
29 |
|
* Constants for output formats and file extensions.
|
30 |
|
*/
|
31 |
|
public final static int OUTPUT_FORMAT_JPEG = 0, OUTPUT_FORMAT_PDF = 1, OUTPUT_FORMAT_PNG = 2, OUTPUT_FORMAT_PS = 3, OUTPUT_FORMAT_SVG = 4, OUTPUT_FORMAT_BMP = 5, OUTPUT_FORMAT_GIF = 6;
|
32 |
|
|
33 |
|
|
34 |
|
/**
|
35 |
|
* Output formats and file extensions.
|
36 |
|
*/
|
37 |
|
public static HashMap<Integer, String> outputFormatDefinitions = new HashMap<Integer, String>();
|
38 |
|
|
39 |
|
/**
|
40 |
|
* Initializes output formats definition and descriptions.
|
41 |
|
*/
|
42 |
|
static {
|
43 |
|
outputFormatDefinitions.put(OUTPUT_FORMAT_JPEG, "jpeg"); //$NON-NLS-1$
|
44 |
|
outputFormatDefinitions.put(OUTPUT_FORMAT_PDF, "pdf"); //$NON-NLS-1$
|
45 |
|
outputFormatDefinitions.put(OUTPUT_FORMAT_PNG, "png"); //$NON-NLS-1$
|
46 |
|
outputFormatDefinitions.put(OUTPUT_FORMAT_PS, "ps"); //$NON-NLS-1$
|
47 |
|
outputFormatDefinitions.put(OUTPUT_FORMAT_SVG, "svg"); //$NON-NLS-1$
|
48 |
|
outputFormatDefinitions.put(OUTPUT_FORMAT_BMP, "bmp"); //$NON-NLS-1$
|
49 |
|
outputFormatDefinitions.put(OUTPUT_FORMAT_GIF, "gif"); //$NON-NLS-1$
|
50 |
|
}
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
/**
|
55 |
|
* Prefix to use for properties names.
|
56 |
|
*/
|
57 |
|
public final static String propertiesPrefix = "charts_engine_";
|
58 |
|
|
59 |
|
/**
|
60 |
|
* Constant for showing title or not in the charts.
|
61 |
|
*/
|
62 |
|
public final static String PROP_CHARTS_SHOW_TITLE = propertiesPrefix + "show_title"; //$NON-NLS-1$
|
63 |
|
|
64 |
|
|
65 |
|
/**
|
66 |
|
* Constant for showing legend or not in the charts.
|
67 |
|
*/
|
68 |
|
public final static String PROP_CHARTS_SHOW_LEGEND = propertiesPrefix + "show_legend"; //$NON-NLS-1$
|
69 |
|
|
70 |
|
|
71 |
|
/**
|
72 |
|
* Constant for showing grid/lines or not in the charts.
|
73 |
|
*/
|
74 |
|
public final static String PROP_CHARTS_SHOW_GRID_LINES = propertiesPrefix + "show_grid"; //$NON-NLS-1$
|
75 |
|
|
76 |
|
|
77 |
|
/**
|
78 |
|
* Constant for the partition dimensions parts order in chart.
|
79 |
|
*/
|
80 |
|
//public final static String PROP_PARTITION_DIMENSIONS_SORTED_BY_SIZE = propertiesPrefix + "partition_dimensions_sort_by_size";
|
81 |
|
// FIXME : rename this property according to the line above
|
82 |
|
public final static String PROP_PARTITION_DIMENSIONS_SORTED_BY_SIZE = "diag_partssort"; //$NON-NLS-1$
|
83 |
|
|
84 |
|
/**
|
85 |
|
* Constant for the partition dimensions display parts count in chart title.
|
86 |
|
*/
|
87 |
|
public final static String PROP_PARTITION_DIMENSIONS_DISPLAY_PARTS_COUNT_IN_TITLE = propertiesPrefix + "partition_dimensions_display_parts_count_in_title"; //$NON-NLS-1$
|
88 |
|
|
89 |
|
/**
|
90 |
|
* Constant for the current charts engine used by the tool box.
|
91 |
|
*/
|
92 |
|
public static final String PROP_CHARTS_ENGINE_NAME = propertiesPrefix + "name"; //$NON-NLS-1$
|
93 |
|
|
94 |
|
/**
|
95 |
|
* Constant for the output format of the current charts engine.
|
96 |
|
*/
|
97 |
|
public static final String PROP_CHARTS_ENGINE_OUTPUT_FORMAT = propertiesPrefix + "output_format"; //$NON-NLS-1$
|
98 |
|
|
99 |
|
|
100 |
|
/**
|
101 |
|
* Properties for each type of result data (as <code>Partition</code> : sort by size, <code>SpecificitesResult</code> : draw bars, draw lines, etc.)
|
102 |
|
*/
|
103 |
|
// FIXME: creates a specific class for this extending Properties ? then put all the constant property names in it ?
|
104 |
|
// FIXME: see that when we'll discuss about using RCP store for TBX plugin.
|
105 |
|
public static Properties properties;
|
106 |
|
|
107 |
|
/**
|
108 |
|
* The engine name.
|
109 |
|
*/
|
110 |
|
protected String name;
|
111 |
|
|
112 |
|
protected String userdir;
|
113 |
|
|
114 |
|
|
115 |
|
/**
|
116 |
|
* The engine description.
|
117 |
|
*/
|
118 |
|
protected String description;
|
119 |
|
|
120 |
|
|
121 |
|
/**
|
122 |
|
* The current output format.
|
123 |
|
*/
|
124 |
|
protected int outputFormat;
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
protected HashMap<Class, ChartCreator> chartCreators;
|
129 |
|
|
130 |
|
/**
|
131 |
|
* Creates a charts engine.
|
132 |
|
*/
|
133 |
|
// FIXME : useless ?
|
134 |
|
// protected ChartsEngine() {
|
135 |
|
// this("abstract_charts_engine", "Abstract Charts Engine"); //$NON-NLS-1$
|
136 |
|
// }
|
137 |
|
|
138 |
|
/**
|
139 |
|
* Creates a charts engine with the specified name, description and output format.
|
140 |
|
* @param name
|
141 |
|
* @param description
|
142 |
|
* @param outputFormat
|
143 |
|
*/
|
144 |
|
protected ___ChartsEngine(String name, String description, String outputFormat) {
|
145 |
|
this(name, description, ___ChartsEngine.getOutputFormatDefinition(outputFormat));
|
146 |
|
}
|
147 |
|
|
148 |
|
|
149 |
|
/**
|
150 |
|
* Creates a charts engine with the specified name, description and output format.
|
151 |
|
* @param name
|
152 |
|
* @param description
|
153 |
|
* @param outputFormat
|
154 |
|
*/
|
155 |
|
protected ___ChartsEngine(String name, String description, int outputFormat) {
|
156 |
|
this.name = name;
|
157 |
|
this.description = description;
|
158 |
|
this.setOutputFormat(outputFormat);
|
159 |
|
|
160 |
|
this.chartCreators = new HashMap<Class, ChartCreator>();
|
161 |
|
}
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
/**
|
166 |
|
*
|
167 |
|
* @param type
|
168 |
|
* @return
|
169 |
|
*/
|
170 |
|
public ChartCreator getChartCreator(Class resultDataType) {
|
171 |
|
return this.chartCreators.get(resultDataType);
|
172 |
|
}
|
173 |
|
|
174 |
|
|
175 |
|
// /**
|
176 |
|
// *
|
177 |
|
// * @param ___ChartCreator
|
178 |
|
// */
|
179 |
|
// public void addChartCreator(Class resultDataType, ChartCreator chartCreator) {
|
180 |
|
// this.chartCreators.put(resultDataType, chartCreator);
|
181 |
|
// chartCreator.setChartsEngine(this);
|
182 |
|
// }
|
183 |
|
//
|
184 |
|
//
|
185 |
|
|
186 |
|
// /**
|
187 |
|
// * Creates a charts engine with the specified output format;
|
188 |
|
// * @param outputFormat
|
189 |
|
// */
|
190 |
|
// protected ChartsEngine(String outputFormat) {
|
191 |
|
// this.outputFormat = outputFormat;
|
192 |
|
// }
|
193 |
|
//
|
194 |
|
//
|
195 |
|
/**
|
196 |
|
* Creates a charts engine according to the specified name.
|
197 |
|
* @param name
|
198 |
|
* @return
|
199 |
|
*/
|
200 |
|
// // FIXME : see if the extension point mechanism could be replace this factory pattern
|
201 |
|
// // FIXME : else use reflection to dynamically instantiate the right charts engine implementation
|
202 |
|
// public static ChartsEngine createChartsEngine(String name) {
|
203 |
|
// return createChartsEngine(name, ChartsEngine.OUTPUT_FORMAT_SVG); //$NON-NLS-1$
|
204 |
|
// // FIXME : tests for other file formats
|
205 |
|
// //return createChartsEngine(name, "PNG"); //$NON-NLS-1$
|
206 |
|
// }
|
207 |
|
|
208 |
|
/**
|
209 |
|
* Creates a charts engine according to the specified name and output format.
|
210 |
|
* @param name
|
211 |
|
* @param outputFormat
|
212 |
|
* @return
|
213 |
|
*/
|
214 |
|
// FIXME : see if the extension point mechanism could be replace this factory pattern
|
215 |
|
// FIXME : else use reflection to dynamically instantiate the right charts engine implementation
|
216 |
|
public static ___ChartsEngine createChartsEngine(String name, String outputFormat) {
|
217 |
|
// if (name.equals(___JFCChartsEngine.NAME)) {
|
218 |
|
// return new ___JFCChartsEngine(outputFormat);
|
219 |
|
// } else if (name.equals(___RChartsEngine.NAME)) {
|
220 |
|
// return new ___RChartsEngine(outputFormat);
|
221 |
|
// }
|
222 |
|
// // Default charts engine
|
223 |
|
// return new ___RChartsEngine(outputFormat);
|
224 |
|
return null;
|
225 |
|
}
|
226 |
|
|
227 |
|
|
228 |
|
/**
|
229 |
|
* Creates a temporary file in USER_TXM_HOME\results with the specified prefix for writing the chart.
|
230 |
|
* The suffix is computed according to the current output format of the charts engine.
|
231 |
|
* @return
|
232 |
|
*/
|
233 |
|
public File createTmpFile(String prefix) {
|
234 |
|
File file = null;
|
235 |
|
try {
|
236 |
|
File resultsDir = new File(userdir, "results"); //$NON-NLS-1$
|
237 |
|
resultsDir.mkdirs();
|
238 |
|
file = File.createTempFile(prefix, "." + getOutputFormatDefinition(this.outputFormat), resultsDir);
|
239 |
|
// FIXME : to remove when ok
|
240 |
|
//tmpFile = File.createTempFile(prefix, this.rDevice.getExt(), resultsDir);
|
241 |
|
}
|
242 |
|
catch (IOException e) {
|
243 |
|
Log.severe(ChartsEngineCoreMessages.ChartsEngine_CANT_CREATE_TMP_FILE_CHART + e);
|
244 |
|
}
|
245 |
|
|
246 |
|
// TODO : old code, useful ? and/or return null instead of the file if canWrite() return false ?
|
247 |
|
if(!file.canWrite()) {
|
248 |
|
Log.severe(ChartsEngineCoreMessages.ChartsEngine_CANT_WRITE_IN_FILE + file);
|
249 |
|
}
|
250 |
|
|
251 |
|
|
252 |
|
// TODO : old code, useless ?
|
253 |
|
// System.out.println(tmp.getAbsolutePath());
|
254 |
|
// try {
|
255 |
|
// this.path = Path.fromOSString(tmp.getCanonicalPath());
|
256 |
|
// } catch (IOException e) {
|
257 |
|
// Log.txm.severe(Messages.CANT_CREATE_GRAPHIC + e);
|
258 |
|
// }
|
259 |
|
return file;
|
260 |
|
|
261 |
|
}
|
262 |
|
|
263 |
|
|
264 |
|
/**
|
265 |
|
* Creates a temporary file in USER_TXM_HOME\results.
|
266 |
|
* The prefix and the suffix are computed according to the specified chart type and the current output format of the charts engine.
|
267 |
|
* @param chartType
|
268 |
|
* @return
|
269 |
|
*/
|
270 |
|
public File createTmpFile(int chartType) {
|
271 |
|
if(chartType == ___ChartsEngine.CHART_TYPE_PARTITION_DIMENSIONS) {
|
272 |
|
return this.createTmpFile("info");
|
273 |
|
}
|
274 |
|
else if(chartType == ___ChartsEngine.CHART_TYPE_SPECIFICITIES) {
|
275 |
|
return this.createTmpFile("specif");
|
276 |
|
}
|
277 |
|
else if(chartType == ___ChartsEngine.CHART_TYPE_CA_SINGULAR_VALUES) {
|
278 |
|
return this.createTmpFile("casingularvalues");
|
279 |
|
}
|
280 |
|
else if(chartType == ___ChartsEngine.CHART_TYPE_CA_FACTORIAL_MAP) {
|
281 |
|
return this.createTmpFile("cafactorialmap");
|
282 |
|
}
|
283 |
|
else if(chartType == ___ChartsEngine.CHART_TYPE_PROGRESSION) {
|
284 |
|
return this.createTmpFile("progression");
|
285 |
|
}
|
286 |
|
else if(chartType == ___ChartsEngine.CHART_TYPE_CAH_2D) {
|
287 |
|
return this.createTmpFile("cah2d");
|
288 |
|
}
|
289 |
|
else if(chartType == ___ChartsEngine.CHART_TYPE_CAH_3D) {
|
290 |
|
return this.createTmpFile("cah3d");
|
291 |
|
}
|
292 |
|
|
293 |
|
|
294 |
|
return this.createTmpFile("unknown");
|
295 |
|
}
|
296 |
|
|
297 |
|
|
298 |
|
// /**
|
299 |
|
// * Creates a factorial map chart from the specified CA result.
|
300 |
|
// * @param ca
|
301 |
|
// * @return the factorial map chart object
|
302 |
|
// */
|
303 |
|
// public abstract Object createCAFactorialMapChart(CA ca);
|
304 |
|
//
|
305 |
|
//
|
306 |
|
// /**
|
307 |
|
// * Creates a factorial map chart from the specified CA result and writes it in the specified file.
|
308 |
|
// * @param ca
|
309 |
|
// * @param file
|
310 |
|
// * @return the generated file containing the chart
|
311 |
|
// */
|
312 |
|
// public abstract File createCAFactorialMapChartFile(CA ca, File file);
|
313 |
|
//
|
314 |
|
//
|
315 |
|
// /**
|
316 |
|
// * Creates a factorial map chart from the specified CA result and writes it in a temporary file in USER_TXM_HOME\results.
|
317 |
|
// * The prefix and the suffix are computed according to the chart type and the current output format of the charts engine.
|
318 |
|
// * @param ca
|
319 |
|
// * @return
|
320 |
|
// */
|
321 |
|
// public File createCAFactorialMapChartFile(CA ca) {
|
322 |
|
// return this.createCAFactorialMapChartFile(ca, this.createTmpFile(___ChartsEngine.CHART_TYPE_CA_FACTORIAL_MAP));
|
323 |
|
// }
|
324 |
|
|
325 |
|
|
326 |
|
// /**
|
327 |
|
// * Creates a string title, shared by charts engine implementations, for the CA factorial map chart from the specified result.
|
328 |
|
// * @param ca
|
329 |
|
// * @return
|
330 |
|
// */
|
331 |
|
// public String createCAFactorialMapChartTitle(CA ca) {
|
332 |
|
//
|
333 |
|
// String partitionName;
|
334 |
|
// if (ca.getPartition() == null) {
|
335 |
|
// partitionName = "<no partition>";
|
336 |
|
// }
|
337 |
|
// else {
|
338 |
|
// partitionName = ca.getPartition().getName();
|
339 |
|
// }
|
340 |
|
//
|
341 |
|
// String corpusName;
|
342 |
|
// if (ca.getCorpus() == null) {
|
343 |
|
// corpusName = "<no corpus>";
|
344 |
|
// }
|
345 |
|
// else {
|
346 |
|
// corpusName = ca.getCorpus().getName();
|
347 |
|
// }
|
348 |
|
//
|
349 |
|
// return ChartsEngineMessages.bind(CAC.ChartsEngine_CA_FACTORIAL_MAP_TITLE, partitionName, corpusName);
|
350 |
|
// }
|
351 |
|
|
352 |
|
// /**
|
353 |
|
// * Creates a bar plot with singular values of the specified CA result.
|
354 |
|
// * @param ca
|
355 |
|
// * @return the singular values bar plot object
|
356 |
|
// */
|
357 |
|
// public abstract Object createCASingularValuesBarChart(CA ca);
|
358 |
|
//
|
359 |
|
// /**
|
360 |
|
// * Creates a bar plot with singular values of the specified CA result and writes it in the specified file.
|
361 |
|
// * @param ca
|
362 |
|
// * @return
|
363 |
|
// */
|
364 |
|
// public abstract File createCASingularValuesBarChartFile(CA ca, File file);
|
365 |
|
//
|
366 |
|
//
|
367 |
|
// /**
|
368 |
|
// * Creates a bar plot with singular values of the specified CA result and writes it in a temporary file in USER_TXM_HOME\results.
|
369 |
|
// * The prefix and the suffix are computed according to the chart type and the current output format of the charts engine.
|
370 |
|
// * @param ca
|
371 |
|
// * @return
|
372 |
|
// */
|
373 |
|
// public File createCASingularValuesBarChartFile(CA ca) {
|
374 |
|
// return this.createCASingularValuesBarChartFile(ca, this.createTmpFile(___ChartsEngine.CHART_TYPE_CA_SINGULAR_VALUES));
|
375 |
|
// }
|
376 |
|
|
377 |
|
|
378 |
|
// FIXME
|
379 |
|
// /**
|
380 |
|
// * Creates a chart from the specified CAH result.
|
381 |
|
// * @param cah
|
382 |
|
// * @return
|
383 |
|
// */
|
384 |
|
// public Object createCAHChart(CAH cah) {
|
385 |
|
// return this.createCAHChart(cah, cah.isDisplay2D());
|
386 |
|
// }
|
387 |
|
//
|
388 |
|
|
389 |
|
// /**
|
390 |
|
// * Creates a chart from the specified CAH result.
|
391 |
|
// * @param cah
|
392 |
|
// * @return
|
393 |
|
// */
|
394 |
|
// public Object createCAHChart(CAH cah, boolean chart2d) {
|
395 |
|
// if(chart2d) {
|
396 |
|
// return this.createCAH2dChart(cah);
|
397 |
|
// }
|
398 |
|
// else {
|
399 |
|
// return this.createCAH3dChart(cah);
|
400 |
|
// }
|
401 |
|
// }
|
402 |
|
|
403 |
|
// FIXME
|
404 |
|
//
|
405 |
|
// /**
|
406 |
|
// * Creates a chart from the specified CAH result and writes it in a temporary file in USER_TXM_HOME\results
|
407 |
|
// * @param cah
|
408 |
|
// * @return
|
409 |
|
// */
|
410 |
|
// public File createCAHChartFile(CAH cah) {
|
411 |
|
// return this.createCAHChartFile(cah, cah.isDisplay2D());
|
412 |
|
// }
|
413 |
|
//
|
414 |
|
//
|
415 |
|
// /**
|
416 |
|
// * Creates a chart from the specified CAH result and writes it in the specified file.
|
417 |
|
// * @param cah
|
418 |
|
// * @param file
|
419 |
|
// * @return
|
420 |
|
// */
|
421 |
|
// public File createCAHChartFile(CAH cah, File file) {
|
422 |
|
// return this.createCAHChartFile(cah, cah.isDisplay2D(), file);
|
423 |
|
// }
|
424 |
|
|
425 |
|
|
426 |
|
// /**
|
427 |
|
// * Creates a chart from the specified CAH result and writes it in the specified file.
|
428 |
|
// * @param cah
|
429 |
|
// * @param file
|
430 |
|
// * @return
|
431 |
|
// */
|
432 |
|
// public File createCAHChartFile(CAH cah, boolean display2D, File file) {
|
433 |
|
// if(display2D) {
|
434 |
|
// return this.createCAH2dChartFile(cah, file);
|
435 |
|
// }
|
436 |
|
// else {
|
437 |
|
// return this.createCAH3dChartFile(cah, file);
|
438 |
|
// }
|
439 |
|
// }
|
440 |
|
//
|
441 |
|
// /**
|
442 |
|
// * Creates a chart from the specified CAH result and writes it in a temporary file in USER_TXM_HOME\results
|
443 |
|
// * @param cah
|
444 |
|
// * @param display2D
|
445 |
|
// * @return
|
446 |
|
// */
|
447 |
|
// public File createCAHChartFile(CAH cah, boolean display2D) {
|
448 |
|
// if(display2D) {
|
449 |
|
// return this.createCAH2dChartFile(cah);
|
450 |
|
// }
|
451 |
|
// else {
|
452 |
|
// return this.createCAH3dChartFile(cah);
|
453 |
|
// }
|
454 |
|
// }
|
455 |
|
//
|
456 |
|
// /**
|
457 |
|
// * Creates a 2d chart from the specified CAH result.
|
458 |
|
// * @param cah
|
459 |
|
// * @return
|
460 |
|
// */
|
461 |
|
// public abstract Object createCAH2dChart(CAH cah);
|
462 |
|
//
|
463 |
|
//
|
464 |
|
// /**
|
465 |
|
// * Creates a 2d chart from the specified CAH result and writes it in the specified file.
|
466 |
|
// * @param cah
|
467 |
|
// * @param file
|
468 |
|
// * @return
|
469 |
|
// */
|
470 |
|
// public abstract File createCAH2dChartFile(CAH cah, File file);
|
471 |
|
//
|
472 |
|
//
|
473 |
|
// /**
|
474 |
|
// * Creates a 2d chart from the specified CAH result and writes it in a temporary file in USER_TXM_HOME\results.
|
475 |
|
// * The prefix and the suffix are computed according to the chart type and the current output format of the charts engine.
|
476 |
|
// * @param cah
|
477 |
|
// * @return
|
478 |
|
// */
|
479 |
|
// public File createCAH2dChartFile(CAH cah) {
|
480 |
|
// return this.createCAH2dChartFile(cah, this.createTmpFile(___ChartsEngine.CHART_TYPE_CAH_2D));
|
481 |
|
// }
|
482 |
|
//
|
483 |
|
// /**
|
484 |
|
// * Creates a 3d chart from the specified CAH result.
|
485 |
|
// * @param cah
|
486 |
|
// * @return
|
487 |
|
// */
|
488 |
|
// public abstract Object createCAH3dChart(CAH cah);
|
489 |
|
//
|
490 |
|
//
|
491 |
|
// /**
|
492 |
|
// * Creates a 3d chart from the specified CAH result and writes it in the specified file.
|
493 |
|
// * @param cah
|
494 |
|
// * @param file
|
495 |
|
// * @return
|
496 |
|
// */
|
497 |
|
// public abstract File createCAH3dChartFile(CAH cah, File file);
|
498 |
|
//
|
499 |
|
//
|
500 |
|
// /**
|
501 |
|
// * Creates a 3d chart from the specified CAH result and writes it in a temporary file in USER_TXM_HOME\results.
|
502 |
|
// * The prefix and the suffix are computed according to the chart type and the current output format of the charts engine.
|
503 |
|
// * @param cah
|
504 |
|
// * @return
|
505 |
|
// */
|
506 |
|
// public File createCAH3dChartFile(CAH cah) {
|
507 |
|
// return this.createCAH3dChartFile(cah, this.createTmpFile(___ChartsEngine.CHART_TYPE_CAH_3D));
|
508 |
|
// }
|
509 |
|
|
510 |
|
// /**
|
511 |
|
// * Creates a chart from the specified specificities result.
|
512 |
|
// * @param specificitesResult the specificities result
|
513 |
|
// * @return
|
514 |
|
// */
|
515 |
|
// public abstract Object createSpecificitiesChart(SpecificitesResult specificitiesResult, boolean transpose, boolean drawBars, boolean drawLines, float banalite, boolean grayscale);
|
516 |
|
//
|
517 |
|
//
|
518 |
|
// /**
|
519 |
|
// * Creates a chart from the specified specificities result and writes it in the specified file.
|
520 |
|
// * @param specificitesResult the specificities result
|
521 |
|
// * @param file
|
522 |
|
// * @return
|
523 |
|
// */
|
524 |
|
// public abstract File createSpecificitiesChartFile(SpecificitesResult specificitiesResult, boolean transpose, boolean drawBars, boolean drawLines, float banalite, boolean grayscale, File file);
|
525 |
|
//
|
526 |
|
//
|
527 |
|
// /**
|
528 |
|
// * Creates a chart from the specified specificities result and writes it in a temporary file in USER_TXM_HOME\results.
|
529 |
|
// * The prefix and the suffix are computed according to the chart type and the current output format of the charts engine.
|
530 |
|
// * @param specificitiesResult
|
531 |
|
// * @param typeNames
|
532 |
|
// * @param partNames
|
533 |
|
// * @param specIndex
|
534 |
|
// * @param transpose
|
535 |
|
// * @param drawBars
|
536 |
|
// * @param drawLines
|
537 |
|
// * @param banalite
|
538 |
|
// * @param monochrome
|
539 |
|
// * @return
|
540 |
|
// */
|
541 |
|
// public File createSpecificitiesChartFile(SpecificitesResult specificitiesResult, boolean transpose, boolean drawBars, boolean drawLines, float banalite, boolean monochrome) {
|
542 |
|
// return this.createSpecificitiesChartFile(specificitiesResult, transpose, drawBars, drawLines, banalite, monochrome, this.createTmpFile(___ChartsEngine.CHART_TYPE_SPECIFICITIES));
|
543 |
|
// }
|
544 |
|
|
545 |
|
|
546 |
|
// /**
|
547 |
|
// * Creates a dimensions partition bar chart from the specified <code>Partition</code> result.
|
548 |
|
// * @param partition
|
549 |
|
// * @param sortPartsBySize
|
550 |
|
// * @return
|
551 |
|
// */
|
552 |
|
// public abstract Object createPartitionDimensionsChart(Partition partition, boolean sortPartsBySize);
|
553 |
|
//
|
554 |
|
//
|
555 |
|
// /**
|
556 |
|
// * Creates a dimensions partition bar chart from the specified <code>Partition</code> result and writes it in the specified file.
|
557 |
|
// * @param partition
|
558 |
|
// * @param sortPartsBySize
|
559 |
|
// * @param file
|
560 |
|
// * @return
|
561 |
|
// */
|
562 |
|
// public abstract File createPartitionDimensionsChartFile(Partition partition, boolean sortPartsBySize, File file);
|
563 |
|
|
564 |
|
|
565 |
|
// /**
|
566 |
|
// * Creates a dimensions partition bar chart from the specified <code>Partition</code> result and writes it in a temporary file in USER_TXM_HOME\results.
|
567 |
|
// * The prefix and the suffix are computed according to the chart type and the current output format of the charts engine.
|
568 |
|
// * @param partition
|
569 |
|
// * @param sortPartsBySize
|
570 |
|
// * @return
|
571 |
|
// */
|
572 |
|
// public File createDimensionsPartitionChartFile(Partition partition, boolean sortPartsBySize) {
|
573 |
|
// return this.createPartitionDimensionsChartFile(partition, sortPartsBySize, this.createTmpFile(___ChartsEngine.CHART_TYPE_PARTITION_DIMENSIONS));
|
574 |
|
// }
|
575 |
|
//
|
576 |
|
// /**
|
577 |
|
// *
|
578 |
|
// * @param partition
|
579 |
|
// * @param file
|
580 |
|
// * @return
|
581 |
|
// */
|
582 |
|
// public File createDimensionsPartitionChartFile(Partition partition, File file) {
|
583 |
|
// return this.createPartitionDimensionsChartFile(partition, (Boolean) ___ChartsEngine.properties.get(___ChartsEngine.PROP_PARTITION_DIMENSIONS_SORTED_BY_SIZE), file);
|
584 |
|
// }
|
585 |
|
//
|
586 |
|
//
|
587 |
|
// /**
|
588 |
|
// * Creates a string title, shared by charts engine implementations, for the dimensions partition chart from the specified result.
|
589 |
|
// * @param the partition result
|
590 |
|
// * @param sortPartsBySize the sort parts by size state
|
591 |
|
// * @return the title string
|
592 |
|
// */
|
593 |
|
// public String createPartitionDimensionsChartTitle(Partition partition, boolean sortPartsBySize) {
|
594 |
|
//
|
595 |
|
// String title = ChartsEngineCoreMessages.bind(ChartsEngineCoreMessages.ChartsEngine_PARTITION_DIMENSIONS_DIMENSIONS_OF_PARTITION, partition.getName(), partition.getCorpus().getName());
|
596 |
|
//
|
597 |
|
// if((Boolean) ___ChartsEngine.properties.get(PROP_PARTITION_DIMENSIONS_DISPLAY_PARTS_COUNT_IN_TITLE)) {
|
598 |
|
// title += "\n(" + partition.getParts().size() + " parts" + ")"; //$NON-NLS-1$ //$NON-NLS-3$
|
599 |
|
// }
|
600 |
|
//
|
601 |
|
// if(sortPartsBySize) {
|
602 |
|
// title += ChartsEngineCoreMessages.ChartsEngine_PARTITION_DIMENSIONS_SORTED_BY_SIZE;
|
603 |
|
// }
|
604 |
|
//
|
605 |
|
// return title;
|
606 |
|
// }
|
607 |
|
|
608 |
|
|
609 |
|
|
610 |
|
// /**
|
611 |
|
// * Creates a progression chart from the specified <code>Progression</code> result and writes it in the specified file.
|
612 |
|
// * @param progression
|
613 |
|
// * @return
|
614 |
|
// */
|
615 |
|
// public abstract Object createProgressionChart(Progression progression, boolean grayscale, boolean monostyle, boolean cumulative);
|
616 |
|
//
|
617 |
|
// /**
|
618 |
|
// * Creates a progression chart from the specified <code>Progression</code> result and writes it in the specified file.
|
619 |
|
// * @param progression
|
620 |
|
// * @param file
|
621 |
|
// * @return
|
622 |
|
// */
|
623 |
|
// public abstract File createProgressionChartFile(Progression progression, boolean grayscale, boolean monostyle, boolean cumulative, File file);
|
624 |
|
//
|
625 |
|
//
|
626 |
|
// /**
|
627 |
|
// * Creates a progression chart from the specified <code>Progression</code> result and writes it in a temporary file in USER_TXM_HOME\results.
|
628 |
|
// * The prefix and the suffix are computed according to the chart type and the current output format of the charts engine.
|
629 |
|
// * @param progression
|
630 |
|
// * @param grayscale
|
631 |
|
// * @param monostyle
|
632 |
|
// * @param cumulative
|
633 |
|
// * @return
|
634 |
|
// */
|
635 |
|
// public File createProgressionChartFile(Progression progression, boolean grayscale, boolean monostyle, boolean cumulative) {
|
636 |
|
// return this.createProgressionChartFile(progression, grayscale, monostyle, cumulative, this.createTmpFile(___ChartsEngine.CHART_TYPE_PROGRESSION));
|
637 |
|
// }
|
638 |
|
//
|
639 |
|
//
|
640 |
|
//
|
641 |
|
// /**
|
642 |
|
// * Creates a string title, shared by charts engine implementations, for the progression chart from the specified result.
|
643 |
|
// * @param the progression result
|
644 |
|
// * @param doCumulative
|
645 |
|
// * @return the titles string
|
646 |
|
// */
|
647 |
|
// public String createProgressionChartTitle(Progression progression, boolean doCumulative) {
|
648 |
|
//
|
649 |
|
// String title = Messages.Progression_9 + " "; //$NON-NLS-1$
|
650 |
|
//
|
651 |
|
// // Put queries in title
|
652 |
|
// for(int i = 0; i < progression.getQueries().size(); i++) {
|
653 |
|
// title += progression.getQueries().get(i).getQueryString();
|
654 |
|
// if(i < progression.getQueries().size() - 1) {
|
655 |
|
// title += ", "; //$NON-NLS-1$
|
656 |
|
// }
|
657 |
|
// }
|
658 |
|
//
|
659 |
|
//
|
660 |
|
// title += " " + Messages.Progression_10 + " " + progression.getCorpus().getName(); //$NON-NLS-1$ //$NON-NLS-2$
|
661 |
|
//
|
662 |
|
// if(!doCumulative) {
|
663 |
|
// title += " " + Messages.Progression_11; //$NON-NLS-1$
|
664 |
|
// }
|
665 |
|
//
|
666 |
|
//
|
667 |
|
// // FIXME : is this useful ? I needed to create the setName() method for this.
|
668 |
|
// progression.setName(title);
|
669 |
|
//
|
670 |
|
// if (progression.getStructure() != null) {
|
671 |
|
// title += "\n(" + Messages.Progression_12 + progression.getStructure().getName();
|
672 |
|
// if (progression.getProperty() != null) {
|
673 |
|
// title += Messages.Progression_13 + progression.getProperty().getName();
|
674 |
|
// if (progression.getPropertyRegex() != null) {
|
675 |
|
// title += Messages.Progression_14 + progression.getPropertyRegex();
|
676 |
|
// }
|
677 |
|
// }
|
678 |
|
// title += ")";
|
679 |
|
// }
|
680 |
|
//
|
681 |
|
// return title;
|
682 |
|
// }
|
683 |
|
|
684 |
|
|
685 |
|
|
686 |
|
// /**
|
687 |
|
// * Creates a chart according to the specified result and current output format and writes it in the specified file.
|
688 |
|
// * @param result
|
689 |
|
// * @param file
|
690 |
|
// * @return
|
691 |
|
// */
|
692 |
|
// public File createChartFile(Object result, File file) {
|
693 |
|
//
|
694 |
|
// // Partition dimensions
|
695 |
|
// if(result instanceof Partition) {
|
696 |
|
// return this.createDimensionsPartitionChartFile((Partition)result, file);
|
697 |
|
// }
|
698 |
|
// // Specificities
|
699 |
|
//// else if(result instanceof SpecificitesResult) {
|
700 |
|
//// // FIXME : need to get the rendering properties
|
701 |
|
//// return this.createSpecificitiesChartFile((SpecificitesResult)result, false, true, false, 2, false, file);
|
702 |
|
//// }
|
703 |
|
// // CA factorial map
|
704 |
|
// else if(result instanceof CA) {
|
705 |
|
// return this.createCAFactorialMapChartFile((CA) result, file);
|
706 |
|
// }
|
707 |
|
// // CA singular values bar plot
|
708 |
|
// // FIXME : j'ai besoin de connaître le type du graphe ici vu que résultat stockée est une CA pour les singular values bar plot
|
709 |
|
// // Ajouter un champ int graphType dans ChartEditorPart ??? FAIT : le champ a été ajouté dans le ItemSelectionRenderer mais donc uniquement dispo pour JFC
|
710 |
|
//// else if(result instanceof Integer && (Integer)result == ChartsEngine.CHART_TYPE_CA_SINGULAR_VALUES) {
|
711 |
|
//// return this.createCASingularValuesBarChartFile(((CA) result, file);
|
712 |
|
//// }
|
713 |
|
//
|
714 |
|
//
|
715 |
|
// return null;
|
716 |
|
// }
|
717 |
|
//
|
718 |
|
//
|
719 |
|
// /**
|
720 |
|
// * Creates a chart according to the specified result and output format and writes it in the specified file.
|
721 |
|
// * @param result
|
722 |
|
// * @param file
|
723 |
|
// * @param outputFormat
|
724 |
|
// * @return
|
725 |
|
// */
|
726 |
|
// public File createChartFile(Object result, File file, String outputFormat) {
|
727 |
|
// // FIXME : bad ? Switch the current charts engine output format, export the chart, and then roll back the output format
|
728 |
|
// int oldOutputFormat = this.outputFormat;
|
729 |
|
// this.setOutputFormat(outputFormat);
|
730 |
|
// file = this.createChartFile(result, file);
|
731 |
|
// this.setOutputFormat(oldOutputFormat);
|
732 |
|
//
|
733 |
|
// return file;
|
734 |
|
// }
|
735 |
|
|
736 |
|
|
737 |
|
/**
|
738 |
|
* Exports the chart to the specified file. Also crops the image according to the specified drawing area values.
|
739 |
|
* @param chart
|
740 |
|
* @param file
|
741 |
|
* @param outputFormat
|
742 |
|
* @param imageWidth
|
743 |
|
* @param imageHeight
|
744 |
|
* @param drawingAreaX
|
745 |
|
* @param drawingAreaY
|
746 |
|
* @param drawingAreaWidth
|
747 |
|
* @param drawingAreaHeight
|
748 |
|
* @return
|
749 |
|
*/
|
750 |
|
public abstract File exportChart(Object chart, File file, int outputFormat, int imageWidth, int imageHeight, int drawingAreaX, int drawingAreaY, int drawingAreaWidth, int drawingAreaHeight);
|
751 |
|
|
752 |
|
|
753 |
|
/**
|
754 |
|
* Exports the chart to the specified file.
|
755 |
|
* @param chart
|
756 |
|
* @param file
|
757 |
|
* @param outputFormat
|
758 |
|
* @param imageWidth
|
759 |
|
* @param imageHeight
|
760 |
|
* @return
|
761 |
|
*/
|
762 |
|
public File exportChart(Object chart, File file, int outputFormat, int imageWidth, int imageHeight) {
|
763 |
|
return this.exportChart(chart, file, outputFormat, imageWidth, imageHeight, 0, 0, imageWidth, imageHeight);
|
764 |
|
}
|
765 |
|
|
766 |
|
|
767 |
|
/**
|
768 |
|
* @return the name
|
769 |
|
*/
|
770 |
|
public String getName() {
|
771 |
|
return name;
|
772 |
|
}
|
773 |
|
|
774 |
|
/**
|
775 |
|
* @param name the name to set
|
776 |
|
*/
|
777 |
|
public void setName(String name) {
|
778 |
|
this.name = name;
|
779 |
|
}
|
780 |
|
|
781 |
|
|
782 |
|
/**
|
783 |
|
* @return the output format
|
784 |
|
*/
|
785 |
|
public int getOutputFormat() {
|
786 |
|
return outputFormat;
|
787 |
|
}
|
788 |
|
|
789 |
|
|
790 |
|
|
791 |
|
/**
|
792 |
|
* Returns the output display formats supported by the implementation.
|
793 |
|
* This method is intended to be used in the purpose of knowing all the possible display outputs offered by the charts engine implementation and dedicated to the UI visualization (ex. Java2D, iplots, etc.).
|
794 |
|
* @return
|
795 |
|
*/
|
796 |
|
public abstract ArrayList<String> getSupportedOutputDisplayFormats();
|
797 |
|
|
798 |
|
/**
|
799 |
|
* Returns the output file formats supported by the implementation.
|
800 |
|
* This method is intended to be used in the purpose of knowing all the possible file outputs offered by the charts engine implementation.
|
801 |
|
* @return
|
802 |
|
*/
|
803 |
|
public abstract ArrayList<String> getSupportedOutputFileFormats();
|
804 |
|
|
805 |
|
|
806 |
|
/**
|
807 |
|
* Sets the output format for the generated charts.
|
808 |
|
* @param outputFormat the output format to set
|
809 |
|
*/
|
810 |
|
public void setOutputFormat(int outputFormat) {
|
811 |
|
this.outputFormat = outputFormat;
|
812 |
|
}
|
813 |
|
|
814 |
|
/**
|
815 |
|
* Sets the output format for the generated charts.
|
816 |
|
* @param outputFormat the output format to set
|
817 |
|
*/
|
818 |
|
public void setOutputFormat(String outputFormat) {
|
819 |
|
this.setOutputFormat(___ChartsEngine.getOutputFormatDefinition(outputFormat));
|
820 |
|
}
|
821 |
|
|
822 |
|
|
823 |
|
|
824 |
|
/**
|
825 |
|
* Replaces all non allowed characters in file name to '_' and returns the cleaned file name.
|
826 |
|
* @param fileName the file name to clean
|
827 |
|
* @return the cleaned file name
|
828 |
|
*/
|
829 |
|
public static String cleanFileName(String fileName) {
|
830 |
|
return fileName.replaceAll("[^a-zA-Z0-9\\._-]+", "_");
|
831 |
|
}
|
832 |
|
|
833 |
|
|
834 |
|
/**
|
835 |
|
* Checks if the specified properties are defined and if not, initializes them with default values.
|
836 |
|
*/
|
837 |
|
public static void initDefaultProperties(Properties props) {
|
838 |
|
// // Set Java/JFreeChart charts engine as default
|
839 |
|
// if(props.getProperty(PROP_CHARTS_ENGINE_NAME) == null || props.getProperty(PROP_CHARTS_ENGINE_NAME).length() == 0) {
|
840 |
|
// props.setProperty(PROP_CHARTS_ENGINE_NAME, ___JFCChartsEngine.NAME);
|
841 |
|
// }
|
842 |
|
// // Set JFreeChart/Java2D as default charts engine display format
|
843 |
|
// if(props.getProperty(PROP_CHARTS_ENGINE_OUTPUT_FORMAT) == null || props.getProperty(PROP_CHARTS_ENGINE_OUTPUT_FORMAT).length() == 0) {
|
844 |
|
// props.setProperty(PROP_CHARTS_ENGINE_OUTPUT_FORMAT, outputFormatDefinitions.get(___JFCChartsEngine.OUTPUT_FORMAT_JFC_JAVA2D));
|
845 |
|
// }
|
846 |
|
// // Default property for partition dimensions charts sorting
|
847 |
|
// if(props.get(___ChartsEngine.PROP_PARTITION_DIMENSIONS_SORTED_BY_SIZE) == null) {
|
848 |
|
// props.put(___ChartsEngine.PROP_PARTITION_DIMENSIONS_SORTED_BY_SIZE, false);
|
849 |
|
// }
|
850 |
|
// // Display partition dimensions parts count in chart title
|
851 |
|
// if(props.get(___ChartsEngine.PROP_PARTITION_DIMENSIONS_DISPLAY_PARTS_COUNT_IN_TITLE) == null) {
|
852 |
|
// props.put(___ChartsEngine.PROP_PARTITION_DIMENSIONS_DISPLAY_PARTS_COUNT_IN_TITLE, false);
|
853 |
|
// }
|
854 |
|
}
|
855 |
|
|
856 |
|
/**
|
857 |
|
* Returns an output format definition as a string specified by its key.
|
858 |
|
* @param key
|
859 |
|
* @return
|
860 |
|
*/
|
861 |
|
public static String getOutputFormatDefinition(int key) {
|
862 |
|
return outputFormatDefinitions.get(key);
|
863 |
|
}
|
864 |
|
|
865 |
|
/**
|
866 |
|
* Returns an output format definition as an integer specified by its string value if it exists otherwise -1.
|
867 |
|
* @param outputFormat
|
868 |
|
* @return
|
869 |
|
*/
|
870 |
|
public static int getOutputFormatDefinition(String outputFormat) {
|
871 |
|
int index = -1;
|
872 |
|
|
873 |
|
for (Map.Entry<Integer, String> e : outputFormatDefinitions.entrySet()) {
|
874 |
|
if(e.getValue().equals(outputFormat) || e.getValue().equals(outputFormat.toLowerCase())) {
|
875 |
|
index = e.getKey();
|
876 |
|
break;
|
877 |
|
}
|
878 |
|
}
|
879 |
|
|
880 |
|
return index;
|
881 |
|
}
|
882 |
|
|
883 |
|
/**
|
884 |
|
* Auto-populate supported output file raster formats list from available system image writers.
|
885 |
|
* @param supportedOutputFileFormats
|
886 |
|
* @return
|
887 |
|
*/
|
888 |
|
// FIXME: this method is useful but can lead to a deadlock when call during the SWT initialization maybe because of a multi-thread problem
|
889 |
|
public static ArrayList<String> populateSupportedOutputRasterFileFormats(ArrayList<String> supportedOutputFileFormats) {
|
890 |
|
String[] writerFormatNames = javax.imageio.ImageIO.getWriterFormatNames();
|
891 |
|
|
892 |
|
for(int i = 0; i < writerFormatNames.length; i++) {
|
893 |
|
int outputFormat = getOutputFormatDefinition(writerFormatNames[i]);
|
894 |
|
if(outputFormat != -1 && !supportedOutputFileFormats.contains(writerFormatNames[i]) && !supportedOutputFileFormats.contains(writerFormatNames[i].toLowerCase())) {
|
895 |
|
supportedOutputFileFormats.add(writerFormatNames[i].toLowerCase());
|
896 |
|
}
|
897 |
|
}
|
898 |
|
return supportedOutputFileFormats;
|
899 |
|
}
|
900 |
|
|
901 |
|
// /**
|
902 |
|
// * Sets the CA factorial map rows visibility and refreshes the chart.
|
903 |
|
// * @param ca
|
904 |
|
// * @param visible
|
905 |
|
// */
|
906 |
|
// public void updateChartCAFactorialMapSetRowsVisible(Object chart, CA ca, boolean visible) {
|
907 |
|
// ca.setShown(ca.isShowIndividuals(), visible);
|
908 |
|
// }
|
909 |
|
//
|
910 |
|
// /**
|
911 |
|
// * Sets the CA factorial map columns visibility and refreshes the chart.
|
912 |
|
// * @param ca
|
913 |
|
// * @param visible
|
914 |
|
// */
|
915 |
|
// public void updateChartCAFactorialMapSetColumnsVisible(Object chart, CA ca, boolean visible) {
|
916 |
|
// ca.setShown(visible, ca.isShowVariables());
|
917 |
|
// }
|
918 |
|
//
|
919 |
|
//
|
920 |
|
// /**
|
921 |
|
// * Sets the CA factorial map dimensions.
|
922 |
|
// * @param editorPart
|
923 |
|
// * @param dimension1
|
924 |
|
// * @param dimension2
|
925 |
|
// */
|
926 |
|
// public void updateChartCAFactorialMapSetDimensions(Object chart, CA ca, int dimension1, int dimension2) {
|
927 |
|
// ca.setDimensions(dimension1, dimension2);
|
928 |
|
// }
|
929 |
|
|
930 |
|
// /**
|
931 |
|
// * Highlights points in the CA factorial map chart according to the specified labels.
|
932 |
|
// * @param chart
|
933 |
|
// * @param rows
|
934 |
|
// * @param labels
|
935 |
|
// */
|
936 |
|
// public abstract void updateChartCAFactorialMapHighlightPoints(Object chart, boolean rows, String[] labels);
|
937 |
|
//
|
938 |
|
// /**
|
939 |
|
// * Sets the items selection order on label.
|
940 |
|
// * @param chart
|
941 |
|
// * @param itemsSelectionOrder
|
942 |
|
// */
|
943 |
|
// public abstract void updateChartCAFactorialMapSetLabelItemsSelectionOrder(Object chart, String[] rowLabels, String[] colLabels);
|
944 |
|
//
|
945 |
|
// /**
|
946 |
|
// * Gets the rows points currently selected in the CA factorial map chart.
|
947 |
|
// * @return
|
948 |
|
// */
|
949 |
|
// public abstract ArrayList<String> getCAFactorialMapChartSelectedRowPoints(Object chart);
|
950 |
|
//
|
951 |
|
// /**
|
952 |
|
// * Gets the columns points currently selected in the CA factorial map chart.
|
953 |
|
// * @return
|
954 |
|
// */
|
955 |
|
// public abstract ArrayList<String> getCAFactorialMapChartSelectedColumnPoints(Object chart);
|
956 |
|
//
|
957 |
|
//
|
958 |
|
}
|