Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes for the chart plug-in. #6

Merged
merged 1 commit into from Dec 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/net.bioclipse.chart/build.properties
Expand Up @@ -3,5 +3,6 @@ bin.includes = plugin.xml,\
icons/,\
jars/batik-awt-util.jar,\
jars/batik-dom.jar,\
jars/batik-svggen.jar
jars/batik-svggen.jar,\
jars/batik-util.jar
source.chart.jar = src/
Expand Up @@ -71,21 +71,24 @@ public BioclipseChartPanel(JFreeChart chart, ChartAction ca) {
public void selectionChanged( IWorkbenchPart part, ISelection selection ) {

if ( part instanceof IEditorPart )
if ( selection instanceof IStructuredSelection) {
XYPlot plot = (XYPlot) getChart().getPlot();
XYItemRenderer plotRenderer = plot.getRenderer();
ScatterPlotRenderer renderer = null;
if (plotRenderer instanceof ScatterPlotRenderer) {
renderer = (ScatterPlotRenderer) plot.getRenderer();
IChartDescriptor cd = ChartUtils.getChartDescriptor( getChart() );
List<ChartPoint> values = cd.handleEvent( selection );
renderer.clearMarkedPoints();
for (ChartPoint cp:values) {
selectPoints( cp.getX(), cp.getY(), plot, renderer );
if ( selection instanceof IStructuredSelection) {
if (getChart().getPlot() instanceof XYPlot) {
XYPlot plot = (XYPlot) getChart().getPlot();
XYItemRenderer plotRenderer = plot.getRenderer();
ScatterPlotRenderer renderer = null;
if (plotRenderer instanceof ScatterPlotRenderer) {
renderer = (ScatterPlotRenderer) plot.getRenderer();
IChartDescriptor cd = ChartUtils.getChartDescriptor( getChart() );
if (cd != null) {
List<ChartPoint> values = cd.handleEvent( selection );
renderer.clearMarkedPoints();
for (ChartPoint cp:values) {
selectPoints( cp.getX(), cp.getY(), plot, renderer );
}
}
}
}
}

}

@Override
Expand Down
Expand Up @@ -17,6 +17,7 @@ public enum plotTypes {
LINE_PLOT,
TIME_SERIES,
BAR_PLOT,
BOX_PLOT,
PLOT_MENU
}

Expand Down
Expand Up @@ -3,6 +3,7 @@
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IEditorPart;

import net.bioclipse.model.BoxPlotDescriptor;
import net.bioclipse.model.ChartDescriptor;
import net.bioclipse.model.HistogramDiscriptor;

Expand Down Expand Up @@ -117,4 +118,13 @@ public static IChartDescriptor histogramDescriptor(IEditorPart source,
return new HistogramDiscriptor( source, xLabel, values, yLable, bins,
originCells, ChartTitle );
}

public static IChartDescriptor boxPlotDescriptor(IEditorPart source,
String[] itemLabels,
double[][] values,
Point[] originCells,
String ChartTitle) {

return new BoxPlotDescriptor( source, itemLabels, values, originCells, ChartTitle );
}
}
Expand Up @@ -19,6 +19,7 @@
import net.bioclipse.chart.events.CellChangedEvent;
import net.bioclipse.chart.events.CellData;
import net.bioclipse.managers.business.IBioclipseManager;
import net.bioclipse.model.BoxPlotDescriptor;
import net.bioclipse.model.ChartManager;
import net.bioclipse.model.ChartModelListener;
import net.bioclipse.model.ChartSelection;
Expand All @@ -43,6 +44,7 @@
import org.jfree.chart.renderer.xy.XYBarRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset;
import org.jfree.data.statistics.HistogramDataset;
import org.jfree.data.xy.DefaultXYDataset;
import org.jfree.data.xy.IntervalXYDataset;
Expand Down Expand Up @@ -308,6 +310,33 @@ public static void barPlot(double[][] dataValues, String[] seriesLabels, String[

}

public static void boxPlot(IChartDescriptor descriptor) {

setupData( descriptor );

if (descriptor instanceof BoxPlotDescriptor) {
BoxPlotDescriptor bpd = (BoxPlotDescriptor) descriptor;

DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

for (int i=0;i<bpd.getNumberOfColumns();i++) {
dataset.add( bpd.getColumn( i ), bpd.getYLabel(), bpd.getItemLabel( i ) );
}

chart = ChartFactory.createBoxAndWhiskerChart( bpd.getTitle(),
"",
"",
dataset,
false );


chartManager.put(chart, descriptor);
ChartViewMouseListener l = new ChartViewMouseListener( view, descriptor );

view.display( chart, l );
}
}

/**
* Utility method for converting JFreeChart to an image
* @param parent used for color correction
Expand Down Expand Up @@ -448,7 +477,7 @@ else if( rangeLabel.equals(e.getCellData().getColName()) ){
}
}
}

public static Set<JFreeChart> getCharts() {
return chartManager.keySet();
}
Expand Down
Expand Up @@ -178,6 +178,11 @@ public interface IChartDescriptor extends IAdaptable {
*/
public void removeItemLabels();

public List<ChartPoint> handleEvent( ISelection selection );
public boolean hasToolTips();

public String getToolTip(int index);

public List<ChartPoint> handleEvent( ISelection selection );

public <T> T getAdapter(int index, Class<T> clazz);
}
Expand Up @@ -173,7 +173,39 @@ public void histogram(double[] values, int bins, String xLabel, String yLabel, S
descriptor.setItemLabels( itemLabels );
this.plot( descriptor );
}


public void boxPlot(double[] values, String boxName) {
Point[] origin = new Point[0];
double[][] valueMatrix = new double[1][values.length];
valueMatrix[0] = values;
String[] itemLabels = {boxName};
IChartDescriptor descriptor = ChartDescriptorFactory.boxPlotDescriptor( null, itemLabels, valueMatrix, origin, "" );
this.plot( descriptor );
}

public void boxPlot(double[] values1, String nameOfbox1, double[] values2, String nameOfbox2) {
Point[] origin = new Point[0];
double[][] valueMatrix = new double[2][values1.length];
valueMatrix[0] = values1;
valueMatrix[1] = values2;
String[] itemLabels = {nameOfbox1, nameOfbox2};
IChartDescriptor descriptor = ChartDescriptorFactory.boxPlotDescriptor( null, itemLabels, valueMatrix, origin, "" );
this.plot( descriptor );
}

public void boxPlot(double[][] values) {
String[] names = new String[values.length];
for (int i=0;i<names.length;i++)
names[i] = "";
this.boxPlot( values, names );
}

public void boxPlot(double[][] values, String[] names) {
Point[] origin = new Point[0];
IChartDescriptor descriptor = ChartDescriptorFactory.boxPlotDescriptor( null, names, values, origin, "" );
this.plot( descriptor );
}

/*
* Start of the internal plot methods
*/
Expand All @@ -192,8 +224,7 @@ public void run() {
switch (chartDescriptor.getPlotType()) {
case LINE_PLOT:
ChartUtils.linePlot( chartDescriptor );
break;

break;
case SCATTER_PLOT:
ChartUtils.scatterPlot( chartDescriptor );
break;
Expand All @@ -203,6 +234,9 @@ public void run() {
case HISTOGRAM:
ChartUtils.histogram( chartDescriptor );
break;
case BOX_PLOT:
ChartUtils.boxPlot( chartDescriptor );
break;
default:
throw new IllegalArgumentException( "The plot type "+chartDescriptor.getPlotType().name()+" is not fully implemented yet." );

Expand Down
Expand Up @@ -96,5 +96,16 @@ public void scatterPlot(double[] xValues, double[] yValues, String xLabel,
@PublishedMethod(methodSummary = "Returns the chart descriptor of the active chart" )
public IChartDescriptor getCharDescriptorOfActiveChart();

@Recorded
@PublishedMethod(methodSummary = "Plot a box plot, with one box for each column.",
params="double[][] values")
public void boxPlot(double[][] values);

@Recorded
@PublishedMethod(methodSummary = "Plot a box plot, with one box for each column and lables the boxes with the names of the array names.",
params="double[][] values, String[] names")

public void boxPlot(double[][] values, String[] names);

public void plot(final IChartDescriptor chartDescriptor);
}