|
|
## Grouped Bar Charts
|
|
|
|
|
|
### Chart Layout
|
|
|
|
|
|
##### Calculating the bar thickness
|
|
|
|
|
|
In the following, a way is presented to numerically find a thickness for the tactile bars such that all groups fit on the available chart area. To use as much of the given area as possible and to minimize big gaps, the software will try to find the maximum possible thickness within the user defined limits `minThickness`, `maxThickness`.
|
|
|
|
|
|
The layout of the bars is as described in the conceptual design:
|
|
|
* There are `g` groups of an arbitrary number of bars `b[i]` in each group `i`, resulting in `b` total bars
|
|
|
* The groups are separated by a padding `gpad`, counted in full cells
|
|
|
* The bars inside a group are separated by a padding `bpad`, also counted in full cells
|
|
|
* All bars are of equal `tickness`
|
|
|
* There are enclosing paddings: Between the axis and its closest bar & between the bar furthest from the axis and the end of the cart area, each 1 exactly 1 cell.
|
|
|
* The paddings contain the bar borders
|
|
|
|
|
|
A sketch for a layout with horizontal bars:
|
|
|
...
|
|
|
|
|
|
For a given value of `thickness`, the full required size of the chart area can be calculated in the following way:
|
|
|
|
|
|
```
|
|
|
reqSize(thickness) = (g-1) * gpad + SUM(0 <= i < g, gSize(i)) + 2
|
|
|
```
|
|
|
`(g-1) * gpad` is the sum of paddings between neighboring groups
|
|
|
|
|
|
`SUM(0 <= i < g, gSize(i))` is the sum of each groups size
|
|
|
|
|
|
`2` constant for the enclosing padding
|
|
|
|
|
|
The size of the group i can be calculated:
|
|
|
|
|
|
```
|
|
|
gSize(i) = (b[i] - 1) * bpad + b[i] * thickness
|
|
|
```
|
|
|
`(b[i] - 1) * bpad` is the sum of paddings between neighboring bars
|
|
|
|
|
|
`b[i] * tickness` is the sum of the sizes of the actual textured area inside the bars
|
|
|
|
|
|
Now it is possible to insert `gSize()` into `reqSize()` and set `thickness=0` to calculate a `baseSize`.
|
|
|
|
|
|
```
|
|
|
baseSize = reqSize(thickness=0) = (g-1) * gpad + SUM(0 <= i < g, (b[i] - 1) * bpad + b[i] * thickness) + 2
|
|
|
= (g-1) * gpad + SUM(0 <= i < g, (b[i] - 1) * bpad + b[i] * 0) + 2
|
|
|
= (g-1) * gpad + SUM(0 <= i < g, (b[i] - 1) * bpad) + 2
|
|
|
|
|
|
// Now the sum term can be replaced
|
|
|
= (g-1) * gpad + SUM(0 <= i < g, (b[i] - 1)) * bpad + 2
|
|
|
= (g-1) * gpad + (SUM(0 <= i < g, b[i]) - g) * bpad + 2
|
|
|
= (g-1) * gpad + (b - g) * bpad + 2
|
|
|
|
|
|
// Simplify term
|
|
|
= g * gpad + (b - g) * bpad + 2 - gpad
|
|
|
= g * gpad - g * bpad + b * bpad + 2 - gpad
|
|
|
= g * (gpad - bpad) + (b * bpad) + 2 - gpad
|
|
|
```
|
|
|
|
|
|
This base size is the required size for all paddings. The required size can now be represented much simpler:
|
|
|
|
|
|
```
|
|
|
reqSize(thickness) = baseSize + b * tickness
|
|
|
``` |
|
|
\ No newline at end of file |