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