Search in sources :

Example 1 with XAxis

use of ofc4j.model.axis.XAxis 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)

Example 2 with XAxis

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

the class AbstractChartFactory method setupRange.

public Axis setupRange() {
    int rangeMin = 0;
    int rangeMax = 100;
    int steps = 9;
    String rangeColor = AXIS_COLOR_DEFAULT;
    String rangeGridColor = AXIS_GRID_COLOR_DEFAULT;
    int rangeStroke = 1;
    MinMax rangeMinMax = getRangeMinMax();
    rangeMin = rangeMinMax.min;
    rangeMax = rangeMinMax.max;
    boolean minDefined = false;
    boolean maxDefined = false;
    Node temp = chartNode.selectSingleNode(RANGE_MINIMUM_NODE_LOC);
    if (getValue(temp) != null) {
        rangeMin = new Integer(getValue(temp)).intValue();
        minDefined = true;
    }
    temp = chartNode.selectSingleNode(RANGE_MAXIMUM_NODE_LOC);
    if (getValue(temp) != null) {
        rangeMax = new Integer(getValue(temp)).intValue();
        maxDefined = true;
    }
    temp = chartNode.selectSingleNode(RANGE_STEPS_NODE_LOC);
    if (getValue(temp) != null) {
        steps = new Integer(getValue(temp)).intValue();
    }
    temp = chartNode.selectSingleNode(RANGE_COLOR_NODE_LOC);
    if (getValue(temp) != null) {
        rangeColor = getValue(temp);
    }
    temp = chartNode.selectSingleNode(RANGE_GRID_COLOR_NODE_LOC);
    if (getValue(temp) != null) {
        rangeGridColor = getValue(temp);
    }
    temp = chartNode.selectSingleNode(RANGE_STROKE_NODE_LOC);
    if (getValue(temp) != null) {
        rangeStroke = Integer.parseInt(getValue(temp));
    }
    int diff = rangeMax - rangeMin;
    int chunksize = diff / steps;
    Integer stepforchart = null;
    if (chunksize > 0) {
        stepforchart = new Integer(chunksize);
        // Read just mins/maxs only if they weren't specified
        if (!minDefined) {
            // If actual min is positive, don't go below ZERO
            if (rangeMin >= 0 && rangeMin - chunksize < 0) {
                rangeMin = 0;
            } else {
                rangeMin = rangeMin - chunksize;
            }
        }
        if (!maxDefined) {
            rangeMax = rangeMin + (chunksize * (steps + 2));
        }
    }
    if (HORIZONTAL_ORIENTATION.equals(orientation)) {
        XAxis xaxis = new XAxis();
        xaxis.setRange(rangeMin, rangeMax, stepforchart);
        xaxis.setStroke(rangeStroke);
        xaxis.setColour(rangeColor);
        xaxis.setGridColour(rangeGridColor);
        chart.setXAxis(xaxis);
        return xaxis;
    } else {
        YAxis yaxis = new YAxis();
        yaxis.setRange(rangeMin, rangeMax, stepforchart);
        yaxis.setStroke(rangeStroke);
        yaxis.setColour(rangeColor);
        yaxis.setGridColour(rangeGridColor);
        chart.setYAxis(yaxis);
        return yaxis;
    }
}
Also used : Node(org.dom4j.Node) XAxis(ofc4j.model.axis.XAxis) YAxis(ofc4j.model.axis.YAxis)

Aggregations

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