diff options
| author | Keith Packard <keithp@keithp.com> | 2013-01-02 16:30:44 -0800 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2013-01-02 16:30:44 -0800 | 
| commit | 722dc277dee915dcd09d3d65c0ee19173b114ef7 (patch) | |
| tree | 1155406f5489cb3d6a48144c28a661f423b62009 | |
| parent | 9e4c5b0a6ed3594cff6ab71398c172daa7c67177 (diff) | |
micropeak: Change graph tooltip units on the fly
Make sure the tooltips show the right units when they change
Signed-off-by: Keith Packard <keithp@keithp.com>
| -rw-r--r-- | micropeak/MicroGraph.java | 29 | 
1 files changed, 16 insertions, 13 deletions
| 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;  	} | 
