protected override Primitives.VisualItem CreateItem( Primitives.BoundsMarker marker )
        {
            Primitives.Path rect = new Primitives.Path();

            rect.Add( new Primitives.Path.Move( marker.Rectangle.TopLeft ) );
            rect.Add( new Primitives.Path.Line( marker.Rectangle.TopRight ) );
            rect.Add( new Primitives.Path.Line( marker.Rectangle.BottomRight ) );
            rect.Add( new Primitives.Path.Line( marker.Rectangle.BottomLeft ) );
            rect.Add( new Primitives.Path.Line( marker.Rectangle.TopLeft ) );
            rect.Add( new Primitives.Path.Close() );

            return rect;
        }
Example #2
0
        public Primitives.Path Create( double x, double y, double width, double height )
        {
            Primitives.Path path = new Primitives.Path();

            path.Add( new Primitives.Path.Move( new Types.Point( x, y ) ) );
            path.Add( new Primitives.Path.Line( new Types.Point( x + width, y ) ) );
            path.Add( new Primitives.Path.Line( new Types.Point( x + width, y + height ) ) );
            path.Add( new Primitives.Path.Line( new Types.Point( x, y + height ) ) );
            path.Add( new Primitives.Path.Line( new Types.Point( x, y ) ) );
            path.Add( new Primitives.Path.Close() );

            return path;
        }
Example #3
0
        public Primitives.Path Create( double x, double y, double width, double height )
        {
            Primitives.Path path = new Primitives.Path();

            path.Add( new Primitives.Path.Move( new Types.Point( x + width / 2, y ) ) );
            path.Add( new Primitives.Path.EllipticalArc( width / 2, height / 2, 0, false, true, new Types.Point( x + width, y + height / 2 ) ) );
            path.Add( new Primitives.Path.EllipticalArc( width / 2, height / 2, 0, false, true, new Types.Point( x + width / 2, y + height ) ) );
            path.Add( new Primitives.Path.EllipticalArc( width / 2, height / 2, 0, false, true, new Types.Point( x, y + height / 2 ) ) );
            path.Add( new Primitives.Path.EllipticalArc( width / 2, height / 2, 0, false, true, new Types.Point( x + width / 2, y ) ) );

            path.Add( new Primitives.Path.Close() );

            return path;
        }
Example #4
0
        public Primitives.Path Create( double x, double y, double width, double height, double radius, Corners corners )
        {
            bool topLeft = (corners & Corners.TopLeft) != 0;
            bool topRight = (corners & Corners.TopRight) != 0;
            bool bottomLeft = (corners & Corners.BottomLeft) != 0;
            bool bottomRight = (corners & Corners.BottomRight) != 0;

            Primitives.Path path = new Primitives.Path();

            path.Add( new Primitives.Path.Move( new Types.Point( x + (topLeft ? radius : 0), y ) ) );
            path.Add( new Primitives.Path.Line( new Types.Point( x + width - (topRight ? radius : 0), y ) ) );

            if( topRight )
            {
                path.Add( new Primitives.Path.EllipticalArc( radius, radius, 0, false, true, new Types.Point( x + width, y + radius ) ) );
            }

            path.Add( new Primitives.Path.Line( new Types.Point( x + width, y + height - (bottomRight ? radius : 0) ) ) );

            if( bottomRight )
            {
                path.Add( new Primitives.Path.EllipticalArc( radius, radius, 0, false, true, new Types.Point( x + width - radius, y + height ) ) );
            }

            path.Add( new Primitives.Path.Line( new Types.Point( x + (bottomLeft ? radius : 0), y + height ) ) );

            if( bottomLeft )
            {
                path.Add( new Primitives.Path.EllipticalArc( radius, radius, 0, false, true, new Types.Point( x, y + height - radius ) ) );
            }

            path.Add( new Primitives.Path.Line( new Types.Point( x, y + (topLeft ? radius : 0) ) ) );

            if( topLeft )
            {
                path.Add( new Primitives.Path.EllipticalArc( radius, radius, 0, false, true, new Types.Point( x + radius, y ) ) );
            }

            path.Add( new Primitives.Path.Close() );

            return path;
        }
Example #5
0
        private Primitives.Path CreateSlice( int index, int count, double start, double sweep, double radius, double move )
        {
            Primitives.Path path = new Primitives.Path();

            double cx = Math.Sin( start + sweep / 2 ) * move, cy = -Math.Cos( start + sweep / 2 ) * move;

            double sx = Math.Sin( start ) * radius, sy = -Math.Cos( start ) * radius;
            double ex = Math.Sin( start + sweep ) * radius, ey = -Math.Cos( start + sweep ) * radius;

            path.Add( new Primitives.Path.Move( new Types.Point( cx, cy ) ) );
            path.Add( new Primitives.Path.Line( new Types.Point( cx + sx, cy + sy ) ) );
            path.Add( new Primitives.Path.EllipticalArc( radius, radius, 0, (sweep > Math.PI), true, new Types.Point( cx + ex, cy + ey ) ) );
            path.Add( new Primitives.Path.Line( new Types.Point( cx, cy ) ) );
            path.Add( new Primitives.Path.Close() );

            path.Style.Add( "GraphPiece" );
            path.Style.AddExtra( "RowIndex", index.ToString() );
            path.Style.AddExtra( "RowCount", count.ToString() );

            return path;
        }
