public Primitives.Container Create( IData data, Settings settings ) { if( data == null ) { throw new ArgumentNullException( "data" ); } if( settings == null ) { throw new ArgumentNullException( "settings" ); } 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 ); double minVertData = double.MaxValue; double maxVertData = double.MinValue; for( int i = 0; i < data.RowCount; ++i ) { for( int j = 0; j < data.ColumnCount; ++j ) { double v = data[i, j]; minVertData = Math.Min( minVertData, v ); maxVertData = Math.Max( maxVertData, v ); } } return container; }
public override Primitives.VisualItem Create( Primitives.Path source ) { Primitives.Container container = new Primitives.Container( _offset ); Primitives.Path shadow = (Primitives.Path) source.Copy(); shadow.Pen = null; shadow.Brush = new Paint.Brushes.SolidBrush( _color ); container.AddBack( shadow ); return container; }
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 != 1 ) { throw new ArgumentException( "Pie data must have exactly one column.", "data" ); } double cx = settings.Width / 2, cy = settings.Height / 2; double radius = Math.Min( cx * 0.8, cy * 0.8); double total = 0; for( int i = 0; i < data.RowCount; ++i ) { double v = data[i, 0]; if( v < 0 ) { v = 0; } total += v; } 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 pie = new Primitives.Container( new Types.Point( cx, cy ) ); double angle = 0; if( total > 0 ) { for( int r = 0; r < data.RowCount; ++r ) { double v = data[r, 0]; if( v < 0 ) { v = 0; } double sweep = 2 * Math.PI * v / total; bool exploded = bool.Parse( data.GetRowExtra( r, "Exploded", "false" ) ); pie.AddBack( CreateSlice( r, data.RowCount, angle, sweep, radius, exploded ? radius * 0.15 : 0 ) ); angle += sweep; } } container.AddBack( pie ); return container; }
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; }
private void Create() { Factories.Rectangle rectangleFactory = new Factories.Rectangle(); Factories.RoundedRectangle roundedRectangleFactory = new Factories.RoundedRectangle(); Factories.SoftShadow softShadowFactory = new Factories.SoftShadow( _renderer, new Types.Point( 2, 2 ), 4, new Paint.Color( 0, 0, 0, 0.4 ) ); Factories.GlossyBrush glossyBrush = new Factories.GlossyBrush(); Random random = new Random(); Styles.StyleSet style = new StyleSets.BlueAndWhite(); _container = new Primitives.Container(); // // Create pie chart. int pieParts = 5; Graphs.StaticData pieChartData = new Graphs.StaticData( pieParts, 1 ); for( int i = 0; i < pieParts; ++i ) { pieChartData[i, 0] = random.NextDouble(); } pieChartData.SetRowExtra( 2, "Exploded", "true" ); Graphs.PieChart.Settings pieChartSettings = new Graphs.PieChart.Settings(); pieChartSettings.Width = 200; pieChartSettings.Height = 200; Primitives.Container pieChartContainer = new Primitives.Container( new Types.Point( 10, 10 ) ); Graphs.PieChart pieChart = new Graphs.PieChart(); pieChartContainer.AddBack( pieChart.Create( pieChartData, pieChartSettings ) ); style.Apply( _renderer, pieChartContainer ); _container.AddBack( pieChartContainer ); // // Create bar chart. int barGroups = 5; int barParts = 3; Graphs.StaticData barChartData = new Graphs.StaticData( barGroups, barParts ); for( int i = 0; i < barGroups; ++i ) { for( int j = 0; j < barParts; ++j ) { barChartData[i, j] = random.NextDouble(); } } Graphs.BarChart.Settings barChartSettings = new Graphs.BarChart.Settings(); barChartSettings.Width = 200; barChartSettings.Height = 200; Primitives.Container barChartContainer = new Primitives.Container( new Types.Point( 220, 10 ) ); Graphs.BarChart barChart = new Graphs.BarChart(); barChartContainer.AddBack( barChart.Create( barChartData, barChartSettings ) ); style.Apply( _renderer, barChartContainer ); _container.AddBack( barChartContainer ); // // Create line chart. int lines = 2; int columns = 10; Graphs.StaticData lineChartData = new Graphs.StaticData( columns, lines + 1 ); for( int i = 0; i < columns; ++i ) { lineChartData[i, 0] = i; lineChartData.SetRowExtra( i, "LABEL", i.ToString() ); } for( int i = 1; i < lines + 1; ++i ) { for( int j = 0; j < columns; ++j ) { lineChartData[j, i] = random.NextDouble() - 0.5; } } Graphs.LineChart.Settings lineChartSettings = new Graphs.LineChart.Settings(); lineChartSettings.Width = 200; lineChartSettings.Height = 200; Primitives.Container lineChartContainer = new Primitives.Container( new Types.Point( 440, 10 ) ); Graphs.LineChart lineChart = new Graphs.LineChart(); lineChartContainer.AddBack( lineChart.Create( lineChartData, lineChartSettings ) ); style.Apply( _renderer, lineChartContainer ); _container.AddBack( lineChartContainer ); }