예제 #1
0
        /// <summary>
        /// Refresh and redraw the diagram
        /// </summary>
        public void Refresh()
        {
            MainCanvas.Children.Clear(); //Clear canvas

            if (SourceData != null)
            {
                // Size of the diagram (in canvas units):
                double radius = 100;

                NamedDataSet axisRanges = AxisRanges;
                if (axisRanges == null)
                {
                    axisRanges = SourceData.GetValueRanges();
                }
                if (MinimumAxisRange.IsValid)
                {
                    axisRanges.UnionAll(MinimumAxisRange);
                }

                //Draw axes:
                List <string> axes = SourceData.GetAllKeys().ToList();
                axes.Sort();

                for (int i = 0; i < axes.Count; i++)
                {
                    string axisName = axes[i];
                    double angle    = ((double)i) * (Math.PI * 2 / axes.Count);
                    Line   axis     = new Line();
                    axis.X2              = Math.Sin(angle) * radius;
                    axis.Y2              = -Math.Cos(angle) * radius;
                    axis.Stroke          = Brushes.Black;
                    axis.StrokeThickness = 1;
                    axis.Opacity         = 0.6;
                    axis.ToolTip         = axisName;

                    MainCanvas.Children.Add(axis);

                    TextBlock tB = new TextBlock();
                    tB.Text     = axisName;
                    tB.Width    = radius - 3;
                    tB.FontSize = LabelFontSize;
                    if (angle <= Math.PI)
                    {
                        tB.TextAlignment = TextAlignment.Right;
                        var rTrans = new RotateTransform(angle * 180 / Math.PI - 90);
                        rTrans.CenterX     = 0;
                        rTrans.CenterY     = 0;
                        tB.RenderTransform = rTrans;
                    }
                    else
                    {
                        Canvas.SetRight(tB, 0);
                        tB.TextAlignment = TextAlignment.Left;
                        var rTrans = new RotateTransform(angle * 180 / Math.PI + 90);
                        rTrans.CenterX     = radius - 3;
                        rTrans.CenterY     = 0;
                        tB.RenderTransform = rTrans;
                    }
                    tB.Opacity = 0.8;
                    tB.ToolTip = axisName;

                    MainCanvas.Children.Add(tB);
                }

                // Draw map:

                foreach (NamedDataSet dataSet in SourceData)
                {
                    Polygon pgon  = new Polygon();
                    Color   color = ToWPF.Convert(dataSet.Colour.CapBrightness(ColourBrightnessCap));
                    pgon.Stroke          = new SolidColorBrush(color);
                    pgon.StrokeThickness = 2;
                    pgon.StrokeLineJoin  = PenLineJoin.Bevel;
                    Color outColor = color;
                    Color inColor  = color;
                    outColor.A = 100;
                    inColor.A  = 100;
                    var fill = new RadialGradientBrush(inColor, outColor);
                    fill.Opacity = FillOpacity;
                    pgon.Fill    = fill;
                    pgon.Opacity = 0.95;
                    pgon.ToolTip = dataSet.Name;
                    PointCollection outerPts = new PointCollection();
                    PointCollection innerPts = new PointCollection();
                    bool            hollow   = false;

                    for (int i = 0; i < axes.Count; i++)
                    {
                        string axisName = axes[i];
                        double angle    = ((double)i) * (Math.PI * 2 / axes.Count);

                        double value  = 0;
                        double value2 = 0;

                        if (dataSet.Data.ContainsKey(axisName))
                        {
                            Interval range;
                            if (axisRanges.Data.ContainsKey(axisName))
                            {
                                range = axisRanges.Data[axisName];
                            }
                            else
                            {
                                range = new Interval(0, 1.0);
                            }
                            if (range.IsSingularity)
                            {
                                range = new Interval(range.Start - 0.1, range.End);
                            }

                            Interval data = dataSet.Data[axisName];
                            value  = range.ParameterOf(data.End) * radius;
                            value2 = range.ParameterOf(data.Start) * radius;
                            if (value2 > 0.001)
                            {
                                hollow = true;
                            }
                        }

                        Point point = new Point(Math.Sin(angle) * value, -Math.Cos(angle) * value);
                        outerPts.Add(point);
                        Point point2 = new Point(Math.Sin(angle) * value2, -Math.Cos(angle) * value2);
                        innerPts.Add(point2);
                    }
                    pgon.Points = outerPts;
                    //TODO: Include 'hollow' polygons that have minimum values

                    MainCanvas.Children.Add(pgon);
                }
            }
        }