source: src/main/java/genius/gui/chart/BidChart.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 8.8 KB
Line 
1package genius.gui.chart;
2
3import java.awt.Color;
4import javax.swing.SwingUtilities;
5import org.jfree.chart.JFreeChart;
6import org.jfree.chart.axis.NumberAxis;
7import org.jfree.chart.axis.ValueAxis;
8import org.jfree.chart.plot.DatasetRenderingOrder;
9import org.jfree.chart.plot.XYPlot;
10import org.jfree.chart.renderer.xy.XYDotRenderer;
11import org.jfree.chart.renderer.xy.XYItemRenderer;
12import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
13import org.jfree.data.xy.DefaultXYDataset;
14
15public class BidChart {
16
17 private double [][] possibleBids_;
18 private double [][] pareto_;
19 private double [][] bidSeriesA_;
20 private double [][] bidSeriesB_;
21 private double [][] lastBidA_;
22 private double [][] lastBidB_;
23 private double [][] nashPoint_;
24 private double [][] kalaiPoint_;
25 private double [][] rvA_;
26 private double [][] rvB_;
27 private double [][] agreement_;
28 private String agentAName = "Agent A";
29 private String agentBName = "Agent B";
30 private JFreeChart chart;
31 private XYPlot plot;
32 private DefaultXYDataset possibleBidData = new DefaultXYDataset();
33 private DefaultXYDataset paretoData = new DefaultXYDataset();
34 private DefaultXYDataset bidderAData = new DefaultXYDataset();
35 private DefaultXYDataset bidderBData = new DefaultXYDataset();
36 private DefaultXYDataset bidderAReservationValueData = new DefaultXYDataset();
37 private DefaultXYDataset bidderBReservationValueData = new DefaultXYDataset();
38 private DefaultXYDataset nashData = new DefaultXYDataset();
39 private DefaultXYDataset kalaiData = new DefaultXYDataset();
40 private DefaultXYDataset agreementData = new DefaultXYDataset();
41 private DefaultXYDataset lastBidAData = new DefaultXYDataset();
42 private DefaultXYDataset lastBidBData = new DefaultXYDataset();
43 final XYDotRenderer dotRenderer = new XYDotRenderer();
44 final XYDotRenderer nashRenderer = new XYDotRenderer();
45 final XYDotRenderer kalaiRenderer = new XYDotRenderer();
46 final XYDotRenderer agreementRenderer = new XYDotRenderer();
47 //final XYItemRenderer agreementRenderer = new XYLineAndShapeRenderer(false, true);
48 final XYDotRenderer lastBidARenderer = new XYDotRenderer();
49 final XYDotRenderer lastBidBRenderer = new XYDotRenderer();
50 final XYItemRenderer paretoRenderer = new XYLineAndShapeRenderer(true,false);
51 final XYItemRenderer reservationValueRenderer = new XYLineAndShapeRenderer(true,false);
52 final XYItemRenderer lineARenderer = new XYLineAndShapeRenderer();
53 final XYItemRenderer lineBRenderer = new XYLineAndShapeRenderer();
54 private NumberAxis domainAxis;
55 private ValueAxis rangeAxis;
56
57 //empty constructor; but: don't you always know the possible bids and the pareto before the 1st bid?
58 public BidChart(){
59
60 BidChart1();
61
62 }
63 public BidChart(String agentAname, String agentBname, double [][] possibleBids,double[][] pareto){
64 this.agentAName = agentAname;
65 this.agentBName = agentBname;
66 setPareto(pareto);
67 setPossibleBids(possibleBids);
68 BidChart1();
69 }
70 public void BidChart1(){
71 chart = createOverlaidChart();
72 NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
73 rangeAxis.setRange(0,1.1);
74
75 NumberAxis domainAxis = (NumberAxis)plot.getDomainAxis();
76 domainAxis.setRange(0,1.1);
77 }
78 //returning the chart
79 public JFreeChart getChart(){
80 return chart;
81 }
82
83 //set-Methods
84 public void setPareto(double [][] pareto){
85 this.pareto_ = pareto;
86 SwingUtilities.invokeLater(new Runnable() {
87 public void run() {
88 paretoData.addSeries("Pareto efficient frontier",pareto_);
89 }
90 });
91 }
92
93 public void setPossibleBids(double [][] possibleBids){
94 this.possibleBids_ = possibleBids;
95 SwingUtilities.invokeLater(new Runnable() {
96 public void run() {
97 possibleBidData.addSeries("all possible bids",possibleBids_);
98 }
99 });
100 }
101
102 public void setLastBidAData(double [][] lastBid)
103 {
104 this.lastBidA_ = lastBid;
105 SwingUtilities.invokeLater(new Runnable() {
106 public void run() {
107 lastBidAData.addSeries("Last bid by A", lastBidA_);
108 }
109 });
110 }
111
112 public void setLastBidBData(double [][] lastBid)
113 {
114 this.lastBidB_ = lastBid;
115 SwingUtilities.invokeLater(new Runnable() {
116 public void run() {
117 lastBidAData.addSeries("Last bid by B", lastBidB_);
118 }
119 });
120 }
121
122 public void setBidSeriesA(double [][] bidSeriesA){
123 this.bidSeriesA_ = bidSeriesA;
124 SwingUtilities.invokeLater(new Runnable() {
125 public void run() {
126 bidderAData.addSeries("Agent A's bids",bidSeriesA_);
127 }
128 });
129 }
130
131 public void setBidSeriesB(double [][] bidSeriesB) {
132 this.bidSeriesB_ = bidSeriesB;
133 SwingUtilities.invokeLater(new Runnable() {
134 public void run() {
135 bidderBData.addSeries("Agent B's bids",bidSeriesB_);
136 }
137 });
138 }
139
140 public void setBidderAReservationValue(double [][] bidderAReservationValue) {
141 this.rvA_ = bidderAReservationValue;
142 SwingUtilities.invokeLater(new Runnable() {
143 public void run() {
144 bidderAReservationValueData.addSeries("Agent A's reservation value", rvA_);
145 }
146 });
147 }
148
149 public void setBidderBReservationValue(double [][] bidderBReservationValue) {
150 this.rvB_ = bidderBReservationValue;
151 SwingUtilities.invokeLater(new Runnable() {
152 public void run() {
153 bidderBReservationValueData.addSeries("Agent B's reservation value", rvB_);
154 }
155 });
156 }
157
158 public void setNash(double[][] nash){
159 this.nashPoint_ = nash;
160 SwingUtilities.invokeLater(new Runnable() {
161 public void run() {
162 nashData.addSeries("Nash Point",nashPoint_);
163 }
164 });
165 }
166 public void setKalai(double[][] kalai){
167 this.kalaiPoint_ = kalai;
168 SwingUtilities.invokeLater(new Runnable() {
169 public void run() {
170 nashData.addSeries("Kalai Point",kalaiPoint_);
171 }
172 });
173 }
174 public void setAgreementPoint(double[][]agreement){
175 this.agreement_ = agreement;
176 SwingUtilities.invokeLater(new Runnable() {
177 public void run() {
178 agreementData.addSeries("Agreement",agreement_);
179 }
180 });
181 }
182
183 /**
184 * Creates an overlaid chart.
185 *
186 * @return The chart.
187 */
188 private JFreeChart createOverlaidChart() {
189 domainAxis = new NumberAxis(agentAName);
190 rangeAxis = new NumberAxis(agentBName);
191 dotRenderer.setDotHeight(2);
192 dotRenderer.setDotWidth(2);
193 reservationValueRenderer.setSeriesPaint(0,Color.GRAY);
194 nashRenderer.setDotHeight(5);
195 nashRenderer.setDotWidth(5);
196 nashRenderer.setSeriesPaint(0,Color.black);
197 kalaiRenderer.setDotHeight(5);
198 kalaiRenderer.setDotWidth(5);
199 kalaiRenderer.setSeriesPaint(0,Color.pink);
200 paretoRenderer.setSeriesPaint(0, Color.RED);
201 lineARenderer.setSeriesPaint(0, Color.GREEN);
202 lineBRenderer.setSeriesPaint(0, Color.BLUE);
203 agreementRenderer.setDotHeight(10);
204 agreementRenderer.setDotWidth(10);
205 //agreementRenderer.setSeriesShape(0, new Ellipse2D.Float(10.0f, 10.0f, 10.0f, 10.0f));
206 agreementRenderer.setSeriesPaint(0, Color.RED);
207 lastBidARenderer.setSeriesPaint(0, Color.YELLOW);
208 lastBidARenderer.setDotHeight(3);
209 lastBidARenderer.setDotWidth(3);
210 lastBidBRenderer.setSeriesPaint(0, Color.ORANGE);
211 lastBidBRenderer.setDotHeight(3);
212 lastBidBRenderer.setDotWidth(3);
213
214 // createFrom plot ...
215 plot = new XYPlot(possibleBidData, domainAxis, rangeAxis, dotRenderer);
216 plot.setDataset(2, paretoData);
217 plot.setRenderer(2, paretoRenderer);
218
219 plot.setDataset(3, bidderAData);
220 plot.setRenderer(3, lineARenderer);
221 plot.setDataset(4, bidderBData);
222 plot.setRenderer(4, lineBRenderer);
223
224 plot.setDataset(5, nashData);
225 plot.setRenderer(5, nashRenderer);
226 plot.setDataset(6, kalaiData);
227 plot.setRenderer(6, kalaiRenderer);
228 plot.setDataset(7, agreementData);
229 plot.setRenderer(7, agreementRenderer);
230 plot.setDataset(8, lastBidAData);
231 plot.setRenderer(8, lastBidARenderer);
232 plot.setDataset(9, lastBidBData);
233 plot.setRenderer(9, lastBidBRenderer);
234 plot.setDataset(10, bidderAReservationValueData);
235 plot.setRenderer(10, reservationValueRenderer);
236 plot.setDataset(11, bidderBReservationValueData);
237 plot.setRenderer(11, reservationValueRenderer);
238 plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
239 // return a new chart containing the overlaid plot...
240 JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
241 chart.setBackgroundPaint(new Color(255,255,255));
242 return chart;
243 }
244 public void setAgentAName (String value) {
245 agentAName = value;
246 domainAxis.setLabel(agentAName);
247 }
248 public void setAgentBName (String value) {
249 agentBName = value;
250 rangeAxis.setLabel(agentBName);
251 }
252}
Note: See TracBrowser for help on using the repository browser.