Révision 639
| tmp/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 639) | ||
|---|---|---|
| 218 | 218 |
* @param parameterType |
| 219 | 219 |
* @throws Exception |
| 220 | 220 |
*/ |
| 221 |
protected void clearLastParameters(int parameterType) throws Exception {
|
|
| 221 |
protected void clearLastParameters(int parameterType) {
|
|
| 222 | 222 |
List<Field> fields = this.getAllFields(); |
| 223 | 223 |
|
| 224 | 224 |
for (Field f : fields) {
|
| ... | ... | |
| 242 | 242 |
} |
| 243 | 243 |
|
| 244 | 244 |
|
| 245 |
/** |
|
| 246 |
* Clears the parameters used for last computing. |
|
| 247 |
* Dedicated to force a full recomputing. |
|
| 248 |
* @throws Exception |
|
| 249 |
*/ |
|
| 250 |
protected void clearLastComputingParameters() {
|
|
| 251 |
this.clearLastParameters(Parameter.COMPUTING); |
|
| 252 |
} |
|
| 253 |
|
|
| 254 |
|
|
| 245 | 255 |
public HashMap<String, Object> getLastParameters() {
|
| 246 | 256 |
return lastParameters; |
| 247 | 257 |
} |
| ... | ... | |
| 757 | 767 |
targetField.setAccessible(true); |
| 758 | 768 |
|
| 759 | 769 |
// FIXME: debug |
| 760 |
System.err.println("TXMResult.setParameter(): setting parameter " + key + " = " + value + " for " + this.getClass() + " (" + value.getClass() + ")");
|
|
| 770 |
if(value != null) {
|
|
| 771 |
System.err.println("TXMResult.setParameter(): setting parameter " + key + " = " + value + " for " + this.getClass() + " (" + value.getClass() + ")");
|
|
| 772 |
} |
|
| 761 | 773 |
|
| 762 | 774 |
targetField.set(this, value); |
| 763 | 775 |
} |
| tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/editors/ChartEditor.java (revision 639) | ||
|---|---|---|
| 205 | 205 |
@Override |
| 206 | 206 |
protected final void __updateEditorFromResult(boolean update) {
|
| 207 | 207 |
|
| 208 |
|
|
| 209 |
// check that the charts engine used for the result matches the SWT components provider otherwise fin a suitable components provider |
|
| 210 |
ChartsEngine chartsEngine = ChartsEngine.getChartsEngine(this.getResult()); |
|
| 211 |
if(chartsEngine != this.getSWTChartsComponentsProvider().getChartsEngine()) {
|
|
| 212 |
this.getEditorInput().setSWTChartsComponentsProvider(SWTChartsComponentsProvider.getComponentsProvider(chartsEngine)); |
|
| 213 |
this.getSWTChartsComponentsProvider().setChartsEngine(chartsEngine); |
|
| 214 |
System.err.println("ChartEditor.__updateEditorFromResult(): charts engine used to create the chart is not the current one. The SWT components provider has been changed to match it: " + this.getSWTChartsComponentsProvider() + ".");
|
|
| 215 |
|
|
| 216 |
// recreating the chart composite |
|
| 217 |
Composite parent = this.chartComposite.getParent(); |
|
| 218 |
this.chartComposite.dispose(); |
|
| 219 |
this.chartComposite = this.getSWTChartsComponentsProvider().createComposite(this, parent); |
|
| 220 |
|
|
| 221 |
GridData gd = new GridData(GridData.FILL_BOTH); |
|
| 222 |
// gd.grabExcessVerticalSpace = true; |
|
| 223 |
// gd.grabExcessHorizontalSpace = true; |
|
| 224 |
//gd.horizontalSpan = 2; // 2 for match the command parameters toolbar AND the chart toolbar |
|
| 225 |
this.chartComposite.setLayoutData(gd); |
|
| 226 |
parent.layout(); |
|
| 227 |
} |
|
| 228 |
|
|
| 229 |
|
|
| 230 |
|
|
| 208 | 231 |
// loading chart |
| 209 | 232 |
this.getResult().subTask("Loading chart.");
|
| 210 | 233 |
this.loadChart(); |
| tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/editors/ChartEditorInput.java (revision 639) | ||
|---|---|---|
| 70 | 70 |
this.swtChartsComponentsProvider = swtComponentsProvider; |
| 71 | 71 |
this.chartContainer = chartContainer; |
| 72 | 72 |
|
| 73 |
// check that the charts engine used for the result matches the SWT components provider otherwise fin a suitable components provider |
|
| 74 |
ChartsEngine chartsEngine = ChartsEngine.getChartsEngine(result); |
|
| 75 |
if(chartsEngine != swtComponentsProvider.getChartsEngine()) {
|
|
| 76 |
this.swtChartsComponentsProvider = SWTChartsComponentsProvider.getComponentsProvider(chartsEngine); |
|
| 77 |
System.err.println("ChartEditorInput.ChartEditorInput(): charts engine used to create the chart is not the current one. The SWT components provider has been changed to match it: " + this.swtChartsComponentsProvider + ".");
|
|
| 78 |
} |
|
| 73 |
// // check that the charts engine used for the result matches the SWT components provider otherwise fin a suitable components provider
|
|
| 74 |
// ChartsEngine chartsEngine = ChartsEngine.getChartsEngine(result);
|
|
| 75 |
// if(chartsEngine != swtComponentsProvider.getChartsEngine()) {
|
|
| 76 |
// this.swtChartsComponentsProvider = SWTChartsComponentsProvider.getComponentsProvider(chartsEngine);
|
|
| 77 |
// System.err.println("ChartEditorInput.ChartEditorInput(): charts engine used to create the chart is not the current one. The SWT components provider has been changed to match it: " + this.swtChartsComponentsProvider + ".");
|
|
| 78 |
// }
|
|
| 79 | 79 |
|
| 80 | 80 |
} |
| 81 | 81 |
|
| tmp/org.txm.progression.core/src/org/txm/progression/core/chartsengine/jfreechart/JFCProgressionChartCreator.java (revision 639) | ||
|---|---|---|
| 1 |
package org.txm.progression.core.chartsengine.jfreechart; |
|
| 2 |
|
|
| 3 |
import java.awt.BasicStroke; |
|
| 4 |
import java.awt.Color; |
|
| 5 |
import java.util.ArrayList; |
|
| 6 |
import java.util.List; |
|
| 7 |
|
|
| 8 |
import org.jfree.chart.JFreeChart; |
|
| 9 |
import org.jfree.chart.axis.NumberAxis; |
|
| 10 |
import org.jfree.chart.plot.Marker; |
|
| 11 |
import org.jfree.chart.plot.ValueMarker; |
|
| 12 |
import org.jfree.data.xy.XYDataset; |
|
| 13 |
import org.jfree.data.xy.XYSeries; |
|
| 14 |
import org.jfree.data.xy.XYSeriesCollection; |
|
| 15 |
import org.jfree.ui.RectangleAnchor; |
|
| 16 |
import org.jfree.ui.TextAnchor; |
|
| 17 |
import org.txm.chartsengine.core.ChartsEngine; |
|
| 18 |
import org.txm.chartsengine.core.results.ChartResult; |
|
| 19 |
import org.txm.chartsengine.jfreechart.core.JFCChartCreator; |
|
| 20 |
import org.txm.chartsengine.jfreechart.core.renderers.MultipleItemsSelector; |
|
| 21 |
import org.txm.chartsengine.jfreechart.core.renderers.interfaces.IRendererWithItemSelection; |
|
| 22 |
import org.txm.chartsengine.jfreechart.core.themes.base.ExtendedNumberAxis; |
|
| 23 |
import org.txm.progression.core.chartsengine.base.ProgressionChartCreator; |
|
| 24 |
import org.txm.progression.core.chartsengine.base.Utils; |
|
| 25 |
import org.txm.progression.core.chartsengine.jfreechart.themes.highcharts.renderers.ProgressionItemSelectionRenderer; |
|
| 26 |
import org.txm.progression.core.functions.Progression; |
|
| 27 |
import org.txm.progression.core.messages.ProgressionCoreMessages; |
|
| 28 |
import org.txm.progression.core.preferences.ProgressionPreferences; |
|
| 29 |
import org.txm.searchengine.cqp.corpus.query.Query; |
|
| 30 |
|
|
| 31 |
/** |
|
| 32 |
* JFC progression chart creator. |
|
| 33 |
* |
|
| 34 |
* @author sjacquot |
|
| 35 |
* |
|
| 36 |
*/ |
|
| 37 |
public class JFCProgressionChartCreator extends JFCChartCreator implements ProgressionChartCreator {
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
@Override |
|
| 41 |
public JFreeChart createChart(ChartResult result) {
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
Progression progression = (Progression) result; |
|
| 45 |
|
|
| 46 |
// parameters |
|
| 47 |
boolean cumulative = result.getBooleanParameterValue(ProgressionPreferences.CHART_CUMULATIVE); |
|
| 48 |
|
|
| 49 |
|
|
| 50 |
JFreeChart chart = null; |
|
| 51 |
|
|
| 52 |
// Creates the empty dataset |
|
| 53 |
XYSeriesCollection dataset = new XYSeriesCollection(); |
|
| 54 |
// Y axis label |
|
| 55 |
String yAxisLabel; |
|
| 56 |
|
|
| 57 |
|
|
| 58 |
// Cumulative |
|
| 59 |
if(cumulative) {
|
|
| 60 |
|
|
| 61 |
// Create the chart |
|
| 62 |
yAxisLabel = ProgressionCoreMessages.ChartsEngine_PROGRESSION_Y_AXIS_CUMULATIVE_LABEL; |
|
| 63 |
chart = this.getChartsEngine().createXYStepChart(dataset, Utils.createProgressionChartTitle(progression, cumulative), |
|
| 64 |
ProgressionCoreMessages.bind(ProgressionCoreMessages.ChartsEngine_PROGRESSION_X_AXIS_LABEL, progression.getXmaxCorpus()), yAxisLabel, true, true, true, true, true); |
|
| 65 |
|
|
| 66 |
|
|
| 67 |
// Custom renderer |
|
| 68 |
chart.getXYPlot().setRenderer(new ProgressionItemSelectionRenderer()); |
|
| 69 |
|
|
| 70 |
} |
|
| 71 |
// FIXME : Density, to implement when textometry R package will store the result in the Progression class |
|
| 72 |
// FIXME: put that in a new ChartCreator dedicated to the density progression chart |
|
| 73 |
else {
|
|
| 74 |
|
|
| 75 |
// FIXME : density not yet implemented |
|
| 76 |
System.err.println("JFCProgressionChartCreator.createChart(): density mode not yet implemented.");
|
|
| 77 |
|
|
| 78 |
// for(int i = 0; i < progression.getAllpositions().size(); i++) {
|
|
| 79 |
// int[] liste = positions.get(i); |
|
| 80 |
// Query query = queries.get(i); |
|
| 81 |
// XYSeries series = new XYSeries(query.toString() + " " + liste.length); |
|
| 82 |
// |
|
| 83 |
// for(int j = 0; j < liste.length; j++) {
|
|
| 84 |
// |
|
| 85 |
// // FIXME : tests y |
|
| 86 |
// // y <- c( c(0), y , c(y[[length(x)]]) ) // R code |
|
| 87 |
// // FIXME : random Y value |
|
| 88 |
// double y = progression.getAllpositions().get(i)[j] * Math.random(); |
|
| 89 |
// // double y = progression.getAllpositions().get(i)[j]; |
|
| 90 |
// series.add(liste[j], y); |
|
| 91 |
// } |
|
| 92 |
// dataset.addSeries(series); |
|
| 93 |
// } |
|
| 94 |
// |
|
| 95 |
// // Create the chart |
|
| 96 |
// yAxisLabel = ProgressionCoreMessages.ChartsEngine_PROGRESSION_Y_AXIS_NOT_CUMULATIVE_LABEL; |
|
| 97 |
// chart = this.getChartsEngine().createXYLineChart(dataset, Utils.createProgressionChartTitle(progression, cumulative), |
|
| 98 |
// ProgressionCoreMessages.bind(ProgressionCoreMessages.ChartsEngine_PROGRESSION_X_AXIS_LABEL, progression.getXmaxCorpus()), yAxisLabel, |
|
| 99 |
// true, true, true, false, true, false, true, null); |
|
| 100 |
} |
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
((IRendererWithItemSelection) chart.getXYPlot().getRenderer()).setChartType(ChartsEngine.CHART_TYPE_PROGRESSION); |
|
| 105 |
((IRendererWithItemSelection) chart.getXYPlot().getRenderer()).getItemsSelector().setResultData(progression); |
|
| 106 |
|
|
| 107 |
|
|
| 108 |
return chart; |
|
| 109 |
|
|
| 110 |
} |
|
| 111 |
|
|
| 112 |
|
|
| 113 |
@Override |
|
| 114 |
public void updateChart(ChartResult result) {
|
|
| 115 |
|
|
| 116 |
Progression progression = (Progression) result; |
|
| 117 |
JFreeChart chart = (JFreeChart) result.getChart(); |
|
| 118 |
|
|
| 119 |
// freeze rendering while computing |
|
| 120 |
chart.setNotify(false); |
|
| 121 |
|
|
| 122 |
|
|
| 123 |
// Fill the data set from the result |
|
| 124 |
if(progression.hasParameterChanged(ProgressionPreferences.QUERIES)) {
|
|
| 125 |
XYSeriesCollection dataset = (XYSeriesCollection) chart.getXYPlot().getDataset(); |
|
| 126 |
dataset.removeAllSeries(); |
|
| 127 |
|
|
| 128 |
List<int[]> positions = progression.getAllPositions(); |
|
| 129 |
List<Query> queries = progression.getQueries(); |
|
| 130 |
for(int i = 0; i < positions.size(); i++) {
|
|
| 131 |
int[] list = positions.get(i); |
|
| 132 |
Query query = queries.get(i); |
|
| 133 |
XYSeries series = new XYSeries(query.toString() + " " + list.length); |
|
| 134 |
int c = 1; |
|
| 135 |
for(int j = 0; j < list.length; j++) {
|
|
| 136 |
// add a first point to draw a vertical line |
|
| 137 |
if(j == 0) {
|
|
| 138 |
series.add(list[j], 0); |
|
| 139 |
} |
|
| 140 |
series.add(list[j], c++); |
|
| 141 |
} |
|
| 142 |
|
|
| 143 |
// add a dummy point to draw horizontal line between last point and max X corpus |
|
| 144 |
series.add(progression.getXmaxCorpus(), --c); |
|
| 145 |
dataset.addSeries(series); |
|
| 146 |
} |
|
| 147 |
|
|
| 148 |
// Custom domain axis for ticks drawing options |
|
| 149 |
chart.getXYPlot().setDomainAxis(new ExtendedNumberAxis((NumberAxis) chart.getXYPlot().getDomainAxis(), true, true, progression.getXminCorpus(), progression.getXmaxCorpus())); |
|
| 150 |
|
|
| 151 |
// Custom range axis for ticks drawing options |
|
| 152 |
chart.getXYPlot().setRangeAxis(new ExtendedNumberAxis((NumberAxis) chart.getXYPlot().getRangeAxis(), false, true, 0, progression.getMaxY())); |
|
| 153 |
|
|
| 154 |
// Match the X-axis origin value to the min x corpus (for subcorpus case) |
|
| 155 |
chart.getXYPlot().getDomainAxis().setLowerBound(progression.getXminCorpus()); |
|
| 156 |
} |
|
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
// removes all existing domain marker |
|
| 161 |
chart.getXYPlot().clearDomainMarkers(); |
|
| 162 |
|
|
| 163 |
// Add the limit markers |
|
| 164 |
BasicStroke dashedStroke = new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] {2f}, 0f);
|
|
| 165 |
Marker marker = new ValueMarker(progression.getXminCorpus()); |
|
| 166 |
marker.setPaint(Color.gray); |
|
| 167 |
marker.setStroke(dashedStroke); |
|
| 168 |
chart.getXYPlot().addDomainMarker(marker); |
|
| 169 |
marker = new ValueMarker(progression.getXmaxCorpus()); |
|
| 170 |
marker.setPaint(Color.gray); |
|
| 171 |
marker.setStroke(dashedStroke); |
|
| 172 |
chart.getXYPlot().addDomainMarker(marker); |
|
| 173 |
|
|
| 174 |
|
|
| 175 |
// // FIXME : limit with annotations rather than markers (marker height is dynamically adapted to the real chart height. |
|
| 176 |
// Annotation have a fixed height) |
|
| 177 |
// XYLineAnnotation annotation = new XYLineAnnotation(0, 0, 0, dataset.getRangeUpperBound(true), dashedStroke, Color.gray); |
|
| 178 |
// chart.getXYPlot().addAnnotation(annotation, true); |
|
| 179 |
|
|
| 180 |
// Add the part markers |
|
| 181 |
String previousPartName = ""; //$NON-NLS-1$ |
|
| 182 |
if(progression.getStructuralUnit() != null && progression.getStructurePositions().length > 0 && |
|
| 183 |
(progression.hasParameterChanged(ProgressionPreferences.STRUCTURAL_UNIT) || |
|
| 184 |
progression.hasParameterChanged(ProgressionPreferences.STRUCTURAL_UNIT_PROPERTY) || |
|
| 185 |
progression.hasParameterChanged(ProgressionPreferences.REPEAT_SAME_VALUES) || |
|
| 186 |
progression.hasParameterChanged(ProgressionPreferences.PROPERTY_REGEX) |
|
| 187 |
)) {
|
|
| 188 |
for(int i = 0; i < progression.getStructurePositions().length; i++) {
|
|
| 189 |
if(progression.getStructurePositions()[i] != 0) {
|
|
| 190 |
|
|
| 191 |
String currentPartName = progression.getStructureNames()[i]; |
|
| 192 |
|
|
| 193 |
if(progression.isRepeatingValues() || !currentPartName.equals(previousPartName)) {
|
|
| 194 |
|
|
| 195 |
marker = new ValueMarker(progression.getStructurePositions()[i]); |
|
| 196 |
marker.setPaint(Color.black); |
|
| 197 |
marker.setLabel(progression.getStructureNames()[i]); |
|
| 198 |
marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); |
|
| 199 |
marker.setLabelTextAnchor(TextAnchor.HALF_ASCENT_LEFT); |
|
| 200 |
|
|
| 201 |
|
|
| 202 |
// FIXME: test of rotated annotations rather than using marker label. The problem with this is that the position of annotation is not adjusted when zooming/dezooming. |
|
| 203 |
// FIXME: the best approach is to redefine the drawing method of |
|
| 204 |
//// double start = marker.getStartValue(); |
|
| 205 |
//// double end = TempIntervalMarker.getEndValue(); |
|
| 206 |
//// double middle = (end - start)/2; |
|
| 207 |
// XYTextAnnotation updateLabel = new XYTextAnnotation("Update", progression.getStructurePositions()[i], 0);
|
|
| 208 |
// updateLabel.setFont(new Font("Sans Serif", Font.BOLD, 10));
|
|
| 209 |
// updateLabel.setRotationAnchor(TextAnchor.BASELINE_CENTER); |
|
| 210 |
// updateLabel.setTextAnchor(TextAnchor.BASELINE_CENTER); |
|
| 211 |
// updateLabel.setRotationAngle(3.14 / 2); |
|
| 212 |
// updateLabel.setPaint(Color.black); |
|
| 213 |
// chart.getXYPlot().addAnnotation(updateLabel); |
|
| 214 |
|
|
| 215 |
chart.getXYPlot().addDomainMarker(marker); |
|
| 216 |
} |
|
| 217 |
|
|
| 218 |
previousPartName = currentPartName; |
|
| 219 |
} |
|
| 220 |
} |
|
| 221 |
} |
|
| 222 |
|
|
| 223 |
chart.setTitle(Utils.createProgressionChartTitle(progression, true)); |
|
| 224 |
|
|
| 225 |
super.updateChart(result); |
|
| 226 |
|
|
| 227 |
} |
|
| 228 |
|
|
| 229 |
@Override |
|
| 230 |
public ArrayList<Integer> getSelectedPointPositions(Object chart) {
|
|
| 231 |
|
|
| 232 |
MultipleItemsSelector selector = (MultipleItemsSelector) ((IRendererWithItemSelection)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector(); |
|
| 233 |
ArrayList<Integer> pointPositionsInCorpora = new ArrayList<Integer>(); |
|
| 234 |
|
|
| 235 |
|
|
| 236 |
// FIXME: returns all the point positions |
|
| 237 |
XYDataset dataset = ((JFreeChart) chart).getXYPlot().getDataset(); |
|
| 238 |
for(int i = 0; i < selector.getSelectedSeries().length; i++) {
|
|
| 239 |
int selectedSeries = selector.getSelectedSeries()[i]; |
|
| 240 |
int[] selectedItemsInSeries = selector.getSelectedItems(selectedSeries) ; |
|
| 241 |
for(int j = 0; j < selectedItemsInSeries.length; j++) {
|
|
| 242 |
// if it's the dummy last chart point, get the previous point position instead of ther last one |
|
| 243 |
if(selectedItemsInSeries[j] == dataset.getItemCount(selectedSeries) - 1) {
|
|
| 244 |
pointPositionsInCorpora.add((int) (dataset.getXValue(selectedSeries, selectedItemsInSeries[j] - 1))); |
|
| 245 |
} |
|
| 246 |
else {
|
|
| 247 |
pointPositionsInCorpora.add((int) (dataset.getXValue(selectedSeries, selectedItemsInSeries[j]))); |
|
| 248 |
} |
|
| 249 |
} |
|
| 250 |
|
|
| 251 |
} |
|
| 252 |
|
|
| 253 |
// put the last selected point at the end of the list |
|
| 254 |
if(selector.getLastSelectedSeries() != -1 && selector.getLastSelectedItem() != -1) {
|
|
| 255 |
int item = selector.getLastSelectedItem(); |
|
| 256 |
// if it's the dummy last chart point, get the previous point position instead of ther last one |
|
| 257 |
if(item == dataset.getItemCount(selector.getLastSelectedSeries()) - 1) {
|
|
| 258 |
item--; |
|
| 259 |
} |
|
| 260 |
|
|
| 261 |
Integer lastSelectedPointPosition = (int) (dataset.getXValue(selector.getLastSelectedSeries(), item)); |
|
| 262 |
pointPositionsInCorpora.remove(lastSelectedPointPosition); |
|
| 263 |
pointPositionsInCorpora.add(lastSelectedPointPosition); |
|
| 264 |
} |
|
| 265 |
return pointPositionsInCorpora; |
|
| 266 |
} |
|
| 267 |
|
|
| 268 |
@Override |
|
| 269 |
public ArrayList<Integer> getSelectedPointNumbers(Object chart) {
|
|
| 270 |
|
|
| 271 |
MultipleItemsSelector selector = (MultipleItemsSelector) ((IRendererWithItemSelection)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector(); |
|
| 272 |
ArrayList<Integer> pointNumbers = new ArrayList<Integer>(); |
|
| 273 |
XYDataset dataset = ((JFreeChart) chart).getXYPlot().getDataset(); |
|
| 274 |
|
|
| 275 |
for(int i = 0; i < selector.getSelectedSeriesCount(); i++) {
|
|
| 276 |
int series = selector.getSelectedSeries()[i]; |
|
| 277 |
int[] items = selector.getSelectedItems(series); |
|
| 278 |
int lastDummyItem = dataset.getItemCount(series) - 1; |
|
| 279 |
for(int j = 0; j < items.length; j++) {
|
|
| 280 |
int item = items[j]; |
|
| 281 |
// manage the first dummy point |
|
| 282 |
if(item == 0) {
|
|
| 283 |
item++; |
|
| 284 |
} |
|
| 285 |
// manage the last dummy point |
|
| 286 |
else if(item == lastDummyItem) {
|
|
| 287 |
item--; |
|
| 288 |
} |
|
| 289 |
|
|
| 290 |
pointNumbers.add(item); |
|
| 291 |
} |
|
| 292 |
} |
|
| 293 |
|
|
| 294 |
return pointNumbers; |
|
| 295 |
} |
|
| 296 |
|
|
| 297 |
|
|
| 298 |
|
|
| 299 |
@Override |
|
| 300 |
public ArrayList<ArrayList<Integer>> getAllPointPositionsBySeries(Object chart) {
|
|
| 301 |
|
|
| 302 |
ArrayList<ArrayList<Integer>> pointPositionsBySeries = new ArrayList<ArrayList<Integer>>(); |
|
| 303 |
|
|
| 304 |
XYDataset dataset = ((JFreeChart) chart).getXYPlot().getDataset(); |
|
| 305 |
|
|
| 306 |
for(int i = 0; i < dataset.getSeriesCount(); i++) {
|
|
| 307 |
ArrayList<Integer> pointPositionsInCorpora = new ArrayList<Integer>(); |
|
| 308 |
for(int j = 0; j < dataset.getItemCount(i) - 1; j++) { // -1 to skip the last dummy point of the step chart
|
|
| 309 |
pointPositionsInCorpora.add((int) dataset.getXValue(i, j)); |
|
| 310 |
} |
|
| 311 |
pointPositionsBySeries.add(pointPositionsInCorpora); |
|
| 312 |
} |
|
| 313 |
|
|
| 314 |
return pointPositionsBySeries; |
|
| 315 |
} |
|
| 316 |
|
|
| 317 |
|
|
| 318 |
|
|
| 319 |
@Override |
|
| 320 |
public ArrayList<Integer> getSelectedSeries(Object chart) {
|
|
| 321 |
ArrayList<Integer> selectedSeries = new ArrayList<Integer>(); |
|
| 322 |
MultipleItemsSelector selector = (MultipleItemsSelector) ((IRendererWithItemSelection)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector(); |
|
| 323 |
Integer[] multipleSelectedSeries = selector.getSelectedSeries(); |
|
| 324 |
for(int i = 0; i < multipleSelectedSeries.length; i++) {
|
|
| 325 |
selectedSeries.add(multipleSelectedSeries[i]); |
|
| 326 |
} |
|
| 327 |
return selectedSeries; |
|
| 328 |
} |
|
| 329 |
|
|
| 330 |
|
|
| 331 |
@Override |
|
| 332 |
public int getLastSelectedSeries(Object chart) {
|
|
| 333 |
return ((MultipleItemsSelector) ((IRendererWithItemSelection)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector()).getLastSelectedSeries(); |
|
| 334 |
} |
|
| 335 |
|
|
| 336 |
|
|
| 337 |
|
|
| 338 |
@Override |
|
| 339 |
public Class getResultDataClass() {
|
|
| 340 |
return Progression.class; |
|
| 341 |
} |
|
| 342 |
|
|
| 343 |
|
|
| 344 |
|
|
| 345 |
|
|
| 346 |
} |
|
| tmp/org.txm.progression.core/src/org/txm/progression/core/chartsengine/jfreechart/JFCProgressionCumulativeChartCreator.java (revision 639) | ||
|---|---|---|
| 1 |
package org.txm.progression.core.chartsengine.jfreechart; |
|
| 2 |
|
|
| 3 |
import java.awt.BasicStroke; |
|
| 4 |
import java.awt.Color; |
|
| 5 |
import java.util.ArrayList; |
|
| 6 |
import java.util.List; |
|
| 7 |
|
|
| 8 |
import org.jfree.chart.JFreeChart; |
|
| 9 |
import org.jfree.chart.axis.NumberAxis; |
|
| 10 |
import org.jfree.chart.plot.Marker; |
|
| 11 |
import org.jfree.chart.plot.ValueMarker; |
|
| 12 |
import org.jfree.data.xy.XYDataset; |
|
| 13 |
import org.jfree.data.xy.XYSeries; |
|
| 14 |
import org.jfree.data.xy.XYSeriesCollection; |
|
| 15 |
import org.jfree.ui.RectangleAnchor; |
|
| 16 |
import org.jfree.ui.TextAnchor; |
|
| 17 |
import org.txm.chartsengine.core.ChartsEngine; |
|
| 18 |
import org.txm.chartsengine.core.results.ChartResult; |
|
| 19 |
import org.txm.chartsengine.jfreechart.core.JFCChartCreator; |
|
| 20 |
import org.txm.chartsengine.jfreechart.core.renderers.MultipleItemsSelector; |
|
| 21 |
import org.txm.chartsengine.jfreechart.core.renderers.interfaces.IRendererWithItemSelection; |
|
| 22 |
import org.txm.chartsengine.jfreechart.core.themes.base.ExtendedNumberAxis; |
|
| 23 |
import org.txm.progression.core.chartsengine.base.ProgressionChartCreator; |
|
| 24 |
import org.txm.progression.core.chartsengine.base.Utils; |
|
| 25 |
import org.txm.progression.core.chartsengine.jfreechart.themes.highcharts.renderers.ProgressionItemSelectionRenderer; |
|
| 26 |
import org.txm.progression.core.functions.Progression; |
|
| 27 |
import org.txm.progression.core.messages.ProgressionCoreMessages; |
|
| 28 |
import org.txm.progression.core.preferences.ProgressionPreferences; |
|
| 29 |
import org.txm.searchengine.cqp.corpus.query.Query; |
|
| 30 |
|
|
| 31 |
/** |
|
| 32 |
* JFC progression chart creator. |
|
| 33 |
* |
|
| 34 |
* @author sjacquot |
|
| 35 |
* |
|
| 36 |
*/ |
|
| 37 |
public class JFCProgressionCumulativeChartCreator extends JFCChartCreator implements ProgressionChartCreator {
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
@Override |
|
| 41 |
public JFreeChart createChart(ChartResult result) {
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
Progression progression = (Progression) result; |
|
| 45 |
|
|
| 46 |
// parameters |
|
| 47 |
boolean cumulative = result.getBooleanParameterValue(ProgressionPreferences.CHART_CUMULATIVE); |
|
| 48 |
|
|
| 49 |
|
|
| 50 |
JFreeChart chart = null; |
|
| 51 |
|
|
| 52 |
// Creates the empty dataset |
|
| 53 |
XYSeriesCollection dataset = new XYSeriesCollection(); |
|
| 54 |
// Y axis label |
|
| 55 |
String yAxisLabel; |
|
| 56 |
|
|
| 57 |
|
|
| 58 |
// Cumulative |
|
| 59 |
if(cumulative) {
|
|
| 60 |
|
|
| 61 |
// Create the chart |
|
| 62 |
yAxisLabel = ProgressionCoreMessages.ChartsEngine_PROGRESSION_Y_AXIS_CUMULATIVE_LABEL; |
|
| 63 |
chart = this.getChartsEngine().createXYStepChart(dataset, Utils.createProgressionChartTitle(progression, cumulative), |
|
| 64 |
ProgressionCoreMessages.bind(ProgressionCoreMessages.ChartsEngine_PROGRESSION_X_AXIS_LABEL, progression.getXmaxCorpus()), yAxisLabel, true, true, true, true, true); |
|
| 65 |
|
|
| 66 |
|
|
| 67 |
// Custom renderer |
|
| 68 |
chart.getXYPlot().setRenderer(new ProgressionItemSelectionRenderer()); |
|
| 69 |
|
|
| 70 |
} |
|
| 71 |
// FIXME : Density, to implement when textometry R package will store the result in the Progression class |
|
| 72 |
// FIXME: put that in a new ChartCreator dedicated to the density progression chart |
|
| 73 |
else {
|
|
| 74 |
|
|
| 75 |
// FIXME : density not yet implemented |
|
| 76 |
System.err.println("JFCProgressionCumulativeChartCreator.createChart(): density mode not yet implemented.");
|
|
| 77 |
|
|
| 78 |
// for(int i = 0; i < progression.getAllpositions().size(); i++) {
|
|
| 79 |
// int[] liste = positions.get(i); |
|
| 80 |
// Query query = queries.get(i); |
|
| 81 |
// XYSeries series = new XYSeries(query.toString() + " " + liste.length); |
|
| 82 |
// |
|
| 83 |
// for(int j = 0; j < liste.length; j++) {
|
|
| 84 |
// |
|
| 85 |
// // FIXME : tests y |
|
| 86 |
// // y <- c( c(0), y , c(y[[length(x)]]) ) // R code |
|
| 87 |
// // FIXME : random Y value |
|
| 88 |
// double y = progression.getAllpositions().get(i)[j] * Math.random(); |
|
| 89 |
// // double y = progression.getAllpositions().get(i)[j]; |
|
| 90 |
// series.add(liste[j], y); |
|
| 91 |
// } |
|
| 92 |
// dataset.addSeries(series); |
|
| 93 |
// } |
|
| 94 |
// |
|
| 95 |
// // Create the chart |
|
| 96 |
// yAxisLabel = ProgressionCoreMessages.ChartsEngine_PROGRESSION_Y_AXIS_NOT_CUMULATIVE_LABEL; |
|
| 97 |
// chart = this.getChartsEngine().createXYLineChart(dataset, Utils.createProgressionChartTitle(progression, cumulative), |
|
| 98 |
// ProgressionCoreMessages.bind(ProgressionCoreMessages.ChartsEngine_PROGRESSION_X_AXIS_LABEL, progression.getXmaxCorpus()), yAxisLabel, |
|
| 99 |
// true, true, true, false, true, false, true, null); |
|
| 100 |
} |
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
((IRendererWithItemSelection) chart.getXYPlot().getRenderer()).setChartType(ChartsEngine.CHART_TYPE_PROGRESSION); |
|
| 105 |
((IRendererWithItemSelection) chart.getXYPlot().getRenderer()).getItemsSelector().setResultData(progression); |
|
| 106 |
|
|
| 107 |
|
|
| 108 |
return chart; |
|
| 109 |
|
|
| 110 |
} |
|
| 111 |
|
|
| 112 |
|
|
| 113 |
@Override |
|
| 114 |
public void updateChart(ChartResult result) {
|
|
| 115 |
|
|
| 116 |
Progression progression = (Progression) result; |
|
| 117 |
JFreeChart chart = (JFreeChart) result.getChart(); |
|
| 118 |
|
|
| 119 |
// freeze rendering while computing |
|
| 120 |
chart.setNotify(false); |
|
| 121 |
|
|
| 122 |
|
|
| 123 |
// Fill the data set from the result |
|
| 124 |
if(progression.hasParameterChanged(ProgressionPreferences.QUERIES)) {
|
|
| 125 |
XYSeriesCollection dataset = (XYSeriesCollection) chart.getXYPlot().getDataset(); |
|
| 126 |
dataset.removeAllSeries(); |
|
| 127 |
|
|
| 128 |
List<int[]> positions = progression.getAllPositions(); |
|
| 129 |
List<Query> queries = progression.getQueries(); |
|
| 130 |
for(int i = 0; i < positions.size(); i++) {
|
|
| 131 |
int[] list = positions.get(i); |
|
| 132 |
Query query = queries.get(i); |
|
| 133 |
XYSeries series = new XYSeries(query.toString() + " " + list.length); |
|
| 134 |
int c = 1; |
|
| 135 |
for(int j = 0; j < list.length; j++) {
|
|
| 136 |
// add a first point to draw a vertical line |
|
| 137 |
if(j == 0) {
|
|
| 138 |
series.add(list[j], 0); |
|
| 139 |
} |
|
| 140 |
series.add(list[j], c++); |
|
| 141 |
} |
|
| 142 |
|
|
| 143 |
// add a dummy point to draw horizontal line between last point and max X corpus |
|
| 144 |
series.add(progression.getXmaxCorpus(), --c); |
|
| 145 |
dataset.addSeries(series); |
|
| 146 |
} |
|
| 147 |
|
|
| 148 |
// Custom domain axis for ticks drawing options |
|
| 149 |
chart.getXYPlot().setDomainAxis(new ExtendedNumberAxis((NumberAxis) chart.getXYPlot().getDomainAxis(), true, true, progression.getXminCorpus(), progression.getXmaxCorpus())); |
|
| 150 |
|
|
| 151 |
// Custom range axis for ticks drawing options |
|
| 152 |
chart.getXYPlot().setRangeAxis(new ExtendedNumberAxis((NumberAxis) chart.getXYPlot().getRangeAxis(), false, true, 0, progression.getMaxY())); |
|
| 153 |
|
|
| 154 |
// Match the X-axis origin value to the min x corpus (for subcorpus case) |
|
| 155 |
chart.getXYPlot().getDomainAxis().setLowerBound(progression.getXminCorpus()); |
|
| 156 |
} |
|
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
// removes all existing domain marker |
|
| 161 |
chart.getXYPlot().clearDomainMarkers(); |
|
| 162 |
|
|
| 163 |
// Add the limit markers |
|
| 164 |
BasicStroke dashedStroke = new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] {2f}, 0f);
|
|
| 165 |
Marker marker = new ValueMarker(progression.getXminCorpus()); |
|
| 166 |
marker.setPaint(Color.gray); |
|
| 167 |
marker.setStroke(dashedStroke); |
|
| 168 |
chart.getXYPlot().addDomainMarker(marker); |
|
| 169 |
marker = new ValueMarker(progression.getXmaxCorpus()); |
|
| 170 |
marker.setPaint(Color.gray); |
|
| 171 |
marker.setStroke(dashedStroke); |
|
| 172 |
chart.getXYPlot().addDomainMarker(marker); |
|
| 173 |
|
|
| 174 |
|
|
| 175 |
// // FIXME : limit with annotations rather than markers (marker height is dynamically adapted to the real chart height. |
|
| 176 |
// Annotation have a fixed height) |
|
| 177 |
// XYLineAnnotation annotation = new XYLineAnnotation(0, 0, 0, dataset.getRangeUpperBound(true), dashedStroke, Color.gray); |
|
| 178 |
// chart.getXYPlot().addAnnotation(annotation, true); |
|
| 179 |
|
|
| 180 |
// Add the part markers |
|
| 181 |
String previousPartName = ""; //$NON-NLS-1$ |
|
| 182 |
if(progression.getStructuralUnit() != null && progression.getStructurePositions().length > 0 && |
|
| 183 |
(progression.hasParameterChanged(ProgressionPreferences.STRUCTURAL_UNIT) || |
|
| 184 |
progression.hasParameterChanged(ProgressionPreferences.STRUCTURAL_UNIT_PROPERTY) || |
|
| 185 |
progression.hasParameterChanged(ProgressionPreferences.REPEAT_SAME_VALUES) || |
|
| 186 |
progression.hasParameterChanged(ProgressionPreferences.PROPERTY_REGEX) |
|
| 187 |
)) {
|
|
| 188 |
for(int i = 0; i < progression.getStructurePositions().length; i++) {
|
|
| 189 |
if(progression.getStructurePositions()[i] != 0) {
|
|
| 190 |
|
|
| 191 |
String currentPartName = progression.getStructureNames()[i]; |
|
| 192 |
|
|
| 193 |
if(progression.isRepeatingValues() || !currentPartName.equals(previousPartName)) {
|
|
| 194 |
|
|
| 195 |
marker = new ValueMarker(progression.getStructurePositions()[i]); |
|
| 196 |
marker.setPaint(Color.black); |
|
| 197 |
marker.setLabel(progression.getStructureNames()[i]); |
|
| 198 |
marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); |
|
| 199 |
marker.setLabelTextAnchor(TextAnchor.HALF_ASCENT_LEFT); |
|
| 200 |
|
|
| 201 |
|
|
| 202 |
// FIXME: test of rotated annotations rather than using marker label. The problem with this is that the position of annotation is not adjusted when zooming/dezooming. |
|
| 203 |
// FIXME: the best approach is to redefine the drawing method of |
|
| 204 |
//// double start = marker.getStartValue(); |
|
| 205 |
//// double end = TempIntervalMarker.getEndValue(); |
|
| 206 |
//// double middle = (end - start)/2; |
|
| 207 |
// XYTextAnnotation updateLabel = new XYTextAnnotation("Update", progression.getStructurePositions()[i], 0);
|
|
| 208 |
// updateLabel.setFont(new Font("Sans Serif", Font.BOLD, 10));
|
|
| 209 |
// updateLabel.setRotationAnchor(TextAnchor.BASELINE_CENTER); |
|
| 210 |
// updateLabel.setTextAnchor(TextAnchor.BASELINE_CENTER); |
|
| 211 |
// updateLabel.setRotationAngle(3.14 / 2); |
|
| 212 |
// updateLabel.setPaint(Color.black); |
|
| 213 |
// chart.getXYPlot().addAnnotation(updateLabel); |
|
| 214 |
|
|
| 215 |
chart.getXYPlot().addDomainMarker(marker); |
|
| 216 |
} |
|
| 217 |
|
|
| 218 |
previousPartName = currentPartName; |
|
| 219 |
} |
|
| 220 |
} |
|
| 221 |
} |
|
| 222 |
|
|
| 223 |
chart.setTitle(Utils.createProgressionChartTitle(progression, true)); |
|
| 224 |
|
|
| 225 |
super.updateChart(result); |
|
| 226 |
|
|
| 227 |
} |
|
| 228 |
|
|
| 229 |
@Override |
|
| 230 |
public ArrayList<Integer> getSelectedPointPositions(Object chart) {
|
|
| 231 |
|
|
| 232 |
MultipleItemsSelector selector = (MultipleItemsSelector) ((IRendererWithItemSelection)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector(); |
|
| 233 |
ArrayList<Integer> pointPositionsInCorpora = new ArrayList<Integer>(); |
|
| 234 |
|
|
| 235 |
|
|
| 236 |
// FIXME: returns all the point positions |
|
| 237 |
XYDataset dataset = ((JFreeChart) chart).getXYPlot().getDataset(); |
|
| 238 |
for(int i = 0; i < selector.getSelectedSeries().length; i++) {
|
|
| 239 |
int selectedSeries = selector.getSelectedSeries()[i]; |
|
| 240 |
int[] selectedItemsInSeries = selector.getSelectedItems(selectedSeries) ; |
|
| 241 |
for(int j = 0; j < selectedItemsInSeries.length; j++) {
|
|
| 242 |
// if it's the dummy last chart point, get the previous point position instead of ther last one |
|
| 243 |
if(selectedItemsInSeries[j] == dataset.getItemCount(selectedSeries) - 1) {
|
|
| 244 |
pointPositionsInCorpora.add((int) (dataset.getXValue(selectedSeries, selectedItemsInSeries[j] - 1))); |
|
| 245 |
} |
|
| 246 |
else {
|
|
| 247 |
pointPositionsInCorpora.add((int) (dataset.getXValue(selectedSeries, selectedItemsInSeries[j]))); |
|
| 248 |
} |
|
| 249 |
} |
|
| 250 |
|
|
| 251 |
} |
|
| 252 |
|
|
| 253 |
// put the last selected point at the end of the list |
|
| 254 |
if(selector.getLastSelectedSeries() != -1 && selector.getLastSelectedItem() != -1) {
|
|
| 255 |
int item = selector.getLastSelectedItem(); |
|
| 256 |
// if it's the dummy last chart point, get the previous point position instead of ther last one |
|
| 257 |
if(item == dataset.getItemCount(selector.getLastSelectedSeries()) - 1) {
|
|
| 258 |
item--; |
|
| 259 |
} |
|
| 260 |
|
|
| 261 |
Integer lastSelectedPointPosition = (int) (dataset.getXValue(selector.getLastSelectedSeries(), item)); |
|
| 262 |
pointPositionsInCorpora.remove(lastSelectedPointPosition); |
|
| 263 |
pointPositionsInCorpora.add(lastSelectedPointPosition); |
|
| 264 |
} |
|
| 265 |
return pointPositionsInCorpora; |
|
| 266 |
} |
|
| 267 |
|
|
| 268 |
@Override |
|
| 269 |
public ArrayList<Integer> getSelectedPointNumbers(Object chart) {
|
|
| 270 |
|
|
| 271 |
MultipleItemsSelector selector = (MultipleItemsSelector) ((IRendererWithItemSelection)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector(); |
|
| 272 |
ArrayList<Integer> pointNumbers = new ArrayList<Integer>(); |
|
| 273 |
XYDataset dataset = ((JFreeChart) chart).getXYPlot().getDataset(); |
|
| 274 |
|
|
| 275 |
for(int i = 0; i < selector.getSelectedSeriesCount(); i++) {
|
|
| 276 |
int series = selector.getSelectedSeries()[i]; |
|
| 277 |
int[] items = selector.getSelectedItems(series); |
|
| 278 |
int lastDummyItem = dataset.getItemCount(series) - 1; |
|
| 279 |
for(int j = 0; j < items.length; j++) {
|
|
| 280 |
int item = items[j]; |
|
| 281 |
// manage the first dummy point |
|
| 282 |
if(item == 0) {
|
|
| 283 |
item++; |
|
| 284 |
} |
|
| 285 |
// manage the last dummy point |
|
| 286 |
else if(item == lastDummyItem) {
|
|
| 287 |
item--; |
|
| 288 |
} |
|
| 289 |
|
|
| 290 |
pointNumbers.add(item); |
|
| 291 |
} |
|
| 292 |
} |
|
| 293 |
|
|
| 294 |
return pointNumbers; |
|
| 295 |
} |
|
| 296 |
|
|
| 297 |
|
|
| 298 |
|
|
| 299 |
@Override |
|
| 300 |
public ArrayList<ArrayList<Integer>> getAllPointPositionsBySeries(Object chart) {
|
|
| 301 |
|
|
| 302 |
ArrayList<ArrayList<Integer>> pointPositionsBySeries = new ArrayList<ArrayList<Integer>>(); |
|
| 303 |
|
|
| 304 |
XYDataset dataset = ((JFreeChart) chart).getXYPlot().getDataset(); |
|
| 305 |
|
|
| 306 |
for(int i = 0; i < dataset.getSeriesCount(); i++) {
|
|
| 307 |
ArrayList<Integer> pointPositionsInCorpora = new ArrayList<Integer>(); |
|
| 308 |
for(int j = 0; j < dataset.getItemCount(i) - 1; j++) { // -1 to skip the last dummy point of the step chart
|
|
| 309 |
pointPositionsInCorpora.add((int) dataset.getXValue(i, j)); |
|
| 310 |
} |
|
| 311 |
pointPositionsBySeries.add(pointPositionsInCorpora); |
|
| 312 |
} |
|
| 313 |
|
|
| 314 |
return pointPositionsBySeries; |
|
| 315 |
} |
|
| 316 |
|
|
| 317 |
|
|
| 318 |
|
|
| 319 |
@Override |
|
| 320 |
public ArrayList<Integer> getSelectedSeries(Object chart) {
|
|
| 321 |
ArrayList<Integer> selectedSeries = new ArrayList<Integer>(); |
|
| 322 |
MultipleItemsSelector selector = (MultipleItemsSelector) ((IRendererWithItemSelection)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector(); |
|
| 323 |
Integer[] multipleSelectedSeries = selector.getSelectedSeries(); |
|
| 324 |
for(int i = 0; i < multipleSelectedSeries.length; i++) {
|
|
| 325 |
selectedSeries.add(multipleSelectedSeries[i]); |
|
| 326 |
} |
|
| 327 |
return selectedSeries; |
|
| 328 |
} |
|
| 329 |
|
|
| 330 |
|
|
| 331 |
@Override |
|
| 332 |
public int getLastSelectedSeries(Object chart) {
|
|
| 333 |
return ((MultipleItemsSelector) ((IRendererWithItemSelection)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector()).getLastSelectedSeries(); |
|
| 334 |
} |
|
| 335 |
|
|
| 336 |
|
|
| 337 |
|
|
| 338 |
@Override |
|
| 339 |
public Class getResultDataClass() {
|
|
| 340 |
return Progression.class; |
|
| 341 |
} |
|
| 342 |
|
|
| 343 |
|
|
| 344 |
|
|
| 345 |
|
|
| 346 |
} |
|
| 0 | 347 | |
| tmp/org.txm.progression.core/src/org/txm/progression/core/chartsengine/r/RProgressionChartCreator.java (revision 639) | ||
|---|---|---|
| 1 |
package org.txm.progression.core.chartsengine.r; |
|
| 2 |
|
|
| 3 |
import java.io.File; |
|
| 4 |
import java.util.ArrayList; |
|
| 5 |
import java.util.List; |
|
| 6 |
|
|
| 7 |
import org.apache.commons.lang.StringEscapeUtils; |
|
| 8 |
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences; |
|
| 9 |
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 |
|
|
| 20 |
/** |
|
| 21 |
* R progression chart creator. |
|
| 22 |
* @author mdecorde |
|
| 23 |
* @author sjacquot |
|
| 24 |
* |
|
| 25 |
*/ |
|
| 26 |
public class RProgressionChartCreator extends RChartCreator implements ProgressionChartCreator {
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
@Override |
|
| 30 |
public File createChartFile(ChartResult result, File file) {
|
|
| 31 |
|
|
| 32 |
try {
|
|
| 33 |
|
|
| 34 |
Progression progression = (Progression) result; |
|
| 35 |
|
|
| 36 |
// parameters |
|
| 37 |
int renderingColorMode = result.getRenderingColorsMode(); |
|
| 38 |
|
|
| 39 |
boolean cumulative = result.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; |
|
| 152 |
} |
|
| 153 |
|
|
| 154 |
|
|
| 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 |
} |
|
| tmp/org.txm.progression.core/src/org/txm/progression/core/chartsengine/r/RProgressionCumulativeChartCreator.java (revision 639) | ||
|---|---|---|
| 1 |
package org.txm.progression.core.chartsengine.r; |
|
| 2 |
|
|
| 3 |
import java.io.File; |
|
| 4 |
import java.util.ArrayList; |
|
| 5 |
import java.util.List; |
|
| 6 |
|
|
| 7 |
import org.apache.commons.lang.StringEscapeUtils; |
|
| 8 |
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences; |
|
| 9 |
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 |
|
|
| 20 |
/** |
|
| 21 |
* R progression chart creator. |
|
| 22 |
* @author mdecorde |
|
| 23 |
* @author sjacquot |
|
| 24 |
* |
|
| 25 |
*/ |
|
| 26 |
public class RProgressionCumulativeChartCreator extends RChartCreator implements ProgressionChartCreator {
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
@Override |
|
| 30 |
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; |
|
| 152 |
} |
|
| 153 |
|
|
| 154 |
|
|
| 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 |
} |
|
| 0 | 198 | |
| tmp/org.txm.progression.core/src/org/txm/progression/core/chartsengine/r/RProgressionDensityChartCreator.java (revision 639) | ||
|---|---|---|
| 1 |
package org.txm.progression.core.chartsengine.r; |
|
| 2 |
|
|
| 3 |
import java.io.File; |
|
| 4 |
import java.util.ArrayList; |
|
| 5 |
import java.util.List; |
|
| 6 |
|
|
| 7 |
import org.apache.commons.lang.StringEscapeUtils; |
|
| 8 |
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences; |
|
| 9 |
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 |
|
|
| 20 |
/** |
|
| 21 |
* R progression chart creator. |
|
| 22 |
* @author mdecorde |
|
| 23 |
* @author sjacquot |
|
| 24 |
* |
|
| 25 |
*/ |
|
| 26 |
public class RProgressionDensityChartCreator extends RChartCreator implements ProgressionChartCreator {
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
@Override |
|
| 30 |
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; |
|
| 152 |
} |
|
| 153 |
|
|
| 154 |
|
|
| 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 |
} |
|
| 0 | 198 | |
| tmp/org.txm.progression.core/plugin.xml (revision 639) | ||
|---|---|---|
| 5 | 5 |
point="org.txm.chartsengine.chartcreator"> |
| 6 | 6 |
<ChartCreator |
| 7 | 7 |
chartsEngineName="jfreechart_charts_engine" |
| 8 |
class="org.txm.progression.core.chartsengine.jfreechart.JFCProgressionChartCreator" |
|
| 9 |
fileNamePrefix="progression"> |
|
| 8 |
class="org.txm.progression.core.chartsengine.jfreechart.JFCProgressionCumulativeChartCreator"
|
|
| 9 |
fileNamePrefix="progression_cumulative">
|
|
| 10 | 10 |
</ChartCreator> |
| 11 | 11 |
<ChartCreator |
| 12 | 12 |
chartsEngineName="r_charts_engine" |
| 13 |
class="org.txm.progression.core.chartsengine.r.RProgressionChartCreator" |
|
| 14 |
fileNamePrefix="progression"> |
|
| 13 |
class="org.txm.progression.core.chartsengine.r.RProgressionCumulativeChartCreator"
|
|
| 14 |
fileNamePrefix="progression_cumulative">
|
|
| 15 | 15 |
</ChartCreator> |
| 16 |
<ChartCreator |
|
| 17 |
chartType="density" |
|
| 18 |
class="org.txm.progression.core.chartsengine.r.RProgressionDensityChartCreator" |
|
| 19 |
fileNamePrefix="progression_density"> |
|
| 20 |
</ChartCreator> |
|
| 16 | 21 |
</extension> |
| 17 | 22 |
<extension |
| 18 | 23 |
point="org.eclipse.core.runtime.preferences"> |
| tmp/org.txm.progression.rcp/src/org/txm/progression/rcp/editors/ProgressionEditor.java (revision 639) | ||
|---|---|---|
| 68 | 68 |
Text bandeField; |
| 69 | 69 |
|
| 70 | 70 |
/** The cumu button. */ |
| 71 |
Button cumuButton; |
|
| 71 |
Button cumulativeButton;
|
|
| 72 | 72 |
|
| 73 | 73 |
/** The colors. */ |
| 74 | 74 |
String[] colors = DefaultTheme.colors; |
| ... | ... | |
| 195 | 195 |
typeLabel.setText(ProgressionUIMessages.ProgressionDialog_1); |
| 196 | 196 |
typeLabel.setAlignment(SWT.CENTER); |
| 197 | 197 |
|
| 198 |
cumuButton = new Button(paramPanel, SWT.RADIO); |
|
| 199 |
cumuButton.setText(ProgressionUIMessages.ProgressionDialog_2); |
|
| 200 |
cumuButton.setSelection(cumulative); |
|
| 201 |
cumuButton.addSelectionListener(new SelectionListener() {
|
|
| 202 |
|
|
| 198 |
cumulativeButton = new Button(paramPanel, SWT.RADIO); |
|
| 199 |
cumulativeButton.setText(ProgressionUIMessages.ProgressionDialog_2); |
|
| 200 |
cumulativeButton.setSelection(cumulative); |
|
| 201 |
// listeners |
|
| 202 |
cumulativeButton.addSelectionListener(new ComputeSelectionListener(this)); |
|
| 203 |
cumulativeButton.addSelectionListener(new SelectionListener() {
|
|
| 203 | 204 |
@Override |
| 204 | 205 |
public void widgetSelected(SelectionEvent e) {
|
| 205 | 206 |
bandeField.setEnabled(densityButton.getSelection()); |
| 207 |
getResult().setDefaultChartType(); |
|
| 206 | 208 |
} |
| 207 | 209 |
|
| 208 | 210 |
@Override |
| ... | ... | |
| 212 | 214 |
densityButton = new Button(paramPanel, SWT.RADIO); |
| 213 | 215 |
densityButton.setText(ProgressionUIMessages.ProgressionDialog_3); |
| 214 | 216 |
densityButton.setSelection(!cumulative); |
| 217 |
// listener |
|
| 215 | 218 |
densityButton.addSelectionListener(new SelectionListener() {
|
| 216 | 219 |
|
| 217 | 220 |
@Override |
| 218 | 221 |
public void widgetSelected(SelectionEvent e) {
|
| 219 | 222 |
bandeField.setEnabled(densityButton.getSelection()); |
| 223 |
getResult().setChartType("density");
|
|
| 220 | 224 |
} |
| 221 | 225 |
|
| 222 | 226 |
@Override |
Formats disponibles : Unified diff