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_13;
22 import java.util.ArrayList;
26 import org.altusmetrum.altoslib_13.*;
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 AltosUITime extends AltosUnits {
39 public double value(double v, boolean imperial_units) { return v; }
41 public double inverse(double v, boolean imperial_unis) { return v; }
43 public String show_units(boolean imperial_units) { return "s"; }
45 public String say_units(boolean imperial_units) { return "seconds"; }
47 public int show_fraction(int width, boolean imperial_units) {
53 public int say_fraction(boolean imperial_units) { return 0; }
56 class AltosXYSeries extends XYSeries {
58 public AltosXYSeries(String label) {
63 public class AltosUITimeSeries extends AltosTimeSeries implements AltosUIGrapher {
64 AltosUILineStyle line_style;
66 boolean custom_axis_set;
70 XYLineAndShapeRenderer renderer;
72 AltosXYSeries xy_series;
73 ArrayList<ValueMarker> markers;
76 /* AltosUIGrapher interface */
77 public boolean need_reset() {
84 public void add(AltosUIDataPoint dataPoint) {
87 public void setNotify(boolean notify) {
90 public void fireSeriesChanged() {
93 public void set_data() {
95 if (markers != null) {
96 for (ValueMarker marker : markers)
97 plot.removeDomainMarker(marker);
99 markers = new ArrayList<ValueMarker>();
100 for (AltosTimeValue v : this) {
101 String s = units.string_value(v.value);
102 ValueMarker marker = new ValueMarker(v.time);
105 marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
106 marker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
108 marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
109 marker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
111 marker.setPaint(line_style.color);
112 marker.setStroke(new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
114 plot.addDomainMarker(marker);
120 xy_series.setNotify(false);
121 for (AltosTimeValue v : this) {
122 double value = v.value;
124 value = units.graph_value(value);
125 xy_series.add(v.time, value);
127 xy_series.setNotify(true);
132 public void set_units() {
134 StandardXYToolTipGenerator ttg;
137 String time_example = (new AltosUITime()).graph_format(7);
138 String example = units.graph_format(7);
140 ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})",
141 units.graph_units()),
142 new java.text.DecimalFormat(time_example),
143 new java.text.DecimalFormat(example));
144 renderer.setBaseToolTipGenerator(ttg);
149 public AltosXYSeries xy_series() {
153 public void set_enable(boolean enable) {
154 if (this.enable != enable) {
155 this.enable = enable;
157 for (ValueMarker marker : markers) {
159 plot.addDomainMarker(marker);
161 plot.removeDomainMarker(marker);
164 renderer.setSeriesVisible(0, enable);
165 axis.set_enable(enable);
170 // public BasicStroke(float width, int cap, int join, float miterlimit,
171 // float dash[], float dash_phase)
173 public void set_line_width(float width) {
175 if (markers != null) {
176 for (ValueMarker marker : markers) {
177 marker.setStroke(new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
180 if (line_style.dash[0] == 0.0)
181 renderer.setSeriesStroke(0, new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
183 renderer.setSeriesStroke(0, new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10.0f, line_style.dash, 0.0f));
187 public void set_axis(AltosUILineStyle line_style, boolean enable, AltosUIAxis axis) {
188 this.line_style = line_style;
189 this.enable = enable;
194 axis.ref(this.enable);
196 renderer = new XYLineAndShapeRenderer(true, false);
197 renderer.setSeriesPaint(0, line_style.color);
198 set_line_width(this.width);
199 renderer.setSeriesVisible(0, enable);
200 xy_series = new AltosXYSeries(label);
203 public void set_marker(AltosUILineStyle line_style, boolean enable, XYPlot plot, boolean marker_top) {
204 this.line_style = line_style;
205 this.enable = enable;
208 this.marker_top = marker_top;
211 public void set_shapes_visible(boolean shapes_visible) {
212 renderer.setSeriesShapesVisible(0, shapes_visible);
215 public AltosUITimeSeries(String label, AltosUnits units) {
219 public AltosUITimeSeries(String label, AltosUnits units,
220 AltosUILineStyle line_style, boolean enable,
223 set_axis(line_style, enable, axis);