TickSpacingEditor.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React from 'react';
  2. import { SelectableValue, StandardEditorProps } from '@grafana/data';
  3. import { Checkbox, HorizontalGroup, RadioButtonGroup, Tooltip } from '@grafana/ui';
  4. const GAPS_OPTIONS: Array<SelectableValue<number>> = [
  5. {
  6. label: 'None',
  7. value: 0,
  8. description: 'Show all tick marks',
  9. },
  10. {
  11. label: 'Small',
  12. value: 100,
  13. description: 'Require 100px spacing',
  14. },
  15. {
  16. label: 'Medium',
  17. value: 200,
  18. description: 'Require 200px spacing',
  19. },
  20. {
  21. label: 'Large',
  22. value: 300,
  23. description: 'Require 300px spacing',
  24. },
  25. ];
  26. export const TickSpacingEditor: React.FC<StandardEditorProps<number, any>> = (props) => {
  27. let value = props.value ?? 0;
  28. const isRTL = value < 0;
  29. if (isRTL) {
  30. value *= -1;
  31. }
  32. let gap = GAPS_OPTIONS[0];
  33. for (const v of GAPS_OPTIONS) {
  34. gap = v;
  35. if (value <= gap.value!) {
  36. break;
  37. }
  38. }
  39. const onSpacingChange = (val: number) => {
  40. props.onChange(val * (isRTL ? -1 : 1));
  41. };
  42. const onRTLChange = () => {
  43. props.onChange(props.value * -1);
  44. };
  45. return (
  46. <HorizontalGroup>
  47. <RadioButtonGroup value={gap.value} options={GAPS_OPTIONS} onChange={onSpacingChange} />
  48. {value !== 0 && (
  49. <Tooltip content="Require space from the right side" placement="top">
  50. <div>
  51. <Checkbox value={isRTL} onChange={onRTLChange} label="RTL" />
  52. </div>
  53. </Tooltip>
  54. )}
  55. </HorizontalGroup>
  56. );
  57. };