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
.Iterator
;
13 import java
.util
.Map
.Entry
;
15 import org
.eclipse
.jface
.window
.ToolTip
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.graphics
.Point
;
18 import org
.eclipse
.swt
.layout
.GridData
;
19 import org
.eclipse
.swt
.layout
.GridLayout
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
21 import org
.eclipse
.swt
.widgets
.Event
;
22 import org
.swtchart
.Chart
;
23 import org
.swtchart
.IAxis
;
24 import org
.swtchart
.IBarSeries
;
25 import org
.swtchart
.ISeries
.SeriesType
;
26 import org
.swtchart
.ISeriesLabel
;
28 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
29 import eu
.etaxonomy
.cdm
.model
.description
.State
;
36 public class ChartTooltip
extends ToolTip
{
38 private CharacterMatrix matrix
;
40 public ChartTooltip(CharacterMatrix matrix
) {
41 super(matrix
.getNatTable(), ToolTip
.NO_RECREATE
, false);
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
);
53 protected Composite
createToolTipContentArea(Event event
,
55 parent
.setLayout(new GridLayout());
57 Chart chart
= new Chart(parent
, SWT
.NONE
);
58 chart
.setLayoutData(new GridData(600, 300));
60 int colPos
= matrix
.getNatTable().getColumnPositionByX(event
.x
);
61 int colIndex
= matrix
.getNatTable().getColumnIndexByPosition(colPos
);
62 Feature feature
= matrix
.getIndexToFeatureMap().get(colIndex
);
63 CategoricalDataHistogram histogram
= matrix
.getFeatureToHistogramMap().get(feature
);
66 chart
.getTitle().setText(feature
.getLabel());
67 IAxis xAxis
= chart
.getAxisSet().getXAxis(0);
68 Map
<State
, Integer
> stateCountMap
= histogram
.getStateCountMap();
69 String
[] states
= new String
[stateCountMap
.size()];
70 double[] counts
= new double[stateCountMap
.size()];
72 for(Iterator
<Entry
<State
, Integer
>> iterator
= histogram
.getStateCountMap().entrySet().iterator();iterator
.hasNext();){
73 Entry
<State
, Integer
> entry
= iterator
.next();
74 states
[index
] = entry
.getKey().getLabel();
75 counts
[index
] = entry
.getValue();
78 xAxis
.setCategorySeries(states
);
79 xAxis
.enableCategory(true);
80 xAxis
.getTitle().setVisible(false);
81 xAxis
.getTick().setTickLabelAngle(25);
83 IAxis yAxis
= chart
.getAxisSet().getYAxis(0);
84 yAxis
.getTitle().setVisible(false);
85 // yAxis.getTick().setVisible(false);
87 // chart.setOrientation(SWT.VERTICAL);
88 chart
.getLegend().setVisible(false);
91 IBarSeries barSeries
= (IBarSeries
) chart
.getSeriesSet()
92 .createSeries(SeriesType
.BAR
, "state counts");
93 ISeriesLabel seriesLabel
= barSeries
.getLabel();
94 seriesLabel
.setFormat("##.0");
95 seriesLabel
.setVisible(true);
96 barSeries
.setYSeries(counts
);
98 // adjust the axis range
99 chart
.getAxisSet().adjustRange();
105 protected boolean shouldCreateToolTip(Event event
) {
106 //Differentiation between "index" and "position" is important here
107 //"position" is the current visible index
108 //"index" refers to the underlying data model
109 int colPos
= matrix
.getNatTable().getColumnPositionByX(event
.x
);
110 int colIndex
= matrix
.getNatTable().getColumnIndexByPosition(colPos
);
111 int rowPos
= matrix
.getNatTable().getRowPositionByY(event
.y
);
112 Feature feature
= matrix
.getIndexToFeatureMap().get(colIndex
);
113 CategoricalDataHistogram histogram
= matrix
.getFeatureToHistogramMap().get(feature
);
116 && colIndex
>=CharacterMatrix
.LEADING_COLUMN_COUNT
118 && !histogram
.getStateCountMap().isEmpty()) {