How to use @vx/scale - 10 common examples

To help you get started, we’ve selected a few @vx/scale 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 williaster / data-ui / packages / event-flow / src / utils / scale-utils.js View on Github external
array.forEach(d => {
    const key = accessor(d);
    if (key) {
      names[key] = true;
    }
  });
  // sort to make color assignment deterministic
  const sortedNames = Object.keys(names).sort();
  if (sortedNames.length > colors.categories.length) {
    console.warn(
      `Unique color values ${sortedNames.length} exceeds the number of unique colors
      (${colors.categories.length}). Consider filtering event types.`,
    );
  }

  return scaleOrdinal({
    range: [`url(#${FILTERED_EVENTS})`, ...colors.categories],
    domain: [FILTERED_EVENTS, ...sortedNames],
  });
}
github hshoff / vx / packages / vx-demo / components / charts / SimpleAreaChart.js View on Github external
const stock = appleStock;

  // bounds
  const xMax = width - margin.left - margin.right;
  const yMax = height - margin.top - margin.bottom;

  // accessors
  const xStock = d => new Date(d.date);
  const yStock = d => d.close;

  // scales
  const xStockScale = scaleTime({
    range: [0, xMax],
    domain: extent(stock, xStock),
  });
  const yStockScale = scaleLinear({
    range: [yMax, 0],
    domain: [0, max(stock, yStock)],
    nice: true,
  });

  return (
    <svg width="{width}" height="{height}">
      
      
        
        </svg>
github hshoff / vx / packages / vx-demo / src / components / tiles / brush.js View on Github external
}

  const brushMargin = { top: 0, bottom: 20, left: 50, right: 20 };

  // bounds
  const xMax = Math.max(width - margin.left - margin.right, 0);
  const yMax = Math.max(height * 0.6 - margin.top - margin.bottom, 0);
  const xBrushMax = Math.max(width - brushMargin.left - brushMargin.right, 0);
  const yBrushMax = Math.max(120 - brushMargin.top - brushMargin.bottom, 0);

  // scales
  const xScale = scaleTime({
    range: [0, xMax],
    domain: extent(filteredStock, xStock),
  });
  const yScale = scaleLinear({
    range: [yMax, 0],
    domain: [0, max(filteredStock, yStock) + yMax / 3],
    nice: true,
  });
  const xBrushScale = scaleTime({
    range: [0, xBrushMax],
    domain: extent(stock, xStock),
  });
  const yBrushScale = scaleLinear({
    range: [yBrushMax, 0],
    domain: [0, max(stock, yStock) + yBrushMax / 3],
    nice: true,
  });

  return (
    <div></div>
github hshoff / vx / packages / vx-demo / components / tiles / brush-i.js View on Github external
focusMargin.bottom;

// data
const data = appleStock;

// accessors
const x = d => new Date(d.date);
const y = d => d.close;

// scales
const xScaleContext = scaleTime({
  range: [0, contextWidth],
  domain: extent(data, x),
  clamp: true,
});
const yScaleContext = scaleLinear({
  range: [contextHeight, 0],
  domain: [0, max(data, y)],
  nice: true,
});
const xScaleFocus = scaleTime({
  range: [0, contextWidth],
  domain: extent(data, x),
  clamp: true,
});
const yScaleFocus = scaleLinear({
  range: [focusHeight, 0],
  domain: [0, max(data, y)],
  nice: true,
});

const invertX = ({ x, tx, sx }) => (x - tx) / sx;
github reubn / tabla / src / components / InfoContainer / Info / lenses / IonisationEnergies / index.js View on Github external
const {tooltipData, tooltipTop, tooltipLeft} = this.state

    const x = ([i, j]) => i
    const y = ([i, j]) => j

    // Bounds
    const margin = {
      top: 20,
      bottom: 60,
      left: 80,
      right: 20
    }
    const xMax = width - margin.left - margin.right
    const yMax = height - margin.top - margin.bottom

    const xScale = scaleLinear({
      range: [0, xMax],
      domain: extent(data, x)
    })
    const yScale = scaleLog({
      range: [yMax, 1],
      domain: [min(data, y), max(data, y)],
      base: 10,
      nice: true
    })

    const maxL = 10 ** Math.ceil(Math.log10(max(data, y)))
    const minL = 10 ** Math.floor(Math.log10(min(data, y)))

    const tNum = Math.ceil(Math.log10(maxL - minL)) + 1
    const tValues = Array(tNum).fill().map((_, p) => 10 ** p)
github hshoff / vx / packages / vx-demo / components / tiles / brush-i.js View on Github external
// accessors
const x = d => new Date(d.date);
const y = d => d.close;

// scales
const xScaleContext = scaleTime({
  range: [0, contextWidth],
  domain: extent(data, x),
  clamp: true,
});
const yScaleContext = scaleLinear({
  range: [contextHeight, 0],
  domain: [0, max(data, y)],
  nice: true,
});
const xScaleFocus = scaleTime({
  range: [0, contextWidth],
  domain: extent(data, x),
  clamp: true,
});
const yScaleFocus = scaleLinear({
  range: [focusHeight, 0],
  domain: [0, max(data, y)],
  nice: true,
});

const invertX = ({ x, tx, sx }) => (x - tx) / sx;

class Brush extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
github hshoff / vx / packages / vx-demo / components / tiles / lines.js View on Github external
export default ({ width, height }) =&gt; {
  // bounds
  const xMax = width;
  const yMax = height / 8;

  // scales
  const xScale = scaleTime({
    range: [0, xMax],
    domain: extent(data, x),
  });
  const yScale = scaleLinear({
    range: [yMax, 0],
    domain: [0, max(data, y)],
  });

  return (
    <svg height="{height}" width="{width}">
      <rect rx="{14}" fill="#242424" height="{height}" width="{width}" y="{0}" x="{0}"></rect>
      {xMax &gt; 8 &amp;&amp;
        series.map((datum, i) =&gt; {
          return (
            
              </svg>
github hshoff / vx / packages / vx-demo / components / charts / SimpleAreaChart.js View on Github external
export default ({ margin, width, height }) =&gt; {
  const stock = appleStock;

  // bounds
  const xMax = width - margin.left - margin.right;
  const yMax = height - margin.top - margin.bottom;

  // accessors
  const xStock = d =&gt; new Date(d.date);
  const yStock = d =&gt; d.close;

  // scales
  const xStockScale = scaleTime({
    range: [0, xMax],
    domain: extent(stock, xStock),
  });
  const yStockScale = scaleLinear({
    range: [yMax, 0],
    domain: [0, max(stock, yStock)],
    nice: true,
  });

  return (
    <svg width="{width}" height="{height}">
      
      
        </svg>
github hshoff / vx / packages / vx-demo / components / tiles / brush-i.js View on Github external
height -
  contextHeight -
  contextMargin.top -
  contextMargin.bottom -
  focusMargin.top -
  focusMargin.bottom;

// data
const data = appleStock;

// accessors
const x = d => new Date(d.date);
const y = d => d.close;

// scales
const xScaleContext = scaleTime({
  range: [0, contextWidth],
  domain: extent(data, x),
  clamp: true,
});
const yScaleContext = scaleLinear({
  range: [contextHeight, 0],
  domain: [0, max(data, y)],
  nice: true,
});
const xScaleFocus = scaleTime({
  range: [0, contextWidth],
  domain: extent(data, x),
  clamp: true,
});
const yScaleFocus = scaleLinear({
  range: [focusHeight, 0],
github hshoff / vx / packages / vx-demo / src / components / tiles / brush.js View on Github external
const xMax = Math.max(width - margin.left - margin.right, 0);
  const yMax = Math.max(height * 0.6 - margin.top - margin.bottom, 0);
  const xBrushMax = Math.max(width - brushMargin.left - brushMargin.right, 0);
  const yBrushMax = Math.max(120 - brushMargin.top - brushMargin.bottom, 0);

  // scales
  const xScale = scaleTime({
    range: [0, xMax],
    domain: extent(filteredStock, xStock),
  });
  const yScale = scaleLinear({
    range: [yMax, 0],
    domain: [0, max(filteredStock, yStock) + yMax / 3],
    nice: true,
  });
  const xBrushScale = scaleTime({
    range: [0, xBrushMax],
    domain: extent(stock, xStock),
  });
  const yBrushScale = scaleLinear({
    range: [yBrushMax, 0],
    domain: [0, max(stock, yStock) + yBrushMax / 3],
    nice: true,
  });

  return (
    <div>
      <svg height="{height}" width="{width}">
        <rect rx="{14}" fill="#32deaa" height="{height}" width="{width}" y="{0}" x="{0}"></rect>
        </svg></div>