Project

General

Profile

« Previous | Next » 

Revision d05bf8bd

Added by Patrick Plitzner over 5 years ago

ref #7549 Add quant statistic tooltip to character matrix

View differences:

eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF
232 232
 org.apache.commons.lang.text,
233 233
 org.apache.commons.logging,
234 234
 org.apache.commons.math3.stat,
235
 org.apache.commons.math3.stat.descriptive,
235 236
 org.apache.fop.apps,
236 237
 org.apache.http,
237 238
 org.apache.http.client,
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
232 232

  
233 233
        //add tooltip to table
234 234
        new CategoricalChartTooltip(this);
235
        new QuantitativeChartTooltip(this);
235 236

  
236 237
        this.layout();
237 238
        natTable.doCommand(new ClientAreaResizeCommand(natTable));
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixBottomToolbar.java
18 18
import java.util.UUID;
19 19
import java.util.stream.Collectors;
20 20

  
21
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
21 22
import org.eclipse.jface.layout.GridDataFactory;
22 23
import org.eclipse.jface.window.Window;
23 24
import org.eclipse.swt.SWT;
......
38 39
import eu.etaxonomy.cdm.model.description.Feature;
39 40
import eu.etaxonomy.cdm.model.description.QuantitativeData;
40 41
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
42
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
41 43
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
42 44
import eu.etaxonomy.cdm.model.taxon.Taxon;
43 45
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
......
157 159
                matrix.addUpdateResult(result);
158 160
                matrix.setDirty();
159 161

  
160
                //aggregate histogram for categorical tooltip
161
                Map<Feature, CategoricalDataHistogram> featureToHistogramMap = matrix.getFeatureToHistogramMap();
162
                featureToHistogramMap.clear();
163
                aggregateCategorcialHistogram(featureToHistogramMap);
162
                aggregateCategorcialHistogram(matrix.getFeatureToHistogramMap());
163
                aggregateQuantitativeSummary(matrix.getFeatureToQuantStatisticsMap());
164 164
            }
165 165

  
166 166
        });
......
168 168

  
169 169
    @SuppressWarnings("unchecked")
170 170
    private void aggregateCategorcialHistogram(Map<Feature, CategoricalDataHistogram> featureToHistogramMap) {
171
        featureToHistogramMap.clear();
171 172
        matrix.getDescriptions()
172 173
                .forEach(o -> ((RowWrapperDTO) o).getSpecimenDescription().getElements().stream()
173 174
                        .filter(descriptionElement -> descriptionElement instanceof CategoricalData)
......
183 184
                        }));
184 185
    }
185 186

  
187
    @SuppressWarnings("unchecked")
188
    private void aggregateQuantitativeSummary(Map<Feature, DescriptiveStatistics> featureToQuantStatisticsMap) {
189
        featureToQuantStatisticsMap.clear();
190
        matrix.getDescriptions()
191
        .forEach(o -> ((RowWrapperDTO) o).getSpecimenDescription().getElements().stream()
192
                .filter(descriptionElement -> descriptionElement instanceof QuantitativeData)
193
                .forEach(quantData -> {
194
                    Feature feature = ((QuantitativeData) quantData).getFeature();
195
                    DescriptiveStatistics statistics = featureToQuantStatisticsMap.get(feature);
196
                    if(statistics==null){
197
                        statistics = new DescriptiveStatistics();
198
                    }
199
                    featureToQuantStatisticsMap.put(feature, statistics);
200
                    ((QuantitativeData) quantData).getStatisticalValues().stream()
201
                    .filter(value -> value.getType().equals(StatisticalMeasure.EXACT_VALUE()))
202
                    .forEach(value -> featureToQuantStatisticsMap.get(feature).addValue(value.getValue()));
203
                }));
204
    }
205

  
186 206
    private SpecimenDescription getDescriptionForDescriptiveDataSet(SpecimenOrObservationBase specimen){
187 207
        Set<Feature> wsFeatures = matrix.getDescriptiveDataSet().getDescriptiveSystem().getDistinctFeatures();
188 208
        List<DescriptionElementBase> matchingDescriptionElements = new ArrayList<>();
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/QuantitativeChartTooltip.java
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 org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
12
import org.eclipse.jface.window.DefaultToolTip;
13
import org.eclipse.jface.window.ToolTip;
14
import org.eclipse.swt.graphics.Point;
15
import org.eclipse.swt.widgets.Event;
16

  
17
import eu.etaxonomy.cdm.model.description.Feature;
18

  
19
/**
20
 * @author pplitzner
21
 * @since Jul 6, 2018
22
 *
23
 */
24
public class QuantitativeChartTooltip extends DefaultToolTip {
25

  
26
    private CharacterMatrix matrix;
27

  
28
    public QuantitativeChartTooltip(CharacterMatrix matrix) {
29
        super(matrix.getNatTable(), ToolTip.NO_RECREATE, false);
30
        this.matrix = matrix;
31
    }
32

  
33
    @Override
34
    protected Object getToolTipArea(Event event) {
35
        int col = matrix.getNatTable().getColumnPositionByX(event.x);
36
        int row = matrix.getNatTable().getRowPositionByY(event.y);
37
        return new Point(col, row);
38
    }
39

  
40
    @Override
41
    protected String getText(Event event) {
42
        int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
43
        int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
44
        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
45
        DescriptiveStatistics statistics = matrix.getFeatureToQuantStatisticsMap().get(feature);
46

  
47
        return statistics.toString();
48
    }
49

  
50
    @Override
51
    protected boolean shouldCreateToolTip(Event event) {
52
        //Differentiation between "index" and "position" is important here
53
        //"position" is the current visible index
54
        //"index" refers to the underlying data model
55
        int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
56
        int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
57
        int rowPos = matrix.getNatTable().getRowPositionByY(event.y);
58
        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
59
        DescriptiveStatistics statistics = matrix.getFeatureToQuantStatisticsMap().get(feature);
60

  
61
        if(matrix.isShowTooltips()
62
                && rowPos==1
63
                && colIndex>=CharacterMatrix.LEADING_COLUMN_COUNT
64
                && statistics!=null) {
65
            return true;
66
        }
67
        return false;
68
    }
69

  
70
}

Also available in: Unified diff