2 * Copyright © 2017 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altosuilib_11;
22 import java.util.ArrayList;
26 import org.altusmetrum.altoslib_11.*;
28 import org.jfree.ui.*;
29 import org.jfree.chart.*;
30 import org.jfree.chart.plot.*;
31 import org.jfree.chart.axis.*;
32 import org.jfree.chart.renderer.*;
33 import org.jfree.chart.renderer.xy.*;
34 import org.jfree.chart.labels.*;
35 import org.jfree.data.xy.*;
36 import org.jfree.data.*;
38 class AltosXYSeries extends XYSeries {
40 public AltosXYSeries(String label) {
45 public class AltosUITimeSeries extends AltosTimeSeries implements AltosUIGrapher {
51 XYItemRenderer renderer;
53 AltosXYSeries xy_series;
54 ArrayList<ValueMarker> markers;
57 /* AltosUIGrapher interface */
58 public boolean need_reset() {
65 public void add(AltosUIDataPoint dataPoint) {
68 public void setNotify(boolean notify) {
71 public void fireSeriesChanged() {
76 if (markers != null) {
77 for (ValueMarker marker : markers)
78 plot.removeDomainMarker(marker);
80 markers = new ArrayList<ValueMarker>();
81 for (AltosTimeValue v : this) {
82 String s = units.string_value(v.value);
83 ValueMarker marker = new ValueMarker(v.time);
86 marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
87 marker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
89 marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
90 marker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
92 marker.setPaint(color);
94 plot.addDomainMarker(marker);
100 xy_series.setNotify(false);
101 for (AltosTimeValue v : this) {
102 double value = v.value;
104 value = units.graph_value(value);
105 xy_series.add(v.time, value);
107 xy_series.setNotify(true);
111 public void set_units() {
113 StandardXYToolTipGenerator ttg;
116 String time_example = (new AltosUITime()).graph_format(7);
117 String example = units.graph_format(7);
119 ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})",
120 units.graph_units()),
121 new java.text.DecimalFormat(time_example),
122 new java.text.DecimalFormat(example));
123 renderer.setBaseToolTipGenerator(ttg);
128 public AltosXYSeries xy_series() {
132 public void set_enable(boolean enable) {
133 if (this.enable != enable) {
134 this.enable = enable;
136 for (ValueMarker marker : markers) {
138 plot.addDomainMarker(marker);
140 plot.removeDomainMarker(marker);
143 renderer.setSeriesVisible(0, enable);
144 axis.set_enable(enable);
149 public void set_axis(Color color, boolean enable, AltosUIAxis axis) {
151 this.enable = enable;
155 axis.ref(this.enable);
157 renderer = new XYLineAndShapeRenderer(true, false);
158 renderer.setSeriesPaint(0, color);
159 renderer.setSeriesStroke(0, new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
160 renderer.setSeriesVisible(0, enable);
161 xy_series = new AltosXYSeries(label);
164 public void set_marker(Color color, boolean enable, XYPlot plot, boolean marker_top) {
166 this.enable = enable;
169 this.marker_top = marker_top;
172 public AltosUITimeSeries(String label, AltosUnits units) {
176 public AltosUITimeSeries(String label, AltosUnits units,
177 Color color, boolean enable,
180 set_axis(color, enable, axis);