How to use @vx/point - 10 common examples

To help you get started, we’ve selected a few @vx/point examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hshoff / vx / packages / vx-axis / src / axis / Axis.jsx View on Github external
const range = scale.range();
  const range0 = range[0] + 0.5 - rangePadding;
  const range1 = range[range.length - 1] + 0.5 + rangePadding;

  const horizontal = orientation !== ORIENT.left && orientation !== ORIENT.right;
  const isLeft = orientation === ORIENT.left;
  const isTop = orientation === ORIENT.top;
  const tickSign = isLeft || isTop ? -1 : 1;

  const position = (scale.bandwidth ? center : identity)(scale.copy());

  const axisFromPoint = new Point({
    x: horizontal ? range0 : 0,
    y: horizontal ? 0 : range0,
  });
  const axisToPoint = new Point({
    x: horizontal ? range1 : 0,
    y: horizontal ? 0 : range1,
  });

  let tickLabelFontSize = 10; // track the max tick label size to compute label offset

  if (children) {
    return (
      
        {children({
          axisFromPoint,
          axisToPoint,
          horizontal,
          tickSign,
          numTicks,
          label,
github williaster / data-ui / packages / sparkline / src / annotation / VerticalReferenceLine.jsx View on Github external
// use a number if passed, else find the index based on the ref type
    let index = reference;
    if (typeof reference !== 'number') {
      index = data.findIndex(
        (d, i) =>
          (reference === 'first' && i === 0) ||
          (reference === 'last' && i === data.length - 1) ||
          (reference === 'min' && Math.abs(getY(d) - yMin) < ZERO_DELTA) ||
          (reference === 'max' && Math.abs(getY(d) - yMax) < ZERO_DELTA),
      );
    }
    const datum = data[index];
    // use passed value if no datum, this enables custom x values
    const refNumber = datum ? getX(datum) : index;
    const scaledRef = xScale(refNumber);
    const fromPoint = new Point({ x: scaledRef, y: y1 });
    const toPoint = new Point({ x: scaledRef, y: y0 });
    const label = renderLabel && renderLabel((datum && getY(datum)) || refNumber);

    return (
github williaster / data-ui / packages / sparkline / src / annotation / VerticalReferenceLine.jsx View on Github external
let index = reference;
    if (typeof reference !== 'number') {
      index = data.findIndex(
        (d, i) =>
          (reference === 'first' && i === 0) ||
          (reference === 'last' && i === data.length - 1) ||
          (reference === 'min' && Math.abs(getY(d) - yMin) < ZERO_DELTA) ||
          (reference === 'max' && Math.abs(getY(d) - yMax) < ZERO_DELTA),
      );
    }
    const datum = data[index];
    // use passed value if no datum, this enables custom x values
    const refNumber = datum ? getX(datum) : index;
    const scaledRef = xScale(refNumber);
    const fromPoint = new Point({ x: scaledRef, y: y1 });
    const toPoint = new Point({ x: scaledRef, y: y0 });
    const label = renderLabel && renderLabel((datum && getY(datum)) || refNumber);

    return (
github hshoff / vx / packages / vx-event / src / touchPoint.js View on Github external
export default function touchPoint(node, event) {
  if (!node) return;
  const svg = node.ownerSVGElement || node;
  if (svg.createSVGPoint) {
    let point = svg.createSVGPoint();
    point.x = event.changedTouches[0].clientX;
    point.y = event.changedTouches[0].clientY;
    point = point.matrixTransform(node.getScreenCTM().inverse());
    return new Point({
      x: point.x,
      y: point.y,
    });
  }
  const rect = node.getBoundingClientRect();
  return new Point({
    x: event.changedTouches[0].clientX - rect.left - node.clientLeft,
    y: event.changedTouches[0].clientY - rect.top - node.clientTop,
  });
}
github hshoff / vx / packages / vx-shape / src / shapes / Polygon.jsx View on Github external
export default function Polygon({
  sides,
  size = 25,
  center = new Point({ x: 0, y: 0 }),
  rotate = 0,
  className,
  children,
  innerRef,
  ...restProps
}) {
  const points = getPoints({
    sides,
    size,
    center,
    rotate,
  }).map(p => p.toArray());

  if (children) return children({ points });

  return (
github hshoff / vx / packages / vx-shape / src / shapes / Line.js View on Github external
export default function Line({
  from = new Point({ x: 0, y: 0 }),
  to = new Point({ x: 1, y: 1 }),
  stroke = 'black',
  strokeWidth = 1,
  strokeDasharray = '',
  transform = '',
  className = '',
  data,
  innerRef,
  ...restProps
}) {
  return (
github hshoff / vx / packages / vx-axis / dist / vx-axis.es.js View on Github external
values.map(function (val, index) {
      if (hideZero && val === 0) return null;

      var tickFromPoint = new Point({
        x: horizontal ? position(val) : 0,
        y: horizontal ? 0 : position(val)
      });
      var tickToPoint = new Point({
        x: horizontal ? position(val) : tickSign * tickLength,
        y: horizontal ? tickLength * tickSign : position(val)
      });

      var tickLabelPropsObj = tickLabelProps(val, index);
      tickLabelFontSize = Math.max(tickLabelFontSize, tickLabelPropsObj.fontSize || 0);

      return React.createElement(
        Group,
        {
          key: 'vx-tick-' + val + '-' + index,
          className: cx('vx-axis-tick', tickClassName),
          transform: tickTransform
        },
        !hideTicks && React.createElement(Line, { from: tickFromPoint, to: tickToPoint, stroke: tickStroke }),
        tickComponent ? tickComponent(_extends({
github hshoff / vx / packages / vx-grid / src / grids / GridColumns.jsx View on Github external
{ticks.map((d, i) => {
        const x = offset ? scale(d) + offset : scale(d);
        const fromPoint = new Point({
          x,
          y: 0,
        });
        const toPoint = new Point({
          x,
          y: height,
        });
        return (
github williaster / data-ui / packages / xy-chart / src / annotation / HorizontalReferenceLine.jsx View on Github external
function HorizontalReferenceLine({
  label,
  labelProps,
  reference,
  stroke,
  strokeDasharray,
  strokeLinecap,
  strokeWidth,
  xScale,
  yScale,
}) {
  if (!xScale || !yScale) return null;
  const [x0, x1] = xScale.range();
  const scaledRef = yScale(reference);
  const fromPoint = new Point({ x: x0, y: scaledRef });
  const toPoint = new Point({ x: x1, y: scaledRef });

  return (
github hshoff / vx / packages / vx-axis / dist / vx-axis.es.js View on Github external
ticks: values.map(function (value, index) {
          var from = new Point({
            x: horizontal ? position(value) : 0,
            y: horizontal ? 0 : position(value)
          });
          var to = new Point({
            x: horizontal ? position(value) : tickSign * tickLength,
            y: horizontal ? tickLength * tickSign : position(value)
          });
          return {
            value: value,
            index: index,
            from: from,
            to: to,
            formattedValue: format(value, index)
          };
        })
      })

@vx/point

vx point

MIT
Latest version published 4 years ago

Package Health Score

80 / 100
Full package analysis

Popular @vx/point functions