Represents a single curve in the radar/spider chart.
示例#1
0
 public SpiderChartPanel()
 {
     MouseDown += OnMouseDown;
     MouseMove += OnMouseMove;
     MouseUp += (sender, args) => nearestLine = null;
     TouchDown += (sender, args) =>
                      {
                          if (!IsInteractive) return;
                          var device = args.Device as TouchDevice;
                          if (device == null) return;
                          device.Updated += DeviceOnUpdated;
                      };
     TouchUp += (sender, args) =>
                    {
                        if (!IsInteractive) return;
                        var device = args.Device as TouchDevice;
                        if (device == null) return;
                        capturedLines.Remove(device.Id);
                        device.Updated -= DeviceOnUpdated;
                    };
 }
示例#2
0
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton != MouseButtonState.Pressed || !IsInteractive) return;
            var position = e.GetPosition(this);

            var smallestDistance = double.MaxValue;
            var nearestIndexOnLine = -1;
            var scale = Maximum - Minimum;
            double angle;
            if (nearestLine == null)
                foreach (var line in Lines.Where(k=>k.CanEdit))
                {
                    for (var j = 0; j < line.PointDataSource.Count; j++)
                    {
                        angle = j*deltaAngle;
                        var curRadius = minRadius + (line.PointDataSource[j] - Minimum)*deltaRadius/scale;
                        var p2 = GetPoint(center, curRadius, angle);
                        var dist = Distance(p2, position);
                        if (dist > InteractivePointRadius || dist > smallestDistance) continue;
                        smallestDistance = dist;
                        nearestLine = line;
                        nearestIndexOnLine = j;
                    }
                }
            else
            {
                var line = nearestLine;
                for (var j = 0; j < line.PointDataSource.Count; j++)
                {
                    angle = j * deltaAngle;
                    var curRadius = minRadius + (line.PointDataSource[j] - Minimum) * deltaRadius / scale;
                    var p2 = GetPoint(center, curRadius, angle);
                    var dist = Distance(p2, position);
                    if (dist > InteractivePointRadius || dist > smallestDistance) continue;
                    smallestDistance = dist;
                    nearestIndexOnLine = j;
                }

            }

            if (nearestIndexOnLine < 0 || nearestLine == null) return;
            ComputeNewValue(position, nearestIndexOnLine);
        }
示例#3
0
        //public event ValuesChangedEventHandler ValuesChanged;

        //public void OnValuesChanged(string name, List<double> values)
        //{
        //    var handler = ValuesChanged;
        //    if (handler != null) handler(this, new ValuesChangedEventArgs(name, values));
        //}

        private void DeviceOnUpdated(object sender, EventArgs e)
        {
            var device = sender as TouchDevice;
            if (device == null) return;
            var position = device.GetTouchPoint(this).Position;
            var smallestDistance = double.MaxValue;
            var nearestIndexOnLine = -1;
            var scale = Maximum - Minimum;
            double angle;
            nearestLine = capturedLines.ContainsKey(device.Id)
                                       ? capturedLines[device.Id]
                                       : null;
            if (nearestLine == null)
                foreach (var line in Lines)
                {
                    for (var j = 0; j < line.PointDataSource.Count; j++)
                    {
                        angle = j * deltaAngle;
                        var curRadius = minRadius + (line.PointDataSource[j] - Minimum) * deltaRadius / scale;
                        var p2 = GetPoint(center, curRadius, angle);
                        var dist = Distance(p2, position);
                        if (dist > InteractivePointRadius || dist > smallestDistance) continue;
                        smallestDistance = dist;
                        nearestLine = capturedLines[device.Id] = line;
                        nearestIndexOnLine = j;
                    }
                }
            else
            {
                var line = nearestLine;
                for (var j = 0; j < line.PointDataSource.Count; j++)
                {
                    angle = j * deltaAngle;
                    var curRadius = minRadius + (line.PointDataSource[j] - Minimum) * deltaRadius / scale;
                    var p2 = GetPoint(center, curRadius, angle);
                    var dist = Distance(p2, position);
                    if (dist > InteractivePointRadius || dist > smallestDistance) continue;
                    smallestDistance = dist;
                    nearestIndexOnLine = j;
                }
            }

            if (nearestIndexOnLine < 0 || nearestLine == null) return;
            ComputeNewValue(position, nearestIndexOnLine);
        }