How to use the d3.scaleLinear function in d3

To help you get started, we’ve selected a few d3 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 OmicsDI / ddi-web-app / src / app / profile / counting-data-dashboard-profile / dashboard-claim-count-profile / dashboard-claim-count-profile.component.ts View on Github external
//
        // console.log(Array.from(annualDataExtends).length);
        // var minDate = new Date(d3.min(annualDataExtends, d => {
        //     return parseInt(d["year"]);
        // }), 0, 0);
        // var maxDate = new Date(d3.max(annualDataExtends, d => {
        //     return parseInt(d["year"]);
        // }), 0, 1);

        const x0 = d3.scaleTime().range([0, width - 30]);
        const y0 = d3.scaleLinear().range([height - heightOffset, 0]);
        const y1 = d3.scaleLinear().range([height - heightOffset, 0]);
        const xAxis = d3.axisBottom(x0).ticks(yearSet.size + 2);
        const yAxisLeft = d3.axisLeft(y0).ticks(2);
        const yAxisRight = d3.axisRight(y1).ticks(2);
        const yLine = d3.scaleLinear().range([15, 0]);
        const yNavLine = d3.axisBottom(yLine).ticks(0);


        const minpointer = processedData.get('minYear');
        // console.log(minpointer);
        const max_M_P = processedData.get('max_M_P');
        const max_G_T = processedData.get('max_G_T');
        console.log(max_G_T);
        console.log(max_M_P);
        // console.log(max);
        x0.domain([new Date(Number(minpointer) - 1, 0, 0), new Date()]);

        y0.domain([0, Number(max_G_T)]);
        y1.domain([0, Number(max_M_P)]);
