Example #1
0
        void DrawAxisX(D2DGraphics g)
        {
            g.RenderTarget.AntialiasMode = AntialiasMode.PerPrimitive;

            int startIdx = dataRange.startIdx;
            int endIdx   = dataRange.endIdx;
            StrokeStyleProperties ssp = new StrokeStyleProperties();

            ssp.DashStyle = DashStyle.DashDot;
            StrokeStyle     strokeStyle = new StrokeStyle(D2DGraphics.d2dFactory, ssp);
            SolidColorBrush brush2      = new SolidColorBrush(g.RenderTarget, GDIDataD2DUtils.TransToRawColor4(XAxisColor));

            g.RenderTarget.DrawLine(new RawVector2(0, Height / 2), new RawVector2(Width, Height / 2), brush2, 0.5f, strokeStyle);

            //
            float widthStep = Width / xAxisSeqCount;

            float numSeq   = GetAxisXSeq();
            float startNum = startIdx * numSeq;
            float numWidth = (endIdx - startIdx) * numSeq;
            float numStep  = numWidth / xAxisSeqCount;

            RawRectangleF rect;

            for (int i = 0; i < xAxisSeqCount; i++)
            {
                float x = (widthStep * i - 100 + widthStep * i + 100) / 2f;
                g.RenderTarget.DrawLine(new RawVector2(x, Height / 2), new RawVector2(x, Height / 2 + 3), brush2, 1f);

                //
                rect = new RawRectangleF(widthStep * i - 100, Height / 2, widthStep * i + 100, Height / 2 + 15);
                string str = (startNum + i * numStep).ToString("#.##");
                g.RenderTarget.DrawText(str, textFormat, rect, brush2, DrawTextOptions.Clip);
            }
        }
Example #2
0
        void DrawDatas(D2DGraphics g)
        {
            g.RenderTarget.AntialiasMode = AntialiasMode.PerPrimitive;
            SolidColorBrush brush = new SolidColorBrush(g.RenderTarget, GDIDataD2DUtils.TransToRawColor4(DataLineColor));

            float baselineY = Height / 2;
            int   startIdx  = dataRange.startIdx;
            int   endIdx    = dataRange.endIdx;
            float step      = Width / (endIdx - startIdx);

            int        prevIdx = startIdx;
            int        lastIdx = startIdx;
            int        sameIdx;
            RawVector2 pt1 = new RawVector2(0, -datas[startIdx] * scale + baselineY);
            RawVector2 pt2 = new RawVector2();
            RawVector2 yrange;

            while (lastIdx < endIdx)
            {
                sameIdx = GetSameAxisxIdx(prevIdx, endIdx, pt1, step, out yrange);

                if (sameIdx != prevIdx)
                {
                    g.RenderTarget.DrawLine(
                        new RawVector2(pt1.X, baselineY - yrange.X),
                        new RawVector2(pt1.X, baselineY - yrange.Y), brush, 0.5f);

                    pt2.X   = pt1.X;
                    pt2.Y   = -datas[sameIdx] * scale + baselineY;
                    pt1     = pt2;
                    prevIdx = sameIdx;
                }

                //
                lastIdx = GetCombineIdx(prevIdx, endIdx, pt1);
                pt2.X   = (lastIdx - startIdx) * step;
                pt2.Y   = -datas[lastIdx] * scale + baselineY;
                g.RenderTarget.DrawLine(pt1, pt2, brush, 0.5f);
                pt1     = pt2;
                prevIdx = lastIdx;
            }
        }