Skip to content

Commit

Permalink
Fix truncate labels to work only for slice labels positioned outside …
Browse files Browse the repository at this point in the history
…the chart
  • Loading branch information
stratoula committed Aug 13, 2021
1 parent 1b644c5 commit 3ac0065
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/plugins/vis_type_pie/public/editor/components/pie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,13 @@ const PieOptions = (props: PieOptionsProps) => {
/>
</>
)}
<TruncateLabelsOption value={stateParams.labels.truncate} setValue={setLabels} />
<TruncateLabelsOption
value={stateParams.labels.truncate}
setValue={setLabels}
disabled={
props.showElasticChartsOptions && stateParams.labels.position === LabelPositions.INSIDE
}
/>
</EuiPanel>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import React, { ChangeEvent } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFormRow, EuiFieldNumber } from '@elastic/eui';
import { EuiFormRow, EuiFieldNumber, EuiIconTip } from '@elastic/eui';

export interface TruncateLabelsOptionProps {
disabled?: boolean;
Expand All @@ -27,6 +27,14 @@ function TruncateLabelsOption({ disabled, value = null, setValue }: TruncateLabe
})}
fullWidth
display="rowCompressed"
labelAppend={
<EuiIconTip
content="Number of characters for labels positioned outside the chart."
position="top"
type="iInCircle"
color="subdued"
/>
}
>
<EuiFieldNumber
data-test-subj="pieLabelTruncateInput"
Expand Down
1 change: 1 addition & 0 deletions src/plugins/vis_type_pie/public/utils/get_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const getConfig = (
config.linkLabel = {
maxCount: Number.POSITIVE_INFINITY,
maximumSection: Number.POSITIVE_INFINITY,
maxTextLength: visParams.labels.truncate ?? undefined,
};
}

Expand Down
7 changes: 1 addition & 6 deletions src/plugins/vis_type_pie/public/utils/get_layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,7 @@ export const getLayers = (
showAccessor: (d: Datum) => d !== EMPTY_SLICE,
nodeLabel: (d: unknown) => {
if (col.format) {
const formattedLabel = formatter.deserialize(col.format).convert(d) ?? '';
if (visParams.labels.truncate && formattedLabel.length <= visParams.labels.truncate) {
return formattedLabel;
} else {
return `${formattedLabel.slice(0, Number(visParams.labels.truncate))}\u2026`;
}
return formatter.deserialize(col.format).convert(d) ?? '';
}
return String(d);
},
Expand Down

0 comments on commit 3ac0065

Please sign in to comment.