Revision a3a12095
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.cdmlib/.classpath | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="UTF-8"?> |
2 | 2 |
<classpath> |
3 |
<classpathentry exported="true" kind="lib" path="lib/commons-math3-3.6.1.jar"/> |
|
3 | 4 |
<classpathentry exported="true" kind="lib" path="lib/org.swtchart_0.10.0.v20160212.jar"/> |
4 | 5 |
<classpathentry exported="true" kind="lib" path="lib/redmine-java-api-3.1.0.jar"/> |
5 | 6 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> |
eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF | ||
---|---|---|
231 | 231 |
org.apache.commons.lang.exception, |
232 | 232 |
org.apache.commons.lang.text, |
233 | 233 |
org.apache.commons.logging, |
234 |
org.apache.commons.math3.stat, |
|
234 | 235 |
org.apache.fop.apps, |
235 | 236 |
org.apache.http, |
236 | 237 |
org.apache.http.client, |
... | ... | |
869 | 870 |
lib/lucene-sandbox-5.4.1.jar, |
870 | 871 |
lib/lucene-suggest-5.4.1.jar, |
871 | 872 |
lib/redmine-java-api-3.1.0.jar, |
872 |
lib/org.swtchart_0.10.0.v20160212.jar |
|
873 |
lib/org.swtchart_0.10.0.v20160212.jar, |
|
874 |
lib/commons-math3-3.6.1.jar |
|
873 | 875 |
Import-Package: eu.etaxonomy.cdm.api.application |
eu.etaxonomy.taxeditor.cdmlib/build.properties | ||
---|---|---|
223 | 223 |
lib/lucene-suggest-5.4.1.jar,\ |
224 | 224 |
lib/cdmlib-cache-5.2.0-SNAPSHOT.jar,\ |
225 | 225 |
lib/redmine-java-api-3.1.0.jar,\ |
226 |
lib/org.swtchart_0.10.0.v20160212.jar |
|
226 |
lib/org.swtchart_0.10.0.v20160212.jar,\ |
|
227 |
lib/commons-math3-3.6.1.jar |
|
227 | 228 |
|
228 | 229 |
jars.compile.order = . |
229 | 230 |
output.. = bin/ |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CategoricalDataHistogram.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix; |
10 | 10 |
|
11 |
import java.util.HashMap; |
|
12 |
import java.util.Map; |
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.List; |
|
13 |
|
|
14 |
import org.apache.commons.math3.stat.Frequency; |
|
13 | 15 |
|
14 | 16 |
import eu.etaxonomy.cdm.model.description.Feature; |
15 | 17 |
import eu.etaxonomy.cdm.model.description.State; |
... | ... | |
22 | 24 |
public class CategoricalDataHistogram { |
23 | 25 |
|
24 | 26 |
private Feature feature; |
25 |
private Map<State, Integer> stateCountMap; |
|
27 |
private Frequency frequency; |
|
28 |
private List<State> states; |
|
26 | 29 |
|
27 | 30 |
public CategoricalDataHistogram(Feature feature) { |
28 | 31 |
this.feature = feature; |
29 |
this.stateCountMap = new HashMap<>(); |
|
32 |
this.states = new ArrayList<>(); |
|
33 |
this.frequency = new Frequency(); |
|
30 | 34 |
feature.getSupportedCategoricalEnumerations() |
31 | 35 |
.forEach(voc->voc.getTerms() |
32 |
.forEach(state->stateCountMap.put(state, 0)));
|
|
36 |
.forEach(state->states.add(state)));
|
|
33 | 37 |
} |
34 | 38 |
|
35 | 39 |
public void addState(State state){ |
36 |
Integer integer = stateCountMap.get(state); |
|
37 |
stateCountMap.put(state, integer+1); |
|
40 |
frequency.addValue(state.getLabel()); |
|
41 |
} |
|
42 |
|
|
43 |
public long getCount(State state){ |
|
44 |
return frequency.getCount(state.getLabel()); |
|
38 | 45 |
} |
39 | 46 |
|
40 |
public Map<State, Integer> getStateCountMap() {
|
|
41 |
return stateCountMap;
|
|
47 |
public List<State> getStates() {
|
|
48 |
return states;
|
|
42 | 49 |
} |
43 | 50 |
|
44 | 51 |
public Feature getFeature() { |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/ChartTooltip.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix; |
10 | 10 |
|
11 |
import java.util.Iterator; |
|
12 |
import java.util.Map; |
|
13 |
import java.util.Map.Entry; |
|
11 |
import java.util.List; |
|
14 | 12 |
|
15 | 13 |
import org.eclipse.jface.window.ToolTip; |
16 | 14 |
import org.eclipse.swt.SWT; |
... | ... | |
57 | 55 |
Chart chart = new Chart(parent, SWT.NONE); |
58 | 56 |
chart.setLayoutData(new GridData(600, 300)); |
59 | 57 |
|
58 |
//get histogram for column |
|
60 | 59 |
int colPos = matrix.getNatTable().getColumnPositionByX(event.x); |
61 | 60 |
int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos); |
62 | 61 |
Feature feature = matrix.getIndexToFeatureMap().get(colIndex); |
63 | 62 |
CategoricalDataHistogram histogram = matrix.getFeatureToHistogramMap().get(feature); |
64 | 63 |
|
65 |
// set titles
|
|
64 |
// set chart title
|
|
66 | 65 |
chart.getTitle().setText(feature.getLabel()); |
67 | 66 |
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()]; |
|
67 |
|
|
68 |
//initalize x and y axis values |
|
69 |
List<State> statesList = histogram.getStates(); |
|
70 |
String[] states = new String[statesList.size()]; |
|
71 |
double[] counts = new double[statesList.size()]; |
|
72 |
|
|
71 | 73 |
int index = 0; |
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(); |
|
74 |
for (State state : statesList) { |
|
75 |
states[index] = state.getLabel(); |
|
76 |
counts[index] = histogram.getCount(state); |
|
76 | 77 |
index++; |
77 | 78 |
} |
78 | 79 |
xAxis.setCategorySeries(states); |
... | ... | |
82 | 83 |
|
83 | 84 |
IAxis yAxis = chart.getAxisSet().getYAxis(0); |
84 | 85 |
yAxis.getTitle().setVisible(false); |
85 |
// yAxis.getTick().setVisible(false); |
|
86 | 86 |
|
87 |
// chart.setOrientation(SWT.VERTICAL); |
|
88 | 87 |
chart.getLegend().setVisible(false); |
89 | 88 |
|
90 |
// create bar series |
|
91 | 89 |
IBarSeries barSeries = (IBarSeries) chart.getSeriesSet() |
92 | 90 |
.createSeries(SeriesType.BAR, "state counts"); |
93 | 91 |
ISeriesLabel seriesLabel = barSeries.getLabel(); |
... | ... | |
95 | 93 |
seriesLabel.setVisible(true); |
96 | 94 |
barSeries.setYSeries(counts); |
97 | 95 |
|
98 |
// adjust the axis range |
|
99 | 96 |
chart.getAxisSet().adjustRange(); |
100 | 97 |
|
101 | 98 |
return chart; |
... | ... | |
116 | 113 |
&& rowPos==1 |
117 | 114 |
&& colIndex>=CharacterMatrix.LEADING_COLUMN_COUNT |
118 | 115 |
&& histogram!=null |
119 |
&& !histogram.getStateCountMap().isEmpty()) {
|
|
116 |
&& !histogram.getStates().isEmpty()) {
|
|
120 | 117 |
return true; |
121 | 118 |
} |
122 | 119 |
return false; |
Also available in: Unified diff
ref #7549 Add/use apache common math for frequency distribution