Search in sources :

Example 1 with ThresholdEntry

use of com.tencent.wstt.gt.ui.model.ThresholdEntry in project GT by Tencent.

the class GTMulOpPerfDetailView method onDraw.

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // 恢复默认的字号
    mPaint.setTextSize(12);
    // 恢复默认线条粗细
    mPaint.setStrokeWidth(0);
    // 恢复默认字间距
    singleTextInterval = 6;
    if (!measured) {
        canvasW = getMeasuredWidth();
        canvasH = getMeasuredHeight();
        // 相对于控件画布x轴的起始位置
        absX = (int) (canvasW / 11.23f);
        // 相对于控件画布x轴的结束位置
        absXMax = (int) (canvasW - canvasW / 19.82f);
        // 相对于控件画布y轴的起始位置
        absY = (int) (canvasH - canvasH / 4.51f);
        // 相对于控件画布y轴的结束位置
        absYMax = (int) (canvasH / 7.43f);
        // y轴数字对屏幕分辨率的适配
        if (devW == 720) {
            curScale = scaleY720;
        } else if (devW == 320) {
            absX = absX + 16;
            // 不减一下锚点线数值会出界
            absXMax = absXMax - 18;
            curScale = scaleY320;
        } else if (devW == 480) {
            absX = absX + 10;
            curScale = scaleY480;
        }
        w = absXMax - absX;
        h = absY - absYMax;
        middle = (absXMax - absX) / 2 + absX;
        anchorX = middle;
        curAve = absY;
        measured = true;
    }
    // 设置画布为黑色背景
    // canvas.drawColor(Color.BLACK);
    // 消除锯齿
    mPaint.setAntiAlias(true);
    // 设置图形为空心
    mPaint.setStyle(Paint.Style.STROKE);
    // 绘制x,y轴
    mPaint.setColor(Color.argb(0xff, 0x87, 0x8c, 0x98));
    // 设置线条粗细
    mPaint.setStrokeWidth(2);
    canvas.drawLine(absX, absY, absXMax, absY, mPaint);
    canvas.drawLine(absX, absYMax - 5, absX, absY, mPaint);
    // x最少显示10个数据,小于10个x坐标长度为10,从左开始显示
    if (curSize <= 5) {
        xGrid = 1;
    } else if (curSize > 5 && curSize <= xMin) {
        // 因为x轴显示时间了,最多显示10个1会展示不下
        xGrid = 2;
    } else {
        xGrid = 10;
    }
    /*
		 * 根据传入的参数绘制点折线
		 * 一个维度一个维度的画,兼容一维和二维的
		 */
    int j = 0;
    do {
        long preX = 0;
        float preY = 0;
        long preValue = 0;
        TagTimeEntry anchorEntry = dataSet;
        if (dataSet.getChildren().length > 0) {
            anchorEntry = dataSet.getChildren()[j];
        }
        // 阈值对象
        ThresholdEntry thresholdEntry = anchorEntry.getThresholdEntry();
        double upper = thresholdEntry.getUpperValue();
        double lower = thresholdEntry.getLowerValue();
        double dUpper = DoubleUtils.mul(upper, anchorEntry.getCarry_l2d());
        double dLower = DoubleUtils.mul(lower, anchorEntry.getCarry_l2d());
        long realUpper = (long) dUpper;
        long realLower = (long) dLower;
        boolean isWarningEable = thresholdEntry.isEnable();
        for (int i = 0; i < curSize; i++) {
            DrawEntry entry = cache[i][j];
            long point = entry.value;
            long x = absX + w * i / curSize;
            float y = calcY(point);
            entry.y = y;
            canvas.drawPoint(x, y, mPaint);
            if (// 画从前一点到当前点的线
            i > 0) {
                // 对于超出阈值的,需要标红线, 而且需要是有效阈值
                if (isWarningEable && (realUpper > realLower && (preValue > realUpper && point > realUpper || preValue < realLower && point < realLower))) {
                    //						mPaint.setColor(Color.argb(0xff, 0xda, 0x7b, 0x2f));
                    mPaint.setColor(Color.argb(0xff, 0xff, 0x00, 0x00));
                } else {
                    mPaint.setColor(lineColors[j]);
                }
                // 设置线条粗细
                mPaint.setStrokeWidth(2);
                canvas.drawLine(x, y, preX, preY, mPaint);
            }
            // 单点
            if (isWarningEable && (realUpper > realLower && (point > realUpper || point < realLower))) {
                mPaint.setColor(Color.argb(0xff, 0xff, 0x00, 0x00));
            } else {
                mPaint.setColor(lineColors[j]);
            }
            mPaint.setStrokeWidth(3);
            canvas.drawPoint(x, y, mPaint);
            mPaint.setStrokeWidth(2);
            preX = x;
            preY = y;
            preValue = point;
            // 要将x位置的数字画在横坐标上,显示内容数字:i,内容位置 x, y是absY
            mPaint.setColor(Color.argb(0xff, 0x87, 0x8c, 0x98));
            // 设置线条粗细
            mPaint.setStrokeWidth(0);
            if (i % xGrid == 0) {
                canvas.drawText(Integer.toString(start + i), x, absY + 30, mPaint);
                canvas.drawText(GTUtils.getSystemTime(entry.time), x, absY + 45, mPaint);
            }
            if (curSize == xMax && i == curSize - 1) {
                canvas.drawText(Integer.toString(start + i), x, absY + 30, mPaint);
            }
            // 画垂直分割线,画一次就可以
            if (j == 0) {
                mPaint.setColor(Color.argb(0x3f, 0x87, 0x8c, 0x98));
                // 设置线条粗细
                mPaint.setStrokeWidth(1);
                if (i % xGrid == 0) {
                    canvas.drawLine(x, absY, x, absYMax - 5, mPaint);
                }
                if (curSize == xMax && i == curSize - 1) {
                    canvas.drawLine(x, absY, x, absYMax - 5, mPaint);
                }
            }
        }
        j++;
    } while (j < dataSet.getChildren().length);
    // TODO 绘制单位
    mPaint.setColor(Color.argb(0xff, 0x87, 0x8c, 0x98));
    // 设置线条粗细
    mPaint.setStrokeWidth(0);
    canvas.drawText(dataSet.getUnit(), absX - 10, absYMax - 15, mPaint);
    // 循环绘制y轴坐标数字,顺便画y轴间隔线
    mPaint.setColor(Color.argb(0xff, 0x87, 0x8c, 0x98));
    // 设置线条粗细
    mPaint.setStrokeWidth(0);
    yGrid = (int) ((curYMax - curYMin) / yMaxGridNum);
    for (int i = 0; i < yMaxGridNum + 1; i++) {
        long g = curYMin + i * yGrid;
        float y = calcY(g);
        double dg = DoubleUtils.div(g, dataSet.getCarry_l2d(), dataSet.getScale());
        String sdg = Double.toString(dg);
        mPaint.setColor(Color.argb(0xff, 0x87, 0x8c, 0x98));
        // 设置线条粗细
        mPaint.setStrokeWidth(0);
        if (sdg.length() > curScale) {
            canvas.drawText(Double.toString(dg).substring(0, curScale), absX - 40, y, mPaint);
        } else {
            canvas.drawText(Double.toString(dg), absX - 40, y, mPaint);
        }
        mPaint.setColor(Color.argb(0x3f, 0x87, 0x8c, 0x98));
        // 设置线条粗细
        mPaint.setStrokeWidth(1);
        canvas.drawLine(absX, y, absXMax, y, mPaint);
    }
    // 画平均值,只在数据源是一维时候画
    if (curYMax != 0 && dataSet.getChildren().length < 2) {
        mPaint.setColor(Color.argb(0xff, 0x14, 0x8d, 0xc0));
        // 设置线条粗细
        mPaint.setStrokeWidth(2);
        canvas.drawLine(absX, curAve, absXMax, curAve, mPaint);
    }
    mPaint.setColor(Color.argb(0xff, 0x87, 0x8c, 0x98));
    // 设置线条粗细
    mPaint.setStrokeWidth(1);
    // 在长按中,需画锚点线
    if (isInLongFlip) {
        //			canvas.drawLine(anchorX, 0, anchorX, canvasH, mPaint);
        canvas.drawLine(anchorX, absY, anchorX, absYMax - 14, mPaint);
    }
    // 恢复线条粗细
    mPaint.setStrokeWidth(0);
    /*
		 * 下面的设置对应长按的文本与各曲线的标识文字
		 */
    // 时间文字显示的位置,默认小屏下取middle - 80
    float timeTextLocation = middle - 80;
    //设置字体大小,需要为大颗粒手机适配
    if (devW > 480) {
        mPaint.setTextSize(24);
        singleTextInterval = 15f;
        timeTextLocation = middle - 155;
    } else if (devW == 480) {
        mPaint.setTextSize(16);
        singleTextInterval = 10f;
        timeTextLocation = middle - 100;
    }
    float offsetY = absYMax - 15;
    // x位置放在单位之后,单位的位置是absX - 10
    float offsetX = absX - 10 + dataSet.getUnit().length() * singleTextInterval + 16;
    if (// TODO 平时显示各条线代表的含义
    !isInLongFlip) {
        // 每一项的偏移位
        float oppositeX = 0;
        for (int i = 0; i < dataSet.getChildren().length; i++) {
            String subKey = dataSet.getChildren()[i].getName();
            // 各条线对应的颜色
            mPaint.setColor(lineColors[i]);
            mPaint.setStrokeWidth(2);
            canvas.drawLine(offsetX + oppositeX, offsetY - 4, offsetX + oppositeX + 16, offsetY - 4, mPaint);
            // 恢复线条粗细
            mPaint.setStrokeWidth(0);
            canvas.drawText(subKey, offsetX + oppositeX + 20, offsetY, mPaint);
            // 下条线标识文本的相对修正位置,因为subKey长度不定,后面的不要折叠了
            oppositeX += subKey.length() * singleTextInterval + 20 + 4;
        }
    }
    // 显示当前y值
    if (null == anchorY) {
        return;
    }
    if (anchorY[0] != 0) {
        // 灰色显示时间
        mPaint.setColor(Color.argb(0xff, 0x87, 0x8c, 0x98));
        canvas.drawText(GTUtils.getSystemTime(anchorTime[0]), timeTextLocation, offsetY, mPaint);
        // 黄色显示当前次数
        mPaint.setColor(Color.argb(0xff, 0xd2, 0x90, 0x29));
        String sAnchorSeq = Integer.toString(anchorSeq[0] + start);
        // 修正位置,因为sAnchorSeq长度不定
        float al = sAnchorSeq.length() * singleTextInterval;
        canvas.drawText(sAnchorSeq, middle, offsetY, mPaint);
        String sbValue = "";
        for (int i = 0; i < anchorY.length; i++) {
            TagTimeEntry anchorEntry = dataSet.getSubTagEntrys()[i];
            double dY = DoubleUtils.div(anchorValue[i], anchorEntry.getCarry_l2d(), anchorEntry.getScale());
            sbValue = sbValue + Double.toString(dY);
            if (i != anchorY.length - 1) {
                sbValue = sbValue + "|";
            }
        }
        // 绿色显示值
        float middleAl = middle + al;
        mPaint.setColor(Color.argb(0xff, 0x38, 0xad, 0x29));
        canvas.drawText(sbValue, middleAl + 10, offsetY, mPaint);
    }
}
Also used : TagTimeEntry(com.tencent.wstt.gt.ui.model.TagTimeEntry) ThresholdEntry(com.tencent.wstt.gt.ui.model.ThresholdEntry) Paint(android.graphics.Paint)

