Skip to content

Commit

Permalink
Check for old enums value like "Horizontal Left" with space to mainta…
Browse files Browse the repository at this point in the history
…in backwards compatibility
  • Loading branch information
adiletelf committed Apr 23, 2024
1 parent b846f80 commit 8cccfbd
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/visual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ export class BulletChart implements IVisual {
const categoricalValues: BulletChartColumns<any[]> =
BulletChartColumns.GET_CATEGORICAL_VALUES(dataView);

BulletChart.updateOrientation(visualSettings, dataView);
BulletChart.limitProperties(visualSettings);
visualSettings = this.SetHighContrastColors(visualSettings, colorHelper);

Expand Down Expand Up @@ -655,6 +656,26 @@ export class BulletChart implements IVisual {
return null;
}

// Implemented for old enums using space containing keys for example "Horizontal Left" which doesn't exist in current version
private static updateOrientation(settings: BulletChartSettingsModel, dataView: DataView): void {
let orientationValue: string = "";

if (settings?.orientation?.orientation.value?.value) {
orientationValue = settings.orientation.orientation.value.value.toString();
}
else if (dataView?.metadata?.objects?.orientation?.orientation) {
orientationValue = dataView.metadata.objects?.orientation?.orientation as string;
}

const noSpaceOrientation: string = orientationValue.toString().replace(" ", "");

if (Object.values(BulletChartOrientation).includes(noSpaceOrientation as BulletChartOrientation)) {
settings.orientation.orientation.value = settings.orientation.orientation.items.find(option => option.value.toString() === noSpaceOrientation);
} else {
settings.orientation.orientation.value = settings.orientation.orientation.items.find(option => option.value.toString() === BulletChartOrientation.HorizontalLeft);
}
}

private static limitProperties(settings: BulletChartSettingsModel): void {
if (settings.values.minimumPercent.value > settings.values.maximumPercent.value) {
settings.values.maximumPercent.value = settings.values.minimumPercent.value;
Expand Down

0 comments on commit 8cccfbd

Please sign in to comment.