1 |
1 |
package org.gvsig.project.documents.view.legend;
|
2 |
2 |
|
|
3 |
import java.awt.Color;
|
3 |
4 |
import java.awt.Graphics2D;
|
4 |
5 |
import java.awt.image.BufferedImage;
|
5 |
6 |
import java.util.ArrayList;
|
... | ... | |
9 |
10 |
import java.util.List;
|
10 |
11 |
import java.util.Map;
|
11 |
12 |
import java.util.Set;
|
|
13 |
import org.apache.commons.lang3.StringUtils;
|
12 |
14 |
|
13 |
15 |
import org.cresques.cts.ICoordTrans;
|
14 |
16 |
|
... | ... | |
38 |
40 |
import org.gvsig.fmap.mapcontext.ViewPort;
|
39 |
41 |
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException;
|
40 |
42 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
|
|
43 |
import static org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend.VECTORIAL_UNIQUE_VALUE_LEGEND_PERSISTENCE_DEFINITION_NAME;
|
41 |
44 |
import org.gvsig.tools.ToolsLocator;
|
42 |
45 |
import org.gvsig.tools.dispose.DisposableIterator;
|
43 |
46 |
import org.gvsig.tools.dynobject.DynStruct;
|
... | ... | |
51 |
54 |
import org.jfree.chart.LegendItem;
|
52 |
55 |
|
53 |
56 |
@Deprecated
|
54 |
|
public final class LinkedChartLegend extends BasePieChartLegend implements ILinkedChartLegend{
|
|
57 |
public final class LinkedChartLegend extends BasePieChartLegend implements ILinkedChartLegend {
|
55 |
58 |
|
56 |
|
public static class RegisterLegend implements Callable {
|
|
59 |
public static class RegisterLegend implements Callable {
|
57 |
60 |
|
58 |
|
public Object call() throws Exception {
|
59 |
|
MapContextManager manager = MapContextLocator.getMapContextManager();
|
|
61 |
public Object call() throws Exception {
|
|
62 |
MapContextManager manager = MapContextLocator.getMapContextManager();
|
60 |
63 |
|
61 |
64 |
manager.registerLegend(IChartLegend.LINKED_LEGEND_NAME,
|
62 |
|
LinkedChartLegend.class);
|
|
65 |
LinkedChartLegend.class);
|
63 |
66 |
|
64 |
|
return Boolean.TRUE;
|
65 |
|
}
|
|
67 |
return Boolean.TRUE;
|
|
68 |
}
|
66 |
69 |
|
67 |
|
}
|
|
70 |
}
|
68 |
71 |
|
|
72 |
public static final String LINKED_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME = "LinkedChartLegend";
|
69 |
73 |
|
70 |
|
public static final String LINKED_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME = "LinkedChartLegend";
|
|
74 |
private static final String FIELD_NAMES = "FieldLegendNames";
|
|
75 |
private static final String FIELD_LABEL_NAMES = "FieldLabelNames";
|
|
76 |
private static final String FIELD_LABEL_COLOR = "FieldLabelColor";
|
71 |
77 |
|
|
78 |
protected Map<String, List> indexHash;
|
|
79 |
private String linkedField;
|
|
80 |
private String groupedByField = "";
|
|
81 |
private List<String> linkedFieldValues;
|
|
82 |
private String[] linkedFieldTableNames;
|
|
83 |
private String[] linkedFieldName;
|
|
84 |
private String linkedTable;
|
|
85 |
private boolean originSelected;
|
|
86 |
private boolean destinationSelected;
|
|
87 |
private String[] linkedFields;
|
72 |
88 |
|
73 |
|
protected Map<String,List> indexHash = new HashMap<String,List>();
|
74 |
|
private String linkedField;
|
75 |
|
private String groupedByField="";
|
76 |
|
private List<String> linkedFieldValues;
|
77 |
|
private String[] linkedFieldTableNames;
|
78 |
|
private String[] linkedFieldName;
|
79 |
|
private String linkedTable;
|
80 |
|
private boolean originSelected;
|
81 |
|
private boolean destinationSelected;
|
82 |
|
private String[] linkedFields;
|
|
89 |
private String timeField;
|
83 |
90 |
|
|
91 |
private String legendType;
|
84 |
92 |
|
85 |
|
private String timeField;
|
|
93 |
public LinkedChartLegend() {
|
|
94 |
this.indexHash = new HashMap<>();
|
|
95 |
}
|
86 |
96 |
|
|
97 |
@Override
|
|
98 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
|
|
99 |
Cancellable cancel, double scale, Map queryParameters,
|
|
100 |
ICoordTrans coordTrans, FeatureStore featureStore,
|
|
101 |
FeatureQuery featureQuery) throws LegendException {
|
|
102 |
FeatureSelection fsel;
|
|
103 |
try {
|
|
104 |
this.featSelection = featureStore.getFeatureSelection();
|
|
105 |
System.out.println("LINKEDCHARTLEGEND: " + featSelection.getSelectedCount() + " seleccionados.");
|
|
106 |
} catch (DataException e) {
|
|
107 |
e.printStackTrace();
|
|
108 |
}
|
87 |
109 |
|
88 |
|
private String legendType;
|
|
110 |
super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans,
|
|
111 |
featureStore, featureQuery);
|
|
112 |
}
|
89 |
113 |
|
90 |
|
public LinkedChartLegend(){
|
91 |
|
}
|
|
114 |
/**
|
|
115 |
* Devuelve un array con los campos seleccionados a pintar de la capa
|
|
116 |
* enlazada
|
|
117 |
*
|
|
118 |
* @return
|
|
119 |
*/
|
|
120 |
public String[] getLinkedClassifyingFieldNames() {
|
|
121 |
return getClassifyingFieldNames();
|
|
122 |
}
|
92 |
123 |
|
93 |
|
@Override
|
94 |
|
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
|
95 |
|
Cancellable cancel, double scale, Map queryParameters,
|
96 |
|
ICoordTrans coordTrans, FeatureStore featureStore,
|
97 |
|
FeatureQuery featureQuery) throws LegendException {
|
98 |
|
FeatureSelection fsel;
|
99 |
|
try {
|
100 |
|
this.featSelection = featureStore.getFeatureSelection();
|
101 |
|
System.out.println("LINKEDCHARTLEGEND: " + featSelection.getSelectedCount() + " seleccionados.");
|
102 |
|
} catch (DataException e) {
|
103 |
|
e.printStackTrace();
|
104 |
|
}
|
|
124 |
@Override
|
|
125 |
public String[] getClassifyingFieldNames() {
|
|
126 |
return this.linkedFieldName;
|
|
127 |
}
|
105 |
128 |
|
|
129 |
@Override
|
|
130 |
public void setLinkedFieldName(String[] fieldName) {
|
|
131 |
this.linkedFieldName = fieldName;
|
|
132 |
updateSymbols();
|
|
133 |
}
|
106 |
134 |
|
107 |
|
super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans,
|
108 |
|
featureStore, featureQuery);
|
109 |
|
}
|
|
135 |
@Override
|
|
136 |
public void setDataHash(Map<String, List> hash) {
|
|
137 |
this.indexHash = hash;
|
|
138 |
}
|
110 |
139 |
|
111 |
|
/**
|
112 |
|
* Devuelve un array con los campos seleccionados a pintar de la capa enlazada
|
113 |
|
* @return
|
114 |
|
*/
|
115 |
|
public String[] getLinkedClassifyingFieldNames() {
|
116 |
|
return getClassifyingFieldNames();
|
117 |
|
}
|
|
140 |
@Override
|
|
141 |
public Set<String> getLinkedFieldValues() {
|
|
142 |
return this.indexHash.keySet();
|
|
143 |
}
|
118 |
144 |
|
|
145 |
public void setLinkedFieldValues(List<String> values) {
|
|
146 |
this.linkedFieldValues = values;
|
|
147 |
updateSymbols();
|
|
148 |
}
|
119 |
149 |
|
120 |
|
@Override
|
121 |
|
public String[] getClassifyingFieldNames() {
|
122 |
|
return this.linkedFieldName;
|
123 |
|
}
|
|
150 |
@Override
|
|
151 |
public Map<String, List> getLinkedData() {
|
124 |
152 |
|
125 |
|
public void setLinkedFieldName(String[] fieldName){
|
126 |
|
this.linkedFieldName = fieldName;
|
127 |
|
updateSymbols();
|
128 |
|
}
|
|
153 |
indexHash = new HashMap<>();
|
129 |
154 |
|
130 |
|
public void setDataHash(Map<String,List> hash){
|
131 |
|
this.indexHash = hash;
|
132 |
|
}
|
|
155 |
ApplicationManager appManager = ApplicationLocator.getManager();
|
|
156 |
final Project project = appManager.getCurrentProject();
|
133 |
157 |
|
|
158 |
TableDocument selDoc = (TableDocument) project.getDocument(this.linkedTable,
|
|
159 |
TableManager.TYPENAME);
|
134 |
160 |
|
|
161 |
if (selDoc != null) {
|
|
162 |
try {
|
|
163 |
FeatureType featType = selDoc.getStore().getDefaultFeatureType();
|
|
164 |
FeatureAttributeDescriptor[] atts = featType.getAttributeDescriptors();
|
135 |
165 |
|
136 |
|
public Set<String> getLinkedFieldValues() {
|
137 |
|
return this.indexHash.keySet();
|
138 |
|
}
|
|
166 |
FeatureSelection fsel = selDoc.getStore().getFeatureSelection();
|
|
167 |
FeatureSet fs = selDoc.getStore().getFeatureSet();
|
139 |
168 |
|
140 |
|
public void setLinkedFieldValues(List<String> values){
|
141 |
|
this.linkedFieldValues = values;
|
142 |
|
updateSymbols();
|
143 |
|
}
|
|
169 |
DisposableIterator it = null;
|
|
170 |
if (this.destinationSelected) {
|
|
171 |
it = fsel.fastIterator();
|
|
172 |
} else {
|
|
173 |
it = fs.fastIterator();
|
|
174 |
}
|
144 |
175 |
|
145 |
|
public Map<String, List> getLinkedData() {
|
|
176 |
while (it.hasNext()) {
|
|
177 |
Feature f = (Feature) it.next();
|
146 |
178 |
|
147 |
|
indexHash = new HashMap<String,List>();
|
|
179 |
String key = f.getString(this.linkedField);
|
|
180 |
if (key != null) {
|
|
181 |
List<Map<String, Double>> array = indexHash.get(key);
|
|
182 |
if (array == null) {
|
|
183 |
array = new ArrayList<>();
|
|
184 |
indexHash.put(key, array);
|
|
185 |
}
|
|
186 |
if (array instanceof DelegatedList) {
|
|
187 |
List<Map<String, Double>> auxarray = new ArrayList<>();
|
|
188 |
for (int i = 0; i < array.size(); i++) {
|
|
189 |
auxarray.add(array.get(i));
|
|
190 |
}
|
|
191 |
array = auxarray;
|
|
192 |
}
|
148 |
193 |
|
149 |
|
ApplicationManager appManager = ApplicationLocator.getManager();
|
150 |
|
final Project project = appManager.getCurrentProject();
|
|
194 |
Map<String, Double> elem = new HashMap<>();
|
|
195 |
for (String field : getLinkedFields()) {
|
|
196 |
if (!field.equalsIgnoreCase(key)) {
|
|
197 |
Double value = f.getDouble(field);
|
|
198 |
elem.put(field, value);
|
|
199 |
}
|
|
200 |
}
|
|
201 |
String xAxis = this.timeField;
|
|
202 |
if (StringUtils.isNotEmpty(xAxis)) {
|
|
203 |
Double value = f.getDouble(xAxis);
|
|
204 |
elem.put(xAxis, value);
|
|
205 |
}
|
|
206 |
array.add(elem);
|
|
207 |
}
|
|
208 |
}
|
151 |
209 |
|
152 |
|
TableDocument selDoc = (TableDocument) project.getDocument(this.linkedTable,
|
153 |
|
TableManager.TYPENAME);
|
|
210 |
it.dispose();
|
|
211 |
} catch (DataException e) {
|
|
212 |
// TODO Auto-generated catch block
|
|
213 |
e.printStackTrace();
|
|
214 |
}
|
154 |
215 |
|
155 |
|
if (selDoc != null) {
|
156 |
|
try {
|
157 |
|
FeatureType featType = selDoc.getStore().getDefaultFeatureType();
|
158 |
|
FeatureAttributeDescriptor[] atts = featType.getAttributeDescriptors();
|
|
216 |
} else {
|
|
217 |
throw new RuntimeException("No se encuentra la tabla "
|
|
218 |
+ this.linkedTable);
|
|
219 |
}
|
159 |
220 |
|
160 |
|
FeatureSelection fsel = selDoc.getStore().getFeatureSelection();
|
161 |
|
FeatureSet fs = selDoc.getStore().getFeatureSet();
|
|
221 |
return indexHash;
|
|
222 |
}
|
162 |
223 |
|
163 |
|
DisposableIterator it = null;
|
164 |
|
if (this.destinationSelected) {
|
165 |
|
it = fsel.fastIterator();
|
166 |
|
}
|
167 |
|
else {
|
168 |
|
it = fs.fastIterator();
|
169 |
|
}
|
|
224 |
@Override
|
|
225 |
public ISymbol getSymbolByFeature(Feature feat) throws MapContextException {
|
170 |
226 |
|
171 |
|
while (it.hasNext()) {
|
172 |
|
Feature f = (Feature) it.next();
|
|
227 |
if (this.onlySelection) {
|
|
228 |
if (!featSelection.isSelected(feat)) {
|
|
229 |
return null;
|
|
230 |
}
|
|
231 |
}
|
|
232 |
String name = "";
|
|
233 |
if (getClassifyingFieldNames() != null && getClassifyingFieldNames().length > 0) {
|
|
234 |
name = feat.getString(getClassifyingFieldNames()[0]);
|
|
235 |
} else {
|
|
236 |
return null;
|
|
237 |
}
|
|
238 |
Set<String> indexes = getLinkedFieldValues();
|
|
239 |
if (!indexes.contains(name)) {
|
|
240 |
return null;
|
|
241 |
}
|
173 |
242 |
|
174 |
|
String key = f.getString(this.linkedField);
|
175 |
|
if(key != null){
|
176 |
|
List<Map<String,Double>> array = indexHash.get(key);
|
177 |
|
if(array == null){
|
178 |
|
array = new ArrayList<Map<String,Double>>();
|
179 |
|
indexHash.put(key, array);
|
180 |
|
}
|
181 |
|
if(array instanceof DelegatedList){
|
182 |
|
List<Map<String,Double>> auxarray = new ArrayList<Map<String,Double>>();
|
183 |
|
for(int i=0;i<array.size();i++){
|
184 |
|
auxarray.add(array.get(i));
|
185 |
|
}
|
186 |
|
array = auxarray;
|
187 |
|
}
|
|
243 |
// TODO: AQU? PRODR?AMOS RECUPERAR VARIOS SIMBOLOS. POR AHORA, SUPONEMOS QUE EL DEFAULTSYMBOL ES EL QUE TIENE EL CHARTSYMBOL
|
|
244 |
symbol = (IChartSymbol) getDefaultSymbol();
|
|
245 |
if (symbol == null) {
|
|
246 |
symbol = (IChartSymbol) MapContextLocator
|
|
247 |
.getSymbolManager().createSymbol(IChartSymbol.SYMBOL_NAME);
|
188 |
248 |
|
189 |
|
Map<String,Double> elem = new HashMap<String,Double>();
|
190 |
|
for(int i=0;i<getLinkedFields().length; i++) {
|
191 |
|
String field = getLinkedFields()[i];
|
192 |
|
if(!field.equalsIgnoreCase(key)){
|
193 |
|
Double value = f.getDouble(field);
|
194 |
|
if(value != null){
|
195 |
|
elem.put(field, value);
|
196 |
|
}
|
197 |
|
}
|
198 |
|
}
|
199 |
|
String xAxis = this.timeField;
|
200 |
|
if(xAxis != "" && xAxis!=null) {
|
201 |
|
Double value = f.getDouble(xAxis);
|
202 |
|
if(value != null){
|
203 |
|
elem.put(xAxis, value);
|
204 |
|
}
|
205 |
|
}
|
206 |
|
array.add(elem);
|
207 |
|
}
|
208 |
|
}
|
|
249 |
}
|
|
250 |
symbol.setOnlySelection(onlySelection);
|
|
251 |
double size = 0;
|
209 |
252 |
|
210 |
|
it.dispose();
|
211 |
|
} catch (DataException e) {
|
212 |
|
// TODO Auto-generated catch block
|
213 |
|
e.printStackTrace();
|
214 |
|
}
|
|
253 |
ChartDataSet dataSet = ChartLocator.getServiceManager()
|
|
254 |
.getChartManager().createChartDataSet();
|
215 |
255 |
|
216 |
|
}else{
|
217 |
|
throw new RuntimeException("No se encuentra la tabla "
|
218 |
|
+ this.linkedTable);
|
219 |
|
}
|
|
256 |
ChartService cs = symbol.getChart();
|
|
257 |
if (StringUtils.equals(cs.getChartType(), "BarsChart")) {
|
|
258 |
addBarsDataSetInfo(dataSet, name);
|
|
259 |
} else {
|
|
260 |
addPieDataSetInfo(dataSet, name);
|
|
261 |
}
|
|
262 |
cs.getChartProperties().setChartDimension(this.is3D);
|
220 |
263 |
|
221 |
|
return indexHash;
|
222 |
|
}
|
|
264 |
String[] names = getFieldNames();
|
|
265 |
if (names != null) {
|
|
266 |
cs.setChartDataSet(dataSet);
|
|
267 |
List<ChartSerieEntity> lst = cs.getChartLegendItems();
|
223 |
268 |
|
|
269 |
for (int j = 0; j < names.length; j++) {
|
|
270 |
colors[j] = getSymbolByValue(names[j]).getColor();
|
|
271 |
LegendItem item = new LegendItem(names[j], colors[j]);
|
|
272 |
item.setSeriesKey(names[j]);
|
|
273 |
ChartSerieEntity e = cs.createNewChartSerieEntity(item);
|
|
274 |
if (e != null) {
|
|
275 |
lst.add(e);
|
|
276 |
}
|
|
277 |
}
|
|
278 |
cs.setCategoriesPaint(Arrays.asList(colors));
|
|
279 |
}
|
|
280 |
double separation = sizeTo - sizeFrom;
|
224 |
281 |
|
225 |
|
@Override
|
226 |
|
public ISymbol getSymbolByFeature(Feature feat) throws MapContextException {
|
|
282 |
switch (sizeOption) {
|
|
283 |
case IChartSymbol.SIZESUM:
|
|
284 |
if (isActiveLimits()) {
|
|
285 |
double difFeat = maxFeature - minFeature;
|
|
286 |
double step = difFeat / separation;
|
|
287 |
size = sizeFrom + ((size - minFeature) / step);
|
|
288 |
}
|
|
289 |
symbol.setSize(size);
|
|
290 |
break;
|
|
291 |
case IChartSymbol.SIZEFIELD:
|
|
292 |
if (separation == 0) {
|
|
293 |
separation = 1;
|
|
294 |
}
|
|
295 |
double value = feat.getDouble(getFieldSize());
|
|
296 |
if (!getFieldNormalize().equals("---")) {
|
|
297 |
double normalize = feat.getDouble(getFieldNormalize());
|
|
298 |
if (normalize != 0) {
|
|
299 |
value = value / normalize;
|
|
300 |
}
|
|
301 |
if (isActiveLimits()) {
|
|
302 |
size = sizeFrom + (value * separation);
|
|
303 |
} else {
|
|
304 |
size = value;
|
|
305 |
}
|
|
306 |
} else {
|
|
307 |
if (isActiveLimits()) {
|
|
308 |
double difFeat = maxFeature - minFeature;
|
|
309 |
double step = difFeat / separation;
|
|
310 |
size = sizeFrom + ((value - minFeature) / step);
|
|
311 |
} else {
|
|
312 |
size = value;
|
|
313 |
}
|
|
314 |
}
|
|
315 |
symbol.setSize(size);
|
|
316 |
break;
|
|
317 |
default:
|
|
318 |
symbol.setSize(getSize());
|
|
319 |
break;
|
|
320 |
}
|
|
321 |
return symbol;
|
|
322 |
}
|
227 |
323 |
|
228 |
|
if (this.onlySelection)
|
229 |
|
if (!featSelection.isSelected(feat))
|
230 |
|
return null;
|
231 |
|
String name="";
|
232 |
|
if(getClassifyingFieldNames()!=null && getClassifyingFieldNames().length>0){
|
233 |
|
name = feat.getString(getClassifyingFieldNames()[0]);
|
234 |
|
}
|
235 |
|
else{
|
236 |
|
return null;
|
237 |
|
}
|
238 |
|
Set<String> indexes = getLinkedFieldValues();
|
239 |
|
if(!indexes.contains(name)){
|
240 |
|
return null;
|
241 |
|
}
|
|
324 |
private void addPieDataSetInfo(ChartDataSet dataSet, String name) {
|
242 |
325 |
|
243 |
|
// TODO: AQU? PRODR?AMOS RECUPERAR VARIOS SIMBOLOS. POR AHORA, SUPONEMOS QUE EL DEFAULTSYMBOL ES EL QUE TIENE EL CHARTSYMBOL
|
244 |
|
symbol = (IChartSymbol) getDefaultSymbol();
|
245 |
|
if (symbol==null){
|
246 |
|
symbol = (IChartSymbol) MapContextLocator
|
247 |
|
.getSymbolManager().createSymbol(IChartSymbol.SYMBOL_NAME);
|
|
326 |
String[] names = getFieldNames();
|
|
327 |
String[] _labels = getFieldLabels();
|
|
328 |
if (names != null && _labels != null && _labels.length == names.length) {
|
|
329 |
ArrayList serie = new ArrayList();
|
|
330 |
ArrayList category = new ArrayList();
|
|
331 |
ArrayList groupedBy = new ArrayList();
|
248 |
332 |
|
249 |
|
}
|
250 |
|
symbol.setOnlySelection(onlySelection);
|
251 |
|
double size=0;
|
|
333 |
Iterator it = indexHash.get(name).iterator();
|
|
334 |
int ji = 1;
|
|
335 |
while (it.hasNext()) {
|
|
336 |
Map<String, Object> it_next = (Map<String, Object>) it.next();
|
252 |
337 |
|
253 |
|
ChartDataSet dataSet = ChartLocator.getServiceManager()
|
254 |
|
.getChartManager().createChartDataSet();
|
|
338 |
for (int i = 0; i < names.length; i++) {
|
|
339 |
if (getGroupedField() != null && getGroupedField() != "") {
|
|
340 |
groupedBy.add("" + it_next.get(getGroupedField()));
|
|
341 |
} else {
|
|
342 |
if (ji != 1 || (ji == 1 && it.hasNext())) {
|
|
343 |
groupedBy.add("" + ji);
|
|
344 |
} else {
|
|
345 |
groupedBy.add(" ");
|
|
346 |
}
|
|
347 |
}
|
|
348 |
double val = (Double) it_next.get(names[i]);
|
|
349 |
if (sizeOption == IChartSymbol.SIZESUM) {
|
|
350 |
size += val;
|
|
351 |
}
|
|
352 |
serie.add(_labels[i]);
|
|
353 |
category.add(val);
|
|
354 |
}
|
|
355 |
ji++;
|
|
356 |
}
|
255 |
357 |
|
|
358 |
dataSet.addData("groupby", groupedBy);
|
|
359 |
dataSet.addData("series", serie);
|
|
360 |
dataSet.addData("categories", category);
|
256 |
361 |
|
257 |
|
ChartService cs = symbol.getChart();
|
258 |
|
if(cs.getChartType()=="BarsChart"){
|
259 |
|
addBarsDataSetInfo(dataSet, name);
|
260 |
|
}else{
|
261 |
|
addPieDataSetInfo(dataSet, name);
|
262 |
|
}
|
263 |
|
cs.getChartProperties().setChartDimension(this.is3D);
|
|
362 |
}
|
|
363 |
}
|
264 |
364 |
|
265 |
|
String[] names=getFieldNames();
|
266 |
|
if (names!=null){
|
267 |
|
//ChartDataSet dataSet = createSeriesCollection(feat);
|
|
365 |
private void addBarsDataSetInfo(ChartDataSet dataSet, String name) {
|
|
366 |
String[] names = getFieldNames();
|
|
367 |
if (names != null) {
|
|
368 |
ArrayList serie = new ArrayList();
|
|
369 |
ArrayList category = new ArrayList();
|
|
370 |
ArrayList groupedBy = new ArrayList();
|
268 |
371 |
|
269 |
|
cs.setChartDataSet(dataSet);
|
|
372 |
Iterator it = indexHash.get(name).iterator();
|
|
373 |
int ji = 1;
|
|
374 |
while (it.hasNext()) {
|
|
375 |
Map<String, Object> it_next = (Map<String, Object>) it.next();
|
270 |
376 |
|
271 |
|
// cs.createChartLegendItems();
|
272 |
|
List<ChartSerieEntity> lst = cs.getChartLegendItems();
|
|
377 |
for (int i = 0; i < names.length; i++) {
|
|
378 |
if (getGroupedField() != null && getGroupedField() != "") {
|
|
379 |
serie.add("" + it_next.get(getGroupedField()));
|
|
380 |
} else {
|
|
381 |
serie.add("" + ji);
|
|
382 |
}
|
|
383 |
double val = (Double) it_next.get(names[i]);
|
|
384 |
if (sizeOption == IChartSymbol.SIZESUM) {
|
|
385 |
size += val;
|
|
386 |
}
|
|
387 |
groupedBy.add(names[i]);
|
|
388 |
category.add(val);
|
|
389 |
}
|
|
390 |
ji++;
|
|
391 |
}
|
273 |
392 |
|
274 |
|
for (int j=0; j < names.length; j++) {
|
275 |
|
colors[j] = getSymbolByValue(names[j]).getColor();
|
276 |
|
LegendItem item = new LegendItem(names[j], colors[j]);
|
277 |
|
item.setSeriesKey(names[j]);
|
278 |
|
ChartSerieEntity e = cs.createNewChartSerieEntity(item);
|
279 |
|
if(e!=null)
|
280 |
|
lst.add(e);
|
281 |
|
}
|
282 |
|
cs.setCategoriesPaint(Arrays.asList(colors));
|
283 |
|
}
|
284 |
|
double separation = sizeTo-sizeFrom;
|
|
393 |
dataSet.addData("groupby", groupedBy);
|
|
394 |
dataSet.addData("series", serie);
|
|
395 |
dataSet.addData("categories", category);
|
|
396 |
}
|
|
397 |
}
|
285 |
398 |
|
286 |
|
if (sizeOption==IChartSymbol.SIZESUM){
|
287 |
|
if (isActiveLimits()){
|
288 |
|
double difFeat = maxFeature - minFeature;
|
289 |
|
double step = difFeat/separation;
|
290 |
|
size = sizeFrom + ((size - minFeature)/step);
|
291 |
|
}
|
292 |
|
symbol.setSize(size);
|
293 |
|
}else if (sizeOption==IChartSymbol.SIZEFIELD){
|
294 |
|
if(separation == 0)
|
295 |
|
separation = 1;
|
296 |
|
double value=feat.getDouble(getFieldSize());
|
|
399 |
@Override
|
|
400 |
public String getLinkedField() {
|
|
401 |
return this.linkedField;
|
|
402 |
}
|
297 |
403 |
|
298 |
|
if (!getFieldNormalize().equals("---")){
|
299 |
|
double normalize=feat.getDouble(getFieldNormalize());
|
300 |
|
if (normalize!=0){
|
301 |
|
value= value/normalize;
|
302 |
|
}
|
303 |
|
if (isActiveLimits())
|
304 |
|
size = sizeFrom + (value * separation) ;
|
305 |
|
else
|
306 |
|
size=value;
|
307 |
|
}else{
|
308 |
|
if (isActiveLimits()){
|
309 |
|
double difFeat = maxFeature - minFeature;
|
310 |
|
double step = difFeat/separation;
|
311 |
|
size = sizeFrom + ((value - minFeature)/step);
|
312 |
|
}else{
|
313 |
|
size=value;
|
314 |
|
}
|
315 |
|
}
|
316 |
|
symbol.setSize(size);
|
317 |
|
}else{
|
318 |
|
symbol.setSize(getSize());
|
319 |
|
}
|
320 |
|
// JFreeChart theChart=configureBarChart(dataSet);
|
321 |
|
// symbol.setChart(theChart);
|
|
404 |
@Override
|
|
405 |
public void setLinkedField(String field) {
|
|
406 |
this.linkedField = field;
|
|
407 |
}
|
322 |
408 |
|
323 |
|
// if (backgroundSymbol!=null){
|
324 |
|
// multiChartSymbol multiChartSymbol=new MultiChartSymbol();
|
325 |
|
// multiChartSymbol.addLayer(backgroundSymbol);
|
326 |
|
// multiChartSymbol.addLayer(symbol);
|
327 |
|
// return multiChartSymbol;
|
328 |
|
// }
|
329 |
|
return symbol;
|
330 |
|
}
|
|
409 |
@Override
|
|
410 |
public String getTimeField() {
|
|
411 |
return this.timeField;
|
|
412 |
}
|
331 |
413 |
|
332 |
|
private void addPieDataSetInfo(ChartDataSet dataSet, String name) {
|
|
414 |
@Override
|
|
415 |
public void setTimeField(String field) {
|
|
416 |
this.timeField = field;
|
|
417 |
}
|
333 |
418 |
|
334 |
|
String[] names=getFieldNames();
|
335 |
|
String[] labels=getFieldLabels();
|
336 |
|
if (names!=null && labels != null && labels.length == names.length){
|
337 |
|
ArrayList serie = new ArrayList();
|
338 |
|
ArrayList category = new ArrayList();
|
339 |
|
ArrayList groupedBy = new ArrayList();
|
|
419 |
@Override
|
|
420 |
public String getLegendType() {
|
|
421 |
return this.legendType;
|
|
422 |
}
|
340 |
423 |
|
341 |
|
Iterator it = indexHash.get(name).iterator();
|
342 |
|
int ji = 1;
|
343 |
|
while(it.hasNext()){
|
344 |
|
Map<String,Object> it_next = (Map<String, Object>) it.next();
|
|
424 |
@Override
|
|
425 |
public void setLegendType(String field) {
|
|
426 |
this.legendType = field;
|
|
427 |
}
|
345 |
428 |
|
346 |
|
for (int i = 0; i < names.length; i++) {
|
347 |
|
if(getGroupedField()!=null && getGroupedField()!= ""){
|
348 |
|
groupedBy.add(""+it_next.get(getGroupedField()));
|
349 |
|
}else{
|
350 |
|
if(ji!=1 || (ji==1 && it.hasNext())){
|
351 |
|
groupedBy.add(""+ji);
|
352 |
|
}else{
|
353 |
|
groupedBy.add(" ");
|
354 |
|
}
|
355 |
|
}
|
356 |
|
double val = (Double) it_next.get(names[i]);
|
357 |
|
if (sizeOption==IChartSymbol.SIZESUM){
|
358 |
|
size+=val;
|
359 |
|
}
|
360 |
|
serie.add(labels[i]);
|
361 |
|
category.add(val);
|
362 |
|
}
|
363 |
|
ji++;
|
364 |
|
}
|
|
429 |
@Override
|
|
430 |
public void setGroupedField(String string) {
|
|
431 |
this.groupedByField = string;
|
|
432 |
}
|
365 |
433 |
|
366 |
|
dataSet.addData("groupby", groupedBy);
|
367 |
|
dataSet.addData("series", serie);
|
368 |
|
dataSet.addData("categories", category);
|
|
434 |
@Override
|
|
435 |
public String getGroupedField() {
|
|
436 |
return this.groupedByField;
|
|
437 |
}
|
369 |
438 |
|
370 |
|
}
|
371 |
|
}
|
|
439 |
@Override
|
|
440 |
public String getLinkedTable() {
|
|
441 |
return this.linkedTable;
|
|
442 |
}
|
372 |
443 |
|
373 |
|
private void addBarsDataSetInfo(ChartDataSet dataSet, String name) {
|
374 |
|
String[] names=getFieldNames();
|
375 |
|
if (names!=null){
|
376 |
|
ArrayList serie = new ArrayList();
|
377 |
|
ArrayList category = new ArrayList();
|
378 |
|
ArrayList groupedBy = new ArrayList();
|
|
444 |
@Override
|
|
445 |
public boolean getLinkedSelected() {
|
|
446 |
return this.destinationSelected;
|
|
447 |
}
|
379 |
448 |
|
380 |
|
Iterator it = indexHash.get(name).iterator();
|
381 |
|
int ji = 1;
|
382 |
|
while(it.hasNext()){
|
383 |
|
Map<String,Object> it_next = (Map<String, Object>) it.next();
|
|
449 |
@Override
|
|
450 |
public String[] getOriginFieldName() {
|
|
451 |
return linkedFieldName;
|
|
452 |
}
|
384 |
453 |
|
385 |
|
for (int i = 0; i < names.length; i++) {
|
386 |
|
if(getGroupedField()!=null && getGroupedField()!= ""){
|
387 |
|
serie.add(""+it_next.get(getGroupedField()));
|
388 |
|
}else{
|
389 |
|
serie.add(""+ji);
|
390 |
|
}
|
391 |
|
double val = (Double) it_next.get(names[i]);
|
392 |
|
if (sizeOption==IChartSymbol.SIZESUM){
|
393 |
|
size+=val;
|
394 |
|
}
|
395 |
|
groupedBy.add(names[i]);
|
396 |
|
category.add(val);
|
397 |
|
}
|
398 |
|
ji++;
|
399 |
|
}
|
|
454 |
@Override
|
|
455 |
public boolean getOriginSelected() {
|
|
456 |
return this.originSelected;
|
|
457 |
}
|
400 |
458 |
|
401 |
|
dataSet.addData("groupby", groupedBy);
|
402 |
|
dataSet.addData("series", serie);
|
403 |
|
dataSet.addData("categories", category);
|
404 |
|
}
|
405 |
|
}
|
|
459 |
@Override
|
|
460 |
public void setLinkedTable(String selectedItem) {
|
|
461 |
this.linkedTable = selectedItem;
|
|
462 |
updateSymbols();
|
|
463 |
}
|
406 |
464 |
|
407 |
|
public String getLinkedField() {
|
408 |
|
return this.linkedField;
|
409 |
|
}
|
|
465 |
@Override
|
|
466 |
public void setOriginSelected(boolean selected) {
|
|
467 |
this.originSelected = selected;
|
|
468 |
}
|
410 |
469 |
|
411 |
|
public void setLinkedField(String field){
|
412 |
|
this.linkedField = field;
|
413 |
|
}
|
|
470 |
@Override
|
|
471 |
public void setLinkedSelected(boolean selected) {
|
|
472 |
this.destinationSelected = selected;
|
|
473 |
}
|
414 |
474 |
|
415 |
|
public String getTimeField() {
|
416 |
|
return this.timeField;
|
417 |
|
}
|
|
475 |
@Override
|
|
476 |
public void setLinkedFields(String[] fields) {
|
|
477 |
this.linkedFields = fields;
|
|
478 |
updateSymbols();
|
|
479 |
}
|
418 |
480 |
|
419 |
|
public void setTimeField(String field){
|
420 |
|
this.timeField = field;
|
421 |
|
}
|
|
481 |
@Override
|
|
482 |
public String[] getLinkedFields() {
|
|
483 |
return linkedFields;
|
|
484 |
}
|
422 |
485 |
|
423 |
|
public String getLegendType() {
|
424 |
|
return this.legendType;
|
425 |
|
}
|
|
486 |
@Override
|
|
487 |
public void loadFromState(PersistentState state)
|
|
488 |
throws PersistenceException {
|
|
489 |
// Set parent properties
|
|
490 |
super.loadFromState(state);
|
426 |
491 |
|
427 |
|
public void setLegendType(String field){
|
428 |
|
this.legendType = field;
|
429 |
|
}
|
|
492 |
this.linkedFields = state.getStringArray("linkedFields");
|
|
493 |
this.linkedFieldName = state.getStringArray("linkedFieldName");
|
|
494 |
this.linkedFieldTableNames = state.getStringArray("linkedFieldTableNames");
|
430 |
495 |
|
431 |
|
public void setGroupedField(String string) {
|
432 |
|
this.groupedByField = string;
|
433 |
|
}
|
|
496 |
// Set own properties
|
|
497 |
this.linkedFieldValues = (List<String>) state.getList("linkedFieldValues");
|
434 |
498 |
|
435 |
|
public String getGroupedField(){
|
436 |
|
return this.groupedByField;
|
437 |
|
}
|
|
499 |
this.originSelected = state.getBoolean("originSelected");
|
|
500 |
this.destinationSelected = state.getBoolean("destinationSelected");
|
438 |
501 |
|
439 |
|
public String getLinkedTable() {
|
440 |
|
return this.linkedTable;
|
441 |
|
}
|
|
502 |
this.linkedTable = state.getString("linkedTable");
|
|
503 |
this.linkedField = state.getString("linkedField");
|
|
504 |
this.groupedByField = state.getString("groupedByField");
|
|
505 |
this.timeField = state.getString("timeField");
|
|
506 |
this.legendType = state.getString("legendType");
|
442 |
507 |
|
443 |
|
public boolean getLinkedSelected() {
|
444 |
|
return this.destinationSelected;
|
445 |
|
}
|
|
508 |
this.indexHash = state.getMap("indexHash");
|
446 |
509 |
|
447 |
|
public String[] getOriginFieldName() {
|
448 |
|
return linkedFieldName;
|
449 |
|
}
|
|
510 |
//getLinkedData();
|
|
511 |
}
|
450 |
512 |
|
451 |
|
public boolean getOriginSelected() {
|
452 |
|
return this.originSelected;
|
453 |
|
}
|
|
513 |
@Override
|
|
514 |
public void saveToState(PersistentState state) throws PersistenceException {
|
|
515 |
// Save parent properties
|
|
516 |
super.saveToState(state);
|
|
517 |
// Save own properties
|
|
518 |
state.set("linkedFields", this.linkedFields);
|
|
519 |
state.set("linkedFieldName", this.linkedFieldName);
|
|
520 |
state.set("linkedFieldTableNames", this.linkedFieldTableNames);
|
454 |
521 |
|
455 |
|
public void setLinkedTable(String selectedItem) {
|
456 |
|
this.linkedTable = selectedItem;
|
457 |
|
updateSymbols();
|
458 |
|
}
|
|
522 |
state.set("linkedFieldValues", this.linkedFieldValues);
|
459 |
523 |
|
460 |
|
public void setOriginSelected(boolean selected) {
|
461 |
|
this.originSelected = selected;
|
462 |
|
}
|
|
524 |
state.set("originSelected", this.originSelected);
|
|
525 |
state.set("destinationSelected", this.destinationSelected);
|
463 |
526 |
|
464 |
|
public void setLinkedSelected(boolean selected) {
|
465 |
|
this.destinationSelected = selected;
|
466 |
|
}
|
|
527 |
state.set("linkedTable", this.linkedTable);
|
|
528 |
state.set("linkedField", this.linkedField);
|
|
529 |
state.set("groupedByField", this.groupedByField);
|
|
530 |
state.set("timeField", this.timeField);
|
467 |
531 |
|
468 |
|
public void setLinkedFields(String[] fields) {
|
469 |
|
this.linkedFields = fields;
|
470 |
|
updateSymbols();
|
471 |
|
}
|
|
532 |
state.set("legendType", this.legendType);
|
472 |
533 |
|
473 |
|
public String[] getLinkedFields() {
|
474 |
|
return linkedFields;
|
475 |
|
}
|
|
534 |
state.set("indexHash", this.indexHash);
|
|
535 |
}
|
476 |
536 |
|
477 |
|
public void loadFromState(PersistentState state)
|
478 |
|
throws PersistenceException {
|
479 |
|
// Set parent properties
|
480 |
|
super.loadFromState(state);
|
|
537 |
public static class RegisterPersistence implements Callable {
|
481 |
538 |
|
482 |
|
this.linkedFields = state.getStringArray("linkedFields");
|
483 |
|
this.linkedFieldName = state.getStringArray("linkedFieldName");
|
484 |
|
this.linkedFieldTableNames = state.getStringArray("linkedFieldTableNames");
|
|
539 |
@Override
|
|
540 |
public Object call() throws Exception {
|
|
541 |
PersistenceManager manager = ToolsLocator.getPersistenceManager();
|
|
542 |
if (manager.getDefinition(LINKED_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) {
|
|
543 |
DynStruct definition = manager.addDefinition(
|
|
544 |
LinkedChartLegend.class,
|
|
545 |
LINKED_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME,
|
|
546 |
LINKED_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME + " Persistence definition",
|
|
547 |
null,
|
|
548 |
null
|
|
549 |
);
|
|
550 |
// Extend the Classified Vector Legend base definition
|
|
551 |
definition.extend(manager.getDefinition(VECTORIAL_UNIQUE_VALUE_LEGEND_PERSISTENCE_DEFINITION_NAME));
|
485 |
552 |
|
|
553 |
// Field names
|
|
554 |
definition.addDynFieldArray(FIELD_NAMES)
|
|
555 |
.setClassOfItems(String.class);
|
|
556 |
definition.addDynFieldArray(FIELD_LABEL_NAMES)
|
|
557 |
.setClassOfItems(String.class);
|
|
558 |
definition.addDynFieldArray(FIELD_LABEL_COLOR)
|
|
559 |
.setClassOfItems(Color.class);
|
486 |
560 |
|
487 |
|
// Set own properties
|
488 |
|
this.linkedFieldValues = (List<String>) state.getList("linkedFieldValues");
|
|
561 |
definition.addDynField("backgroundSymbol").setClassOfValue(ISymbol.class);
|
|
562 |
definition.addDynFieldInt("size");
|
|
563 |
definition.addDynFieldBoolean("is3D");
|
489 |
564 |
|
490 |
|
this.originSelected = state.getBoolean("originSelected");
|
491 |
|
this.destinationSelected = state.getBoolean("destinationSelected");
|
|
565 |
definition.addDynFieldBoolean("isOutlineShow");
|
|
566 |
definition.addDynFieldBoolean("onlySelection");
|
|
567 |
definition.addDynFieldBoolean("isActiveLimits");
|
492 |
568 |
|
493 |
|
this.linkedTable = state.getString("linkedTable");
|
494 |
|
this.linkedField = state.getString("linkedField");
|
495 |
|
this.groupedByField = state.getString("groupedByField");
|
496 |
|
this.timeField = state.getString("timeField");
|
497 |
|
this.legendType = state.getString("legendType");
|
|
569 |
definition.addDynFieldInt("outlineWidth");
|
|
570 |
definition.addDynFieldInt("referenceSystem");
|
|
571 |
definition.addDynFieldInt("sizeFrom");
|
|
572 |
definition.addDynFieldInt("sizeTo");
|
|
573 |
definition.addDynFieldInt("unit");
|
|
574 |
definition.addDynFieldInt("sizeOption");
|
498 |
575 |
|
499 |
|
this.indexHash = state.getMap("indexHash");
|
|
576 |
definition.addDynFieldObject("outlineColor").setClassOfValue(Color.class);
|
|
577 |
definition.addDynFieldObject("symbol").setClassOfValue(IChartSymbol.class);
|
|
578 |
definition.addDynFieldObject("featSelection").setClassOfValue(FeatureSelection.class);
|
500 |
579 |
|
501 |
|
//getLinkedData();
|
502 |
|
}
|
|
580 |
definition.addDynFieldString("fieldSize");
|
|
581 |
definition.addDynFieldString("fieldNormalize");
|
503 |
582 |
|
504 |
|
public void saveToState(PersistentState state) throws PersistenceException {
|
505 |
|
// Save parent properties
|
506 |
|
super.saveToState(state);
|
507 |
|
// Save own properties
|
508 |
|
state.set("linkedFields", this.linkedFields);
|
509 |
|
state.set("linkedFieldName", this.linkedFieldName);
|
510 |
|
state.set("linkedFieldTableNames", this.linkedFieldTableNames);
|
|
583 |
definition.addDynFieldDouble("minFeature");
|
|
584 |
definition.addDynFieldDouble("maxFeature");
|
|
585 |
definition.addDynFieldDouble("maxField");
|
511 |
586 |
|
512 |
|
state.set("linkedFieldValues", this.linkedFieldValues);
|
|
587 |
// Field names
|
|
588 |
definition.addDynFieldArray("linkedFields")
|
|
589 |
.setClassOfItems(String.class);
|
|
590 |
definition.addDynFieldArray("linkedFieldName")
|
|
591 |
.setClassOfItems(String.class);
|
|
592 |
definition.addDynFieldArray("linkedFieldTableNames")
|
|
593 |
.setClassOfItems(String.class);
|
|
594 |
definition.addDynFieldList("linkedFieldValues")
|
|
595 |
.setClassOfItems(String.class);
|
513 |
596 |
|
514 |
|
state.set("originSelected", this.originSelected);
|
515 |
|
state.set("destinationSelected", this.destinationSelected);
|
|
597 |
definition.addDynFieldBoolean("originSelected");
|
|
598 |
definition.addDynFieldBoolean("destinationSelected");
|
516 |
599 |
|
517 |
|
state.set("linkedTable", this.linkedTable);
|
518 |
|
state.set("linkedField", this.linkedField);
|
519 |
|
state.set("groupedByField", this.groupedByField);
|
520 |
|
state.set("timeField", this.timeField);
|
|
600 |
definition.addDynFieldString("linkedTable");
|
|
601 |
definition.addDynFieldString("linkedField");
|
|
602 |
definition.addDynFieldString("groupedByField");
|
|
603 |
definition.addDynFieldString("timeField");
|
521 |
604 |
|
522 |
|
state.set("legendType", this.legendType);
|
|
605 |
definition.addDynFieldMap("indexHash").setClassOfItems(List.class);
|
|
606 |
definition.addDynFieldString("legendType");
|
523 |
607 |
|
524 |
|
state.set("indexHash", this.indexHash);
|
525 |
|
}
|
|
608 |
}
|
|
609 |
return Boolean.TRUE;
|
|
610 |
}
|
526 |
611 |
|
527 |
|
public static class RegisterPersistence implements Callable {
|
528 |
|
|
529 |
|
public Object call() throws Exception {
|
530 |
|
PersistenceManager manager = ToolsLocator.getPersistenceManager();
|
531 |
|
if( manager.getDefinition(LINKED_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME)==null ) {
|
532 |
|
DynStruct definition = manager.addDefinition(
|
533 |
|
LinkedChartLegend.class,
|
534 |
|
LINKED_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME,
|
535 |
|
LINKED_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
|
536 |
|
null,
|
537 |
|
null
|
538 |
|
);
|
539 |
|
// Extend the Classified Vector Legend base definition
|
540 |
|
definition.extend(manager.getDefinition(PIE_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME));
|
541 |
|
|
542 |
|
// Field names
|
543 |
|
definition.addDynFieldArray("linkedFields")
|
544 |
|
.setClassOfItems(String.class);
|
545 |
|
definition.addDynFieldArray("linkedFieldName")
|
546 |
|
.setClassOfItems(String.class);
|
547 |
|
definition.addDynFieldArray("linkedFieldTableNames")
|
548 |
|
.setClassOfItems(String.class);
|
549 |
|
definition.addDynFieldList("linkedFieldValues")
|
550 |
|
.setClassOfItems(String.class);
|
551 |
|
|
552 |
|
definition.addDynFieldBoolean("originSelected");
|
553 |
|
definition.addDynFieldBoolean("destinationSelected");
|
554 |
|
|
555 |
|
definition.addDynFieldString("linkedTable");
|
556 |
|
definition.addDynFieldString("linkedField");
|
557 |
|
definition.addDynFieldString("groupedByField");
|
558 |
|
definition.addDynFieldString("timeField");
|
559 |
|
|
560 |
|
definition.addDynFieldMap("indexHash").setClassOfItems(List.class);
|
561 |
|
definition.addDynFieldString("legendType");
|
562 |
|
|
563 |
|
}
|
564 |
|
return Boolean.TRUE;
|
565 |
|
}
|
566 |
|
|
567 |
|
}
|
|
612 |
}
|
568 |
613 |
}
|