How to use the @vx/scale.scaleOrdinal function in @vx/scale

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 / src / components / tiles / streamgraph.js View on Github external
const BUMPS_PER_LAYER = 10;

const keys = range(NUM_LAYERS);

// scales
const yScale = scaleLinear({
  domain: [-30, 50],
});
const xScale = scaleLinear({
  domain: [0, SAMPLES_PER_LAYER - 1],
});
const colorScale = scaleOrdinal({
  domain: keys,
  range: ['#ffc409', '#f14702', '#262d97', 'white', '#036ecd', '#9ecadd', '#51666e'],
});
const patternScale = scaleOrdinal({
  domain: keys,
  range: ['mustard', 'cherry', 'navy', 'circles', 'circles', 'circles', 'circles'],
});

export default class Streamgraph extends React.Component {
  render() {
    const { width, height } = this.props;
    if (width < 10) return null;

    const layers = transpose(keys.map(() => bumps(SAMPLES_PER_LAYER, BUMPS_PER_LAYER)));

    xScale.range([0, width]);
    yScale.range([height, 0]);

    return (
      <svg height="{height}" width="{width}"></svg>
github hshoff / vx / packages / vx-demo / components / tiles / barstackhorizontal.js View on Github external
const xMax = width - margin.left - margin.right;
    const yMax = height - margin.top - margin.bottom;

    // // scales
    const xScale = scaleLinear({
      rangeRound: [0, xMax],
      domain: [0, max(totals)],
      nice: true
    });
    const yScale = scaleBand({
      rangeRound: [yMax, 0],
      domain: data.map(y),
      padding: 0.2,
      tickFormat: () =&gt; val =&gt; formatDate(val)
    });
    const zScale = scaleOrdinal({
      domain: keys,
      range: ['#6c5efb', '#c998ff', '#a44afe']
    });

    let tooltipTimeout;

    return (
      <div style="{{">
        <svg height="{height}" width="{width}">
          <rect rx="{14}" fill="#eaedff" height="{height}" width="{width}" y="{0}" x="{0}"></rect>
          
            </svg></div>
github hshoff / vx / packages / vx-demo / src / components / tiles / legends.js View on Github external
const quantileScale = scaleQuantize({
  domain: [0, 0.15],
  range: ['#eb4d70', '#f19938', '#6ce18b', '#78f6ef', '#9096f8'],
});

const linearScale = scaleLinear({
  domain: [0, 10],
  range: ['#ed4fbb', '#e9a039'],
});

const thresholdScale = scaleThreshold({
  domain: [0.01, 0.02, 0.04, 0.06, 0.08, 0.1],
  range: ['#f2f0f7', '#dadaeb', '#bcbddc', '#9e9ac8', '#756bb1', '#54278f'],
});

const ordinalColorScale = scaleOrdinal({
  domain: ['a', 'b', 'c', 'd'],
  range: ['#66d981', '#71f5ef', '#4899f1', '#7d81f6'],
});

const ordinalColor2Scale = scaleOrdinal({
  domain: ['a', 'b', 'c', 'd'],
  range: ['#fae856', '#f29b38', '#e64357', '#8386f7'],
});

const shapeScale = scaleOrdinal({
  domain: ['a', 'b', 'c', 'd', 'e'],
  range: [
    ,
    ,
    ,
    ,
github hshoff / vx / packages / vx-demo / components / tiles / bargrouphorizontal.js View on Github external
rangeRound: [0, y0Scale.bandwidth()],
    domain: keys,
    padding: 0.1
  });

  const xScale = scaleLinear({
    rangeRound: [xMax, 0],
    domain: [
      0,
      max(data, d =&gt; {
        return max(keys, key =&gt; d[key]);
      })
    ]
  });

  const zScale = scaleOrdinal({
    domain: keys,
    range: ['#aeeef8', '#e5fd3d', '#9caff6']
  });

  return (
    <svg height="{height}" width="{width}">
      <rect rx="{14}" fill="#612efb" height="{height}" width="{width}" y="{0}" x="{0}"></rect>
      
        </svg>
github hshoff / vx / packages / vx-demo / components / tiles / drag-i.js View on Github external
constructor(props) {
    super(props);
    this.state = {
      items: genItems({ ...props })
    };
    this.colorScale = scaleOrdinal({
      range: colors,
      domain: this.state.items.map(d => d.id)
    });
  }
github neo4j-apps / graph-app-kit / src / components / Chart / charts / circular / RadialChart.jsx View on Github external
export default ({
  data = [],
  width = 500,
  height = 500,
  margin = { top: 50, right: 50, bottom: 50, left: 50 },
  chartType,
  innerRadius = 0
}) =&gt; {
  const filteredList = data.filter(i =&gt; i !== undefined);
  if (filteredList.length === 0) {
    return null;
  }
  const total = filteredList.reduce(
    (acc, value) =&gt; (acc.value ? acc.value + value.value : acc + value.value)
  );
  const colorScale = scaleOrdinal({ range: chartTheme.colors.categories });
  return (
    <div>
       (
          <div>
            <strong>{datum.label}</strong> ({datum.value})
          </div>
        )}
      &gt;
         d.value}</div>
github hshoff / vx / packages / vx-demo / components / tiles / bargroup.js View on Github external
});
  const x1Scale = scaleBand({
    rangeRound: [0, x0Scale.bandwidth()],
    domain: keys,
    padding: 0.1
  });
  const yScale = scaleLinear({
    rangeRound: [yMax, 0],
    domain: [
      0,
      max(data, d =&gt; {
        return max(keys, key =&gt; d[key]);
      })
    ]
  });
  const zScale = scaleOrdinal({
    domain: keys,
    range: ['#aeeef8', '#e5fd3d', '#9caff6']
  });

  return (
    <svg height="{height}" width="{width}">
      <rect rx="{14}" fill="{`#612efb`}" height="{height}" width="{width}" y="{0}" x="{0}"></rect>
      </svg>
github hshoff / vx / packages / vx-demo / src / components / tiles / legends.js View on Github external
const thresholdScale = scaleThreshold({
  domain: [0.01, 0.02, 0.04, 0.06, 0.08, 0.1],
  range: ['#f2f0f7', '#dadaeb', '#bcbddc', '#9e9ac8', '#756bb1', '#54278f'],
});

const ordinalColorScale = scaleOrdinal({
  domain: ['a', 'b', 'c', 'd'],
  range: ['#66d981', '#71f5ef', '#4899f1', '#7d81f6'],
});

const ordinalColor2Scale = scaleOrdinal({
  domain: ['a', 'b', 'c', 'd'],
  range: ['#fae856', '#f29b38', '#e64357', '#8386f7'],
});

const shapeScale = scaleOrdinal({
  domain: ['a', 'b', 'c', 'd', 'e'],
  range: [
    ,
    ,
    ,
    ,
    () =&gt; (
      
    ),
  ],
});

export default ({ width }) =&gt; {
  if (width &lt; 10) return null;
github williaster / data-ui / packages / radial-chart / src / util / fillScaleFactory.js View on Github external
export function singleHueScaleFactory(hue) {
  return scaleOrdinal({ range: [...(allColors[hue] || grayColors)].reverse() });
}