Proposal: Bar Chart API #1
hdralexandru
started this conversation in
Ideas
Replies: 1 comment
-
We should take into account this comment here as well. |
Beta Was this translation helpful? Give feedback.
0 replies
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
📢 Place of discussion for the Bar's Chart API.
See the current proposal beneath. React with 👍🏻 if you like it or with 👎🏻 if you don't.
If you 👎🏻 the API, please specify why and suggest an alternative.
The API
We are suggesting the following approach
BarChart
See A Complete Guide to Bar Charts for more info about bar charts.
modifier: Modifier
The
Modifier
object from compose, used for customizing the behaviour of this composable.data: List <Bar>
Bar
is a data class that gives us the information to show.DataLabel is a
value class
, used for displaying the labels. For vertical bar charts, they are the labels displayed on the X axisyAxisInterval: AxisInterval
The AxisInterval class gives us the min and max values of the ax. We use it in order to compute where a point should be in our chart.
We use the following formula:
Let:
cy
be the maximum space we have for drawing on the Y axis (vertically)curr
be the current value we have to draw on the screenmax
= AxisInterval.maxmin
= AxisInterval.minWe assume that
min <= curr <= max
.Having those conditions set, the point P where the
curr
value is represented on the screen will be deducted using the following formula:verticalLabels: List<ValueLable>
Same as
DataLabel
,ValueLabel
is avalue class
that defines the label that will be displayed on the Y axis (in this case)labelStyle: TextStyle
The TextStyle we'll be using for drawing the labels
axisStyle: AxisStyle
The style used for drawing the axis.
backgroundStyles: List<BackgroundStyle>
Across the many examples we've seen of BarCharts, there were different kind of background: gradients, horizontal lines or grid.
The user will decide what style to apply, by passing a list of
BackgroundStyle
barColor: List<Color>
The user will provide a list of colors, used for drawing the bars.
The list should have the same size as
data
. We'll be using the index to determine the colorStackedBarChart
See A Complete Guide to Stacked Bar Charts for more info about stacked bar charts.
The api is mostly the same, with a few exceptions.
data: List<BarEntrySet>
Just like a key-value, we use
dataLabel
to determine what set of data is being represented.barColor: Map<DataLabel, Color>
We use the
DataLabel
from theBarEntrySet
to determine what color to use for a bar.The number of keys in this map should be equal to the number of entries in
BarEntrySet.bars
GroupedBarChart
The api is the same as in StackedBarChart
Beta Was this translation helpful? Give feedback.
All reactions