How to use the d3-array.range function in d3-array

To help you get started, we’ve selected a few d3-array 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 rrag / react-stockcharts / src / lib / axes / Axis.js View on Github external
ticks: tickArguments, tickValues: tickValuesProp,
		tickStroke, tickStrokeOpacity, tickInterval, tickIntervalFunction
	} = props;

	// if (tickArguments) tickArguments = [tickArguments];

	let tickValues;
	if (isDefined(tickValuesProp)) {
		if (typeof tickValuesProp === "function") {
			tickValues = tickValuesProp(scale.domain());
		} else {
			tickValues = tickValuesProp;
		}
	} else if (isDefined(tickInterval)) {
		const [min, max] = scale.domain();
		const baseTickValues = d3Range(min, max, (max - min) / tickInterval);

		tickValues = tickIntervalFunction
			? tickIntervalFunction(min, max, tickInterval)
			: baseTickValues;
	} else if (isDefined(scale.ticks)) {
		tickValues = scale.ticks(tickArguments, flexTicks);
	} else {
		tickValues = scale.domain();
	}

	const baseFormat = scale.tickFormat
		? scale.tickFormat(tickArguments)
		: identity;

	const format = isNotDefined(tickFormat)
		? baseFormat
github pbeshai / d3-scale-interactive / src / ui / RangeInput.js View on Github external
const { domain, range, onChange } = this.props;

    if (domain.length === range.length) {
      return;
    }

    const rangeMin = range[0];
    const rangeMax = range[range.length - 1];
    const step = Math.round(1000 * ((rangeMax - rangeMin) / (domain.length - 1))) / 1000;

    let matched;
    // non-number solution - just copy the last element or truncate the array
    if (isNaN(step)) {
      const numToAdd = domain.length - range.length;
      if (numToAdd > 0) { // adding elements
        matched = [...range, ...d3Range(numToAdd).map(() => range[range.length - 1])];
      } else { // removing elements
        matched = range.slice(0, domain.length);
      }
    } else {
      matched = d3Range(rangeMin, rangeMax, step).concat(rangeMax);
    }

    onChange(matched);
  }
github gluon-project / gluon-rxp / src / Components / Graphs / BondingCurveGraph.tsx View on Github external
render() {

    const numTokens = this.props.numTokens
    const totalSupply = this.props.totalSupply
    let maxTotalSupply = (totalSupply + numTokens) > totalSupply * 2 ? (totalSupply + numTokens) * 1.3 : (totalSupply || 10) * 2
    maxTotalSupply = maxTotalSupply < 10 ? 10 : maxTotalSupply
    const numberOfDataPoints = 200
    const exponent = this.props.exponent

    let data = range(0, maxTotalSupply, maxTotalSupply / numberOfDataPoints / 2)
    data.push(maxTotalSupply)

    let supplyData = range(0, totalSupply, totalSupply / numberOfDataPoints / 2)
    supplyData.push(totalSupply)

    let txData
    const step = numTokens / numberOfDataPoints
    if (this.props.isMint) {
      txData = range(totalSupply, totalSupply + numTokens, step)
      txData.push(totalSupply + numTokens)
    } else {
      txData = range(totalSupply - numTokens, totalSupply, step)
      txData.push(totalSupply)
    }

    const price = (supply: number) => Math.pow(supply, exponent)

    const x = scaleLinear().domain([0, maxTotalSupply]).range([0, this.state.width])
    const y = scaleLinear().domain([price(maxTotalSupply), 0]).range([0, this.props.height])
github pbeshai / d3-scale-interactive / src / ui / DomainInput.js View on Github external
handleMatchRange() {
    const { domain, range, onChange } = this.props;
    const domainMin = domain[0];
    const domainMax = domain[domain.length - 1];
    const step = Math.round(1000 * ((domainMax - domainMin) / (range.length - 1))) / 1000;
    const matched = d3Range(domainMin, domainMax, step).concat(domainMax);
    onChange(matched);
  }
github pbeshai / d3-scale-interactive / src / ui / InterpolatorInput.js View on Github external
renderColorBar() {
    const interpolatorColors = range(0, 1, 0.01).map(t => this.props.interpolator(t));
    this.colorBar = renderComponent(this.colorBar, ColorBar, this.root.node(), {
      colors: interpolatorColors,
    });
  }
github sghall / resonance / docs / src / routes / documentation / Animate / Example2.js View on Github external
function getRandomColor() {
  return range(6).reduce((m) => {
    return `${m}${'0123456789ABCDEF'[Math.floor(Math.random() * 16)]}`;
  }, '#');
}
github williaster / data-ui / packages / demo / examples / 03-sparkline / LineSeriesExamples.jsx View on Github external
strokeWidth={1}
                      reference={tooltipData.index}
                      stroke={allColors.pink[6]}
                      strokeDasharray="4 4"
                    />,
                    ,
                  ]}
                
              )}
            
          
        ))(range(40).map(() => Math.random() * (Math.random() > 0.2 ? 1 : 2)))}

        
           Math.random() * (Math.random() > 0.2 ? 1 : 2))}
          >
github chrisrzhou / react-wordcloud / src / utils.ts View on Github external
export function getDefaultColors(): string[] {
  return range(20)
    .map(number => number.toString())
    .map(scaleOrdinal(schemeCategory10));
}
github williaster / data-ui / packages / demo / examples / 03-sparkline / BarSeriesExamples.jsx View on Github external
const randomData = n => range(n).map(() => Math.random() * (Math.random() > 0.2 ? 1 : 2));