Revision 19357 trunk/extensions/extRasterTools-SE/src/org/gvsig/raster/beans/canvas/layers/GraphicHistogram.java

View differences:

GraphicHistogram.java
22 22
import java.awt.Graphics;
23 23

  
24 24
import org.gvsig.raster.beans.canvas.DrawableElement;
25

  
26

  
27

  
28 25
/**
29 26
 * Gr?fica que representa un histograma con los valores pasados en el constructor 
30 27
 *
......
37 34
	public static final int TYPE_FILL = 2;
38 35
	private int             border    = 2; 
39 36
	
40
	//Valores de la funci?n a dibujar
37
	//Valores de la funci?n original
41 38
	private double[]         hValues = null;
42 39
	//Valores que se pintan en la gr?fica 
43 40
	private double[]            valuesY = null;
......
51 48
	 */
52 49
	public GraphicHistogram(double[] values, Color c) {
53 50
		setColor(c);
54
		this.hValues = values;
55
		
56
		max = Double.NEGATIVE_INFINITY;
57
		for (int i = 0; i < values.length; i++) {
58
			if (values[i] > max)
59
				max = values[i];
60
		}
61
		
62
		valuesY = new double[values.length];
63
		for (int i = 0; i < values.length; i++)
64
			valuesY[i] = 1.0D - (values[i] / max);
51
		setHistogramDrawed(values);
65 52
	}
66 53

  
67 54
	/*
......
96 83
						x1 = canvas.getCanvasMinX() + border;
97 84
					if (x2 > (canvas.getCanvasMaxX() - border))
98 85
						x2 = canvas.getCanvasMaxX() - border;
99
					x1 += 2;
100
					x2 -= 2;
101 86
					g.setColor(color);
102 87
					g.fillRect(x1, y1, x2 - x1, canvas.getCanvasMaxY() - border - y1);
103 88
				}
......
160 145
	 */
161 146
	public void setHistogramDrawed(double[] histogramDrawed) {
162 147
		hValues = histogramDrawed;
163
		firstDrawActions();
148
		
149
		max = Double.NEGATIVE_INFINITY;
150
		for (int i = 0; i < histogramDrawed.length; i++) {
151
			if (histogramDrawed[i] > max)
152
				max = histogramDrawed[i];
153
		}
154
		
155
		valuesY = new double[histogramDrawed.length];
156
		for (int i = 0; i < histogramDrawed.length; i++)
157
			valuesY[i] = histogramDrawed[i] / max;
158
		
159
		if (canvas != null)
160
			canvas.repaint();
164 161
	}
165 162
}

Also available in: Unified diff