Search in sources :

Example 1 with DotInfo

use of org.xclcharts.renderer.line.DotInfo in project XCL-Charts by xcltapestry.

the class SplineChart method calcAllPoints.

private void calcAllPoints(SplineData bd, List<PointF> lstPoints, List<DotInfo> lstDotInfo) {
    if (null == bd) {
        Log.w(TAG, "传入的数据序列参数为空.");
        return;
    }
    if (Double.compare(mMaxValue, mMinValue) == -1) {
        Log.w(TAG, "轴最大值小于最小值.");
        return;
    }
    if (Double.compare(mMaxValue, mMinValue) == 0) {
        Log.w(TAG, "轴最大值与最小值相等.");
        return;
    }
    float initX = plotArea.getLeft();
    float initY = plotArea.getBottom();
    float lineStartX = initX, lineStartY = initY;
    float lineStopX = 0.0f, lineStopY = 0.0f;
    // 得到标签对应的值数据集
    List<PointD> chartValues = bd.getLineDataSet();
    if (null == chartValues)
        return;
    // 画出数据集对应的线条
    int count = chartValues.size();
    for (int i = 0; i < count; i++) {
        PointD entry = chartValues.get(i);
        lineStopX = getLnXValPosition(entry.x, mMaxValue, mMinValue);
        lineStopY = getVPValPosition(entry.y);
        if (0 == i) {
            lineStartX = lineStopX;
            lineStartY = lineStopY;
            // line
            lstPoints.add(new PointF(lineStartX, lineStartY));
            lstPoints.add(new PointF(lineStopX, lineStopY));
        } else {
            // line
            lstPoints.add(new PointF(lineStopX, lineStopY));
        }
        // dot
        lstDotInfo.add(new DotInfo(entry.x, entry.y, lineStopX, lineStopY));
        lineStartX = lineStopX;
        lineStartY = lineStopY;
    }
}
Also used : DotInfo(org.xclcharts.renderer.line.DotInfo) PointF(android.graphics.PointF)

Example 2 with DotInfo

use of org.xclcharts.renderer.line.DotInfo in project XCL-Charts by xcltapestry.

the class AreaChart method renderDotAndLabel.

/**
 * 绘制区域
 *
 * @param bd
 *            数据序列
 * @param type
 *            绘制类型
 * @param alpha
 *            透明度
 */
private boolean renderDotAndLabel(Canvas canvas, AreaData bd, int dataID, List<DotInfo> lstDotInfo) {
    float itemAngle = bd.getItemLabelRotateAngle();
    PlotLine pLine = bd.getPlotLine();
    if (pLine.getDotStyle().equals(XEnum.DotStyle.HIDE) == true && bd.getLabelVisible() == false) {
        return true;
    }
    PlotDot pDot = pLine.getPlotDot();
    float radius = pDot.getDotRadius();
    int count = lstDotInfo.size();
    for (int i = 0; i < count; i++) {
        DotInfo dotInfo = lstDotInfo.get(i);
        if (!pLine.getDotStyle().equals(XEnum.DotStyle.HIDE)) {
            PlotDotRender.getInstance().renderDot(canvas, pDot, dotInfo.mX, dotInfo.mY, pLine.getDotPaint());
            savePointRecord(dataID, i, dotInfo.mX + mMoveX, dotInfo.mY + mMoveY, dotInfo.mX - radius + mMoveX, dotInfo.mY - radius + mMoveY, dotInfo.mX + radius + mMoveX, dotInfo.mY + radius + mMoveY);
        }
        // 显示批注形状
        drawAnchor(getAnchorDataPoint(), dataID, i, canvas, dotInfo.mX, dotInfo.mY, radius);
        if (bd.getLabelVisible()) {
            bd.getLabelOptions().drawLabel(canvas, pLine.getDotLabelPaint(), getFormatterItemLabel(dotInfo.mValue), dotInfo.mX, dotInfo.mY, itemAngle, bd.getLineColor());
        }
    }
    return true;
}
Also used : DotInfo(org.xclcharts.renderer.line.DotInfo) PlotDot(org.xclcharts.renderer.line.PlotDot) PlotLine(org.xclcharts.renderer.line.PlotLine) Paint(android.graphics.Paint)

Example 3 with DotInfo

use of org.xclcharts.renderer.line.DotInfo in project XCL-Charts by xcltapestry.

the class AreaChart method calcAllPoints.

