Révision 3178
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/prototypes/stats/CAStyleMacro.groovy (revision 3178) | ||
---|---|---|
1 | 1 |
// STANDARD DECLARATIONS |
2 |
// @author mdecorde sheiden sjacquot
|
|
2 |
// @author mdecorde sjacquot sheiden
|
|
3 | 3 |
package org.txm.macro |
4 | 4 |
|
5 | 5 |
import org.kohsuke.args4j.* |
... | ... | |
258 | 258 |
|
259 | 259 |
|
260 | 260 |
|
261 |
// UPDATE THE CHART RENDERER |
|
262 |
|
|
261 |
// Redefine the chart renderer and update the chart |
|
263 | 262 |
def chartEditor = editor.getEditors()[0] |
264 |
def chartComposite = chartEditor.getComposite() |
|
265 |
|
|
266 |
ddebug = debug |
|
267 |
monitor.syncExec( new Runnable() { |
|
268 |
|
|
269 |
public void run() { |
|
270 |
println chartComposite |
|
271 |
def chart = chartEditor.getChart() |
|
263 |
def chartComposite = chartEditor.getComposite() |
|
264 |
|
|
265 |
ddebug = debug |
|
266 |
monitor.syncExec( new Runnable() { |
|
267 |
|
|
268 |
public void run() { |
|
269 |
println chartComposite |
|
270 |
def chart = chartEditor.getChart() |
|
271 |
|
|
272 |
/* |
|
273 |
println "chart: "+chart |
|
274 |
println "Plot: "+chart.getPlot() |
|
275 |
println "Dataset: "+chart.getPlot().getDataset() |
|
276 |
println "Renderer 1: "+chart.getPlot().getRenderer() |
|
277 |
*/ |
|
278 |
|
|
279 |
def renderer = new CAItemSelectionRenderer(ica, chart) { |
|
280 |
Area EMPTYAREA = new Area() |
|
281 |
|
|
282 |
@Override |
|
283 |
public void initItemLabelGenerator() { |
|
284 |
XYItemLabelGenerator generator = new XYItemLabelGenerator() { |
|
285 |
|
|
286 |
@Override |
|
287 |
public String generateLabel(XYDataset dataset, int series, int item) { |
|
288 |
if (series == 0 && rowHiddenStyle.contains(item)) { |
|
289 |
if (ddebug > 1) println "HIDDING ROW LABEL '$item' '${rows[item]}'" |
|
290 |
return "" |
|
291 |
} else if (series == 1 && colHiddenStyle.contains(item)) { |
|
292 |
if (ddebug > 1) println "HIDDING COL LABEL '$item' '${cols[item]}'" |
|
293 |
return "" |
|
294 |
} else if (series == 0 && rowLabelStyle.containsKey(item)) { |
|
295 |
if (ddebug > 1) println "RENAME ROW LABEL '$item' '${rows[item]}' -> '${rowLabelStyle[item]}'" |
|
296 |
return rowLabelStyle[item] |
|
297 |
} else if (series == 1 && colLabelStyle.containsKey(item)) { |
|
298 |
if (ddebug > 1) println "RENAME COL LABEL '$item' '${cols[item]}' -> '${colLabelStyle[item]}'" |
|
299 |
return colLabelStyle[item] |
|
300 |
} else { |
|
301 |
CAXYDataset caDataset = (CAXYDataset) dataset; |
|
302 |
return caDataset.getLabel(series, item); |
|
303 |
} |
|
304 |
} |
|
305 |
}; |
|
306 |
|
|
307 |
// don't use setBaseItemLabelGenerator BUT setDefaultItemLabelGenerator |
|
308 |
this.setDefaultItemLabelGenerator(generator); |
|
309 |
this.setDefaultItemLabelsVisible(true); |
|
310 |
} |
|
272 | 311 |
|
273 |
/* |
|
274 |
println "chart: "+chart |
|
275 |
println "Plot: "+chart.getPlot() |
|
276 |
println "Dataset: "+chart.getPlot().getDataset() |
|
277 |
println "Renderer 1: "+chart.getPlot().getRenderer() |
|
278 |
*/ |
|
279 | 312 |
|
280 |
def renderer = new CAItemSelectionRenderer(ica, chart) { |
|
281 |
Area EMPTYAREA = new Area() |
|
282 |
|
|
283 |
@Override |
|
284 |
public void initItemLabelGenerator() { |
|
285 |
XYItemLabelGenerator generator = new XYItemLabelGenerator() { |
|
286 |
|
|
287 |
@Override |
|
288 |
public String generateLabel(XYDataset dataset, int series, int item) { |
|
289 |
if (series == 0 && rowHiddenStyle.contains(item)) { |
|
290 |
if (ddebug > 1) println "HIDDING ROW LABEL '$item' '${rows[item]}'" |
|
291 |
return "" |
|
292 |
} else if (series == 1 && colHiddenStyle.contains(item)) { |
|
293 |
if (ddebug > 1) println "HIDDING COL LABEL '$item' '${cols[item]}'" |
|
294 |
return "" |
|
295 |
} else if (series == 0 && rowLabelStyle.containsKey(item)) { |
|
296 |
if (ddebug > 1) println "RENAME ROW LABEL '$item' '${rows[item]}' -> '${rowLabelStyle[item]}'" |
|
297 |
return rowLabelStyle[item] |
|
298 |
} else if (series == 1 && colLabelStyle.containsKey(item)) { |
|
299 |
if (ddebug > 1) println "RENAME COL LABEL '$item' '${cols[item]}' -> '${colLabelStyle[item]}'" |
|
300 |
return colLabelStyle[item] |
|
301 |
} else { |
|
302 |
CAXYDataset caDataset = (CAXYDataset) dataset; |
|
303 |
return caDataset.getLabel(series, item); |
|
304 |
} |
|
305 |
} |
|
306 |
}; |
|
307 |
|
|
308 |
// don't use setBaseItemLabelGenerator BUT setDefaultItemLabelGenerator |
|
309 |
this.setDefaultItemLabelGenerator(generator); |
|
310 |
this.setDefaultItemLabelsVisible(true); |
|
313 |
|
|
314 |
@Override |
|
315 |
public Font getItemLabelFont(int series, int item) { |
|
316 |
Font d = super.getItemLabelFont(series, item); |
|
317 |
Integer style = d.getStyle(); |
|
318 |
Integer size = d.getSize(); |
|
319 |
String family = d.getFontName(); |
|
320 |
|
|
321 |
// size |
|
322 |
if (series == 0 && rowFontSizeStyle.containsKey(item)) { |
|
323 |
if (ddebug > 1) println "FIX ROW FONT-SIZE $item ${rows[item]} -> ${rowFontSizeStyle[item]}" |
|
324 |
size *= rowFontSizeStyle[item]; |
|
325 |
} else if (series == 1 && colFontSizeStyle.containsKey(item)) { |
|
326 |
if (ddebug > 1) println "FIX COL FONT-SIZE $item ${cols[item]} -> ${colFontSizeStyle[item]}" |
|
327 |
size *= colFontSizeStyle[item]; |
|
311 | 328 |
} |
312 | 329 |
|
330 |
// family |
|
331 |
if (series == 0 && rowFontFamilyStyle.containsKey(item)) { |
|
332 |
if (ddebug > 1) println "FIX ROW FONT-Family $item ${rows[item]} -> ${rowFontFamilyStyle[item]}" |
|
333 |
family = rowFontFamilyStyle[item]; |
|
334 |
} else if (series == 1 && colFontFamilyStyle.containsKey(item)) { |
|
335 |
if (ddebug > 1) println "FIX COL FONT-Family $item ${cols[item]} -> ${colFontFamilyStyle[item]}" |
|
336 |
family = colFontFamilyStyle[item]; |
|
337 |
} |
|
313 | 338 |
|
339 |
// style |
|
340 |
if (series == 0 && rowFontStyleStyle.containsKey(item)) { |
|
341 |
if (ddebug > 1) println "FIX ROW FONT-Style $item ${rows[item]} -> ${rowFontStyleStyle[item]}" |
|
342 |
style = rowFontStyleStyle[item]; |
|
343 |
} else if (series == 1 && colFontFamilyStyle.containsKey(item)) { |
|
344 |
if (ddebug > 1) println "FIX COL FONT-Style $item ${cols[item]} -> ${colFontStyleStyle[item]}" |
|
345 |
style = colFontStyleStyle[item]; |
|
346 |
} |
|
314 | 347 |
|
315 |
@Override |
|
316 |
public Font getItemLabelFont(int series, int item) { |
|
317 |
Font d = super.getItemLabelFont(series, item); |
|
318 |
Integer style = d.getStyle(); |
|
319 |
Integer size = d.getSize(); |
|
320 |
String family = d.getFontName(); |
|
348 |
|
|
349 |
return new Font(family, style, size); |
|
350 |
} |
|
351 |
|
|
352 |
|
|
353 |
@Override |
|
354 |
public Shape getItemShape(int series, int item) { |
|
355 |
// Rows (series == 0), Cols (series == 1) |
|
356 |
if (series == 0 && rowHiddenStyle.contains(item)) { |
|
357 |
return EMPTYAREA; |
|
358 |
} else if (series == 1 && colHiddenStyle.contains(item)) { |
|
359 |
return EMPTYAREA; |
|
360 |
} else { |
|
321 | 361 |
|
322 |
// size |
|
323 |
if (series == 0 && rowFontSizeStyle.containsKey(item)) { |
|
324 |
if (ddebug > 1) println "FIX ROW FONT-SIZE $item ${rows[item]} -> ${rowFontSizeStyle[item]}" |
|
325 |
size *= rowFontSizeStyle[item]; |
|
326 |
} else if (series == 1 && colFontSizeStyle.containsKey(item)) { |
|
327 |
if (ddebug > 1) println "FIX COL FONT-SIZE $item ${cols[item]} -> ${colFontSizeStyle[item]}" |
|
328 |
size *= colFontSizeStyle[item]; |
|
329 |
} |
|
362 |
Shape shape = super.getItemShape(series, item); |
|
330 | 363 |
|
331 |
// family |
|
332 |
if (series == 0 && rowFontFamilyStyle.containsKey(item)) { |
|
333 |
if (ddebug > 1) println "FIX ROW FONT-Family $item ${rows[item]} -> ${rowFontFamilyStyle[item]}" |
|
334 |
family = rowFontFamilyStyle[item]; |
|
335 |
} else if (series == 1 && colFontFamilyStyle.containsKey(item)) { |
|
336 |
if (ddebug > 1) println "FIX COL FONT-Family $item ${cols[item]} -> ${colFontFamilyStyle[item]}" |
|
337 |
family = colFontFamilyStyle[item]; |
|
364 |
// not-visible shapes mode |
|
365 |
if(!((CA) this.multipleItemsSelector.getResult()).isShowPointShapes()) { |
|
366 |
return shape; |
|
338 | 367 |
} |
339 | 368 |
|
340 |
// style
|
|
341 |
if (series == 0 && rowFontStyleStyle.containsKey(item)) {
|
|
342 |
if (ddebug > 1) println "FIX ROW FONT-Style $item ${rows[item]} -> ${rowFontStyleStyle[item]}"
|
|
343 |
style = rowFontStyleStyle[item];
|
|
344 |
} else if (series == 1 && colFontFamilyStyle.containsKey(item)) {
|
|
345 |
if (ddebug > 1) println "FIX COL FONT-Style $item ${cols[item]} -> ${colFontStyleStyle[item]}"
|
|
346 |
style = colFontStyleStyle[item];
|
|
369 |
// shape replacement
|
|
370 |
if (series == 0 && rowPointShapeStyle.containsKey(item)) {
|
|
371 |
if (ddebug > 1) println "FIX ROW SHAPE $item ${rows[item]} -> ${rowPointShapeStyle[item]}"
|
|
372 |
shape = rowPointShapeStyle.get(item);
|
|
373 |
} else if (series == 1 && colPointShapeStyle.containsKey(item)) {
|
|
374 |
if (ddebug > 1) println "FIX COL SHAPE $item ${cols[item]} -> ${colPointShapeStyle[item]}"
|
|
375 |
shape = colPointShapeStyle.get(item);
|
|
347 | 376 |
} |
348 | 377 |
|
349 | 378 |
|
350 |
return new Font(family, style, size); |
|
351 |
} |
|
352 |
|
|
353 |
|
|
354 |
@Override |
|
355 |
public Shape getItemShape(int series, int item) { |
|
356 |
// Rows (series == 0), Cols (series == 1) |
|
357 |
if (series == 0 && rowHiddenStyle.contains(item)) { |
|
358 |
return EMPTYAREA; |
|
359 |
} else if (series == 1 && colHiddenStyle.contains(item)) { |
|
360 |
return EMPTYAREA; |
|
361 |
} else { |
|
362 |
|
|
363 |
Shape shape = super.getItemShape(series, item); |
|
364 |
|
|
365 |
// not-visible shapes mode |
|
366 |
if(!((CA) this.multipleItemsSelector.getResult()).isShowPointShapes()) { |
|
367 |
return shape; |
|
368 |
} |
|
369 |
|
|
370 |
// shape replacement |
|
371 |
if (series == 0 && rowPointShapeStyle.containsKey(item)) { |
|
372 |
if (ddebug > 1) println "FIX ROW SHAPE $item ${rows[item]} -> ${rowPointShapeStyle[item]}" |
|
373 |
shape = rowPointShapeStyle.get(item); |
|
374 |
} else if (series == 1 && colPointShapeStyle.containsKey(item)) { |
|
375 |
if (ddebug > 1) println "FIX COL SHAPE $item ${cols[item]} -> ${colPointShapeStyle[item]}" |
|
376 |
shape = colPointShapeStyle.get(item); |
|
377 |
} |
|
378 |
|
|
379 |
|
|
380 |
// shape scaling |
|
381 |
AffineTransform t = new AffineTransform(); |
|
382 |
if (series == 0 && rowPointSizeStyle.containsKey(item)) { |
|
383 |
if (ddebug > 1) println "FIX ROW POINT SIZE $item ${rows[item]} -> ${rowPointSizeStyle[item]}" |
|
384 |
t.setToScale(rowPointSizeStyle.get(item), rowPointSizeStyle.get(item)); |
|
385 |
shape = t.createTransformedShape(shape); |
|
386 |
} else if (series == 1 && colPointSizeStyle.containsKey(item)) { |
|
387 |
if (ddebug > 1) println "FIX COL POINT SIZE $item ${cols[item]} -> ${colPointSizeStyle[item]}" |
|
388 |
t.setToScale(colPointSizeStyle.get(item), colPointSizeStyle.get(item)); |
|
389 |
shape = t.createTransformedShape(shape); |
|
390 |
} |
|
391 |
|
|
392 |
return shape; |
|
379 |
// shape scaling |
|
380 |
AffineTransform t = new AffineTransform(); |
|
381 |
if (series == 0 && rowPointSizeStyle.containsKey(item)) { |
|
382 |
if (ddebug > 1) println "FIX ROW POINT SIZE $item ${rows[item]} -> ${rowPointSizeStyle[item]}" |
|
383 |
t.setToScale(rowPointSizeStyle.get(item), rowPointSizeStyle.get(item)); |
|
384 |
shape = t.createTransformedShape(shape); |
|
385 |
} else if (series == 1 && colPointSizeStyle.containsKey(item)) { |
|
386 |
if (ddebug > 1) println "FIX COL POINT SIZE $item ${cols[item]} -> ${colPointSizeStyle[item]}" |
|
387 |
t.setToScale(colPointSizeStyle.get(item), colPointSizeStyle.get(item)); |
|
388 |
shape = t.createTransformedShape(shape); |
|
393 | 389 |
} |
394 |
} |
|
395 |
|
|
396 |
|
|
397 |
@Override |
|
398 |
public Paint getItemPaint(int series, int item) { |
|
399 | 390 |
|
400 |
// visible shapes mode |
|
401 |
if (!((CA) this.multipleItemsSelector.getResult()).isShowPointShapes()) { |
|
402 |
return super.getItemPaint(series, item); |
|
403 |
} |
|
404 |
|
|
405 |
if (series == 0 && rowPointColorStyle.containsKey(item)) { |
|
406 |
if (ddebug > 1) println "FIX ROW POINT COLOR $item ${rows[item]} -> ${rowPointColorStyle[item]}" |
|
407 |
return rowPointColorStyle.get(item); |
|
408 |
} else if (series == 1 && colPointColorStyle.containsKey(item)) { |
|
409 |
if (ddebug > 1) println "FIX COL POINT COLOR $item ${cols[item]} -> ${colPointColorStyle[item]}" |
|
410 |
return colPointColorStyle.get(item); |
|
411 |
} |
|
412 |
else { |
|
413 |
return super.getItemPaint(series, item); |
|
414 |
} |
|
391 |
return shape; |
|
415 | 392 |
} |
393 |
} |
|
394 |
|
|
395 |
|
|
396 |
@Override |
|
397 |
public Paint getItemPaint(int series, int item) { |
|
416 | 398 |
|
417 |
|
|
418 |
@Override |
|
419 |
public Paint getItemLabelPaint(int series, int item) { |
|
420 |
if (series == 0 && rowFontColorStyle.containsKey(item)) { |
|
421 |
if (ddebug > 1) println "FIX ROW LABEL COLOR $item ${rows[item]} -> ${rowFontColorStyle[item]}" |
|
422 |
return rowFontColorStyle.get(item); |
|
423 |
} else if (series == 1 && colFontColorStyle.containsKey(item)) { |
|
424 |
if (ddebug > 1) println "FIX COL LABEL COLOR $item ${cols[item]} -> ${colFontColorStyle[item]}" |
|
425 |
return colFontColorStyle.get(item); |
|
426 |
} else { |
|
427 |
return super.getItemLabelPaint(series, item); |
|
428 |
} |
|
399 |
// visible shapes mode |
|
400 |
if (!((CA) this.multipleItemsSelector.getResult()).isShowPointShapes()) { |
|
401 |
return super.getItemPaint(series, item); |
|
429 | 402 |
} |
430 | 403 |
|
431 |
|
|
432 |
|
|
433 |
}; |
|
404 |
if (series == 0 && rowPointColorStyle.containsKey(item)) { |
|
405 |
if (ddebug > 1) println "FIX ROW POINT COLOR $item ${rows[item]} -> ${rowPointColorStyle[item]}" |
|
406 |
return rowPointColorStyle.get(item); |
|
407 |
} else if (series == 1 && colPointColorStyle.containsKey(item)) { |
|
408 |
if (ddebug > 1) println "FIX COL POINT COLOR $item ${cols[item]} -> ${colPointColorStyle[item]}" |
|
409 |
return colPointColorStyle.get(item); |
|
410 |
} |
|
411 |
else { |
|
412 |
return super.getItemPaint(series, item); |
|
413 |
} |
|
414 |
} |
|
434 | 415 |
|
435 | 416 |
|
436 |
def cp = editor.editors[0].getChart(); |
|
437 |
renderer.chart = cp |
|
438 |
renderer.setSeriesVisible(0, ica.isShowVariables()); // Rows |
|
439 |
renderer.setSeriesVisible(1, ica.isShowIndividuals()); // Columns |
|
440 |
chart.getXYPlot().setRenderer(renderer) |
|
417 |
@Override |
|
418 |
public Paint getItemLabelPaint(int series, int item) { |
|
419 |
if (series == 0 && rowFontColorStyle.containsKey(item)) { |
|
420 |
if (ddebug > 1) println "FIX ROW LABEL COLOR $item ${rows[item]} -> ${rowFontColorStyle[item]}" |
|
421 |
return rowFontColorStyle.get(item); |
|
422 |
} else if (series == 1 && colFontColorStyle.containsKey(item)) { |
|
423 |
if (ddebug > 1) println "FIX COL LABEL COLOR $item ${cols[item]} -> ${colFontColorStyle[item]}" |
|
424 |
return colFontColorStyle.get(item); |
|
425 |
} else { |
|
426 |
return super.getItemLabelPaint(series, item); |
|
427 |
} |
|
428 |
} |
|
441 | 429 |
|
442 |
ica.getChartCreator().updateChart(chartEditor.getResult()) |
|
443 |
|
|
444 |
} |
|
445 |
}); |
|
430 |
}; |
|
431 |
|
|
432 |
|
|
433 |
def cp = editor.editors[0].getChart(); |
|
434 |
renderer.chart = cp // SJ: seems useless |
|
435 |
renderer.setSeriesVisible(0, ica.isShowVariables()); // Rows // SJ: seems useless |
|
436 |
renderer.setSeriesVisible(1, ica.isShowIndividuals()); // Columns // SJ: seems useless |
|
437 |
chart.getXYPlot().setRenderer(renderer) |
|
438 |
|
|
439 |
ica.getChartCreator().updateChart(chartEditor.getResult()) |
|
440 |
|
|
441 |
} |
|
442 |
}); |
|
446 | 443 |
|
447 | 444 |
|
448 | 445 |
|
Formats disponibles : Unified diff