OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 67 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13 ilm 1
package org.jopenchart;
2
 
3
import java.awt.Graphics2D;
4
import java.awt.RenderingHints;
67 ilm 5
import java.util.List;
13 ilm 6
 
7
public class LeftAxis extends Axis {
8
 
9
    public LeftAxis(Axis a) {
10
        super("y");
11
        this.addLabels(a.getLabels());
83 ilm 12
        this.setColor(a.getColor());
13 ilm 13
    }
14
 
15
    public LeftAxis() {
16
        super("y");
17
    }
18
 
19
    public void render(Graphics2D g) {
67 ilm 20
        List<AxisLabel> l = this.getLabels();
21
        Number max = 0;
22
        for (AxisLabel axisLabel : l) {
23
            Number value = axisLabel.getValue();
24
            if (value != null && value.doubleValue() > max.doubleValue()) {
25
                max = value;
26
            }
27
        }
28
 
29
        double ratioy = (double) this.getHeight() / max.doubleValue();
30
 
13 ilm 31
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
32
        double dy = (double) this.getHeight() / (this.getLabels().size() - 1);
33
        double y = this.getHeight() + this.getY();
34
        for (AxisLabel label : this.getLabels()) {
35
            g.setColor(this.getColor());
36
 
67 ilm 37
            int minXValue = 0;
38
            int y1 = (int) y;
39
            if (max.intValue() > 0)
40
                y1 = getY() + getHeight() - (int) ((label.getValue().doubleValue() - minXValue) * ratioy);
41
 
42
            g.drawLine(this.getX() + this.getWidth() - getMarkerLenght() - 1, (int) y1, this.getX() + this.getWidth() - 1, (int) y1);
13 ilm 43
            int labelH = (int) g.getFontMetrics().getStringBounds(label.getLabel(), g).getHeight() / 2 - 1;
44
            int labelW = (int) g.getFontMetrics().getStringBounds(label.getLabel(), g).getWidth();
45
 
46
            g.setColor(label.getColor());
67 ilm 47
            g.drawString(label.getLabel(), this.getX() + this.getWidth() - this.getMarkerLenght() - labelW - 2, labelH + (int) y1);
13 ilm 48
 
49
            y -= dy;
50
        }
51
        g.setColor(this.getColor());
52
        g.drawLine(this.getX() + this.getWidth() - 1, this.getY(), this.getX() + this.getWidth() - 1, this.getY() + this.getHeight());
53
 
54
    }
55
}