Cabinet20 opened a new issue, #21848:
URL: https://github.com/apache/echarts/issues/21848

   ### What problem does this feature solve?
   
   Version checked: ECharts 6.1.0. Component: cartesian `series-bar` (stacked).
   
   ### Summary
   
   When bars are stacked, the only way to visually separate adjacent segments 
is to give every bar an `itemStyle.borderColor` that matches the chart 
background. That is a workaround, not a gap, and it has side effects that make 
it unsuitable for accessible charts. A first-class `stackGap` option would put 
a gap **between** stacked segments only, leaving the outer edges (baseline, top 
of stack, left and right) untouched.
   
   ### Why separation between segments matters (accessibility)
   
   Stacked segments are usually told apart by colour alone. That breaks down 
for readers with colour vision deficiency (CVD) or low vision, and for anyone 
viewing a greyscale print or a low-contrast display. In the figure below, the 
same data is shown with segments touching (left) and with a gap (right), under 
simulated normal vision, protanopia, deuteranopia, tritanopia and greyscale.
   
   <img width="2000" height="1876" alt="image" 
src="https://github.com/user-attachments/assets/7a00b0a0-0d62-4906-89e7-aa83e4efa84d";
 />
   
   What to look for:
   
   - **Deuteranopia and protanopia:** the red, green, orange and brown segments 
collapse into a narrow band of olive and brown tones. Without a gap the 
boundaries between neighbouring segments are hard to find. With the gap, each 
segment reads as a separate block.
   - **Greyscale:** the orange and green segments become the same grey. Without 
a gap they merge into one block. With the gap they are two blocks.
   
   A gap helps because it means each segment is distinguished from the 
*background* rather than only from its neighbour. This is relevant to [WCAG 2.2 
SC 1.4.11 Non-text 
Contrast](https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html), 
which asks for a 3:1 contrast ratio between graphical objects that are needed 
to understand content and their adjacent colours. If segments touch, every pair 
of neighbouring segments is "adjacent" to the other, so each pair needs enough 
contrast against each other, which is difficult to satisfy across a 
multi-series palette. With a gap, the adjacent colour is the background. (SC 
1.4.11 does not require a gap. This is the argument for why a gap makes 
compliance achievable.)
   
   Published guidance recommends this separation:
   
   - The [data.europa.eu Data Visualisation 
Guide](https://data.europa.eu/apps/data-visualisation-guide/stacked-bars) 
advises "a visible outline between the bars in a stack", saying it improves 
legibility, especially for people with colour blindness.
   - The [Morningstar design 
system](https://design.morningstar.com/systems/data-visualization/guidelines/accessibility)
 builds 3px gaps between all adjacent plots (for example in stacked bars) into 
its chart elements, so that colour-blind and low-vision users can tell plots 
apart.
   - [Storytelling with 
Data](https://www.storytellingwithdata.com/blog/2018/6/26/accessible-data-viz-is-better-data-viz)
 recommends white divider lines between categories as a way to separate 
sections without relying on colour alone.
   
   ### Why a border is not a substitute
   
   The current workaround is:
   
   ```js
   itemStyle: { borderColor: '#ffffff', borderWidth: 1 }
   ```
   
   This has real limitations, most seriously for thin segments.
   
   **1. It hides thin segments.** The border is a stroke centred on the edge of 
each rectangle, so it removes about half its width from each side of the 
segment. A segment whose height is less than the border width is covered 
completely. Small segments are exactly the ones readers most need to be able to 
find (for example a 0.5% allocation in a 100% stacked chart). In the figure 
below the purple segment has a value of 0.5. It is visible with no border 
(left), disappears with a 1px border (centre), and stays visible with the 
proposed 1px gap (right). A wider border hides progressively larger segments.
   
   <img width="2000" height="624" alt="image" 
src="https://github.com/user-attachments/assets/3f23392a-691a-4de8-a4e5-3ccec8900848";
 />
   
   **2. It is coupled to the background colour.** `borderColor` must equal the 
background, so it breaks on gradients, images, theme changes, and hover or 
`emphasis` states unless the application keeps them in sync. `transparent` does 
not work, because the stroke does not erase the fill beneath it.
   
   **3. It affects every edge.** Bars become slightly narrower and shorter, and 
stop short of the baseline and the top of the stack. The gap is not confined to 
the boundary between segments.
   
   **4. Zero-height segments can leave a line.** A zero or near-zero segment 
can still draw its border across the segment below it.
   
   Other approaches are also unsatisfactory. A transparent spacer series puts 
the gap in data units rather than pixels, distorts axis totals and tooltips, 
and has to be hidden from the legend. A `custom` series with `renderItem` loses 
stacking, labels, emphasis and `barMaxWidth` handling, so it is not practical 
as a general solution.
   
   ### Intended geometry
   
   <img width="2000" height="670" alt="image" 
src="https://github.com/user-attachments/assets/40758905-9d0a-4b0c-8a1b-458de19cf7a6";
 />
   
   ### What does the proposed API look like?
   
   A new option on bar series, in pixels, default `0` (no change to existing 
charts):
   
   ```js
   option = {
     xAxis: { type: 'category', data: ['A', 'B', 'C'] },
     yAxis: { type: 'value' },
     series: [
       { type: 'bar', stack: 'total', stackGap: 1, data: [20, 15, 25] },
       { type: 'bar', stack: 'total', stackGap: 1, data: [20, 25, 10] },
       { type: 'bar', stack: 'total', stackGap: 1, data: [20, 20, 25] }
     ]
   };
   ```
   
   ### Proposed behaviour
   
   - `stackGap` is the width of the visible gap in pixels between two touching 
segments of the same stack. Each segment is inset by `stackGap / 2` at the edge 
it shares with a neighbour.
   - Only **interior** edges are inset. The edge at the baseline, the outermost 
edge of the stack, and the left and right edges are unchanged.
   - No gap is added next to a neighbour that is zero, `null` or missing, 
because there is no shared edge.
   - Positive and negative stacks are handled separately: a gap is applied 
between same-sign neighbours only. The edge next to the baseline is an outer 
edge.
   - **A non-zero segment is never reduced below 1px (or `barMinHeight`, if 
set).** If the segment is too thin to give up `stackGap / 2` at both ends, the 
inset is reduced for that segment rather than hiding it. This is the key 
difference from the border workaround.
   - The gap is purely visual. Data values, axis scale, tooltips and labels are 
unchanged. The gap area is not part of either segment's hit area.
   - Applies to both vertical and horizontal bars. Polar bars could be a 
follow-up.
   - Works with `itemStyle.borderRadius`, rounding the corners of each inset 
segment.
   
   I am happy to work on a PR for this if the API is acceptable. The figures 
were produced with a `custom` series mock-up (not the proposed implementation) 
and with Machado, Oliveira and Fernandes (2009) colour vision deficiency 
simulation matrices.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to