Search in sources :

Example 11 with PlotDot

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

the class PlotLegendRender method calcContentRect.

private void calcContentRect() {
    int countDots = (null != mLstDotStyle) ? mLstDotStyle.size() : 0;
    int countText = (null != mLstKey) ? mLstKey.size() : 0;
    if (0 == countText && 0 == countDots)
        return;
    // int count = (countText > countDots)?countText:countDots;
    String text = "";
    float textHeight = getLabelTextHeight();
    int row = 1;
    mMapID.clear();
    float areaWidth = mPlotArea.getWidth() - 2 * mMargin;
    float rectWidth = getRectWidth();
    float rowWidth = 0.0f;
    float rowHeight = textHeight;
    float maxHeight = rowHeight;
    float maxWidth = 0.0f;
    for (int i = 0; i < countText; i++) {
        if (countDots > i) {
            PlotDot plot = mLstDotStyle.get(i);
            if (mIsLnChart) {
                rowWidth += rectWidth + mColSpan;
            } else {
                if (plot.getDotStyle() != XEnum.DotStyle.HIDE)
                    rowWidth += rectWidth + mColSpan;
            }
        }
        text = mLstKey.get(i);
        float labelWidth = getLabelTextWidth(text);
        rowWidth += labelWidth;
        switch(getType()) {
            case ROW:
                if (Float.compare(rowWidth, areaWidth) == 1) {
                    // 换行
                    rowWidth = rectWidth + mColSpan + labelWidth;
                    maxHeight += rowHeight + mRowSpan;
                    row++;
                } else {
                    rowWidth += mColSpan;
                    if (Float.compare(rowWidth, maxWidth) == 1)
                        maxWidth = rowWidth;
                }
                break;
            case COLUMN:
                if (Float.compare(rowWidth, maxWidth) == 1)
                    maxWidth = rowWidth;
                maxHeight += rowHeight + mRowSpan;
                rowWidth = 0.0f;
                row++;
                break;
            default:
                break;
        }
        mMapID.put(i, row);
    }
    mRectWidth = maxWidth + 2 * mMargin;
    mRectHeight = maxHeight + 2 * mMargin;
    if (XEnum.LegendType.COLUMN == getType())
        mRectHeight -= 2 * mRowSpan;
}
Also used : PlotDot(org.xclcharts.renderer.line.PlotDot) Paint(android.graphics.Paint)

Example 12 with PlotDot

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

the class PlotLegendRender method drawLegend.

private void drawLegend(Canvas canvas) {
    int countDots = (null != mLstDotStyle) ? mLstDotStyle.size() : 0;
    int countText = (null != mLstKey) ? mLstKey.size() : 0;
    if (0 == countText && 0 == countDots)
        return;
    int countColor = (null != mLstColor) ? mLstColor.size() : 0;
    float currDotsX = mKeyLabelX + mMargin;
    float currRowX = currDotsX;
    float currRowY = mKeyLabelY + mMargin;
    float textHeight = getLabelTextHeight();
    float rowHeight = textHeight;
    // 2 * textHeight;
    float rectWidth = getRectWidth();
    int currRowID = 0;
    Iterator iter = this.mMapID.entrySet().iterator();
    // 背景
    drawBox(canvas);
    // 图例
    while (iter.hasNext()) {
        Entry entry = (Entry) iter.next();
        Integer id = (Integer) entry.getKey();
        // 行号
        Integer row = (Integer) entry.getValue();
        if (// 换行
        row > currRowID) {
            if (0 < currRowID)
                currRowY += rowHeight + mRowSpan;
            currRowX = mKeyLabelX + mMargin;
            currRowID = row;
        }
        // 颜色
        if (countColor > id) {
            this.getPaint().setColor(mLstColor.get(id));
            if (mIsLnChart)
                mPaintLine.setColor(mLstColor.get(id));
        } else {
            this.getPaint().setColor(Color.BLACK);
            if (mIsLnChart)
                mPaintLine.setColor(Color.BLACK);
        }
        if (countDots > id) {
            PlotDot plot = mLstDotStyle.get(id);
            if (// line
            mIsLnChart) {
                canvas.drawLine(currRowX, currRowY + rowHeight / 2, currRowX + rectWidth, currRowY + rowHeight / 2, this.mPaintLine);
                PlotDotRender.getInstance().renderDot(canvas, plot, currRowX + rectWidth / 2, currRowY + rowHeight / 2, this.getPaint());
                currRowX += rectWidth + mColSpan;
            } else {
                if (plot.getDotStyle() != XEnum.DotStyle.HIDE) {
                    PlotDotRender.getInstance().renderDot(canvas, plot, currRowX + rectWidth / 2, currRowY + rowHeight / 2, this.getPaint());
                    currRowX += rectWidth + mColSpan;
                }
            }
        }
        String label = mLstKey.get(id);
        if ("" != label)
            canvas.drawText(label, currRowX, currRowY + rowHeight, this.getPaint());
        currRowX += this.getLabelTextWidth(label);
        currRowX += mColSpan;
    }
    mMapID.clear();
    clearLst();
}
Also used : Entry(java.util.Map.Entry) PlotDot(org.xclcharts.renderer.line.PlotDot) Iterator(java.util.Iterator) Paint(android.graphics.Paint)

Example 13 with PlotDot

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

the class PlotLegendRender method convertArrayPieKey.

private void convertArrayPieKey(List<PieData> dataSet) {
    if (null == dataSet)
        return;
    String key = "";
    for (PieData cData : dataSet) {
        key = cData.getKey();
        if (!isDrawKey(key))
            continue;
        if ("" == key)
            continue;
        mLstKey.add(key);
        mLstColor.add(cData.getSliceColor());
        PlotDot dot = new PlotDot();
        dot.setDotStyle(XEnum.DotStyle.RECT);
        mLstDotStyle.add(dot);
    }
}
Also used : PlotDot(org.xclcharts.renderer.line.PlotDot) PieData(org.xclcharts.chart.PieData)

Example 14 with PlotDot

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

the class PlotLegendRender method convertArrayArcLineKey.

private void convertArrayArcLineKey(List<ArcLineData> dataSet) {
    if (null == dataSet)
        return;
    String key = "";
    for (ArcLineData cData : dataSet) {
        key = cData.getKey();
        if (!isDrawKey(key))
            continue;
        if ("" == key)
            continue;
        mLstKey.add(key);
        mLstColor.add(cData.getBarColor());
        PlotDot pDot = new PlotDot();
        pDot.setDotStyle(XEnum.DotStyle.RECT);
        mLstDotStyle.add(pDot);
    }
}
Also used : PlotDot(org.xclcharts.renderer.line.PlotDot) ArcLineData(org.xclcharts.chart.ArcLineData)

Example 15 with PlotDot

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

the class PlotLegendRender method convertArrayBarKey.

private void convertArrayBarKey(List<BarData> dataSet) {
    if (null == dataSet)
        return;
    String key = "";
    for (BarData cData : dataSet) {
        key = cData.getKey();
        if (!isDrawKey(key))
            continue;
        if ("" == key)
            continue;
        mLstKey.add(key);
        mLstColor.add(cData.getColor());
        PlotDot dot = new PlotDot();
        dot.setDotStyle(XEnum.DotStyle.RECT);
        mLstDotStyle.add(dot);
    }
}
Also used : BarData(org.xclcharts.chart.BarData) PlotDot(org.xclcharts.renderer.line.PlotDot)

Aggregations

PlotDot (org.xclcharts.renderer.line.PlotDot)17 Paint (android.graphics.Paint)7 PlotLine (org.xclcharts.renderer.line.PlotLine)4 DotInfo (org.xclcharts.renderer.line.DotInfo)2 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 ArcLineData (org.xclcharts.chart.ArcLineData)1 BarData (org.xclcharts.chart.BarData)1 BubbleData (org.xclcharts.chart.BubbleData)1 PieData (org.xclcharts.chart.PieData)1 Legend (org.xclcharts.renderer.info.Legend)1