-
Notifications
You must be signed in to change notification settings - Fork 408
Bars
To work with single bars, it's possible to use ChartBarsLayer
as well as ChartPointsViewsLayer
. It's of course recommended to use the dedicated bars layers but you may find situations sometimes where you need more flexibility and decide to create them just as generic views, using ChartPointsViewsLayer
.
Bars example uses custom views instead of a dedicated bars layer just for demonstrative purposes. Bars +/- example uses a dedicated bars layer, to which it passes the +/- parts of the bars as individual bars (the gap in the middle is done by creating a white overlay using ChartPointsViewsLayer
:
We will focus here on the dedicated bar layers.
To pass bars to ChartBarsLayer
we use instances of ChartBarModel
. A bar model is defined by:
-
constant
: The domain value of the bar that doesn't change between top/bottom (or left/right). For a vertical bar this is the x domain coordinate, and for an horizontal bar this is the y domain coordinate. -
axisValue1
,axisValue2
: The first and last variable domain coordinate. For a left-to-right (horizontal) bar,axisValue1
is the "left" x value,axisValue2
is the right axis value, for a bottom-to-top (vertical) bar,axisValue1
is the "bottom" y value andaxisValue2
is the "top" y value.
Besides of the bars models and some other self explanatory parameters, we can pass following to bars layer:
-
tapHandler
: This will be called when a bar is tapped, passing all relevant information, including the bar's view, so you can highlight, animate it, show an info bubble next to it, etc. -
mode
: This defines how the bar views handle zooming - if they scale themselves or keep their size unchanged. Thecustom
mode is available but not supported for bars yet. For more details aboutmode
, see https://github.com/i-schuetz/SwiftCharts/wiki/View-hierarchy-and-transforms#chartpointsviewslayer-transform-modes (this is from a different layer but everything applies, exceptcustom
mode). -
viewGenerator
: This is in case you want to generate your own custom views for bars. This was added in0.6
, which makes the alternative usage ofChartPointsViewsLayer
to display bars in most cases unnecessary.
All the bar layers are focused only on displaying bars. To add labels you can use either a separate ChartPointsViewsLayer
, to which you have to pass an array of chart points representing the edges of the bars where the labels should be placed (like it's done in +/- example), or GroupedBarsCompanionLayer when working with grouped bars (it currently requires the bars to be grouped and stacked, though this should be fixed as the stacked requirement isn't necessary. You can in the meantime model your grouped bars as grouped and stacked with only 1 stack frame). More about GroupedBarsCompanionsLayer
in TODO.