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 {
50 XYItemRenderer renderer;
52 AltosXYSeries xy_series;
53 ArrayList<ValueMarker> markers;
56 /* AltosUIGrapher interface */
57 public boolean need_reset() {
64 public void add(AltosUIDataPoint dataPoint) {
67 public void setNotify(boolean notify) {
70 public void fireSeriesChanged() {
75 if (markers != null) {
76 for (ValueMarker marker : markers)
77 plot.removeDomainMarker(marker);
79 markers = new ArrayList<ValueMarker>();
80 for (AltosTimeValue v : this) {
81 String s = units.string_value(v.value);
82 ValueMarker marker = new ValueMarker(v.time);
84 marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
85 marker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
86 marker.setPaint(color);
88 plot.addDomainMarker(marker);
94 for (AltosTimeValue v : this) {
95 double value = v.value;
97 value = units.graph_value(value);
98 xy_series.add(v.time, value);
103 public void set_units() {
105 StandardXYToolTipGenerator ttg;
108 String time_example = (new AltosUITime()).graph_format(7);
109 String example = units.graph_format(7);
111 ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})",
112 units.graph_units()),
113 new java.text.DecimalFormat(time_example),
114 new java.text.DecimalFormat(example));
115 renderer.setBaseToolTipGenerator(ttg);
120 public AltosXYSeries xy_series() {
124 public void set_enable(boolean enable) {
125 if (this.enable != enable) {
126 this.enable = enable;
128 for (ValueMarker marker : markers) {
130 plot.addDomainMarker(marker);
132 plot.removeDomainMarker(marker);
135 renderer.setSeriesVisible(0, enable);
136 axis.set_enable(enable);
141 public void set_axis(Color color, boolean enable, AltosUIAxis axis) {
143 this.enable = enable;
147 axis.ref(this.enable);
149 renderer = new XYLineAndShapeRenderer(true, false);
150 renderer.setSeriesPaint(0, color);
151 renderer.setSeriesStroke(0, new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
152 renderer.setSeriesVisible(0, enable);
153 xy_series = new AltosXYSeries(label);
156 public void set_marker(Color color, boolean enable, XYPlot plot) {
158 this.enable = enable;
163 public AltosUITimeSeries(String label, AltosUnits units) {
167 public AltosUITimeSeries(String label, AltosUnits units,
168 Color color, boolean enable,
171 set_axis(color, enable, axis);