All files / src/components/graph/LineGraphCell/Axes Axes.tsx

0% Statements 0/4
0% Branches 0/2
0% Functions 0/1
0% Lines 0/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81                                                                                                                                                                 
import { Point } from "@/objects/interfaces/graph/Point";
import { Size } from "@/objects/interfaces/number/Size";
import { GraphAxis } from "@/objects/interfaces/graph/GraphAxis";
import "./Axes.css";
import { guidGenerator } from "@/util/id";
 
export interface AxisProps {
  x_axis: GraphAxis;
  y_axis: GraphAxis;
  pad: number;
  size: Size;
  center: Point;
}
 
export const Axes = (props: AxisProps) => {
  const center = {
    x: Math.min(props.center.x, props.pad + props.size.width),
    y:
      props.y_axis.range.min < 0
        ? Math.min(props.center.y, props.pad + props.size.height)
        : Math.max(props.center.y, props.pad + props.size.height),
  };
  const nodes: React.ReactNode[] = [
    <path
      key={guidGenerator()}
      d={`M ${props.pad} ${center.y} L ${props.pad + props.size.width} ${
        center.y
      }`}
      className="axis"
    ></path>,
    <text
      key={guidGenerator()}
      x={props.pad - props.pad / 2}
      y={center.y}
      className="axis-text"
      textLength={30}
      lengthAdjust="spacingAndGlyphs"
    >
      {props.x_axis.range.min}
    </text>,
    <text
      key={guidGenerator()}
      x={props.pad + props.size.width + props.pad / 2}
      y={center.y}
      className="axis-text"
      textLength={30}
      lengthAdjust="spacingAndGlyphs"
    >
      {props.x_axis.range.max}
    </text>,
    <path
      key={guidGenerator()}
      d={`M ${center.x} ${props.pad} L ${center.x} ${
        props.pad + props.size.height
      }`}
      className="axis"
    ></path>,
    <text
      key={guidGenerator()}
      x={center.x}
      y={props.pad - props.pad / 2}
      className="axis-text"
      textLength={30}
      lengthAdjust="spacingAndGlyphs"
    >
      {props.y_axis.range.max}
    </text>,
    <text
      key={guidGenerator()}
      x={center.x}
      y={props.pad + props.size.height + props.pad / 2}
      className="axis-text"
      textLength={30}
      lengthAdjust="spacingAndGlyphs"
    >
      {props.y_axis.range.min}
    </text>,
  ];
  return nodes;
};