Branch data Line data Source code
1 : : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 : : /*
3 : : * Copyright 2024 GNOME Foundation, Inc.
4 : : *
5 : : * This library is free software; you can redistribute it and/or
6 : : * modify it under the terms of the GNU Lesser General Public
7 : : * License as published by the Free Software Foundation; either
8 : : * version 2 of the License, or (at your option) any later version.
9 : : *
10 : : * This library is distributed in the hope that it will be useful,
11 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : : * Lesser General Public License for more details.
14 : : *
15 : : * You should have received a copy of the GNU Lesser General
16 : : * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 : : *
18 : : * Authors:
19 : : * - Philip Withnall <pwithnall@gnome.org>
20 : : *
21 : : * SPDX-License-Identifier: GPL-3.0-or-later
22 : : */
23 : :
24 : : #pragma once
25 : :
26 : : #include <glib-object.h>
27 : : #include <gtk/gtk.h>
28 : :
29 : : G_BEGIN_DECLS
30 : :
31 : : #define CC_TYPE_BAR_CHART (cc_bar_chart_get_type())
32 [ # # # # : 0 : G_DECLARE_FINAL_TYPE (CcBarChart, cc_bar_chart, CC, BAR_CHART, GtkWidget)
# # ]
33 : :
34 : : CcBarChart *cc_bar_chart_new (void);
35 : :
36 : : const char * const *cc_bar_chart_get_discrete_axis_labels (CcBarChart *self,
37 : : size_t *out_n_discrete_axis_labels);
38 : : void cc_bar_chart_set_discrete_axis_labels (CcBarChart *self,
39 : : const char * const *labels);
40 : :
41 : : /**
42 : : * CcBarChartLabelCallback:
43 : : * @chart: a #CcBarChart
44 : : * @value: value to represent as a label
45 : : * @user_data: user data passed to cc_bar_chart_set_continuous_axis_label_callback()
46 : : *
47 : : * Build a human readable textual label representing @value.
48 : : *
49 : : * @value comes from the same domain as the chart data, but might not be one of
50 : : * the chart data values — it might come from the #CcBarChartGridLineCallback,
51 : : * for example.
52 : : *
53 : : * The returned label may be used to label a point on the continuous axis of the
54 : : * chart.
55 : : *
56 : : * Typically a #CcBarChartLabelCallback will format @value to an appropriate
57 : : * precision and with an appropriate unit, as per the
58 : : * [SI Brochure](https://www.bipm.org/en/publications/si-brochure).
59 : : *
60 : : * Returns: (not nullable) (transfer full): human readable text form of @value
61 : : */
62 : : typedef char *(*CcBarChartLabelCallback) (CcBarChart *chart,
63 : : double value,
64 : : void *user_data);
65 : :
66 : : void cc_bar_chart_set_continuous_axis_label_callback (CcBarChart *self,
67 : : CcBarChartLabelCallback callback,
68 : : void *user_data,
69 : : GDestroyNotify destroy_notify);
70 : :
71 : : /**
72 : : * CcBarChartGridLineCallback:
73 : : * @chart: a #CcBarChart
74 : : * @idx: grid line index
75 : : * @user_data: user data passed to cc_bar_chart_set_continuous_axis_grid_line_callback()
76 : : *
77 : : * Generate the value of the @idx-th grid line.
78 : : *
79 : : * The return value is in the same domain as the chart data, but does not have
80 : : * to be one of the chart data values. The returned values must be monotonically
81 : : * increasing with @idx.
82 : : *
83 : : * This function is called repeatedly when laying out the chart, to generate the
84 : : * grid lines for the chart area. It is called with increasing values of @idx
85 : : * until the chart area layout is complete. @idx has no special meaning beyond
86 : : * being a generator index.
87 : : *
88 : : * Typically a #CcBarChartGridLineCallback will return @idx multiplied by the
89 : : * desired interval (in the data domain) between grid lines. Logarithmic graphs
90 : : * would return an exponential of @idx.
91 : : *
92 : : * Returns: @idx-th grid line value
93 : : */
94 : : typedef double (*CcBarChartGridLineCallback) (CcBarChart *chart,
95 : : unsigned int idx,
96 : : void *user_data);
97 : :
98 : : void cc_bar_chart_set_continuous_axis_grid_line_callback (CcBarChart *self,
99 : : CcBarChartGridLineCallback callback,
100 : : void *user_data,
101 : : GDestroyNotify destroy_notify);
102 : :
103 : : const double *cc_bar_chart_get_data (CcBarChart *self,
104 : : size_t *out_n_data);
105 : : void cc_bar_chart_set_data (CcBarChart *self,
106 : : const double *data,
107 : : size_t n_data);
108 : :
109 : : double cc_bar_chart_get_overlay_line_value (CcBarChart *self);
110 : : void cc_bar_chart_set_overlay_line_value (CcBarChart *self,
111 : : double value);
112 : :
113 : : gboolean cc_bar_chart_get_selected_index (CcBarChart *self,
114 : : size_t *out_index);
115 : : void cc_bar_chart_set_selected_index (CcBarChart *self,
116 : : gboolean is_selected,
117 : : size_t idx);
118 : :
119 : : G_END_DECLS
|