Skip to content

Partition: calculate relative luminance for text #606

@rshen91

Description

@rshen91

Is your feature request related to a problem? Please describe.
Currently in pie charts there's logic in place for white text or black text

/** @internal */
export function colorIsDark(color: Color) {
  // fixme this assumes a white or very light background
  const rgba = stringToRGB(color);
  const { r, g, b, opacity } = rgba;
  const a = rgba.hasOwnProperty('opacity') ? opacity : 1;
  return r * 0.299 + g * 0.587 + b * 0.114 < a * 150;
}

but this needs to account for relative luminance to be in accordance with WCAG standards for text and background contrast.

Additional context
This logic may be in place already in this elastic/kibana#60261 and we can potentially just move the logic onto the elastic-charts end.

Kibana Cross Issues
Add any Kibana related issues/feature requests here.

Checklist

Delete any items that are not applicable to this feature request.

  • this request is checked against already exist requests
  • every related Kibana issue is listed under Kibana Cross Issues list
  • kibana cross issue tag is associated to the issue if any kibana cross issue is present

Metadata

Metadata

Assignees

Labels

:partitionPartition/PieChart/Donut/Sunburst/Treemap chart related:stylingStyling related issueenhancementNew feature or requestreleasedIssue released publicly

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions