public void Draw(Dictionary<string, string> stat)
        {
            CtlPresenter.Clear();

            if (stat == null)
            {
                return;
            }

            string text = string.Empty;
            foreach (var pair in stat)
            {
                if (pair.Key.Length == 0)
                {
                    text += "\r\n";
                }
                else
                {
                    text += pair.Key + ": " + pair.Value + "\r\n";
                }
            }

            var formattedText = new FormattedText(text, Culture.Current, FlowDirection.LeftToRight, Font, 10, Brushes.Black, Render.PixelsPerDip);
            CtlPresenter.DrawText(formattedText, Points.Get(10, 0));

            Width = Math.Max(ActualWidth, formattedText.WidthIncludingTrailingWhitespace + 10);

            CtlPresenter.Update();
        }
Example #2
0
        private void Rearrange(int pointsCount)
        {
            CtlPresenter.Clear();

            if (pointsCount != Const.CurrentValue)
            {
                PointsCount = pointsCount;
            }

            if (Data == null || Data.Length != PointsCount)
            {
                Data = new double[PointsCount];
                Stat = new double[PointsCount];
            }

            double maxStat = Stat == null ? 0 : Stat.Max();

            for (int p = 0; p < PointsCount; ++p)
            {
                var pos = GetPointPosition(p);

                if (Data[p] > Threshold)
                {
                    DrawPoint(pos.Item1, pos.Item2, Data[p], true);
                }
                else
                {
                    DrawPoint(pos.Item1, pos.Item2, maxStat > 0 ? Stat[p] / maxStat : 0, false);
                }
            }

            CtlPresenter.Update();
        }
Example #3
0
        private void Draw(bool fullState, NetworkDataModel model, bool isOnlyWeights, bool isOnlyChangedWeights, bool isHighlightChangedWeights)
        {
            if (model == null)
            {
                CtlPresenter.Clear();
                return;
            }

            CtlPresenter.Clear();

            //lock (Main.ApplyChangesLocker)
            {
                if (model.Layers.Count > 0)
                {
                    foreach (var layer in model.Layers)
                    {
                        if (layer == model.Layers.Last())
                        {
                            break;
                        }

                        DrawLayersLinks(fullState, model, layer, layer.Next, isOnlyWeights, isOnlyChangedWeights, isHighlightChangedWeights);
                    }

                    foreach (var layer in model.Layers)
                    {
                        DrawLayerNeurons(fullState, model, layer);
                    }
                }
            }

            CtlPresenter.Update();
        }
        public void Draw(ListX <NetworkDataModel> models, NetworkDataModel selectedModel)
        {
            if (IsBaseRedrawNeeded)
            {
                DrawPlotter();
                IsBaseRedrawNeeded = false;
            }

            CtlPresenter.Clear();

            if (models == null)
            {
                return;
            }

            var model = models[0];

            while (model != null)
            {
                if (!model.IsEnabled)
                {
                    continue;
                }

                DrawData(model.DynamicStatistics.CopyForRender.PercentData, Tools.Draw.GetColor(220, model.Color), GetPointPercentData, false);
                DrawData(model.DynamicStatistics.CopyForRender.CostData, Tools.Draw.GetColor(150, model.Color), GetPointCostData, true);

                model = model.Next;
            }

            if (selectedModel != null && selectedModel.DynamicStatistics.PercentData.Count > 0)
            {
                DrawLabel(selectedModel.DynamicStatistics.PercentData, selectedModel.Color);
            }

            CtlPresenter.Update();
        }
Example #5
0
 public void Clear()
 {
     CtlPresenter.Clear();
 }