private boolean calcAllPoints(AreaData bd, List<DotInfo> lstDotInfo, List<PointF> lstPoints, List<PointF> lstPathPoints) {
    if (null == bd) {
        Log.w(TAG, "传入的数据序列参数为空.");
        return false;
    }
    // 数据源
    List<Double> chartValues = bd.getLinePoint();
    if (null == chartValues) {
        Log.w(TAG, "线数据集合为空.");
        return false;
    }
    float lineStartX = plotArea.getLeft(), lineStartY = plotArea.getBottom();
    float lineStopX = 0.0f, lineStopY = 0.0f;
    float currLablesSteps = div(getPlotScreenWidth(), (categoryAxis.getDataSet().size() - 1));
    int count = chartValues.size();
    if (count <= 0)
        return false;
    for (int i = 0; i < count; i++) {
        double bv = chartValues.get(i);
        // 首尾为0,path不能闭合,改成 0.001都可以闭合?
        lineStopX = add(plotArea.getLeft(), mul(i, currLablesSteps));
        lineStopY = getVPValPosition(bv);
        if (0 == i) {
            lineStartX = lineStopX;
            lineStartY = lineStopY;
            if (2 < count) {
                if (Double.compare(bv, dataAxis.getAxisMin()) != 0)
                    lstPathPoints.add(new PointF(plotArea.getLeft(), plotArea.getBottom()));
            }
            lstPathPoints.add(new PointF(lineStartX, lineStartY));
            lstPoints.add(new PointF(lineStartX, lineStartY));
        }
        // path
        lstPathPoints.add(new PointF(lineStopX, lineStopY));
        // line
        lstPoints.add(new PointF(lineStopX, lineStopY));
        // dot
        lstDotInfo.add(new DotInfo(bv, lineStopX, lineStopY));
        lineStartX = lineStopX;
        lineStartY = lineStopY;
    }
    if (count > 2) {
        lstPathPoints.add(new PointF(lineStartX, lineStartY));
        if (Double.compare(chartValues.get(count - 1), dataAxis.getAxisMin()) != 0) {
            lstPathPoints.add(new PointF(lineStartX, plotArea.getBottom()));
        }
    }
    return true;
}
Also used : DotInfo(org.xclcharts.renderer.line.DotInfo) PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Example 4 with DotInfo

use of org.xclcharts.renderer.line.DotInfo in project XCL-Charts by xcltapestry.

the class SplineChart method renderDotAndLabel.

private boolean renderDotAndLabel(Canvas canvas, SplineData spData, int dataID, List<PointF> lstPoints) {
    PlotLine pLine = spData.getPlotLine();
    if (pLine.getDotStyle().equals(XEnum.DotStyle.HIDE) == true && spData.getLabelVisible() == false) {
        return true;
    }
    float itemAngle = spData.getItemLabelRotateAngle();
    PlotDot pDot = pLine.getPlotDot();
    float radius = pDot.getDotRadius();
    int count = mLstDotInfo.size();
    for (int i = 0; i < count; i++) {
        DotInfo dotInfo = mLstDotInfo.get(i);
        if (!pLine.getDotStyle().equals(XEnum.DotStyle.HIDE)) {
            PlotDotRender.getInstance().renderDot(canvas, pDot, dotInfo.mX, dotInfo.mY, // 标识图形
            pLine.getDotPaint());
            savePointRecord(dataID, i, dotInfo.mX + mMoveX, dotInfo.mY + mMoveY, dotInfo.mX - radius + mMoveX, dotInfo.mY - radius + mMoveY, dotInfo.mX + radius + mMoveX, dotInfo.mY + radius + mMoveY);
        // childID++;
        }
        // Log.e("spchart","dataID:"+Float.toString(dataID));
        // Log.e("spchart","  I:"+Integer.toString(i));
        // 显示批注形状
        drawAnchor(getAnchorDataPoint(), dataID, i, canvas, dotInfo.mX, dotInfo.mY, radius);
        if (spData.getLabelVisible()) {
            // 请自行在回调函数中处理显示格式
            spData.getLabelOptions().drawLabel(canvas, pLine.getDotLabelPaint(), getFormatterDotLabel(dotInfo.getLabel()), dotInfo.mX, dotInfo.mY, itemAngle, spData.getLineColor());
        }
    }
    return true;
}
Also used : DotInfo(org.xclcharts.renderer.line.DotInfo) PlotDot(org.xclcharts.renderer.line.PlotDot) PlotLine(org.xclcharts.renderer.line.PlotLine)

Aggregations

DotInfo (org.xclcharts.renderer.line.DotInfo)4 Paint (android.graphics.Paint)2 PointF (android.graphics.PointF)2 PlotDot (org.xclcharts.renderer.line.PlotDot)2 PlotLine (org.xclcharts.renderer.line.PlotLine)2