Describes a value range on the meter
Exemplo n.º 1
0
        /// <summary>
        /// Draws an interval for the meter
        /// </summary>
        /// <param name="interval">The MeterRangeInteraval which represents this range of the meter</param>
        /// <param name="tickLength">The length of the ticks for this range</param>
        /// <param name="group">The geometry group to add this to add this to</param>
        /// <param name="startAngle"></param>
        private void DrawInterval(MeterRangeInterval interval, double tickLength, GeometryGroup group, double startAngle = 0.0)
        {
            double startRad = interval.StartDegree * (Math.PI / 180), endRad = interval.EndDegree * (Math.PI / 180);
            double radianInterval = (endRad - startRad) * (interval.TickInterval / (interval.EndValue - interval.StartValue));
            var    tickCount      = (uint)((endRad - startRad) / radianInterval);


            for (var i = 0; i <= tickCount; i++)
            {
                var pathGeometry = new PathGeometry();
                var figure       = new PathFigure();

                // draw tick line
                double x1     = MeterRadius * Math.Sin(startAngle),
                       y1     = MeterRadius * Math.Cos(startAngle),
                       x2     = (MeterRadius + tickLength) * Math.Sin(startAngle),
                       y2     = (MeterRadius + tickLength) * Math.Cos(startAngle),
                       labelX = (MeterRadius + LabelOffset + (tickLength / 2)) * Math.Sin(startAngle),
                       labelY = (MeterRadius + LabelOffset + (tickLength / 2)) * Math.Cos(startAngle);

                figure.StartPoint = new Point(Radius + x1, Radius - y1);

                var line = new LineSegment
                {
                    Point = new Point(Radius + x2, Radius - y2)
                };

                MeterTickPoints?.Add(new TickPoint()
                {
                    // midway point in the tick - the point the tick crosses the meter circle
                    Point      = new Point(Radius + (MeterRadius * Math.Sin(startAngle)), Radius - (MeterRadius * Math.Cos(startAngle))),
                    LabelPoint = new Point(Radius + labelX, Radius - labelY),
                    Value      = i * interval.TickInterval + interval.StartValue
                });

                figure.Segments.Add(line);
                pathGeometry.Figures.Add(figure);
                group.Children.Add(pathGeometry);
                startAngle += radianInterval;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws an interval for the meter
        /// </summary>
        /// <param name="interval">The MeterRangeInteraval which represents this range of the meter</param>
        /// <param name="tickLength">The length of the ticks for this range</param>
        /// <param name="group">The geometry group to add this to add this to</param>
        /// <param name="startAngle"></param>
        private void DrawInterval(MeterRangeInterval interval, double tickLength, GeometryGroup group, double startAngle = 0.0)
        {
            double startRad = interval.StartDegree*(Math.PI/180), endRad = interval.EndDegree*(Math.PI/180);
            double radianInterval = (endRad - startRad) * (interval.TickInterval / (interval.EndValue - interval.StartValue));
            var tickCount = (uint)((endRad - startRad)/ radianInterval);

            for (var i = 0; i <= tickCount; i++)
            {
                var pathGeometry = new PathGeometry();
                var figure = new PathFigure();

                // draw tick line
                double x1 = MeterRadius * Math.Sin(startAngle),
                       y1 = MeterRadius * Math.Cos(startAngle),
                       x2 = (MeterRadius + tickLength) * Math.Sin(startAngle),
                       y2 = (MeterRadius + tickLength) * Math.Cos(startAngle),
                       labelX = (MeterRadius + LabelOffset + (tickLength / 2)) * Math.Sin(startAngle),
                       labelY = (MeterRadius + LabelOffset + (tickLength / 2)) * Math.Cos(startAngle);

                figure.StartPoint = new Point(Radius + x1, Radius - y1);

                var line = new LineSegment
                {
                    Point = new Point(Radius + x2, Radius - y2)
                };

                MeterTickPoints?.Add(new TickPoint() {
                    // midway point in the tick - the point the tick crosses the meter circle
                    Point = new Point(Radius + (MeterRadius * Math.Sin(startAngle)), Radius - (MeterRadius * Math.Cos(startAngle))),
                    LabelPoint = new Point(Radius + labelX, Radius - labelY),
                    Value = i * interval.TickInterval + interval.StartValue
                });

                figure.Segments.Add(line);
                pathGeometry.Figures.Add(figure);
                group.Children.Add(pathGeometry);
                startAngle += radianInterval;
            }
        }