1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   Line Chart Management (Line Chart)                                  */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_context.h"
29 #include "gx_canvas.h"
30 #include "gx_window.h"
31 #include "gx_line_chart.h"
32 
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _gx_line_chart_data_draw                            PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Kenneth Maxwell, Microsoft Corporation                              */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function draws the chart data line                             */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    chart                                 Line chart                    */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    None                                                                */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _gx_line_chart_y_scale_calculate                                    */
59 /*    _gx_context_brush_width_set                                         */
60 /*    _gx_context_brush_define                                            */
61 /*    _gx_canvas_line_draw                                                */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Application Code                                                    */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
72 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_gx_line_chart_data_draw(GX_LINE_CHART * chart)76 VOID _gx_line_chart_data_draw(GX_LINE_CHART *chart)
77 {
78 INT                 x_pos;
79 INT                 last_x_pos;
80 INT                 x_step;
81 INT                 y_scale;
82 INT                 y_pos;
83 INT                 index;
84 INT                 last_y_pos;
85 GX_RECTANGLE        chart_bound;
86 GX_LINE_CHART_INFO *chart_info;
87 
88     chart_info = &chart -> gx_line_chart_info;
89 
90     if (chart_info -> gx_line_chart_active_data_count <= 0 ||
91         chart_info -> gx_line_chart_data == GX_NULL)
92     {
93         return;
94     }
95 
96     chart_bound = chart -> gx_widget_size;
97     chart_bound.gx_rectangle_left = (GX_VALUE)(chart_bound.gx_rectangle_left + chart_info -> gx_line_chart_left_margin);
98     chart_bound.gx_rectangle_top = (GX_VALUE)(chart_bound.gx_rectangle_top + chart_info -> gx_line_chart_top_margin);
99     chart_bound.gx_rectangle_right = (GX_VALUE)(chart_bound.gx_rectangle_right - chart_info -> gx_line_chart_right_margin);
100     chart_bound.gx_rectangle_bottom = (GX_VALUE)(chart_bound.gx_rectangle_bottom - chart_info -> gx_line_chart_bottom_margin);
101 
102     x_step = chart_bound.gx_rectangle_right - chart_bound.gx_rectangle_left - chart_info -> gx_line_chart_axis_line_width;
103     x_step = GX_FIXED_VAL_MAKE(x_step);
104 
105     if (chart_info -> gx_line_chart_max_data_count > 0)
106     {
107         x_step /= chart_info -> gx_line_chart_max_data_count;
108     }
109     last_x_pos = GX_FIXED_VAL_MAKE(chart_bound.gx_rectangle_left + chart_info -> gx_line_chart_axis_line_width + 1);
110 
111     _gx_line_chart_y_scale_calculate(chart, &y_scale);
112 
113     last_y_pos = chart_info -> gx_line_chart_data[0] - chart_info -> gx_line_chart_min_val;
114     last_y_pos *= y_scale;
115     last_y_pos = (INT)(chart_bound.gx_rectangle_bottom) - GX_FIXED_VAL_TO_INT(last_y_pos);
116 
117     _gx_context_brush_width_set((UINT)(chart_info -> gx_line_chart_data_line_width));
118     _gx_context_brush_define(chart_info -> gx_line_chart_line_color, chart_info -> gx_line_chart_line_color, GX_BRUSH_ALIAS | GX_BRUSH_ROUND);
119 
120     for (index = 1; index < chart_info -> gx_line_chart_active_data_count; index++)
121     {
122         y_pos = chart_info -> gx_line_chart_data[index] - chart_info -> gx_line_chart_min_val;
123         y_pos *= y_scale;
124         y_pos = chart_bound.gx_rectangle_bottom - GX_FIXED_VAL_TO_INT(y_pos);
125 
126         x_pos = last_x_pos + x_step;
127         _gx_canvas_line_draw((GX_VALUE)(GX_FIXED_VAL_TO_INT(last_x_pos)), (GX_VALUE)last_y_pos,
128                              (GX_VALUE)(GX_FIXED_VAL_TO_INT(x_pos)), (GX_VALUE)y_pos);
129         last_x_pos = x_pos;
130         last_y_pos = y_pos;
131     }
132 }
133 
134