Ejemplo n.º 1
0
 // Sets the indicator geometry based on the scale and the current value
 private void SetIndicatorGeometry(RadialScale scale, double value)
 {
     if (thePath != null)
     {
         double min = scale.MinAngle;
         double max = scale.GetAngleFromValue(Value);
         if (scale.SweepDirection == SweepDirection.Counterclockwise)
         {
             min = -min;
             max = -max;
         }
         double rad = scale.GetIndicatorRadius();
         if (rad > BarThickness)
         {
             Geometry geom = RadialScaleHelper.CreateArcGeometry(min, max, rad, BarThickness, scale.SweepDirection);
             // Stop the recursive loop. Only set a new geometry if it is different from the current one
             if (thePath.Data == null || thePath.Data.Bounds != geom.Bounds)
             {
                 thePath.Data = geom;
             }
         }
     }
 }
Ejemplo n.º 2
0
        protected override void ArrangeRanges(Size finalSize)
        {
            try
            {
                double maxRad = RadialScaleHelper.GetRadius(RadialType, finalSize, MinAngle, MaxAngle, SweepDirection);
                Point  center = RadialScaleHelper.GetCenterPosition(RadialType, finalSize, MinAngle, MaxAngle, SweepDirection);

                // Cache the center of the RadialScale
                this.Center = center;

                double x = center.X;
                double y = center.Y;
                // Calculate the ranges' radius
                double rad = maxRad;
                //if (TickPlacement == RadialTickPlacement.Outward)
                //{
                //    rad = maxRad - GetLabels().Max(p => p.DesiredSize.Height) - GetTicks().Max(p => p.DesiredSize.Height) - 1;
                //}
                // Draw the default range
                if (UseDefaultRange)
                {
                    double min = MinAngle, max = MaxAngle;
                    if (SweepDirection == SweepDirection.Counterclockwise)
                    {
                        min = -min;
                        max = -max;
                    }
                    // The null check needs to be done because otherwise the arrange pass will be called
                    // recursevely as I set new content for the path in every call
                    Geometry geom = RadialScaleHelper.CreateArcGeometry(min, max, rad, RangeThickness, SweepDirection);
                    if (def.Data == null || def.Data.Bounds != geom.Bounds)
                    {
                        def.Data = geom;
                    }
                    // Arrange the default range. move the start point of the
                    // figure (0, 0) in the center point (center)
                    def.Arrange(new Rect(center, finalSize));
                }

                // Arrange the rest of the ranges
                double prevAngle = MinAngle;
                if (SweepDirection == SweepDirection.Counterclockwise)
                {
                    prevAngle = -prevAngle;
                }

                for (int i = 0; i < ranges.Count; i++)
                {
                    Path       range     = ranges[i];
                    GaugeRange rng       = Ranges[i];
                    double     nextAngle = GetAngleFromValue(rng.Offset);
                    if (SweepDirection == SweepDirection.Counterclockwise)
                    {
                        nextAngle = -nextAngle;
                    }

                    range.Fill = new SolidColorBrush(rng.Color);
                    Geometry geom = RadialScaleHelper.CreateArcGeometry(prevAngle, nextAngle, rad, RangeThickness, SweepDirection);
                    // Check to avoid infinite loop
                    if (range.Data == null || range.Data.Bounds != geom.Bounds)
                    {
                        range.Data = geom;
                    }
                    // Arrange the default range. move the start point of the
                    // figure (0, 0) in the center point (center)
                    range.Arrange(new Rect(center, finalSize));
                    prevAngle = nextAngle;
                }
            }
            catch { /* In the designer this throws an argument exception. I don't know why. */ }
        }