2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.matrix
;
11 import java
.util
.List
;
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
.FillLayout
;
20 import org
.eclipse
.swt
.layout
.GridData
;
21 import org
.eclipse
.swt
.layout
.GridLayout
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.swt
.widgets
.Event
;
24 import org
.eclipse
.swt
.widgets
.Label
;
25 import org
.swtchart
.Chart
;
26 import org
.swtchart
.IAxis
;
27 import org
.swtchart
.ILineSeries
;
28 import org
.swtchart
.ILineSeries
.PlotSymbolType
;
29 import org
.swtchart
.ISeries
.SeriesType
;
30 import org
.swtchart
.LineStyle
;
32 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
39 public class QuantitativeChartTooltip
extends DefaultToolTip
{
41 private CharacterMatrix matrix
;
43 public QuantitativeChartTooltip(CharacterMatrix matrix
) {
44 super(matrix
.getNatTable(), ToolTip
.NO_RECREATE
, false);
49 protected Object
getToolTipArea(Event event
) {
50 int col
= matrix
.getNatTable().getColumnPositionByX(event
.x
);
51 int row
= matrix
.getNatTable().getRowPositionByY(event
.y
);
52 return new Point(col
, row
);
56 protected Composite
createToolTipContentArea(Event event
,
59 int colPos
= matrix
.getNatTable().getColumnPositionByX(event
.x
);
60 int colIndex
= matrix
.getNatTable().getColumnIndexByPosition(colPos
);
61 Feature feature
= matrix
.getIndexToFeatureMap().get(colIndex
);
62 QuantitativeDataStatistics dataStatistics
= matrix
.getFeatureToQuantDataStatisticsMap().get(feature
);
65 if(dataStatistics
!=null){
66 parent
.setLayout(new GridLayout());
67 tooltip
= createTooltip(event
, parent
);
70 tooltip
= new Composite(parent
, SWT
.NONE
);
71 tooltip
.setLayout(new FillLayout());
72 Label label
= new Label(tooltip
, SWT
.NONE
);
73 label
.setText(CategoricalChartTooltip
.TOOLTIP_NOT_AVAILABLE
);
79 private Composite
createTooltip(Event event
, Composite parent
){
80 Chart chart
= new Chart(parent
, SWT
.NONE
);
81 chart
.setLayoutData(new GridData(600, 300));
83 //get statistics for column
84 int colPos
= matrix
.getNatTable().getColumnPositionByX(event
.x
);
85 int colIndex
= matrix
.getNatTable().getColumnIndexByPosition(colPos
);
86 Feature feature
= matrix
.getIndexToFeatureMap().get(colIndex
);
87 QuantitativeDataStatistics quantitativeDataStatistics
= matrix
.getFeatureToQuantDataStatisticsMap().get(feature
);
88 List
<DescriptiveStatistics
> statistics
= quantitativeDataStatistics
.getStatistics();
91 double[] exactMean
= statistics
.stream().mapToDouble(statistic
->statistic
.getMean()).toArray();
92 double[] mins
= statistics
.stream().mapToDouble(statistic
->statistic
.getMin()).toArray();
93 double[] maxs
= statistics
.stream().mapToDouble(statistic
->statistic
.getMax()).toArray();
96 chart
.getTitle().setText(feature
.getLabel());
98 // create exact/mean series
99 ILineSeries meanExactSeries
= (ILineSeries
) chart
.getSeriesSet()
100 .createSeries(SeriesType
.LINE
, "exact/mean");
101 meanExactSeries
.setYSeries(exactMean
);
102 meanExactSeries
.setLineStyle(LineStyle
.NONE
);
103 meanExactSeries
.setSymbolColor(GUIHelper
.COLOR_BLUE
);
106 ILineSeries minSeries
= (ILineSeries
) chart
.getSeriesSet()
107 .createSeries(SeriesType
.LINE
, "min");
108 minSeries
.setYSeries(mins
);
109 minSeries
.setLineStyle(LineStyle
.NONE
);
110 minSeries
.setSymbolType(PlotSymbolType
.INVERTED_TRIANGLE
);
111 minSeries
.setSymbolColor(GUIHelper
.COLOR_GREEN
);
114 ILineSeries maxSeries
= (ILineSeries
) chart
.getSeriesSet()
115 .createSeries(SeriesType
.LINE
, "max");
116 maxSeries
.setYSeries(maxs
);
117 maxSeries
.setLineStyle(LineStyle
.NONE
);
118 maxSeries
.setSymbolType(PlotSymbolType
.TRIANGLE
);
119 maxSeries
.setSymbolColor(GUIHelper
.COLOR_RED
);
121 IAxis yAxis
= chart
.getAxisSet().getYAxis(0);
122 yAxis
.getTitle().setVisible(false);
123 IAxis xAxis
= chart
.getAxisSet().getXAxis(0);
124 xAxis
.getTitle().setVisible(false);
126 chart
.getAxisSet().adjustRange();
132 protected boolean shouldCreateToolTip(Event event
) {
133 //Differentiation between "index" and "position" is important here
134 //"position" is the current visible index
135 //"index" refers to the underlying data model
136 int colPos
= matrix
.getNatTable().getColumnPositionByX(event
.x
);
137 int colIndex
= matrix
.getNatTable().getColumnIndexByPosition(colPos
);
138 int rowPos
= matrix
.getNatTable().getRowPositionByY(event
.y
);
139 Feature feature
= matrix
.getIndexToFeatureMap().get(colIndex
);
141 if(matrix
.isShowTooltips()
144 && feature
.isSupportsQuantitativeData()
145 && colIndex
>=CharacterMatrix
.LEADING_COLUMN_COUNT
) {