public void DrawGraph() { _hzAxisY = _coords.ToYPix(0); if (_hzAxisY < 0) { _hzAxisY = 0; } if (_hzAxisY > _coords.Height) { _hzAxisY = _coords.Height; } _hzNumsY = _hzAxisY + 14; if (_hzAxisY > _coords.Height - 10) { _hzNumsY = _coords.Height - 3; } _vtAxisX = _coords.ToXPix(0); if (_vtAxisX < 0) { _vtAxisX = 0; } if (_vtAxisX > _coords.Width) { _vtAxisX = _coords.Width; } _vtNumsX = _vtAxisX - 5; if (_vtAxisX < 10) { _vtNumsX = 20; } if (_coords.UseXLog) { DrawLinesLogX(); } else { if (_horizontalLinesVisible) { DrawHorizontalLines(); } } if (_coords.UseYLog) { DrawLinesLogY(); } else { if (_verticalLinesVisible) { DrawVerticalLines(); } } }
private void DrawNewton(CanvasDrawingSession ds) { if (_parser?.RootNode == null) { return; } var width = _coords.Width; var height = _coords.Height; var xmin = _coords.XStart; var xmax = _coords.XEnd; var ymin = _coords.YStart; var ymax = _coords.YEnd; var xpixstep = (xmax - xmin) / width; var ypixstep = -(ymax - ymin) / height; var bitmap = new byte[width * height * 4]; // 4 bytes per pixel for (var i = 0; i < bitmap.Length; i++) { bitmap[i] = 0; } var toler = xpixstep * xpixstep * 0.1; var xGridStep = xpixstep * _nStep; var yGridStep = ypixstep * _nStep; for (var x1 = xmin; x1 < xmax; x1 += xGridStep) { for (var y1 = ymin; y1 < ymax; y1 -= yGridStep) { double score; if (_nStep > 1) { var widefact = 1; score = GetNewtonScore( x1 - xpixstep * widefact, y1 + ypixstep * widefact, x1 + xGridStep + xpixstep * widefact, y1 - yGridStep - ypixstep * widefact, x1 + xGridStep / 2, y1 - yGridStep / 2, 10, toler * 10 ); } else { score = 1; } if (score > 0) { for (int i = 0; i < _nStep; i++) { for (var j = 0; j < _nStep; j++) { var x2 = x1 + i * xpixstep; var y2 = y1 - j * ypixstep; score = GetNewtonScore( x2, y2, x2 + xpixstep, y2 - ypixstep, x2 + xpixstep / 2, y2 - ypixstep / 2, 5, toler ); if (score > 0) { var xn = (int)_coords.ToXPix(x2 + xpixstep / 2); var yn = (int)_coords.ToYPix(y2 - ypixstep / 2); SetPix(bitmap, xn, yn, (int)(255 * score)); } } } } } } var target = new CanvasRenderTarget(ds, _coords.Width, _coords.Height); target.SetPixelBytes(bitmap); ds.DrawImage(target); }