diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0424e364448..9a5faa45732 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)
+- Updated `barSeriesStyle.displayValue` of the elastic-charts `Theme` for better default styles ([#4845](https://github.com/elastic/eui/pull/4845))
+
**Bug fixes**
- Fixed `EuiDataGrid` focus ring to be contained in the cell ([#5194](https://github.com/elastic/eui/pull/5194))
diff --git a/src-docs/src/views/elastic_charts/category_chart.js b/src-docs/src/views/elastic_charts/category_chart.js
index ad89e526cbc..9ad087fdb87 100644
--- a/src-docs/src/views/elastic_charts/category_chart.js
+++ b/src-docs/src/views/elastic_charts/category_chart.js
@@ -38,7 +38,7 @@ export const CategoryChart = () => {
const [ordered, setOrdered] = useState(true);
const [formatted, setFormatted] = useState(false);
const [chartType, setChartType] = useState('BarSeries');
-
+ const [valueLabels, setValueLabels] = useState(false);
const onMultiChange = (multiObject) => {
const { multi, stacked } = multiObject;
setMulti(multi);
@@ -61,6 +61,10 @@ export const CategoryChart = () => {
setChartType(chartType);
};
+ const onValueLabelsChange = (e) => {
+ setValueLabels(e.target.checked);
+ };
+
const isDarkTheme = themeContext.theme.includes('dark');
const theme = isDarkTheme
? EUI_CHARTS_THEME_DARK.theme
@@ -70,6 +74,115 @@ export const CategoryChart = () => {
const DATASET = multi ? GITHUB_DATASET : SIMPLE_GITHUB_DATASET;
+ const displayValueSettings = {
+ showValueLabel: true,
+ };
+
+ const customTheme = {
+ ...theme,
+ barSeriesStyle: {
+ displayValue: {
+ ...theme.barSeriesStyle.displayValue,
+ offsetX: rotated ? 4 : 0,
+ offsetY: rotated ? 0 : -4,
+ ...(multi && stacked
+ ? {
+ alignment: {
+ vertical: 'middle',
+ horizontal: 'center',
+ },
+ }
+ : {
+ alignment: rotated
+ ? {
+ vertical: 'middle',
+ }
+ : {
+ horizontal: 'center',
+ },
+ }),
+ },
+ },
+ };
+
+ const defaultAlignmentToCopy = `alignment: {
+ vertical: 'middle',
+ horizontal: 'center',
+ }`;
+
+ const alignmentRotatedToCopy = rotated
+ ? `alignment: {
+ vertical: 'middle',
+ }`
+ : `alignment: {
+ horizontal: 'center',
+ }`;
+
+ const chartVariablesForValueLabels = `const theme = isDarkTheme
+ ? EUI_CHARTS_THEME_DARK.theme
+ : EUI_CHARTS_THEME_LIGHT.theme;
+
+const customTheme = {
+ ...theme,
+ barSeriesStyle: {
+ displayValue: {
+ ...theme.barSeriesStyle.displayValue,
+ offsetX: ${rotated ? '4' : '0'},
+ offsetY: ${rotated ? '0' : '-4'},
+ ${multi && stacked ? defaultAlignmentToCopy : alignmentRotatedToCopy},
+ },
+ },
+};`;
+
+ const multiConfigData = `[{ vizType: "Data Table", count: 6, issueType: "Bug" },
+ { vizType: "Data Table", count: 24, issueType: "Other" },
+ { vizType: "Heatmap", count: 12, issueType: "Bug" },
+ { vizType: "Heatmap", count: 20, issueType: "Other" }]
+`;
+
+ const singleConfigData = `[{vizType: 'Data Table', count: 24, issueType: 'Bug'},
+ {vizType: 'Heatmap',count: 12, issueType: 'Other'}]
+`;
+
+ const chartConfigurationToCopy = `
+
+ <${chartType}
+ id="issues"
+ name="Issues"
+ data={
+ ${multi ? multiConfigData : singleConfigData}
+ }
+ xAccessor="vizType"
+ yAccessors={['count']}
+ ${multi ? "splitSeriesAccessors={['issueType']}" : ''}
+ ${stacked ? "stackAccessors={['issueType']}" : ''}
+ ${valueLabels ? 'displayValueSettings={{showValueLabel: true}}' : ''}
+ />
+
+ `${round(Number(d) / 1000, 2)}k`}' : ''}
+ />
+`;
+
+ const removeEmptyLines = (string) => string.replace(/(^[ \t]*\n)/gm, '');
+
+ const textToCopy = valueLabels
+ ? `${chartVariablesForValueLabels}
+
+${removeEmptyLines(chartConfigurationToCopy)}`
+ : `${removeEmptyLines(chartConfigurationToCopy)}`;
+
return (
@@ -81,9 +194,9 @@ export const CategoryChart = () => {
-
+
{
yAccessors={['count']}
splitSeriesAccessors={multi ? ['issueType'] : undefined}
stackAccessors={stacked ? ['issueType'] : undefined}
+ displayValueSettings={valueLabels && displayValueSettings}
/>
{
+
+
+
+
+
+
+
-
-
- <${chartType}
- id="issues"
- name="Issues"
- data={${
- ordered
- ? "orderBy([{vizType: 'Data Table', count: 24, issueType: 'Bug'},{vizType: 'Heatmap',count: 12, issueType: 'Other'}], ['count'], ['desc'])"
- : "orderBy([{vizType: 'Data Table', count: 24, issueType: 'Bug'},{vizType: 'Heatmap',count: 12, issueType: 'Other'}], ['vizType'], ['asc'])"
- }}
- xAccessor="vizType"
- yAccessors={['count']}
- ${multi ? "splitSeriesAccessors={['issueType']}" : ''}
- ${stacked ? "stackAccessors={['issueType']}" : ''}
- />
-
- `${round(Number(d) / 1000, 2)}k`}' : ''}
- />
-`}
- >
+
{(copy) => (
Copy code of current configuration
diff --git a/src/themes/charts/themes.ts b/src/themes/charts/themes.ts
index 3be039357c6..315a4f457e5 100644
--- a/src/themes/charts/themes.ts
+++ b/src/themes/charts/themes.ts
@@ -100,9 +100,17 @@ function createTheme(colors: any): EuiChartThemeType {
},
barSeriesStyle: {
displayValue: {
- fontSize: 8,
+ fontSize: 10,
fontFamily: fontFamily,
- fill: colors.euiTextSubduedColor.rgba,
+ fill: {
+ textInvertible: true,
+ textContrast: true,
+ textBorder: 0,
+ },
+ alignment: {
+ horizontal: 'center',
+ vertical: 'middle',
+ },
},
},
scales: {