Project

General

Profile

Download (4.63 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
10

    
11
import java.util.Arrays;
12

    
13
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
14
import org.eclipse.jface.window.DefaultToolTip;
15
import org.eclipse.jface.window.ToolTip;
16
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.graphics.Point;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.layout.GridLayout;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Event;
23
import org.swtchart.Chart;
24
import org.swtchart.IAxis;
25
import org.swtchart.ILineSeries;
26
import org.swtchart.ISeries.SeriesType;
27
import org.swtchart.LineStyle;
28

    
29
import eu.etaxonomy.cdm.model.description.Feature;
30

    
31
/**
32
 * @author pplitzner
33
 * @since Jul 6, 2018
34
 *
35
 */
36
public class QuantitativeChartTooltip extends DefaultToolTip {
37

    
38
    private CharacterMatrix matrix;
39

    
40
    public QuantitativeChartTooltip(CharacterMatrix matrix) {
41
        super(matrix.getNatTable(), ToolTip.NO_RECREATE, false);
42
        this.matrix = matrix;
43
    }
44

    
45
    @Override
46
    protected Object getToolTipArea(Event event) {
47
        int col = matrix.getNatTable().getColumnPositionByX(event.x);
48
        int row = matrix.getNatTable().getRowPositionByY(event.y);
49
        return new Point(col, row);
50
    }
51

    
52
    @Override
53
    protected Composite createToolTipContentArea(Event event,
54
            Composite parent) {
55
        parent.setLayout(new GridLayout());
56

    
57
        Chart chart = new Chart(parent, SWT.NONE);
58
        chart.setLayoutData(new GridData(600, 300));
59

    
60
        //get statistics for column
61
        int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
62
        int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
63
        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
64
        DescriptiveStatistics statistics = matrix.getFeatureToQuantStatisticsMap().get(feature);
65
        double[] ySeries = statistics.getValues();
66
        Arrays.sort(ySeries);
67

    
68
        // set chart title
69
        chart.getTitle().setText(feature.getLabel());
70

    
71
        // create exact/mean series
72
        ILineSeries meanExactSeries = (ILineSeries) chart.getSeriesSet()
73
                .createSeries(SeriesType.LINE, "exact/mean");
74
        meanExactSeries.setYSeries(ySeries);
75
        meanExactSeries.setLineStyle(LineStyle.NONE);
76
        meanExactSeries.setSymbolColor(GUIHelper.COLOR_BLUE);
77

    
78
        //TODO get min and max values
79
        // create min series
80
//        ILineSeries minSeries = (ILineSeries) chart.getSeriesSet()
81
//                .createSeries(SeriesType.LINE, "min");
82
//        double[] mins = { 0.3, 0.4, 0.3, 0.9, 1.1, 2.5, 2.6, 2.6};
83
//        minSeries.setYSeries(mins);
84
//        minSeries.setLineStyle(LineStyle.NONE);
85
//        minSeries.setSymbolType(PlotSymbolType.INVERTED_TRIANGLE);
86
//        minSeries.setSymbolColor(GUIHelper.COLOR_GREEN);
87
//
88
//        // create max series
89
//        ILineSeries maxSeries = (ILineSeries) chart.getSeriesSet()
90
//                .createSeries(SeriesType.LINE, "max");
91
//        double[] maxs = { 1.3, 2.4, 2.5, 2.6, 2.8, 3.6, 3.6, 3.8 };
92
//        maxSeries.setYSeries(maxs);
93
//        maxSeries.setLineStyle(LineStyle.NONE);
94
//        maxSeries.setSymbolType(PlotSymbolType.TRIANGLE);
95
//        maxSeries.setSymbolColor(GUIHelper.COLOR_RED);
96

    
97
        IAxis yAxis = chart.getAxisSet().getYAxis(0);
98
        yAxis.getTitle().setVisible(false);
99
        IAxis xAxis = chart.getAxisSet().getXAxis(0);
100
        xAxis.getTitle().setVisible(false);
101

    
102
        chart.getAxisSet().adjustRange();
103

    
104
        return chart;
105
    }
106

    
107
    @Override
108
    protected boolean shouldCreateToolTip(Event event) {
109
        //Differentiation between "index" and "position" is important here
110
        //"position" is the current visible index
111
        //"index" refers to the underlying data model
112
        int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
113
        int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
114
        int rowPos = matrix.getNatTable().getRowPositionByY(event.y);
115
        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
116
        DescriptiveStatistics statistics = matrix.getFeatureToQuantStatisticsMap().get(feature);
117

    
118
        if(matrix.isShowTooltips()
119
                && rowPos==1
120
                && colIndex>=CharacterMatrix.LEADING_COLUMN_COUNT
121
                && statistics!=null) {
122
            return true;
123
        }
124
        return false;
125
    }
126

    
127
}
(17-17/19)