Révision 642
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/swt/AdvancedChartEditorToolBar.java (revision 642) | ||
---|---|---|
193 | 193 |
&& this.getEditorPart().getChartsEngine().getName().equals(chartsEngineNames.get(i))) { |
194 | 194 |
currentChartTypeIndex = i; |
195 | 195 |
} |
196 |
chartTypes[i] = chartsEngineNames.get(i) + " / " + chartTypes[i]; |
|
196 |
chartTypes[i] = chartsEngineNames.get(i) + " / " + chartTypes[i]; //$NON-NLS-1$
|
|
197 | 197 |
} |
198 | 198 |
chartTypeCombo.setItems(chartTypes); |
199 | 199 |
|
... | ... | |
231 | 231 |
chartEditorPart.getResult().setRenderingColorsMode(renderingModeCombo.getSelectionIndex()); |
232 | 232 |
} |
233 | 233 |
else if(e.getSource() == fontCombo || e.getSource() == fontSizeCombo) { |
234 |
chartEditorPart.getResult().setFont("1|" + fontCombo.getItem(fontCombo.getSelectionIndex()) + "|" + fontSizeCombo.getItem(fontSizeCombo.getSelectionIndex()) + "|0"); |
|
234 |
chartEditorPart.getResult().setFont("1|" + fontCombo.getItem(fontCombo.getSelectionIndex()) + "|" + fontSizeCombo.getItem(fontSizeCombo.getSelectionIndex()) + "|0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
235 | 235 |
} |
236 | 236 |
else if(e.getSource() == chartTypeCombo) { |
237 | 237 |
|
tmp/org.txm.progression.core/src/org/txm/progression/core/chartsengine/r/RProgressionBaseChartCreator.java (revision 642) | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package org.txm.progression.core.chartsengine.r; |
|
5 |
|
|
6 |
import java.io.File; |
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.List; |
|
9 |
|
|
10 |
import org.apache.commons.lang.StringEscapeUtils; |
|
11 |
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences; |
|
12 |
import org.txm.chartsengine.core.results.ChartResult; |
|
13 |
import org.txm.chartsengine.r.core.RChartCreator; |
|
14 |
import org.txm.chartsengine.r.core.themes.DefaultTheme; |
|
15 |
import org.txm.progression.core.chartsengine.base.ProgressionChartCreator; |
|
16 |
import org.txm.progression.core.chartsengine.base.Utils; |
|
17 |
import org.txm.progression.core.functions.Progression; |
|
18 |
import org.txm.statsengine.r.core.RWorkspace; |
|
19 |
import org.txm.statsengine.r.core.exceptions.RWorkspaceException; |
|
20 |
import org.txm.utils.logger.Log; |
|
21 |
|
|
22 |
/** |
|
23 |
* Base chart creator for R Progression charts. |
|
24 |
* |
|
25 |
* @author mdecorde |
|
26 |
* @author sjacquot |
|
27 |
* |
|
28 |
*/ |
|
29 |
public class RProgressionBaseChartCreator extends RChartCreator implements ProgressionChartCreator { |
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
/** |
|
34 |
* Creates a progression chart file. |
|
35 |
* @param result |
|
36 |
* @param file |
|
37 |
* @param cumulative |
|
38 |
* @return |
|
39 |
*/ |
|
40 |
public File createChartFile(ChartResult result, File file, boolean cumulative) { |
|
41 |
|
|
42 |
try { |
|
43 |
|
|
44 |
Progression progression = (Progression) result; |
|
45 |
|
|
46 |
// parameters |
|
47 |
int renderingColorMode = progression.getRenderingColorsMode(); |
|
48 |
|
|
49 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
|
50 |
rw.eval("library(textometry)"); |
|
51 |
// System.out.println("create list of positions"); |
|
52 |
|
|
53 |
|
|
54 |
List<int[]> allPositions = progression.getAllPositions(); |
|
55 |
String listString = "list("; //$NON-NLS-1$ |
|
56 |
for(int i = 0; i < allPositions.size(); i++) { |
|
57 |
int[] positions = allPositions.get(i); |
|
58 |
// System.out.println("add vector "+i); |
|
59 |
rw.eval("rm(x" + i + ")"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
60 |
rw.addVectorToWorkspace("x" + i, positions); //$NON-NLS-1$ |
|
61 |
listString += "x" + i + ","; //$NON-NLS-1$ //$NON-NLS-2$ |
|
62 |
} |
|
63 |
listString = listString.substring(0, listString.length() - 1) + ")"; //$NON-NLS-1$ |
|
64 |
// System.out.println("create positions"); |
|
65 |
rw.eval("rm(positions)"); //$NON-NLS-1$ |
|
66 |
rw.eval("positions <- " + listString); //$NON-NLS-1$ |
|
67 |
|
|
68 |
rw.eval("rm(structurepositions)"); //$NON-NLS-1$ |
|
69 |
rw.addVectorToWorkspace("structurepositions", progression.getStructurePositions()); //$NON-NLS-1$ |
|
70 |
rw.eval("rm(structurenames)"); //$NON-NLS-1$ |
|
71 |
// if (structurenames != null) structurenames = new |
|
72 |
// String[structurepositions.length]; |
|
73 |
for(int i = 0; i < progression.getStructureNames().length; i++) { // Fix empty attribute values |
|
74 |
if("".equals(progression.getStructureNames()[i]) || progression.getStructureNames()[i] == null) { //$NON-NLS-1$ |
|
75 |
progression.getStructureNames()[i] = "--"; //$NON-NLS-1$ |
|
76 |
} |
|
77 |
} |
|
78 |
rw.addVectorToWorkspace("structurenames", progression.getStructureNames()); //$NON-NLS-1$ |
|
79 |
// System.out.println("create list positions"); |
|
80 |
// rw.getConnection().assign("positions",Rpositions); |
|
81 |
|
|
82 |
this.getChartsEngine().setColors(renderingColorMode, progression.getQueries().size()); |
|
83 |
|
|
84 |
// if(monochrome) { |
|
85 |
// rw.addVectorToWorkspace("colors", DefaultTheme.monocolors); //$NON-NLS-1$ |
|
86 |
// } |
|
87 |
// else { |
|
88 |
// if(progression.getQueries().size() <= 5) { |
|
89 |
// // System.out.println("uses colors5"); |
|
90 |
// |
|
91 |
// |
|
92 |
// rw.addVectorToWorkspace("colors", this.getChartsEngine().getTheme().getColorPaletteAsHexFor(5)); |
|
93 |
// |
|
94 |
// |
|
95 |
// //rw.addVectorToWorkspace("colors", DefaultTheme.colors5); //$NON-NLS-1$ |
|
96 |
// } |
|
97 |
// else if(progression.getQueries().size() <= 10) { |
|
98 |
// // System.out.println("uses colors10"); |
|
99 |
// rw.addVectorToWorkspace("colors", DefaultTheme.colors10); //$NON-NLS-1$ |
|
100 |
// } |
|
101 |
// else { |
|
102 |
// // System.out.println("uses colors16"); |
|
103 |
// rw.addVectorToWorkspace("colors", DefaultTheme.colors); //$NON-NLS-1$ |
|
104 |
// } |
|
105 |
// } |
|
106 |
|
|
107 |
// System.out.println("create styles vector"); |
|
108 |
rw.eval("rm(styles)"); //$NON-NLS-1$ |
|
109 |
if(!progression.isMultipleLineStrokes()) { |
|
110 |
rw.addVectorToWorkspace("styles", DefaultTheme.monostyles); //$NON-NLS-1$ |
|
111 |
} |
|
112 |
else { |
|
113 |
rw.addVectorToWorkspace("styles", DefaultTheme.styles); //$NON-NLS-1$ |
|
114 |
} |
|
115 |
|
|
116 |
// System.out.println("create styles vector"); |
|
117 |
rw.eval("rm(widths)"); //$NON-NLS-1$ |
|
118 |
rw.addVectorToWorkspace("widths", DefaultTheme.monoWidths); //$NON-NLS-1$ |
|
119 |
|
|
120 |
// System.out.println("create names vector"); |
|
121 |
String[] queriesstring = new String[progression.getQueries().size()]; |
|
122 |
for(int i = 0; i < progression.getQueries().size(); i++) { |
|
123 |
queriesstring[i] = progression.getQueries().get(i).getQueryString(); |
|
124 |
} |
|
125 |
rw.eval("rm(names)"); //$NON-NLS-1$ |
|
126 |
rw.addVectorToWorkspace("names", queriesstring); //$NON-NLS-1$ |
|
127 |
|
|
128 |
String name = progression.getCorpus().getName(); |
|
129 |
|
|
130 |
// Create chart title |
|
131 |
String title = ""; |
|
132 |
if(result.getBooleanParameterValue(ChartsEnginePreferences.SHOW_TITLE)) { |
|
133 |
title = Utils.createProgressionChartTitle(progression, cumulative); |
|
134 |
} |
|
135 |
|
|
136 |
// Escape title string |
|
137 |
title = StringEscapeUtils.escapeJava(title); |
|
138 |
|
|
139 |
// System.out.println("BANDE="+bande); |
|
140 |
|
|
141 |
String cmd = "progression(positions, names, colors, styles, widths, \"" + name + "\"," + progression.getXminCorpus() + "," + progression.getXmaxCorpus() + ",\"" + cumulative + "\",structurepositions,structurenames, \"" + title + "\", " + progression.getBande() + ");\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ |
|
142 |
|
|
143 |
// FIXME: the grid must be plotted behind the chart and it is not possible with the current R progression object code |
|
144 |
// Grid |
|
145 |
if(result.getBooleanParameterValue(ChartsEnginePreferences.SHOW_GRID)) { |
|
146 |
cmd += this.getChartsEngine().getGridPlotCmd(); |
|
147 |
} |
|
148 |
|
|
149 |
this.getChartsEngine().plot(file, cmd); |
|
150 |
|
|
151 |
RWorkspace.getRWorkspaceInstance().eval(Progression.prefixR + Progression.norep + " <- list(positions=positions, names=names, xmin=" + progression.getXminCorpus() + ",xmax=" + progression.getXmaxCorpus() + ", structpositions=structurepositions, structnames=structurenames)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
152 |
Progression.norep++; |
|
153 |
} |
|
154 |
catch(RWorkspaceException e) { |
|
155 |
// TODO Auto-generated catch block |
|
156 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
157 |
} |
|
158 |
|
|
159 |
return file; |
|
160 |
} |
|
161 |
|
|
162 |
|
|
163 |
@Override |
|
164 |
public ArrayList<Integer> getSelectedPointPositions(Object chart) { |
|
165 |
// FIXME: not implemented |
|
166 |
Log.severe(this.getClass() + ".getProgressionChartSelectedPointPositions(): Not yet implemented."); //$NON-NLS-1$ |
|
167 |
return new ArrayList<Integer>(0); |
|
168 |
} |
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
@Override |
|
173 |
public ArrayList<Integer> getSelectedSeries(Object chart) { |
|
174 |
Log.severe(this.getClass() + ".getProgressionChartSelectedSeries(): Not yet implemented."); //$NON-NLS-1$ |
|
175 |
return new ArrayList<Integer>(0); |
|
176 |
} |
|
177 |
|
|
178 |
|
|
179 |
@Override |
|
180 |
public ArrayList<Integer> getSelectedPointNumbers(Object chart) { |
|
181 |
Log.severe(this.getClass() + ".getProgressionChartSelectedPointNumber(): Not yet implemented."); //$NON-NLS-1$ |
|
182 |
return new ArrayList<Integer>(0); |
|
183 |
} |
|
184 |
|
|
185 |
|
|
186 |
@Override |
|
187 |
public int getLastSelectedSeries(Object chart) { |
|
188 |
Log.severe(this.getClass() + ".getProgressionChartLastSelectedSeries(): Not yet implemented."); //$NON-NLS-1$ |
|
189 |
return -1; |
|
190 |
} |
|
191 |
|
|
192 |
|
|
193 |
@Override |
|
194 |
public Class getResultDataClass() { |
|
195 |
return Progression.class; |
|
196 |
} |
|
197 |
|
|
198 |
@Override |
|
199 |
public ArrayList<ArrayList<Integer>> getAllPointPositionsBySeries(Object chart) { |
|
200 |
Log.severe(this.getClass() + ".getAllPointPositionsBySeries(): Not yet implemented."); //$NON-NLS-1$ |
|
201 |
return null; |
|
202 |
} |
|
203 |
|
|
204 |
|
|
205 |
} |
|
0 | 206 |
tmp/org.txm.progression.core/src/org/txm/progression/core/chartsengine/r/RProgressionCumulativeChartCreator.java (revision 642) | ||
---|---|---|
1 | 1 |
package org.txm.progression.core.chartsengine.r; |
2 | 2 |
|
3 | 3 |
import java.io.File; |
4 |
import java.util.ArrayList; |
|
5 |
import java.util.List; |
|
6 | 4 |
|
7 |
import org.apache.commons.lang.StringEscapeUtils; |
|
8 |
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences; |
|
9 | 5 |
import org.txm.chartsengine.core.results.ChartResult; |
10 |
import org.txm.chartsengine.r.core.RChartCreator; |
|
11 |
import org.txm.chartsengine.r.core.themes.DefaultTheme; |
|
12 |
import org.txm.progression.core.chartsengine.base.ProgressionChartCreator; |
|
13 |
import org.txm.progression.core.chartsengine.base.Utils; |
|
14 |
import org.txm.progression.core.functions.Progression; |
|
15 |
import org.txm.progression.core.preferences.ProgressionPreferences; |
|
16 |
import org.txm.statsengine.r.core.RWorkspace; |
|
17 |
import org.txm.statsengine.r.core.exceptions.RWorkspaceException; |
|
18 |
import org.txm.utils.logger.Log; |
|
19 | 6 |
|
20 | 7 |
/** |
21 |
* R progression chart creator. |
|
22 |
* @author mdecorde
|
|
8 |
* R progression cumulative chart creator.
|
|
9 |
* |
|
23 | 10 |
* @author sjacquot |
24 | 11 |
* |
25 | 12 |
*/ |
26 |
public class RProgressionCumulativeChartCreator extends RChartCreator implements ProgressionChartCreator {
|
|
13 |
public class RProgressionCumulativeChartCreator extends RProgressionBaseChartCreator {
|
|
27 | 14 |
|
28 | 15 |
|
29 | 16 |
@Override |
30 | 17 |
public File createChartFile(ChartResult result, File file) { |
31 |
|
|
32 |
try { |
|
33 |
|
|
34 |
Progression progression = (Progression) result; |
|
35 |
|
|
36 |
// parameters |
|
37 |
int renderingColorMode = progression.getRenderingColorsMode(); |
|
38 |
|
|
39 |
boolean cumulative = progression.getBooleanParameterValue(ProgressionPreferences.CHART_CUMULATIVE); |
|
40 |
|
|
41 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
|
42 |
rw.eval("library(textometry)"); |
|
43 |
// System.out.println("create list of positions"); |
|
44 |
|
|
45 |
|
|
46 |
List<int[]> allPositions = progression.getAllPositions(); |
|
47 |
String listString = "list("; //$NON-NLS-1$ |
|
48 |
for(int i = 0; i < allPositions.size(); i++) { |
|
49 |
int[] positions = allPositions.get(i); |
|
50 |
// System.out.println("add vector "+i); |
|
51 |
rw.eval("rm(x" + i + ")"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
52 |
rw.addVectorToWorkspace("x" + i, positions); //$NON-NLS-1$ |
|
53 |
listString += "x" + i + ","; //$NON-NLS-1$ //$NON-NLS-2$ |
|
54 |
} |
|
55 |
listString = listString.substring(0, listString.length() - 1) + ")"; //$NON-NLS-1$ |
|
56 |
// System.out.println("create positions"); |
|
57 |
rw.eval("rm(positions)"); //$NON-NLS-1$ |
|
58 |
rw.eval("positions <- " + listString); //$NON-NLS-1$ |
|
59 |
|
|
60 |
rw.eval("rm(structurepositions)"); //$NON-NLS-1$ |
|
61 |
rw.addVectorToWorkspace("structurepositions", progression.getStructurePositions()); //$NON-NLS-1$ |
|
62 |
rw.eval("rm(structurenames)"); //$NON-NLS-1$ |
|
63 |
// if (structurenames != null) structurenames = new |
|
64 |
// String[structurepositions.length]; |
|
65 |
for(int i = 0; i < progression.getStructureNames().length; i++) { // Fix empty attribute values |
|
66 |
if("".equals(progression.getStructureNames()[i]) || progression.getStructureNames()[i] == null) { //$NON-NLS-1$ |
|
67 |
progression.getStructureNames()[i] = "--"; //$NON-NLS-1$ |
|
68 |
} |
|
69 |
} |
|
70 |
rw.addVectorToWorkspace("structurenames", progression.getStructureNames()); //$NON-NLS-1$ |
|
71 |
// System.out.println("create list positions"); |
|
72 |
// rw.getConnection().assign("positions",Rpositions); |
|
73 |
|
|
74 |
this.getChartsEngine().setColors(renderingColorMode, progression.getQueries().size()); |
|
75 |
|
|
76 |
// if(monochrome) { |
|
77 |
// rw.addVectorToWorkspace("colors", DefaultTheme.monocolors); //$NON-NLS-1$ |
|
78 |
// } |
|
79 |
// else { |
|
80 |
// if(progression.getQueries().size() <= 5) { |
|
81 |
// // System.out.println("uses colors5"); |
|
82 |
// |
|
83 |
// |
|
84 |
// rw.addVectorToWorkspace("colors", this.getChartsEngine().getTheme().getColorPaletteAsHexFor(5)); |
|
85 |
// |
|
86 |
// |
|
87 |
// //rw.addVectorToWorkspace("colors", DefaultTheme.colors5); //$NON-NLS-1$ |
|
88 |
// } |
|
89 |
// else if(progression.getQueries().size() <= 10) { |
|
90 |
// // System.out.println("uses colors10"); |
|
91 |
// rw.addVectorToWorkspace("colors", DefaultTheme.colors10); //$NON-NLS-1$ |
|
92 |
// } |
|
93 |
// else { |
|
94 |
// // System.out.println("uses colors16"); |
|
95 |
// rw.addVectorToWorkspace("colors", DefaultTheme.colors); //$NON-NLS-1$ |
|
96 |
// } |
|
97 |
// } |
|
98 |
|
|
99 |
// System.out.println("create styles vector"); |
|
100 |
rw.eval("rm(styles)"); //$NON-NLS-1$ |
|
101 |
if(progression.isMultipleLineStrokes()) { |
|
102 |
rw.addVectorToWorkspace("styles", DefaultTheme.monostyles); //$NON-NLS-1$ |
|
103 |
} |
|
104 |
else { |
|
105 |
rw.addVectorToWorkspace("styles", DefaultTheme.styles); //$NON-NLS-1$ |
|
106 |
} |
|
107 |
|
|
108 |
// System.out.println("create styles vector"); |
|
109 |
rw.eval("rm(widths)"); //$NON-NLS-1$ |
|
110 |
rw.addVectorToWorkspace("widths", DefaultTheme.monoWidths); //$NON-NLS-1$ |
|
111 |
|
|
112 |
// System.out.println("create names vector"); |
|
113 |
String[] queriesstring = new String[progression.getQueries().size()]; |
|
114 |
for(int i = 0; i < progression.getQueries().size(); i++) { |
|
115 |
queriesstring[i] = progression.getQueries().get(i).getQueryString(); |
|
116 |
} |
|
117 |
rw.eval("rm(names)"); //$NON-NLS-1$ |
|
118 |
rw.addVectorToWorkspace("names", queriesstring); //$NON-NLS-1$ |
|
119 |
|
|
120 |
String name = progression.getCorpus().getName(); |
|
121 |
|
|
122 |
// Create chart title |
|
123 |
String title = ""; |
|
124 |
if(result.getBooleanParameterValue(ChartsEnginePreferences.SHOW_TITLE)) { |
|
125 |
title = Utils.createProgressionChartTitle(progression, cumulative); |
|
126 |
} |
|
127 |
|
|
128 |
// Escape title string |
|
129 |
title = StringEscapeUtils.escapeJava(title); |
|
130 |
|
|
131 |
// System.out.println("BANDE="+bande); |
|
132 |
|
|
133 |
String cmd = "progression(positions, names, colors, styles, widths, \"" + name + "\"," + progression.getXminCorpus() + "," + progression.getXmaxCorpus() + ",\"" + cumulative + "\",structurepositions,structurenames, \"" + title + "\", " + progression.getBande() + ");\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ |
|
134 |
|
|
135 |
// FIXME: the grid must be plotted behind the chart and it is not possible with the current R progression object code |
|
136 |
// Grid |
|
137 |
if(result.getBooleanParameterValue(ChartsEnginePreferences.SHOW_GRID)) { |
|
138 |
cmd += this.getChartsEngine().getGridPlotCmd(); |
|
139 |
} |
|
140 |
|
|
141 |
this.getChartsEngine().plot(file, cmd); |
|
142 |
|
|
143 |
RWorkspace.getRWorkspaceInstance().eval(Progression.prefixR + Progression.norep + " <- list(positions=positions, names=names, xmin=" + progression.getXminCorpus() + ",xmax=" + progression.getXmaxCorpus() + ", structpositions=structurepositions, structnames=structurenames)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
144 |
Progression.norep++; |
|
145 |
} |
|
146 |
catch(RWorkspaceException e) { |
|
147 |
// TODO Auto-generated catch block |
|
148 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
149 |
} |
|
150 |
|
|
151 |
return file; |
|
18 |
return super.createChartFile(result, file, true); |
|
152 | 19 |
} |
153 | 20 |
|
154 | 21 |
|
155 |
@Override |
|
156 |
public ArrayList<Integer> getSelectedPointPositions(Object chart) { |
|
157 |
// FIXME: not implemented |
|
158 |
Log.severe(this.getClass() + ".getProgressionChartSelectedPointPositions(): Not yet implemented."); //$NON-NLS-1$ |
|
159 |
return new ArrayList<Integer>(0); |
|
160 |
} |
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
@Override |
|
165 |
public ArrayList<Integer> getSelectedSeries(Object chart) { |
|
166 |
Log.severe(this.getClass() + ".getProgressionChartSelectedSeries(): Not yet implemented."); //$NON-NLS-1$ |
|
167 |
return new ArrayList<Integer>(0); |
|
168 |
} |
|
169 |
|
|
170 |
|
|
171 |
@Override |
|
172 |
public ArrayList<Integer> getSelectedPointNumbers(Object chart) { |
|
173 |
Log.severe(this.getClass() + ".getProgressionChartSelectedPointNumber(): Not yet implemented."); //$NON-NLS-1$ |
|
174 |
return new ArrayList<Integer>(0); |
|
175 |
} |
|
176 |
|
|
177 |
|
|
178 |
@Override |
|
179 |
public int getLastSelectedSeries(Object chart) { |
|
180 |
Log.severe(this.getClass() + ".getProgressionChartLastSelectedSeries(): Not yet implemented."); //$NON-NLS-1$ |
|
181 |
return -1; |
|
182 |
} |
|
183 |
|
|
184 |
|
|
185 |
@Override |
|
186 |
public Class getResultDataClass() { |
|
187 |
return Progression.class; |
|
188 |
} |
|
189 |
|
|
190 |
@Override |
|
191 |
public ArrayList<ArrayList<Integer>> getAllPointPositionsBySeries(Object chart) { |
|
192 |
Log.severe(this.getClass() + ".getAllPointPositionsBySeries(): Not yet implemented."); //$NON-NLS-1$ |
|
193 |
return null; |
|
194 |
} |
|
195 |
|
|
196 |
|
|
197 | 22 |
} |
tmp/org.txm.progression.core/src/org/txm/progression/core/chartsengine/r/RProgressionDensityChartCreator.java (revision 642) | ||
---|---|---|
1 | 1 |
package org.txm.progression.core.chartsengine.r; |
2 | 2 |
|
3 | 3 |
import java.io.File; |
4 |
import java.util.ArrayList; |
|
5 |
import java.util.List; |
|
6 | 4 |
|
7 |
import org.apache.commons.lang.StringEscapeUtils; |
|
8 |
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences; |
|
9 | 5 |
import org.txm.chartsengine.core.results.ChartResult; |
10 |
import org.txm.chartsengine.r.core.RChartCreator; |
|
11 |
import org.txm.chartsengine.r.core.themes.DefaultTheme; |
|
12 |
import org.txm.progression.core.chartsengine.base.ProgressionChartCreator; |
|
13 |
import org.txm.progression.core.chartsengine.base.Utils; |
|
14 |
import org.txm.progression.core.functions.Progression; |
|
15 |
import org.txm.progression.core.preferences.ProgressionPreferences; |
|
16 |
import org.txm.statsengine.r.core.RWorkspace; |
|
17 |
import org.txm.statsengine.r.core.exceptions.RWorkspaceException; |
|
18 |
import org.txm.utils.logger.Log; |
|
19 | 6 |
|
20 | 7 |
/** |
21 |
* R progression chart creator. |
|
22 |
* @author mdecorde
|
|
8 |
* R progression density chart creator.
|
|
9 |
* |
|
23 | 10 |
* @author sjacquot |
24 | 11 |
* |
25 | 12 |
*/ |
26 |
public class RProgressionDensityChartCreator extends RChartCreator implements ProgressionChartCreator {
|
|
13 |
public class RProgressionDensityChartCreator extends RProgressionBaseChartCreator {
|
|
27 | 14 |
|
28 | 15 |
|
29 | 16 |
@Override |
30 | 17 |
public File createChartFile(ChartResult result, File file) { |
31 |
|
|
32 |
try { |
|
33 |
|
|
34 |
Progression progression = (Progression) result; |
|
35 |
|
|
36 |
// parameters |
|
37 |
int renderingColorMode = progression.getRenderingColorsMode(); |
|
38 |
|
|
39 |
//boolean cumulative = progression.getBooleanParameterValue(ProgressionPreferences.CHART_CUMULATIVE); |
|
40 |
|
|
41 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
|
42 |
rw.eval("library(textometry)"); |
|
43 |
// System.out.println("create list of positions"); |
|
44 |
|
|
45 |
|
|
46 |
List<int[]> allPositions = progression.getAllPositions(); |
|
47 |
String listString = "list("; //$NON-NLS-1$ |
|
48 |
for(int i = 0; i < allPositions.size(); i++) { |
|
49 |
int[] positions = allPositions.get(i); |
|
50 |
// System.out.println("add vector "+i); |
|
51 |
rw.eval("rm(x" + i + ")"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
52 |
rw.addVectorToWorkspace("x" + i, positions); //$NON-NLS-1$ |
|
53 |
listString += "x" + i + ","; //$NON-NLS-1$ //$NON-NLS-2$ |
|
54 |
} |
|
55 |
listString = listString.substring(0, listString.length() - 1) + ")"; //$NON-NLS-1$ |
|
56 |
// System.out.println("create positions"); |
|
57 |
rw.eval("rm(positions)"); //$NON-NLS-1$ |
|
58 |
rw.eval("positions <- " + listString); //$NON-NLS-1$ |
|
59 |
|
|
60 |
rw.eval("rm(structurepositions)"); //$NON-NLS-1$ |
|
61 |
rw.addVectorToWorkspace("structurepositions", progression.getStructurePositions()); //$NON-NLS-1$ |
|
62 |
rw.eval("rm(structurenames)"); //$NON-NLS-1$ |
|
63 |
// if (structurenames != null) structurenames = new |
|
64 |
// String[structurepositions.length]; |
|
65 |
for(int i = 0; i < progression.getStructureNames().length; i++) { // Fix empty attribute values |
|
66 |
if("".equals(progression.getStructureNames()[i]) || progression.getStructureNames()[i] == null) { //$NON-NLS-1$ |
|
67 |
progression.getStructureNames()[i] = "--"; //$NON-NLS-1$ |
|
68 |
} |
|
69 |
} |
|
70 |
rw.addVectorToWorkspace("structurenames", progression.getStructureNames()); //$NON-NLS-1$ |
|
71 |
// System.out.println("create list positions"); |
|
72 |
// rw.getConnection().assign("positions",Rpositions); |
|
73 |
|
|
74 |
this.getChartsEngine().setColors(renderingColorMode, progression.getQueries().size()); |
|
75 |
|
|
76 |
// if(monochrome) { |
|
77 |
// rw.addVectorToWorkspace("colors", DefaultTheme.monocolors); //$NON-NLS-1$ |
|
78 |
// } |
|
79 |
// else { |
|
80 |
// if(progression.getQueries().size() <= 5) { |
|
81 |
// // System.out.println("uses colors5"); |
|
82 |
// |
|
83 |
// |
|
84 |
// rw.addVectorToWorkspace("colors", this.getChartsEngine().getTheme().getColorPaletteAsHexFor(5)); |
|
85 |
// |
|
86 |
// |
|
87 |
// //rw.addVectorToWorkspace("colors", DefaultTheme.colors5); //$NON-NLS-1$ |
|
88 |
// } |
|
89 |
// else if(progression.getQueries().size() <= 10) { |
|
90 |
// // System.out.println("uses colors10"); |
|
91 |
// rw.addVectorToWorkspace("colors", DefaultTheme.colors10); //$NON-NLS-1$ |
|
92 |
// } |
|
93 |
// else { |
|
94 |
// // System.out.println("uses colors16"); |
|
95 |
// rw.addVectorToWorkspace("colors", DefaultTheme.colors); //$NON-NLS-1$ |
|
96 |
// } |
|
97 |
// } |
|
98 |
|
|
99 |
// System.out.println("create styles vector"); |
|
100 |
rw.eval("rm(styles)"); //$NON-NLS-1$ |
|
101 |
if(!progression.isMultipleLineStrokes()) { |
|
102 |
rw.addVectorToWorkspace("styles", DefaultTheme.monostyles); //$NON-NLS-1$ |
|
103 |
} |
|
104 |
else { |
|
105 |
rw.addVectorToWorkspace("styles", DefaultTheme.styles); //$NON-NLS-1$ |
|
106 |
} |
|
107 |
|
|
108 |
// System.out.println("create styles vector"); |
|
109 |
rw.eval("rm(widths)"); //$NON-NLS-1$ |
|
110 |
rw.addVectorToWorkspace("widths", DefaultTheme.monoWidths); //$NON-NLS-1$ |
|
111 |
|
|
112 |
// System.out.println("create names vector"); |
|
113 |
String[] queriesstring = new String[progression.getQueries().size()]; |
|
114 |
for(int i = 0; i < progression.getQueries().size(); i++) { |
|
115 |
queriesstring[i] = progression.getQueries().get(i).getQueryString(); |
|
116 |
} |
|
117 |
rw.eval("rm(names)"); //$NON-NLS-1$ |
|
118 |
rw.addVectorToWorkspace("names", queriesstring); //$NON-NLS-1$ |
|
119 |
|
|
120 |
String name = progression.getCorpus().getName(); |
|
121 |
|
|
122 |
// Create chart title |
|
123 |
String title = ""; |
|
124 |
if(result.getBooleanParameterValue(ChartsEnginePreferences.SHOW_TITLE)) { |
|
125 |
title = Utils.createProgressionChartTitle(progression, false); |
|
126 |
} |
|
127 |
|
|
128 |
// Escape title string |
|
129 |
title = StringEscapeUtils.escapeJava(title); |
|
130 |
|
|
131 |
// System.out.println("BANDE="+bande); |
|
132 |
|
|
133 |
String cmd = "progression(positions, names, colors, styles, widths, \"" + name + "\"," + progression.getXminCorpus() + "," + progression.getXmaxCorpus() + ",\"" + false + "\",structurepositions,structurenames, \"" + title + "\", " + progression.getBande() + ");\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ |
|
134 |
|
|
135 |
// FIXME: the grid must be plotted behind the chart and it is not possible with the current R progression object code |
|
136 |
// Grid |
|
137 |
if(result.getBooleanParameterValue(ChartsEnginePreferences.SHOW_GRID)) { |
|
138 |
cmd += this.getChartsEngine().getGridPlotCmd(); |
|
139 |
} |
|
140 |
|
|
141 |
this.getChartsEngine().plot(file, cmd); |
|
142 |
|
|
143 |
RWorkspace.getRWorkspaceInstance().eval(Progression.prefixR + Progression.norep + " <- list(positions=positions, names=names, xmin=" + progression.getXminCorpus() + ",xmax=" + progression.getXmaxCorpus() + ", structpositions=structurepositions, structnames=structurenames)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
144 |
Progression.norep++; |
|
145 |
} |
|
146 |
catch(RWorkspaceException e) { |
|
147 |
// TODO Auto-generated catch block |
|
148 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
149 |
} |
|
150 |
|
|
151 |
return file; |
|
18 |
return super.createChartFile(result, file, false); |
|
152 | 19 |
} |
153 | 20 |
|
154 | 21 |
|
155 |
@Override |
|
156 |
public ArrayList<Integer> getSelectedPointPositions(Object chart) { |
|
157 |
// FIXME: not implemented |
|
158 |
Log.severe(this.getClass() + ".getProgressionChartSelectedPointPositions(): Not yet implemented."); //$NON-NLS-1$ |
|
159 |
return new ArrayList<Integer>(0); |
|
160 |
} |
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
@Override |
|
165 |
public ArrayList<Integer> getSelectedSeries(Object chart) { |
|
166 |
Log.severe(this.getClass() + ".getProgressionChartSelectedSeries(): Not yet implemented."); //$NON-NLS-1$ |
|
167 |
return new ArrayList<Integer>(0); |
|
168 |
} |
|
169 |
|
|
170 |
|
|
171 |
@Override |
|
172 |
public ArrayList<Integer> getSelectedPointNumbers(Object chart) { |
|
173 |
Log.severe(this.getClass() + ".getProgressionChartSelectedPointNumber(): Not yet implemented."); //$NON-NLS-1$ |
|
174 |
return new ArrayList<Integer>(0); |
|
175 |
} |
|
176 |
|
|
177 |
|
|
178 |
@Override |
|
179 |
public int getLastSelectedSeries(Object chart) { |
|
180 |
Log.severe(this.getClass() + ".getProgressionChartLastSelectedSeries(): Not yet implemented."); //$NON-NLS-1$ |
|
181 |
return -1; |
|
182 |
} |
|
183 |
|
|
184 |
|
|
185 |
@Override |
|
186 |
public Class getResultDataClass() { |
|
187 |
return Progression.class; |
|
188 |
} |
|
189 |
|
|
190 |
@Override |
|
191 |
public ArrayList<ArrayList<Integer>> getAllPointPositionsBySeries(Object chart) { |
|
192 |
Log.severe(this.getClass() + ".getAllPointPositionsBySeries(): Not yet implemented."); //$NON-NLS-1$ |
|
193 |
return null; |
|
194 |
} |
|
195 |
|
|
196 |
|
|
197 | 22 |
} |
tmp/org.txm.partition.core/plugin.xml (revision 642) | ||
---|---|---|
12 | 12 |
<ChartCreator |
13 | 13 |
chartsEngineName="jfreechart_charts_engine" |
14 | 14 |
class="org.txm.partition.core.chartsengine.jfreechart.JFCPartitionDimensionsBarChartCreator" |
15 |
fileNamePrefix="info">
|
|
15 |
fileNamePrefix="partition_dimensions_bar">
|
|
16 | 16 |
</ChartCreator> |
17 | 17 |
<ChartCreator |
18 | 18 |
chartType="Partition Dimensions Pie Chart" |
19 | 19 |
chartsEngineName="jfreechart_charts_engine" |
20 | 20 |
class="org.txm.partition.core.chartsengine.jfreechart.JFCPartitionDimensionsPieChartCreator" |
21 |
fileNamePrefix="partition_dimensions"> |
|
21 |
fileNamePrefix="partition_dimensions_pie">
|
|
22 | 22 |
</ChartCreator> |
23 | 23 |
<ChartCreator |
24 | 24 |
chartsEngineName="r_charts_engine" |
25 | 25 |
class="org.txm.partition.core.chartsengine.r.RPartitionDimensionsBarChartCreator" |
26 |
fileNamePrefix="info">
|
|
26 |
fileNamePrefix="partition_dimensions_bar">
|
|
27 | 27 |
</ChartCreator> |
28 | 28 |
<ChartCreator |
29 | 29 |
chartType="Partition Dimensions Pie Chart" |
30 | 30 |
chartsEngineName="r_charts_engine" |
31 | 31 |
class="org.txm.partition.core.chartsengine.r.RPartitionDimensionsPieChartCreator" |
32 |
fileNamePrefix="partition_dimensions"> |
|
32 |
fileNamePrefix="partition_dimensions_pie">
|
|
33 | 33 |
</ChartCreator> |
34 | 34 |
</extension> |
35 | 35 |
|
Formats disponibles : Unified diff