public void DrawGraph(DisplayParam disp_param, DisplayLayerParam[] layer_params) { if ((disp_param == null) || (disp_param.AxisX_Min == disp_param.AxisX_Max) ) { return; } DrawGraphDetails(disp_param, layer_params); }
private void DrawGraphDetails(DisplayParam disp_param, DisplayLayerParam[] layer_params) { var graph_rect = new Rectangle( disp_param.CanvasRect.Left + GRAPH_DETAILS_MARGIN.Left, disp_param.CanvasRect.Top + GRAPH_DETAILS_MARGIN.Top, disp_param.CanvasRect.Width - GRAPH_DETAILS_MARGIN.Horizontal, disp_param.CanvasRect.Height - GRAPH_DETAILS_MARGIN.Vertical); if ((graph_rect.Width > 0) && (graph_rect.Height > 0) && (disp_param.AxisX_Min < disp_param.AxisX_Max) && (disp_param.AxisY_Min < disp_param.AxisY_Max) ) { /* レイヤー描画 */ { var graphics_layer = BufferedGraphicsManager.Current.Allocate(disp_param.Canvas, graph_rect); /* 背景を初期化 */ graphics_layer.Graphics.FillRectangle(GRAPH_DETAILS_BG_BRUSH, graph_rect); /* グラフの線を描画 */ DrawGraphDetails_Grid(graphics_layer.Graphics, graph_rect, disp_param); /* グラフのデータを描画 */ for (var layer_index = (uint)0; layer_index < layer_params.Length; layer_index++) { DrawGraphDetails_Data( graphics_layer.Graphics, graph_rect, disp_param.AxisX_Min, disp_param.AxisX_Max, disp_param.AxisY_Min, disp_param.AxisY_Max, layer_index, layer_params[layer_index]); } /* グラフの枠を描画 */ DrawGraphDetails_Frame(graphics_layer.Graphics, graph_rect); graphics_layer.Render(disp_param.Canvas); graphics_layer.Dispose(); } } }
private void DrawGraphDetails_Grid(Graphics graphics, Rectangle graphics_rect, DisplayParam disp_param) { var draw_offset = 0; var draw_scale_rect = new Rectangle(); var draw_scale_format = new StringFormat(); /* --- X軸 --- */ draw_scale_rect.Width = graphics_rect.Width * GRID_X_LINES_MAIN / GRID_X_LINES; draw_scale_rect.Height = GRAPH_DETAILS_GRID_SCALE_FONT.Height; draw_scale_rect.X = graphics_rect.Left - draw_scale_rect.Width / 2; draw_scale_rect.Y = graphics_rect.Bottom; draw_scale_format.Alignment = StringAlignment.Center; draw_scale_format.LineAlignment = StringAlignment.Near; for (var index = 0; index <= GRID_X_LINES; index++) { draw_offset = graphics_rect.Left + graphics_rect.Width * index / GRID_X_LINES; /* 目盛(最右を0とする) */ if ((index % GRID_X_LINES_MAIN) == 0) { disp_param.Canvas.DrawString( (disp_param.AxisX_Min + index * ((disp_param.AxisX_Max - disp_param.AxisX_Min) / GRID_X_LINES) - PointCount).ToString(), GRAPH_DETAILS_GRID_SCALE_FONT, GRAPH_DETAILS_GRID_SCALE_BRUSH, draw_scale_rect, draw_scale_format); draw_scale_rect.X += draw_scale_rect.Width; } /* ライン */ if ((index > 0) && (index < GRID_X_LINES)) { graphics.DrawLine( ((index % 5) == 0) ? (GRAPH_DETAILS_GRID_LINE_MAIN_PEN) : (GRAPH_DETAILS_GRID_LINE_SUB_PEN), draw_offset, graphics_rect.Top, draw_offset, graphics_rect.Bottom); } } /* --- Y軸 --- */ draw_scale_rect.Width = GRAPH_DETAILS_MARGIN.Right; draw_scale_rect.Height = graphics_rect.Height * GRID_Y_LINES_MAIN / GRID_Y_LINES; draw_scale_rect.X = graphics_rect.Right; draw_scale_rect.Y = graphics_rect.Top - draw_scale_rect.Height / 2; draw_scale_format.Alignment = StringAlignment.Near; draw_scale_format.LineAlignment = StringAlignment.Center; for (var index = 0; index <= GRID_Y_LINES; index++) { draw_offset = graphics_rect.Top + graphics_rect.Height * index / GRID_Y_LINES; /* 目盛 */ if ((index % GRID_Y_LINES_MAIN) == 0) { disp_param.Canvas.DrawString( (disp_param.AxisY_Max - index * ((disp_param.AxisY_Max - disp_param.AxisY_Min) / GRID_Y_LINES)).ToString(), GRAPH_DETAILS_GRID_SCALE_FONT, GRAPH_DETAILS_GRID_SCALE_BRUSH, draw_scale_rect, draw_scale_format); draw_scale_rect.Y += draw_scale_rect.Height; } /* ライン */ if ((index > 0) && (index < GRID_Y_LINES)) { graphics.DrawLine( ((index % 5) == 0) ? (GRAPH_DETAILS_GRID_LINE_MAIN_PEN) : (GRAPH_DETAILS_GRID_LINE_SUB_PEN), graphics_rect.Left, draw_offset, graphics_rect.Right, draw_offset); } } }