private void DrawLayerNeurons(bool fullState, NetworkDataModel model, LayerDataModel layer) { double threshold = model.Layers[0] == layer ? model.InputThreshold : 0; var biasColor = Tools.Draw.GetPen(Colors.Orange); NeuronDataModel prevNeuron = null; foreach (var neuron in layer.Neurons) { if (fullState || neuron.IsBias || neuron.Activation > threshold || layer.Id > 0) { if (!Coordinator.ContainsKey(neuron)) { Coordinator.Add(neuron, Points.Get(LayerX(model, layer), TOP_OFFSET + VerticalShift(model, layer) + neuron.Id * VerticalDistance(layer.Height))); } // Skip intersected neurons on first layer to improove performance. if (!fullState && !neuron.IsBias && model.Layers[0] == layer && prevNeuron != null) { if (Coordinator[neuron].Y - Coordinator[prevNeuron].Y < NEURON_SIZE) { continue; } } prevNeuron = neuron; var pen = Tools.Draw.GetPen(neuron.Activation); var brush = pen.Brush; if (neuron.IsBias) { CtlPresenter.DrawEllipse(Brushes.Orange, biasColor, Coordinator[neuron], BIAS_RADIUS, BIAS_RADIUS); } CtlPresenter.DrawEllipse(brush, pen, Coordinator[neuron], NEURON_RADIUS, NEURON_RADIUS); } } }
private void DrawData(DynamicStatistics.PlotPoints data, Color color, PointFunc func, bool isRect) { if (data == null || data.FirstOrDefault() == null) { return; } var pen = Tools.Draw.GetPen(color); var firstData = data[0]; var lastData = data.Last(); var ticks = lastData.Item2 - firstData.Item2; Point prevPoint = new Point(-1000, -1000); var prevData = firstData; foreach (var d in data) { var point = func(data, d, ticks); if ((point.X - prevPoint.X) > 10 || Math.Abs(point.Y - prevPoint.Y) > 10 || d == lastData) // opt { CtlPresenter.DrawLine(pen, func(data, prevData, ticks), point); if (isRect) { CtlPresenter.DrawRectangle(pen.Brush, pen, Rects.Get(point.X - 6 / 2, point.Y - 6 / 2, 6, 6)); } else { CtlPresenter.DrawEllipse(pen.Brush, pen, Points.Get(point.X, point.Y), 7 / 2, 7 / 2); } prevData = d; prevPoint = point; } } }
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; }