source: trunk/src/org/expeditee/items/widgets/charts/AbstractXY.java@ 1102

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File size: 3.6 KB
Line 
1/**
2 * AbstractXY.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.items.widgets.charts;
20
21import java.util.Collection;
22import java.util.HashSet;
23
24import org.expeditee.core.Colour;
25import org.expeditee.gio.swing.SwingConversions;
26import org.expeditee.gui.AttributeValuePair;
27import org.expeditee.items.Item;
28import org.expeditee.items.Text;
29import org.jfree.data.xy.XYDataset;
30import org.jfree.data.xy.XYSeries;
31import org.jfree.data.xy.XYSeriesCollection;
32
33public abstract class AbstractXY extends AbstractValueAxis {
34
35 private XYSeriesCollection _data;
36
37 protected XYDataset getChartData() {
38 _data = new XYSeriesCollection();
39 return _data;
40 }
41
42 public AbstractXY(Text source, String[] args) {
43 super(source, args);
44 }
45
46 /**
47 * @param dataFrame
48 */
49 @Override
50 protected void clearData() {
51 _data.removeAllSeries();
52 }
53
54 @Override
55 protected boolean addCategoryData(String categoryName,
56 Collection<Text> items, boolean swap) {
57 XYSeries newSeries = new XYSeries(categoryName);
58 Colour categoryColor = null;
59 boolean foundData = false;
60 Collection<Item> seen = new HashSet<Item>();
61 for (Text i : items) {
62 if (i.isLineEnd() || seen.contains(i)) {
63 continue;
64 }
65
66 Text t = (Text) i;
67 AttributeValuePair avp = new AttributeValuePair(t.getText());
68 if (avp != null) {
69 Double attribute = null;
70 Double value = null;
71 try {
72 value = avp.getDoubleValue();
73 attribute = avp.getDoubleAttribute();
74 } catch (Exception e) {
75
76 }
77 // If the data is not valid move to the next item
78 if (attribute == null && value != null) {
79 String stringAttribute = avp.getAttribute();
80 if (stringAttribute == null)
81 continue;
82 // Check if there is another item within the same
83 // enclosure
84 Collection<Item> sameEnclosure = t
85 .getItemsInSameEnclosure();
86 seen.addAll(sameEnclosure);
87 for (Item enclosed : sameEnclosure) {
88 if (enclosed instanceof Text && enclosed != t) {
89 AttributeValuePair avp2 = new AttributeValuePair(
90 enclosed.getText());
91 String stringAtt2 = avp2.getAttribute();
92 Double value2 = null;
93 try {
94 value2 = avp2.getDoubleValue();
95 } catch (Exception e) {
96 }
97 if (stringAtt2 != null && value2 != null) {
98 if (String.CASE_INSENSITIVE_ORDER.compare(
99 stringAttribute, stringAtt2) < 0) {
100 attribute = value;
101 value = value2;
102 } else {
103 attribute = value2;
104 }
105 break;
106 }
107 }
108 }
109 }
110
111 if (value == null)
112 continue;
113 if (swap) {
114 newSeries.add(value, attribute);
115 } else {
116 newSeries.add(attribute, value);
117 }
118 foundData = true;
119 if (categoryColor == null) {
120 categoryColor = i.getColor();
121 }
122 }
123 }
124 if (foundData) {
125 _data.addSeries(newSeries);
126 _paints.put(categoryName, SwingConversions.toSwingColor(categoryColor));
127 }
128 return foundData;
129 }
130}
Note: See TracBrowser for help on using the repository browser.