From: Keith Packard Date: Thu, 3 Jan 2013 00:30:44 +0000 (-0800) Subject: micropeak: Change graph tooltip units on the fly X-Git-Tag: 1.1.9.3~8^2~9^2~13 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=722dc277dee915dcd09d3d65c0ee19173b114ef7 micropeak: Change graph tooltip units on the fly Make sure the tooltips show the right units when they change Signed-off-by: Keith Packard --- diff --git a/micropeak/MicroGraph.java b/micropeak/MicroGraph.java index d2e86f9f..84320be3 100644 --- a/micropeak/MicroGraph.java +++ b/micropeak/MicroGraph.java @@ -39,15 +39,19 @@ class MicroSeries extends XYSeries { String label; String units; Color color; + XYItemRenderer renderer; - String label() { - return String.format("%s (%s)", label, units); - } - void set_units(String units) { this.units = units; - axis.setLabel(label()); + axis.setLabel(String.format("%s (%s)", label, units)); + + StandardXYToolTipGenerator ttg; + + ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})", units), + new java.text.DecimalFormat("0.00"), + new java.text.DecimalFormat("0.00")); + renderer.setBaseToolTipGenerator(ttg); } public MicroSeries (String label, String units, Color color) { @@ -56,9 +60,13 @@ class MicroSeries extends XYSeries { this.units = units; this.color = color; - axis = new NumberAxis(label()); + axis = new NumberAxis(); axis.setLabelPaint(color); axis.setTickLabelPaint(color); + + renderer = new XYLineAndShapeRenderer(true, false); + renderer.setSeriesPaint(0, color); + set_units(units); } } @@ -88,16 +96,11 @@ public class MicroGraph implements AltosUnitsListener { private MicroSeries addSeries(int index, String label, String units, Color color) { MicroSeries series = new MicroSeries(label, units, color); XYSeriesCollection dataset = new XYSeriesCollection(series); - XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); - renderer.setSeriesPaint(0, color); - renderer.setPlot(plot); - renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})", units), - new java.text.DecimalFormat("0.00"), - new java.text.DecimalFormat("0.00"))); + series.renderer.setPlot(plot); plot.setRangeAxis(index, series.axis); plot.setDataset(index, dataset); - plot.setRenderer(index, renderer); + plot.setRenderer(index, series.renderer); plot.mapDatasetToRangeAxis(index, index); return series; }