utils.tsx 782 B

12345678910111213141516171819202122232425262728
  1. import type {AxisOption} from '../../data';
  2. export function getAxisOrBackupAxis(axis: AxisOption, usingBackupAxis: boolean) {
  3. const displayedAxis = usingBackupAxis ? getBackupAxisOption(axis) ?? axis : axis;
  4. return displayedAxis;
  5. }
  6. export function getBackupAxisOption(axis: AxisOption) {
  7. return axis.backupOption;
  8. }
  9. export function getBackupAxes(axes: AxisOption[], usingBackupAxis: boolean) {
  10. return usingBackupAxis ? axes.map(axis => getBackupAxisOption(axis) ?? axis) : axes;
  11. }
  12. export function getBackupField(axis: AxisOption) {
  13. const backupOption = getBackupAxisOption(axis);
  14. if (!backupOption) {
  15. return undefined;
  16. }
  17. return backupOption.field;
  18. }
  19. export function getFieldOrBackup(field: string, backupField?: string) {
  20. return backupField ?? field;
  21. }