GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_line_chart_data_draw.c Lines: 30 30 100.0 %
Date: 2026-03-06 19:21:09 Branches: 8 8 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
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
/**************************************************************************/
68
1452
VOID _gx_line_chart_data_draw(GX_LINE_CHART *chart)
69
{
70
INT                 x_pos;
71
INT                 last_x_pos;
72
INT                 x_step;
73
INT                 y_scale;
74
INT                 y_pos;
75
INT                 index;
76
INT                 last_y_pos;
77
GX_RECTANGLE        chart_bound;
78
GX_LINE_CHART_INFO *chart_info;
79
80
1452
    chart_info = &chart -> gx_line_chart_info;
81
82
1452
    if (chart_info -> gx_line_chart_active_data_count <= 0 ||
83
36
        chart_info -> gx_line_chart_data == GX_NULL)
84
    {
85
1417
        return;
86
    }
87
88
35
    chart_bound = chart -> gx_widget_size;
89
35
    chart_bound.gx_rectangle_left = (GX_VALUE)(chart_bound.gx_rectangle_left + chart_info -> gx_line_chart_left_margin);
90
35
    chart_bound.gx_rectangle_top = (GX_VALUE)(chart_bound.gx_rectangle_top + chart_info -> gx_line_chart_top_margin);
91
35
    chart_bound.gx_rectangle_right = (GX_VALUE)(chart_bound.gx_rectangle_right - chart_info -> gx_line_chart_right_margin);
92
35
    chart_bound.gx_rectangle_bottom = (GX_VALUE)(chart_bound.gx_rectangle_bottom - chart_info -> gx_line_chart_bottom_margin);
93
94
35
    x_step = chart_bound.gx_rectangle_right - chart_bound.gx_rectangle_left - chart_info -> gx_line_chart_axis_line_width;
95
35
    x_step = GX_FIXED_VAL_MAKE(x_step);
96
97
35
    if (chart_info -> gx_line_chart_max_data_count > 0)
98
    {
99
33
        x_step /= chart_info -> gx_line_chart_max_data_count;
100
    }
101
35
    last_x_pos = GX_FIXED_VAL_MAKE(chart_bound.gx_rectangle_left + chart_info -> gx_line_chart_axis_line_width + 1);
102
103
35
    _gx_line_chart_y_scale_calculate(chart, &y_scale);
104
105
35
    last_y_pos = chart_info -> gx_line_chart_data[0] - chart_info -> gx_line_chart_min_val;
106
35
    last_y_pos *= y_scale;
107
35
    last_y_pos = (INT)(chart_bound.gx_rectangle_bottom) - GX_FIXED_VAL_TO_INT(last_y_pos);
108
109
35
    _gx_context_brush_width_set((UINT)(chart_info -> gx_line_chart_data_line_width));
110
35
    _gx_context_brush_define(chart_info -> gx_line_chart_line_color, chart_info -> gx_line_chart_line_color, GX_BRUSH_ALIAS | GX_BRUSH_ROUND);
111
112
1492
    for (index = 1; index < chart_info -> gx_line_chart_active_data_count; index++)
113
    {
114
1457
        y_pos = chart_info -> gx_line_chart_data[index] - chart_info -> gx_line_chart_min_val;
115
1457
        y_pos *= y_scale;
116
1457
        y_pos = chart_bound.gx_rectangle_bottom - GX_FIXED_VAL_TO_INT(y_pos);
117
118
1457
        x_pos = last_x_pos + x_step;
119
1457
        _gx_canvas_line_draw((GX_VALUE)(GX_FIXED_VAL_TO_INT(last_x_pos)), (GX_VALUE)last_y_pos,
120
1457
                             (GX_VALUE)(GX_FIXED_VAL_TO_INT(x_pos)), (GX_VALUE)y_pos);
121
1457
        last_x_pos = x_pos;
122
1457
        last_y_pos = y_pos;
123
    }
124
}
125