Example #6
0
        public override Primitives.Path FlattenPath( Primitives.Path source )
        {
            PathCommandVisitor visitor = new PathCommandVisitor();

            foreach( Primitives.Path.Command pathCommand in source.Commands )
            {
                pathCommand.Visit( visitor );
            }

            using( GraphicsPath gp = visitor.GetGraphicsPath() )
            {
                gp.Flatten();

                PointF lastPoint = PointF.Empty;

                Primitives.Path path = new Primitives.Path();

                path.Pen = source.Pen;
                path.Brush = source.Brush;

                for( int i = 0; i < gp.PointCount; ++i )
                {
                    PointF point = gp.PathPoints[i];
                    byte type = gp.PathTypes[i];
                    PointF nextPoint = point;

                    if( i < gp.PointCount - 1 && gp.PathTypes[i + 1] == 1 )
                    {
                        nextPoint = gp.PathPoints[i + 1];
                    }

                    switch( type )
                    {
                        case 0:
                            {
                                path.Add( new Primitives.Path.Move( new Types.Point( point.X, point.Y ) ) );
                                break;
                            }
                        case 1:
                            {
                                bool first = (i == 0) || gp.PathTypes[i - 1] != 1;
                                bool last = (i == gp.PointCount - 1) || gp.PathTypes[i + 1] != 1;

                                if( first || last
                                    || Math.Sqrt( Math.Pow( point.X - lastPoint.X, 2 ) + Math.Pow( point.Y - lastPoint.Y, 2 ) ) > _accuracy
                                    || Math.Sqrt( Math.Pow( point.X - nextPoint.X, 2 ) + Math.Pow( point.Y - nextPoint.Y, 2 ) ) > _accuracy )
                                {
                                    path.Add( new Primitives.Path.Line( new Types.Point( point.X, point.Y ) ) );
                                    lastPoint = point;
                                }

                                break;
                            }
                        case 129:
                            {
                                path.Add( new Primitives.Path.Line( new Types.Point( point.X, point.Y ) ) );
                                path.Add( new Primitives.Path.Close() );
                                break;
                            }
                        default:
                            throw new InvalidOperationException();
                    }
                }

                return path;
            }
        }
Example #7
0
        public Primitives.Container Create( IData data, Settings settings )
        {
            if( data == null )
            {
                throw new ArgumentNullException( "data" );
            }
            if( settings == null )
            {
                throw new ArgumentNullException( "settings" );
            }
            if( data.ColumnCount < 2 )
            {
                throw new ArgumentException( "Line data must have at least two columns.", "data" );
            }

            Primitives.Container container = new Primitives.Container();

            Primitives.BoundsMarker bounds = new Primitives.BoundsMarker( new Types.Rectangle( 0, 0, settings.Width, settings.Height ) );

            bounds.Style.Add( "GraphContainer" );

            container.AddBack( bounds );

            Primitives.Container lines = new Primitives.Container();

            double minHorzData = double.MaxValue;
            double maxHorzData = double.MinValue;

            for( int i = 0; i < data.RowCount; ++i )
            {
                double v = data[i, 0];

                minHorzData = Math.Min( minHorzData, v );
                maxHorzData = Math.Max( maxHorzData, v );
            }

            double minVertData = double.MaxValue;
            double maxVertData = double.MinValue;

            for( int i = 0; i < data.RowCount; ++i )
            {
                for( int j = 1; j < data.ColumnCount; ++j )
                {
                    double v = data[i, j];

                    minVertData = Math.Min( minVertData, v );
                    maxVertData = Math.Max( maxVertData, v );
                }
            }

            if( maxVertData == minVertData )
            {
                maxVertData = minVertData + 1;
            }

            double maxExtent = Math.Max( settings.Width, settings.Height);
            double textHeight = 2;
            double border = 20;
            Types.Rectangle visibleArea = new Types.Rectangle( border, border, settings.Width - border * 2, settings.Height - border * 2 - textHeight );
            double zero = visibleArea.Bottom + minVertData / (maxVertData - minVertData) * visibleArea.Height;

            for( int col = 1; col < data.ColumnCount; ++col )
            {
                Primitives.Container line = new Primitives.Container();

                List<Types.Point> points = new List<Types.Point>();
                List<Primitives.Path.Command> pathCommands = new List<Primitives.Path.Command>();

                pathCommands.Add( new Primitives.Path.Move( new Types.Point( visibleArea.X, zero ) ) );

                for( int row = 0; row < data.RowCount; ++row )
                {
                    double y = data[row, col];
                    double x = data[row, 0];

                    x = visibleArea.X + (x - minHorzData) / (maxHorzData - minHorzData) * visibleArea.Width;
                    y = visibleArea.Bottom - (y - minVertData) / (maxVertData - minVertData) * visibleArea.Height;

                    Primitives.Path.Command pathCommand = new Primitives.Path.Line( new Types.Point( x, y ) );

                    pathCommands.Add( pathCommand );
                }

                pathCommands.Add( new Primitives.Path.Line( new Types.Point( visibleArea.Right, zero ) ) );
                pathCommands.Add( new Primitives.Path.Close() );

                Primitives.Path path = new Primitives.Path( pathCommands.ToArray() );

                path.Style.Add( "GraphPiece" );
                path.Style.AddExtra( "RowIndex", (col - 1).ToString() );
                path.Style.AddExtra( "RowCount", (data.ColumnCount - 1).ToString() );

                line.AddBack( path );

                lines.AddBack( line );
            }

            container.AddBack( lines );

            double available = settings.Height - visibleArea.Bottom;

            for( int i = 0; i < data.RowCount; ++i )
            {
                string label = data.GetRowExtra( i, "LABEL", null );

                if( label != null )
                {
                    double x = data[i, 0];

                    x = visibleArea.X + (x - minHorzData) / (maxHorzData - minHorzData) * visibleArea.Width;

                    Primitives.Text text = new Primitives.Text( label, new Types.Point( x, visibleArea.Bottom + available / 5 ), Primitives.Text.Position.TopCenter );

                    text.FontSizePoints = textHeight / 2;
                    text.Style.Add( "GraphText" );

                    container.AddBack( text );
                }
            }

            return container;
        }