Search in sources :

Example 1 with Rotation

use of ofc4j.model.axis.Label.Rotation in project pentaho-platform by pentaho.

the class AbstractChartFactory method setupDomain.

public Axis setupDomain() {
    String[] labels = null;
    Number domainMin = null;
    Number domainMax = null;
    Integer stepforchart = null;
    String domainRotation = null;
    if (CATEGORY_TYPE.equals(datasetType)) {
        int rowCount = getRowCount();
        labels = new String[rowCount];
        for (int j = 0; j < rowCount; j++) {
            labels[j] = getRowHeader(j);
        }
    } else if (XYZ_TYPE.equals(datasetType) || XY_TYPE.equals(datasetType)) {
        domainMin = ((Number) getValueAt(0, 0)).intValue();
        domainMax = domainMin;
        // Iterate over rows
        for (int r = 1; r < getRowCount(); r++) {
            if (domainMin.intValue() > ((Number) getValueAt(r, 0)).intValue()) {
                domainMin = ((Number) getValueAt(r, 0)).intValue();
            }
            if (domainMax.intValue() < ((Number) getValueAt(r, 0)).intValue()) {
                domainMax = ((Number) getValueAt(r, 0)).intValue();
            }
        }
        if (domainMin.equals(domainMax)) {
            if (domainMin.intValue() == 0) {
                domainMax = new Integer(100);
            } else if (domainMin.intValue() < 0) {
                domainMax = new Integer(0);
            } else {
                domainMin = new Integer(0);
            }
        }
        int steps = 9;
        int diff = domainMax.intValue() - domainMin.intValue();
        Node temp = chartNode.selectSingleNode(DOMAIN_STEPS_NODE_LOC);
        if (getValue(temp) != null) {
            steps = new Integer(getValue(temp)).intValue();
        }
        int chunksize = diff / steps;
        if (chunksize > 0) {
            stepforchart = new Integer(chunksize);
            // If actual min is positive, don't go below ZERO
            if (domainMin.intValue() >= 0 && domainMin.intValue() - chunksize < 0) {
                domainMin = 0;
            } else {
                domainMin = domainMin.intValue() - chunksize;
            }
            domainMax = domainMin.intValue() + (chunksize * (steps + 2));
        }
        temp = chartNode.selectSingleNode(DOMAIN_MINIMUM_NODE_LOC);
        if (getValue(temp) != null) {
            domainMin = new Integer(getValue(temp)).intValue();
        }
        temp = chartNode.selectSingleNode(DOMAIN_MAXIMUM_NODE_LOC);
        if (getValue(temp) != null) {
            domainMax = new Integer(getValue(temp)).intValue();
        }
    }
    String domainColor = AXIS_COLOR_DEFAULT;
    String domainGridColor = AXIS_GRID_COLOR_DEFAULT;
    int domainStroke = 1;
    Node temp = chartNode.selectSingleNode(DOMAIN_COLOR_NODE_LOC);
    if (getValue(temp) != null) {
        domainColor = getValue(temp);
    }
    temp = chartNode.selectSingleNode(DOMAIN_GRID_COLOR_NODE_LOC);
    if (getValue(temp) != null) {
        domainGridColor = getValue(temp);
    }
    temp = chartNode.selectSingleNode(DOMAIN_STROKE_NODE_LOC);
    if (getValue(temp) != null) {
        domainStroke = Integer.parseInt(getValue(temp));
    }
    temp = chartNode.selectSingleNode(DOMAIN_ROTATION_NODE_LOC);
    if (getValue(temp) != null) {
        domainRotation = getValue(temp);
    }
    // Orientation
    temp = chartNode.selectSingleNode(ORIENTATION_NODE_LOC);
    if (getValue(temp) != null) {
        orientation = getValue(temp);
    } else {
        orientation = ORIENTATION_DEFAULT;
    }
    if (HORIZONTAL_ORIENTATION.equals(orientation)) {
        YAxis yaxis = new YAxis();
        if (labels != null) {
            // BISERVER-3075: must reverse the category labels on hbar
            // charts due to bug in OFC2.
            String[] reversedLabels = new String[labels.length];
            int reversedLabelCount = 0;
            for (int i = reversedLabels.length - 1; i >= 0; i--) {
                reversedLabels[reversedLabelCount++] = labels[i];
            }
            yaxis.setLabels(reversedLabels);
        }
        yaxis.setStroke(domainStroke);
        yaxis.setColour(domainColor);
        yaxis.setGridColour(domainGridColor);
        if (domainMin != null && domainMax != null) {
            yaxis.setRange(domainMin.intValue(), domainMax.intValue(), stepforchart);
        }
        chart.setYAxis(yaxis);
        return yaxis;
    } else {
        XAxis xaxis = new XAxis();
        if (labels != null) {
            xaxis.addLabels(labels);
        }
        xaxis.setStroke(domainStroke);
        xaxis.setColour(domainColor);
        xaxis.setGridColour(domainGridColor);
        if (domainMin != null && domainMax != null) {
            xaxis.setRange(domainMin.intValue(), domainMax.intValue(), stepforchart);
        }
        if (domainRotation != null) {
            Rotation rot = null;
            if (domainRotation.equals("vertical")) {
                rot = Rotation.VERTICAL;
            } else if (domainRotation.equals("diagonal")) {
                rot = Rotation.DIAGONAL;
            } else {
                rot = Rotation.HORIZONTAL;
            }
            xaxis.getLabels().setRotation(rot);
        }
        chart.setXAxis(xaxis);
        return xaxis;
    }
}
Also used : Node(org.dom4j.Node) Rotation(ofc4j.model.axis.Label.Rotation) XAxis(ofc4j.model.axis.XAxis) YAxis(ofc4j.model.axis.YAxis)

Aggregations

Rotation (ofc4j.model.axis.Label.Rotation)1 XAxis (ofc4j.model.axis.XAxis)1 YAxis (ofc4j.model.axis.YAxis)1 Node (org.dom4j.Node)1