Example #6
0
        public void Draw(ErrorMatrix matrix)
        {
            if (!IsLoaded)
            {
                return;
            }

            if (IsClassesChanged(matrix.Classes))
            {
                InitClassesFmtText(matrix.Classes);
                DrawBase(matrix);
            }

            Classes = matrix.Classes;
            CtlPresenter.Clear();

            int  size       = 9;
            long goodMax    = 1;
            long badMax     = 1;
            long axisOffset = 12;
            long bound      = 30;

            for (int y = 0; y < matrix.Output.Length; ++y)
            {
                for (int x = 0; x < matrix.Input.Length; ++x)
                {
                    if (x == y)
                    {
                        goodMax = Math.Max(goodMax, matrix.Matrix[x, y]);
                    }
                    else
                    {
                        badMax = Math.Max(badMax, matrix.Matrix[x, y]);
                    }
                }
            }

            for (int y = 0; y < matrix.Output.Length; ++y)
            {
                for (int x = 0; x < matrix.Input.Length; ++x)
                {
                    if (matrix.Matrix[y, x] > 0)
                    {
                        var value = (double)matrix.Matrix[y, x] / (double)(x == y ? goodMax : badMax);
                        var color = Tools.Draw.GetColorDradient(Colors.LightGray, x == y ? Colors.Green : Colors.Red, 255, value);
                        var brush = Tools.Draw.GetBrush(color);
                        CtlPresenter.DrawRectangle(brush, PenSilver, Rects.Get(axisOffset + x * size, axisOffset + y * size, size, size));
                    }
                }
            }

            long outputMax = Math.Max(matrix.Output.Max(), 1);

            for (int x = 0; x < matrix.Output.Length; ++x)
            {
                var color = Tools.Draw.GetColorDradient(Colors.White, matrix.Output[x] > matrix.Input[x] ? Colors.Red : matrix.Output[x] < matrix.Input[x] ? Colors.Blue : Colors.Green, 100, (double)matrix.Output[x] / (double)outputMax);
                var brush = Tools.Draw.GetBrush(color);
                CtlPresenter.DrawRectangle(brush, PenSilver, Rects.Get(axisOffset + x * size, 10 + axisOffset + matrix.Input.Length * size, size, (int)(bound * (double)matrix.Output[x] / (double)outputMax)));
            }

            long inputMax = Math.Max(matrix.Input.Max(), 1);

            for (int y = 0; y < matrix.Input.Length; ++y)
            {
                var color = Tools.Draw.GetColorDradient(Colors.White, Colors.Green, 100, (double)matrix.Input[y] / (double)inputMax);
                var brush = Tools.Draw.GetBrush(color);
                CtlPresenter.DrawRectangle(brush, PenSilver, Rects.Get(11 + axisOffset + matrix.Output.Length * size, axisOffset + y * size, (int)(bound * (double)matrix.Input[y] / (double)inputMax), size));
            }

            CtlPresenter.Update();
        }
        public void Render(DateTime start, DateTime end)
        {
            CtlPresenter.Clear();

            byte alpha = 100;

            var winterColor = Draw.GetBrush(Draw.GetColor(alpha, Colors.White));
            var springColor = Draw.GetBrush(Draw.GetColor(alpha, Colors.Blue));
            var summerColor = Draw.GetBrush(Draw.GetColor(alpha, Colors.Green));
            var autumColor  = Draw.GetBrush(Draw.GetColor(alpha, Colors.Yellow));

            var year0Color = Draw.GetBrush(Draw.GetColor(255, Colors.WhiteSmoke));
            var year1Color = Draw.GetBrush(Draw.GetColor(255, Colors.DarkGray));

            var dictMonth = new Dictionary <int, Brush>()
            {
                { 1, winterColor },
                { 2, winterColor },
                { 3, springColor },
                { 4, springColor },
                { 5, springColor },
                { 6, summerColor },
                { 7, summerColor },
                { 8, summerColor },
                { 9, autumColor },
                { 10, autumColor },
                { 11, autumColor },
                { 12, winterColor }
            };

            var dictYear = new Dictionary <int, Brush>()
            {
                { 0, year0Color },
                { 1, year1Color }
            };

            var width  = CtlPresenter.ActualWidth;
            var height = CtlPresenter.ActualHeight;

            const double yearHeight = 5;

            // grid
            for (DateTime day = start; day <= end; day = day.AddMonths(1))
            {
                double x  = GetX(start.Ticks, end.Ticks, day.Ticks);
                double x2 = GetX(start.Ticks, end.Ticks, day.AddMonths(1).Ticks);

                CtlPresenter.DrawRectangle(dictMonth[day.Month], penGrid, Rects.Get(x, 0, x2 - x, height - yearHeight));

                if (day.Month == 1)
                {
                    CtlPresenter.DrawLine(penGridYear, Points.Get(x, 0), Points.Get(x, height - yearHeight));
                }

                var fmt = new FormattedText(day.Date.ToString("MMM") + "\r\n" + (day.Date.Year - 2000), Culture.Current, FlowDirection.LeftToRight, Font, 9, Brushes.Black, Tools.Render.PixelsPerDip);
                CtlPresenter.DrawText(fmt, Points.Get(x + (x2 - x - fmt.Width) / 2, (height - fmt.Height) / 2 - 3));

                CtlPresenter.DrawRectangle(dictYear[day.Year % 2], null, Rects.Get(x, height - yearHeight, x2 - x, yearHeight));
            }
            CtlPresenter.DrawLine(penGrid, Points.Get(0, 0), Points.Get(width, 0));
            //
        }
        public void Render(long startTicks, long endTicks, DataManager manager, bool isOdd, bool isHeadOfGroup)
        {
            CtlPresenter.Clear();

            using (var dc = CtlPresenter.G())
            {
                var width  = CtlPresenter.ActualWidth;
                var height = CtlPresenter.ActualHeight;

                if (Values.Count == 0)
                {
                    //todo: add grid
                    return;
                }

                CtlGroup.Visibility = isHeadOfGroup ? Visibility.Visible : Visibility.Collapsed;

                double rangeMin = RangeMinimum;
                double rangeMax = RangeMaximum;

                /* auto range
                 * if (manager.IsAutoRangeMinMax)
                 * {
                 *  var min = Values.Min(v => v.CtlValue.Value);
                 *  var max = Values.Max(v => v.CtlValue.Value);
                 *
                 *  rangeMax = max + min;
                 *  rangeMin = 0;
                 * }
                 */

                // Min-Max range
                if (manager.IsAutoRangeMinMax)
                {
                    var min = Values.Min(v => v.CtlValue.Value);
                    var max = Values.Max(v => v.CtlValue.Value);

                    rangeMax = max;
                    rangeMin = min;
                }

                if (rangeMin == rangeMax)
                {
                    var pen = GetPenFromValue(rangeMin);

                    CtlMinRange.Text = Converter.DoubleToText(rangeMin, "F3", true);
                    CtlMinRange.VerticalAlignment = VerticalAlignment.Center;
                    CtlMinRange.Background        = pen.Brush;
                    CtlMaxRange.Visibility        = Visibility.Collapsed;
                }
                else
                {
                    var penMin = GetPenFromValue(rangeMin);
                    var penMax = GetPenFromValue(rangeMax);

                    CtlMinRange.Text       = Converter.DoubleToText(rangeMin, "F3", true);
                    CtlMinRange.Background = penMin.Brush;
                    CtlMaxRange.Text       = Converter.DoubleToText(rangeMax, "F3", true);
                    CtlMaxRange.Background = penMax.Brush;
                }

                double optimalValue = CriticalMinumim + (CriticalMaximum - CriticalMinumim) / 2;

                if (manager.IsShowOptimalLine && CriticalMinumim > 0)
                {
                    if (rangeMax < optimalValue)
                    {
                        rangeMax = optimalValue;
                    }

                    if (rangeMin > optimalValue)
                    {
                        rangeMin = optimalValue;
                    }
                }

                var prevValue = Values[0];

                double val     = prevValue.CtlValue.Value;
                var    prevPen = GetPenFromValue(val);
                double prevX   = GetX(startTicks, endTicks, prevValue.CtlDate.SelectedDate.Value);

                foreach (var value in Values)
                {
                    if (prevValue != null)
                    {
                        var v       = value.CtlValue.Value;
                        var currPen = GetPenFromValue(v);
                        if (currPen != prevPen)
                        {
                            var end         = value == Values[Values.Count - 1] ? value.CtlDate.SelectedDate.Value : value.CtlDate.SelectedDate.Value.AddDays(-1);
                            var dayOfChange = GetDayOfChange2(prevValue, value, end, prevPen);

                            val = GetValueForDate(prevValue, value, dayOfChange.Ticks);
                            var pen = GetPenFromValue(val);

                            bool lastDay = value == Values[Values.Count - 1] && dayOfChange == end;
                            if (pen != prevPen || lastDay)
                            {
                                double x = (lastDay && pen == prevPen) ? width : GetX(startTicks, endTicks, dayOfChange);
                                CtlPresenter.DrawRectangle(prevPen.Brush, prevPen, Rects.Get(prevX, 0, x - prevX, height), dc);

                                prevX   = x;
                                prevPen = pen;
                            }
                        }
                    }

                    prevValue = value;
                }

                CtlPresenter.DrawRectangle(prevPen.Brush, prevPen, Rects.Get(prevX, 0, width - prevX, height), dc);

                // grid

                var endDate   = new DateTime(endTicks);
                var startDate = new DateTime(startTicks);

                for (DateTime day = startDate; day <= endDate; day = day.AddMonths(1))
                {
                    double x = GetX(startTicks, endTicks, day);
                    CtlPresenter.DrawLine(day.Month == 1 ? penGridYear : (isOdd ? penGrid : penGridAlt), Points.Get(x, 0), Points.Get(x, height), dc);
                }

                double xt = GetX(startTicks, endTicks, DateTime.Today);
                CtlPresenter.DrawLine(penToday, Points.Get(xt, 0), Points.Get(xt, height), dc);

                // optimal line
                if (manager.IsShowOptimalLine && CriticalMinumim > 0)
                {
                    double y = GetY(optimalValue, rangeMin, rangeMax);
                    CtlPresenter.DrawLine(penOptimalValue, Points.Get(0, y), Points.Get(width, y), dc);
                }

                // graph
                prevValue = null;
                foreach (var value in Values)
                {
                    var point = GetValuePoint(value, startTicks, endTicks, rangeMin, rangeMax);
                    if (prevValue != null)
                    {
                        var prevPoint = GetValuePoint(prevValue, startTicks, endTicks, rangeMin, rangeMax);
                        CtlPresenter.DrawLine(penLine, prevPoint, point, dc);
                    }

                    // Critical border circle

                    var pointPen = penLine;

                    double pointRadius = 5 * Tools.Render.PixelSize;

                    if (CriticalMinumim != CriticalMaximum)
                    {
                        if (CriticalMinumim > RangeMinimum && value.CtlValue.Value == CriticalMinumim)
                        {
                            CtlPresenter.DrawEllipse(penCriticalBorder.Brush, penCriticalBorder, point, pointRadius, pointRadius, dc);
                            pointPen = penLow;
                        }
                        else if (CriticalMaximum < RangeMaximum && value.CtlValue.Value == CriticalMaximum)
                        {
                            CtlPresenter.DrawEllipse(penCriticalBorder.Brush, penCriticalBorder, point, pointRadius, pointRadius, dc);
                            pointPen = penHigh;
                        }
                    }

                    // Value point

                    CtlPresenter.DrawEllipse(pointPen.Brush, pointPen, point, pointRadius / 2, pointRadius / 2, dc);

                    prevValue = value;
                }
                //

                // values
                var brush     = Tools.Draw.GetBrush(Colors.White);
                var prevRects = new List <Rect>();
                for (int i = Values.Count - 1; i >= 0; --i)
                {
                    var value = Values[i];
                    var point = GetValuePoint(value, startTicks, endTicks, rangeMin, rangeMax);
                    var fmt   = new FormattedText(Converter.DoubleToText(value.CtlValue.Value, "F3"), Culture.Current, FlowDirection.LeftToRight, Font, 9, Brushes.Black, Tools.Render.PixelsPerDip);
                    var x     = point.X + Tools.Render.PixelSize;
                    var y     = point.Y >= height / 2 ? point.Y - Tools.Render.PixelSize - fmt.Height : point.Y + Tools.Render.PixelSize;
                    var rect  = Rects.Get(x, y, fmt.Width + 2 * Tools.Render.PixelSize, fmt.Height - 2 * Tools.Render.PixelSize);

                    if (!prevRects.Any(prevRect => Rects.Intersects(rect, prevRect)))
                    {
                        CtlPresenter.DrawRectangle(brush, null, rect, dc);
                        CtlPresenter.DrawText(fmt, Points.Get(x + Tools.Render.PixelSize, y - Tools.Render.PixelSize), 0, dc);
                        prevRects.Add(rect);
                    }
                }
            }

            IsRenderNeeded = false;
        }