github w3reality / three-laser-pointer / examples / demo-path / src / index.js View on Github external
const getDem = (contours, northWest, southEast, radius, cb) => {
        // console.log('getDem():', contours, northWest, southEast, radius);

        const colorRange = d3.scaleLinear()
            .domain([0, contours.length])
            .interpolate(d3.interpolateRgb)
            .range(["#231918", "#ed6356"]);

        const objs = [];
        const addSlice = (coords, iContour) => {
            let [lines, extrudeShade] = buildSliceGeometry(
                coords, iContour, colorRange(iContour),
                contours, northWest, southEast, radius);
            lines.forEach((line) => { objs.push(line); });
            objs.push(extrudeShade);
        };

        // iterate through elevations
        for (let iContour = 0; iContour < contours.length; iContour++) {
            let level = contours[iContour].geometry.geometry;
github lablup / backend.ai-console / src / components / backend-ai-chart.js View on Github external
graphWidth  = this.width - margin.left - margin.right,
          graphHeight = this.height - margin.top - margin.bottom;

    // assumption: data is already zipped
    const { data } = this.collection;

    const xScale = d3
      .scaleTime()
      .domain(d3.extent(data[0], d => d.x))
      .range([0, graphWidth]);

    const xAxis = d3
      .axisBottom(xScale)
      .tickFormat(d3.timeFormat("%b %d %H:%M"));

    const yScale = d3
      .scaleLinear()
      .domain([0, d3.max(data.map(datum => d3.max(datum, d => d.y)))])
      .range([graphHeight, 0]);

    const yAxis = d3
      .axisLeft(yScale)
      .ticks(5);

    const line = d3
      .line()
      .x(d => xScale(d.x))
      .y(d => yScale(d.y))
      .curve(d3.curveMonotoneX);

    const rectWidth = 40, rectHeight = 40;
github victordibia / anomagram / app / src / components / rocchart / ROCChart.jsx View on Github external
// this.xScale = d3.scaleLinear()
        //     .domain([d3.min(data, function (d) { return d.fpr }),
        //     d3.max(data, function (d) { return d.fpr })]) // input 
        //     .range([0, this.chartWidth]); // output
        this.xScale = d3.scaleLinear()
            .domain([0, 1]) // input 
            .range([0, this.chartWidth]); // output


        // this.yScale = d3.scaleLinear()
        //     .domain([d3.min(data, function (d) { return d.tpr }),
        //     d3.max(data, function (d) { return d.tpr })]) // input 
        //     .range([this.chartHeight, 0])
        this.yScale = d3.scaleLinear()
            .domain([0, 1]) // input 
            .range([this.chartHeight, 0])

        this.xAxis = d3.axisBottom(this.xScale)
        this.yAxis = d3.axisRight(this.yScale)
            .tickSize(this.minChartWidth)
    }
    drawLines(svg, data) {
github ft-interactive / visual-vocabulary-templates / hemicycle / hemicycle.js View on Github external
export function draw() {
    let distanceScale = d3.scaleLinear();
    let angleScale = d3.scaleLinear();
    let rem = 16;
    let interpolation = false;
    let rows = 10;
    let arc = 180;
    let datasize;
    // let data;
    let partyOrder;
    let innerRadiusCoefficient = 0.4;

    const colourScale = d3.scaleOrdinal()
        .unknown(undefined);

    function chart(parent) {
        const { data, width, height } = parent.datum();
        const { seats, rowWidth } = computeSeats(data, width, height, innerRadiusCoefficient);
        const seatRadius = (d) => {
github ft-interactive / visual-vocabulary-templates / line / annotations.js View on Github external
export function draw() {
    let lineWidth = 100
    let plotDim = [100,100];
    let yScale = d3.scaleLinear();
    let xScale = d3.scaleLinear();
    let scaleFactor = 1
    let seriesNames  = []; // eslint-disable-line
    let rem = 16;
    let sizeScale = d3.scaleSqrt();
    let formatDecimal = d3.format(".2f")
    let frameName = ''
    const colourScale = d3.scaleOrdinal();
    let offset = []

    function label(parent) {

        const annotation = parent.append('g')
            .on('mouseover', pointer);
        
        annotation.selectAll('line')
github mitmedialab / MediaCloud-Web-Tools / src / components / vis / Word2VecChart.js View on Github external
.text(maxLengthWord)
    .style('font-size', `${options.maxFontSize}px`)
    .node()
    .getBoundingClientRect()
    .width;
  d3.select('.word-width-span').remove();

  const margin = {
    top: options.maxFontSize,
    right: maxWordWidth / 2,
    bottom: options.maxFontSize,
    left: maxWordWidth / 2,
  };

  // Define Scales
  const xScale = d3.scaleLinear()
    .domain([d3.min(options.scaleWords, d => d[options.xProperty]), d3.max(options.scaleWords, d => d[options.xProperty])])
    .range([margin.left, options.width - margin.right]);

  const yScale = d3.scaleLinear()
    .domain([d3.min(options.scaleWords, d => d[options.yProperty]), d3.max(options.scaleWords, d => d[options.yProperty])])
    .range([options.height - margin.top, margin.bottom]);

  // Add Text Labels
  const sizeRange = { min: options.minFontSize, max: options.maxFontSize };
  if (fullExtent === undefined) {
    options.fullExtent = d3.extent(words, d => d.tfnorm);
  }

  const colorScale = d3.scaleLinear()
    .domain(options.fullExtent)
    .range([options.minColor, options.maxColor]);
github Vetkdf / yang-test / src / app / business / m3 / m3v2 / m3v2.component.ts View on Github external
let width = 700, height = 400, margin = {left:35, top:20, right:20,bottom:20},
        g_width = width - margin.left - margin.right,g_height = height - margin.top - margin.bottom;

        let colors=[d3.rgb(0,0,255),d3.rgb(255,0,0)];
        let data = [{a1:[[0,3],[1,1],[2,3],[3,5],[4,9],[5,4],[6,2],[7,3],[8,6],[9,8],[10,10],[11,5],[12,3],]},
                    {a1:[[0,4],[1,3],[2,8],[3,5],[4,5],[5,10],[6,7],[7,5],[8,1],[9,2],[10,8],[11,11],[12,7],]},];

        let gdpmax=0;
        for(let i=0;igdpmax) gdpmax=currGdp;
        }
        //gdpmax = gdpmax + 1;

        let scale_x = d3.scaleLinear()
        .domain([0, data[0].a1.length-1])
        .range([0, g_width]);

        let scale_y = d3.scaleLinear()
        .domain([0, gdpmax])  //domain([0, gdpmax * 1.1])   domain([0, gdpmax])
        .range([g_height,0]);

        let line_generator = d3.line()
        .x(function(d){return scale_x(d[0]);})
        .y(function(d){return scale_y(d[1]);})
        //.curve(d3.curveBasis);

        let svg = d3.select("#container")
        .append("svg:svg")
        .attr("width", width)
        .attr("height", height);
github apache / drat / webapps / proteus-new / src / main / webapp / resources / src / components / barchartcomp.vue View on Github external
init(){
          var  svg = d3.select("#barsvg"),
              margin = {top: 20, right: 20, bottom: 50, left: 40},
              width = +svg.attr("width") - margin.left - margin.right,
              height = +svg.attr("height") - margin.top - margin.bottom;

              svg.selectAll("*").remove();

          var x = d3.scaleBand().rangeRound([0, width]).padding(0.1),
              y = d3.scaleLinear().rangeRound([height, 0]);

          var g = svg.append("g")
              .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

          
          
          var dataval = this.dts;
          if(dataval.length!=0){
            this.emptynote='';
            x.domain(dataval.map(function(d) { return d.letter; }));
            y.domain([0, d3.max(dataval, function(d) { return d.frequency; })]);

            g.append("g")
                .attr("class", "axis axis--x")
                .attr("transform", "translate(0," + height + ")")
github flekschas / hipiler / src / components / fragments / fragments-utils.js View on Github external
for (let i = 1; i < matrices.length; i++) {
    for (let j = i - 1; j >= 0; j--) {
      const distance = calculateDistance(matrices[i], matrices[j]);

      distanceMatrix[i][j] = distance;
      distanceMatrix[j][i] = distance;

      maxDistance = Math.max(maxDistance, distance);
    }
  }

  return { distanceMatrix, maxDistance };
}

export const cellValue = scaleLinear().range([0, 1]).nice();

export const cellValueLogNorm = scaleLinear().domain([0, 1]).range([1, 10]);
export const cellValueLogTransform = scaleLog().nice();
export const cellValueLog = value => (value === -1 ? -1 : cellValueLogTransform(
  cellValueLogNorm(value)
));

export const frameValue = scaleLinear().range([0.1, 0.9]).nice();

/**
 * Get the minimal dimension of two matrices assuming that both are squared.
 *
 * @param {array} matrix1 - First raw matrix.
 * @param {array} matrix2 - Second raw matrix.
 * @return {number} Smaller dimension of the two matrices.
 */