chore(format) add formatting for examples & demos, merge test config
This commit is contained in:
@@ -2,10 +2,9 @@
|
||||
#if LV_USE_CHART && LV_DRAW_COMPLEX && LV_BUILD_EXAMPLES
|
||||
|
||||
/* A struct is used to keep track of the series list because later we need to draw to the series in the reverse order to which they were initialised. */
|
||||
typedef struct
|
||||
{
|
||||
lv_obj_t *obj;
|
||||
lv_chart_series_t *series_list[3];
|
||||
typedef struct {
|
||||
lv_obj_t * obj;
|
||||
lv_chart_series_t * series_list[3];
|
||||
} stacked_area_chart_t;
|
||||
|
||||
static stacked_area_chart_t stacked_area_chart;
|
||||
@@ -13,20 +12,20 @@ static stacked_area_chart_t stacked_area_chart;
|
||||
/**
|
||||
* Callback which draws the blocks of colour under the lines
|
||||
**/
|
||||
static void draw_event_cb(lv_event_t *e)
|
||||
static void draw_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t *obj = lv_event_get_target(e);
|
||||
lv_obj_t * obj = lv_event_get_target(e);
|
||||
|
||||
/*Add the faded area before the lines are drawn*/
|
||||
lv_obj_draw_part_dsc_t *dsc = lv_event_get_draw_part_dsc(e);
|
||||
if (dsc->part == LV_PART_ITEMS)
|
||||
{
|
||||
if (!dsc->p1 || !dsc->p2)
|
||||
lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e);
|
||||
if(dsc->part == LV_PART_ITEMS) {
|
||||
if(!dsc->p1 || !dsc->p2)
|
||||
return;
|
||||
|
||||
/*Add a line mask that keeps the area below the line*/
|
||||
lv_draw_mask_line_param_t line_mask_param;
|
||||
lv_draw_mask_line_points_init(&line_mask_param, dsc->p1->x, dsc->p1->y, dsc->p2->x, dsc->p2->y, LV_DRAW_MASK_LINE_SIDE_BOTTOM);
|
||||
lv_draw_mask_line_points_init(&line_mask_param, dsc->p1->x, dsc->p1->y, dsc->p2->x, dsc->p2->y,
|
||||
LV_DRAW_MASK_LINE_SIDE_BOTTOM);
|
||||
int16_t line_mask_id = lv_draw_mask_add(&line_mask_param, NULL);
|
||||
|
||||
/*Draw a rectangle that will be affected by the mask*/
|
||||
@@ -39,7 +38,8 @@ static void draw_event_cb(lv_event_t *e)
|
||||
a.x1 = dsc->p1->x;
|
||||
a.x2 = dsc->p2->x;
|
||||
a.y1 = LV_MIN(dsc->p1->y, dsc->p2->y);
|
||||
a.y2 = obj->coords.y2 - 13; /* -13 cuts off where the rectangle draws over the chart margin. Without this an area of 0 doesn't look like 0 */
|
||||
a.y2 = obj->coords.y2 -
|
||||
13; /* -13 cuts off where the rectangle draws over the chart margin. Without this an area of 0 doesn't look like 0 */
|
||||
lv_draw_rect(dsc->draw_ctx, &draw_rect_dsc, &a);
|
||||
|
||||
/*Remove the mask*/
|
||||
@@ -55,8 +55,7 @@ static int32_t round_fixed_point(int32_t n, int8_t shift)
|
||||
{
|
||||
/* Create a bitmask to isolates the decimal part of the fixed point number */
|
||||
int32_t mask = 1;
|
||||
for (int32_t bit_pos = 0; bit_pos < shift; bit_pos++)
|
||||
{
|
||||
for(int32_t bit_pos = 0; bit_pos < shift; bit_pos++) {
|
||||
mask = (mask << 1) + 1;
|
||||
}
|
||||
|
||||
@@ -83,19 +82,21 @@ void lv_example_chart_8(void)
|
||||
lv_obj_add_event_cb(stacked_area_chart.obj, draw_event_cb, LV_EVENT_DRAW_PART_BEGIN, NULL);
|
||||
|
||||
/* Set range to 0 to 100 for percentages. Draw ticks */
|
||||
lv_chart_set_range(stacked_area_chart.obj,LV_CHART_AXIS_PRIMARY_Y,0,100);
|
||||
lv_chart_set_range(stacked_area_chart.obj, LV_CHART_AXIS_PRIMARY_Y, 0, 100);
|
||||
lv_chart_set_axis_tick(stacked_area_chart.obj, LV_CHART_AXIS_PRIMARY_Y, 3, 0, 5, 1, true, 30);
|
||||
|
||||
/*Set point size to 0 so the lines are smooth */
|
||||
lv_obj_set_style_size(stacked_area_chart.obj, 0, LV_PART_INDICATOR);
|
||||
|
||||
/*Add some data series*/
|
||||
stacked_area_chart.series_list[0] = lv_chart_add_series(stacked_area_chart.obj, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y);
|
||||
stacked_area_chart.series_list[1] = lv_chart_add_series(stacked_area_chart.obj, lv_palette_main(LV_PALETTE_BLUE), LV_CHART_AXIS_PRIMARY_Y);
|
||||
stacked_area_chart.series_list[2] = lv_chart_add_series(stacked_area_chart.obj, lv_palette_main(LV_PALETTE_GREEN), LV_CHART_AXIS_PRIMARY_Y);
|
||||
stacked_area_chart.series_list[0] = lv_chart_add_series(stacked_area_chart.obj, lv_palette_main(LV_PALETTE_RED),
|
||||
LV_CHART_AXIS_PRIMARY_Y);
|
||||
stacked_area_chart.series_list[1] = lv_chart_add_series(stacked_area_chart.obj, lv_palette_main(LV_PALETTE_BLUE),
|
||||
LV_CHART_AXIS_PRIMARY_Y);
|
||||
stacked_area_chart.series_list[2] = lv_chart_add_series(stacked_area_chart.obj, lv_palette_main(LV_PALETTE_GREEN),
|
||||
LV_CHART_AXIS_PRIMARY_Y);
|
||||
|
||||
for (int point = 0; point < 10; point++)
|
||||
{
|
||||
for(int point = 0; point < 10; point++) {
|
||||
/* Make some random data */
|
||||
uint32_t vals[3] = {lv_rand(10, 20), lv_rand(20, 30), lv_rand(20, 30)};
|
||||
|
||||
@@ -106,8 +107,7 @@ void lv_example_chart_8(void)
|
||||
uint32_t decimal_sum = 0;
|
||||
|
||||
/* Fixed point cascade rounding ensures percentages add to 100 */
|
||||
for (int32_t series_index = 0; series_index < 3; series_index++)
|
||||
{
|
||||
for(int32_t series_index = 0; series_index < 3; series_index++) {
|
||||
decimal_sum += (((vals[series_index] * 100) << fixed_point_shift) / total);
|
||||
int_sum += (vals[series_index] * 100) / total;
|
||||
|
||||
@@ -120,7 +120,8 @@ void lv_example_chart_8(void)
|
||||
/* Draw to the series in the reverse order to which they were initialised.
|
||||
Without this the higher values will draw on top of the lower ones.
|
||||
This is because the Z-height of a series matches the order it was initialised */
|
||||
lv_chart_set_next_value(stacked_area_chart.obj, stacked_area_chart.series_list[3 - series_index - 1], draw_heights[series_index]);
|
||||
lv_chart_set_next_value(stacked_area_chart.obj, stacked_area_chart.series_list[3 - series_index - 1],
|
||||
draw_heights[series_index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user