Example 2 with ThresholdEntry

use of com.tencent.wstt.gt.ui.model.ThresholdEntry in project GT by Tencent.

the class GTPerfDetailView method onDraw.

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // 恢复默认的字号
    mPaint.setTextSize(12);
    // 恢复默认线条粗细
    mPaint.setStrokeWidth(0);
    // 恢复默认字间距
    singleTextInterval = 6;
    if (!measured) {
        canvasW = getMeasuredWidth();
        canvasH = getMeasuredHeight();
        // 相对于控件画布x轴的起始位置
        absX = (int) (canvasW / 11.23f);
        // 相对于控件画布x轴的结束位置
        absXMax = (int) (canvasW - canvasW / 19.82f);
        // 相对于控件画布y轴的起始位置
        absY = (int) (canvasH - canvasH / 4.51f);
        // 相对于控件画布y轴的结束位置
        absYMax = (int) (canvasH / 7.43f);
        // y轴数字对屏幕分辨率的适配
        if (devW == 720) {
            curScale = scaleY720;
        } else if (devW == 320) {
            absX = absX + 16;
            // 不减一下锚点线数值会出界
            absXMax = absXMax - 18;
            curScale = scaleY320;
        } else if (devW == 480) {
            absX = absX + 10;
            curScale = scaleY480;
        }
        w = absXMax - absX;
        h = absY - absYMax;
        middle = (absXMax - absX) / 2 + absX;
        anchorX = middle;
        curAve = absY;
        measured = true;
    }
    // 设置画布为黑色背景
    // canvas.drawColor(Color.BLACK);
    // 消除锯齿
    mPaint.setAntiAlias(true);
    // 设置图形为空心
    mPaint.setStyle(Paint.Style.STROKE);
    // 绘制x,y轴
    mPaint.setColor(Color.argb(0xff, 0x87, 0x8c, 0x98));
    // 设置线条粗细
    mPaint.setStrokeWidth(2);
    canvas.drawLine(absX, absY, absXMax, absY, mPaint);
    canvas.drawLine(absX, absYMax - 5, absX, absY, mPaint);
    // x最少显示10个数据,小于10个x坐标长度为10,从左开始显示
    if (curSize <= 5) {
        xGrid = 1;
    } else if (curSize > 5 && curSize <= xMin) {
        // 因为x轴显示时间了,最多显示10个1会展示不下
        xGrid = 2;
    } else {
        xGrid = 10;
    }
    // 根据传入的参数绘制点折线
    long preX = 0;
    float preY = 0;
    long preValue = 0;
    // 阈值对象
    ThresholdEntry thresholdEntry = dataSet.getThresholdEntry();
    double upper = thresholdEntry.getUpperValue();
    double lower = thresholdEntry.getLowerValue();
    double dUpper = DoubleUtils.mul(upper, dataSet.getCarry_l2d());
    double dLower = DoubleUtils.mul(lower, dataSet.getCarry_l2d());
    long realUpper = (long) dUpper;
    long realLower = (long) dLower;
    for (int i = 0; i < curSize; i++) {
        DrawEntry entry = cache[i];
        long point = entry.value;
        long x = absX + w * i / curSize;
        float y = calcY(point);
        entry.y = y;
        canvas.drawPoint(x, y, mPaint);
        if (// 画从前一点到当前点的线
        i > 0) {
            // 对于超出阈值的,需要标红线,而且需要是有效阈值
            if (dataSet.getThresholdEntry().isEnable() && (realUpper > realLower && (preValue > realUpper && point > realUpper || preValue < realLower && point < realLower))) {
                //					mPaint.setColor(Color.argb(0xff, 0xda, 0x7b, 0x2f));
                mPaint.setColor(Color.argb(0xff, 0xff, 0x00, 0x00));
            } else {
                mPaint.setColor(Color.argb(0xff, 0xd2, 0x90, 0x29));
            }
            // 设置线条粗细
            mPaint.setStrokeWidth(2);
            canvas.drawLine(x, y, preX, preY, mPaint);
        }
        // 单点, 而且需要是有效阈值;但是时间区间的情况下是否加描单点不一定
        if (dataSet.getThresholdEntry().isEnable() && (realUpper > realLower && (point > realUpper || point < realLower))) {
            mPaint.setColor(Color.argb(0xff, 0xff, 0x00, 0x00));
        } else {
            mPaint.setColor(Color.argb(0xff, 0xd2, 0x90, 0x29));
        }
        mPaint.setStrokeWidth(3);
        canvas.drawPoint(x, y, mPaint);
        preX = x;
        preY = y;
        preValue = point;
        // 要将x位置的数字画在横坐标上,显示内容数字:i,内容位置 x, y是absY
        // add on 20131123 将时间画在x轴上
        mPaint.setColor(Color.argb(0xff, 0x87, 0x8c, 0x98));
        // 设置线条粗细
        mPaint.setStrokeWidth(0);
        if (i % xGrid == 0) {
            canvas.drawText(Integer.toString(start + i), x, absY + 30, mPaint);
            canvas.drawText(GTUtils.getSystemTime(entry.time), x, absY + 45, mPaint);
        }
        if (curSize == xMax && i == curSize - 1) {
            canvas.drawText(Integer.toString(start + i), x, absY + 30, mPaint);
        }
        // 画垂直分割线
        mPaint.setColor(Color.argb(0x3f, 0x87, 0x8c, 0x98));
        // 设置线条粗细
        mPaint.setStrokeWidth(1);
        if (i % xGrid == 0) {
            canvas.drawLine(x, absY, x, absYMax - 5, mPaint);
        }
        if (curSize == xMax && i == curSize - 1) {
            canvas.drawLine(x, absY, x, absYMax - 5, mPaint);
        }
    }
    // TODO 绘制单位
    mPaint.setColor(Color.argb(0xff, 0x87, 0x8c, 0x98));
    // 设置线条粗细
    mPaint.setStrokeWidth(0);
    canvas.drawText(dataSet.getUnit(), absX - 10, absYMax - 15, mPaint);
    // 循环绘制y轴坐标数字,顺便画y轴间隔线
    mPaint.setColor(Color.argb(0xff, 0x87, 0x8c, 0x98));
    // 设置线条粗细
    mPaint.setStrokeWidth(0);
    yGrid = (int) ((curYMax - curYMin) / yMaxGridNum);
    for (int i = 0; i < yMaxGridNum + 1; i++) {
        long g = curYMin + i * yGrid;
        float y = calcY(g);
        double dg = DoubleUtils.div(g, dataSet.getCarry_l2d(), dataSet.getScale());
        String sdg = Double.toString(dg);
        mPaint.setColor(Color.argb(0xff, 0x87, 0x8c, 0x98));
        // 设置线条粗细
        mPaint.setStrokeWidth(0);
        if (sdg.length() > curScale) {
            canvas.drawText(Double.toString(dg).substring(0, curScale), absX - 40, y, mPaint);
        } else {
            canvas.drawText(Double.toString(dg), absX - 40, y, mPaint);
        }
        mPaint.setColor(Color.argb(0x3f, 0x87, 0x8c, 0x98));
        // 设置线条粗细
        mPaint.setStrokeWidth(1);
        canvas.drawLine(absX, y, absXMax, y, mPaint);
    }
    // 画平均值
    if (curYMax != 0 && curSize > 0) {
        mPaint.setColor(Color.argb(0xff, 0x14, 0x8d, 0xc0));
        // 设置线条粗细
        mPaint.setStrokeWidth(2);
        canvas.drawLine(absX, curAve, absXMax, curAve, mPaint);
    }
    mPaint.setColor(Color.argb(0xff, 0x87, 0x8c, 0x98));
    // 设置线条粗细
    mPaint.setStrokeWidth(1);
    // 在长按中,需画锚点线
    if (isInLongFlip) {
        //			canvas.drawLine(anchorX, 0, anchorX, canvasH, mPaint);
        canvas.drawLine(anchorX, absY, anchorX, absYMax - 14, mPaint);
    }
    // 恢复线条粗细
    mPaint.setStrokeWidth(0);
    // 显示当前y值
    if (anchorY != 0) {
        // 时间文字显示的位置,默认小屏下取middle - 80
        float timeTextLocation = middle - 80;
        //设置字体大小,需要为大颗粒手机适配
        if (devW >= 480) {
            mPaint.setTextSize(24);
            singleTextInterval = 15f;
            timeTextLocation = middle - 155;
        }
        double dY = DoubleUtils.div(anchorValue, dataSet.getCarry_l2d(), dataSet.getScale());
        canvas.drawText(GTUtils.getSystemTime(anchorTime), timeTextLocation, absYMax - 15, mPaint);
        // 黄色显示当前次数
        mPaint.setColor(Color.argb(0xff, 0xd2, 0x90, 0x29));
        String sAnchorSeq = Integer.toString(anchorSeq + start);
        // 修正位置,因为sAnchorSeq长度不定
        float al = sAnchorSeq.length() * singleTextInterval;
        canvas.drawText(sAnchorSeq, middle, absYMax - 15, mPaint);
        // 绿色显示值
        float middleAl = middle + al;
        mPaint.setColor(Color.argb(0xff, 0x38, 0xad, 0x29));
        canvas.drawText(Double.toString(dY), middleAl + 10, absYMax - 15, mPaint);
    }
}
Also used : ThresholdEntry(com.tencent.wstt.gt.ui.model.ThresholdEntry) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)2 ThresholdEntry (com.tencent.wstt.gt.ui.model.ThresholdEntry)2 TagTimeEntry (com.tencent.wstt.gt.ui.model.TagTimeEntry)1