Example #1
0
 public void SetAxis(AxisModel axis)
 {
     Config = new CanvasConfiguration();
     Config.BuildConfiguration(axis, AttachedCanvas.ActualWidth, AttachedCanvas.ActualHeight);
     DrawGrid();
     AdjustLocationsAfterResize();
 }
Example #2
0
        private void DrawGrid()
        {
            if (dotGrid == null)
            {
                dotGrid = new CanvasComponent();
            }

            if (Config == null)
            {
                // If we don't have a configuration yet, create the default...
                Config = new CanvasConfiguration();
                Config.BuildConfiguration(-800, 800, -400, 400,
                                          AttachedCanvas.ActualWidth, AttachedCanvas.ActualHeight,
                                          40, 20, 5, 5);
            }

            ResetGrid();

            double total_x   = Math.Abs(Config.XMin) + Config.XMax;
            double total_y   = Math.Abs(Config.YMin) + Config.YMax;
            double pct_x     = Math.Abs(Config.XMin) / total_x;
            double pct_y     = Math.Abs(Config.YMax) / total_y;
            int    origin_xi = (int)(pct_x * (double)Config.XCount);
            int    origin_yi = (int)(pct_y * (double)Config.YCount);
            double origin_xp = origin_xi * Config.XIncrement + Config.XStart + 1;
            double origin_yp = origin_yi * Config.YIncrement + Config.YStart + 1;

            var axisLine = CreateLine(0, origin_yp, AttachedCanvas.ActualWidth, origin_yp);

            axisLine.Stroke = new SolidColorBrush(Colors.Black);

            if (axisLineX != null)
            {
                GetBaseLayer().RemoveComponent(axisLineX);
                axisLineX.Shapes.Clear();
            }
            else
            {
                axisLineX = new CanvasComponent();
            }

            axisLineX.AddUiElement(axisLine);
            GetBaseLayer().AddComponent(axisLineX);

            axisLine        = CreateLine(origin_xp, 0, origin_xp, AttachedCanvas.ActualHeight);
            axisLine.Stroke = new SolidColorBrush(Colors.Black);

            if (axisLineY != null)
            {
                GetBaseLayer().RemoveComponent(axisLineY);
                axisLineY.Shapes.Clear();
            }
            else
            {
                axisLineY = new CanvasComponent();
            }

            axisLineY.AddUiElement(axisLine);
            GetBaseLayer().AddComponent(axisLineY);
        }