You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

72 lines
1.7 KiB

  1. import { fillArray } from '../utils/helpers';
  2. const AXIS_TICK_LENGTH = 6;
  3. const MIN_BAR_PERCENT_HEIGHT = 0.01;
  4. export function getXLineProps(totalHeight, mode) {
  5. let startAt = totalHeight + 6, height, textStartAt, axisLineClass = '';
  6. if(mode === 'span') { // long spanning lines
  7. startAt = -7;
  8. height = totalHeight + 15;
  9. textStartAt = totalHeight + 25;
  10. } else if(mode === 'tick'){ // short label lines
  11. startAt = totalHeight;
  12. height = 6;
  13. textStartAt = 9;
  14. axisLineClass = 'x-axis-label';
  15. }
  16. return [startAt, height, textStartAt, axisLineClass];
  17. }
  18. export function getYLineProps(totalWidth, mode, specific=false) {
  19. if(specific) {
  20. return[totalWidth, totalWidth + 5, 'specific-value', 0];
  21. }
  22. let width, text_end_at = -9, axisLineClass = '', startAt = 0;
  23. if(mode === 'span') { // long spanning lines
  24. width = totalWidth + 6;
  25. startAt = -6;
  26. } else if(mode === 'tick'){ // short label lines
  27. width = -6;
  28. axisLineClass = 'y-axis-label';
  29. }
  30. return [width, text_end_at, axisLineClass, startAt];
  31. }
  32. export function getBarHeightAndYAttr(yTop, zeroLine, totalHeight) {
  33. let height, y;
  34. if (yTop <= zeroLine) {
  35. height = zeroLine - yTop;
  36. y = yTop;
  37. // In case of invisible bars
  38. if(height === 0) {
  39. height = totalHeight * MIN_BAR_PERCENT_HEIGHT;
  40. y -= height;
  41. }
  42. } else {
  43. height = yTop - zeroLine;
  44. y = zeroLine;
  45. // In case of invisible bars
  46. if(height === 0) {
  47. height = totalHeight * MIN_BAR_PERCENT_HEIGHT;
  48. }
  49. }
  50. return [height, y];
  51. }
  52. export function equilizeNoOfElements(array1, array2,
  53. extra_count=array2.length - array1.length) {
  54. if(extra_count > 0) {
  55. array1 = fillArray(array1, extra_count);
  56. } else {
  57. array2 = fillArray(array2, extra_count);
  58. }
  59. return [array1, array2];
  60. }