src/grid/Grid.js
// get state object with calculated params, ready for rendering
get state object with calculated params, ready for rendering
get state object with calculated params ready for rendering
calcCoordinate(coord, shape) {
    const state = {
      coordinate: coord,
      shape,
      grid: this
    };
    state.range = coord.getRange(state);
    state.offset = clamp(
      coord.offset - state.range * clamp(0.5, 0, 1),
      Math.max(coord.min, -Number.MAX_VALUE + 1),
      Math.min(coord.max, Number.MAX_VALUE) - state.range
    );
    state.zoom = coord.zoom;
    state.axisColor = typeof coord.axisColor === 'number'
      ? alpha(coord.color, coord.axisColor)
      : coord.axisColor || coord.color;
    state.axisWidth = coord.axisWidth || coord.lineWidth;
    state.lineWidth = coord.lineWidth;
    state.tickAlign = coord.tickAlign;
    state.labelColor = state.color;
    if (typeof coord.padding === 'number') {
      state.padding = Array(4).fill(coord.padding);
    } else if (coord.padding instanceof Function) {
      state.padding = coord.padding(state);
    } else {
      state.padding = coord.padding;
    }
    if (typeof coord.fontSize === 'number') {
      state.fontSize = coord.fontSize;
    } else {
      const units = parseUnit(coord.fontSize);
      state.fontSize = units[0] * toPx(units[1]);
    }
    state.fontFamily = coord.fontFamily || 'sans-serif';
    let lines;
    if (coord.lines instanceof Function) {
      lines = coord.lines(state);
    } else {
      lines = coord.lines || [];
    }
    state.lines = lines;
    if (coord.lineColor instanceof Function) {
      state.lineColors = coord.lineColor(state);
    } else if (Array.isArray(coord.lineColor)) {
      state.lineColors = coord.lineColor;
    } else {
      let color = alpha(coord.color, coord.lineColor);
      if (typeof coord.lineColor !== 'number') {
        color = coord.lineColor === false || coord.lineColor == null ? null : coord.color;
      }
      state.lineColors = Array(lines.length).fill(color);
    }
    let ticks;
    if (coord.ticks instanceof Function) {
      ticks = coord.ticks(state);
    } else if (Array.isArray(coord.ticks)) {
      ticks = coord.ticks;
    } else {
      const tick = coord.ticks === true || coord.ticks === true
        ? state.axisWidth * 2 : coord.ticks || 0;
      ticks = Array(lines.length).fill(tick);
    }
    state.ticks = ticks;
    let labels;
    if (coord.labels === true) labels = state.lines;
    else if (coord.labels instanceof Function) {
      labels = coord.labels(state);
    } else if (Array.isArray(coord.labels)) {
      labels = coord.labels;
    } else if (isObj(coord.labels)) {
      labels = coord.labels;
    } else {
      labels = Array(state.lines.length).fill(null);
    }
    state.labels = labels;
    if (isObj(ticks)) {
      state.ticks = Array(lines.length).fill(0);
    }
    if (isObj(labels)) {
      state.labels = Array(lines.length).fill(null);
    }
    if (isObj(ticks)) {
      Object.keys(ticks).forEach((value, tick) => {
        state.ticks.push(tick);
        state.lines.push(parseFloat(value));
        state.lineColors.push(null);
        state.labels.push(null);
      });
    }
    if (isObj(labels)) {
      Object.keys(labels).forEach((label, value) => {
        state.labels.push(label);
        state.lines.push(parseFloat(value));
        state.lineColors.push(null);
        state.ticks.push(null);
      });
    }
    return state;
  }
calcCoordinate ( coord , shape ) { const state = { coordinate : coord , shape , grid : this } ; state . range = coord . getRange ( state ) ; state . offset = clamp ( coord . offset - state . range * clamp ( 0.5 , 0 , 1 ) , Math . max ( coord . min , - Number . MAX_VALUE + 1 ) , Math . min ( coord . max , Number . MAX_VALUE ) - state . range ) ; state . zoom = coord . zoom ; state . axisColor = typeof coord . axisColor === 'number' ? alpha ( coord . color , coord . axisColor ) : coord . axisColor || coord . color ; state . axisWidth = coord . axisWidth || coord . lineWidth ; state . lineWidth = coord . lineWidth ; state . tickAlign = coord . tickAlign ; state . labelColor = state . color ; if ( typeof coord . padding === 'number' ) { state . padding = Array ( 4 ) . fill ( coord . padding ) ; } else if ( coord . padding instanceof Function ) { state . padding = coord . padding ( state ) ; } else { state . padding = coord . padding ; } if ( typeof coord . fontSize === 'number' ) { state . fontSize = coord . fontSize ; } else { const units = parseUnit ( coord . fontSize ) ; state . fontSize = units [ 0 ] * toPx ( units [ 1 ] ) ; } state . fontFamily = coord . fontFamily || 'sans-serif' ; let lines ; if ( coord . lines instanceof Function ) { lines = coord . lines ( state ) ; } else { lines = coord . lines || [ ] ; } state . lines = lines ; if ( coord . lineColor instanceof Function ) { state . lineColors = coord . lineColor ( state ) ; } else if ( Array . isArray ( coord . lineColor ) ) { state . lineColors = coord . lineColor ; } else { let color = alpha ( coord . color , coord . lineColor ) ; if ( typeof coord . lineColor !== 'number' ) { color = coord . lineColor === false || coord . lineColor == null ? null : coord . color ; } state . lineColors = Array ( lines . length ) . fill ( color ) ; } let ticks ; if ( coord . ticks instanceof Function ) { ticks = coord . ticks ( state ) ; } else if ( Array . isArray ( coord . ticks ) ) { ticks = coord . ticks ; } else { const tick = coord . ticks === true || coord . ticks === true ? state . axisWidth * 2 : coord . ticks || 0 ; ticks = Array ( lines . length ) . fill ( tick ) ; } state . ticks = ticks ; let labels ; if ( coord . labels === true ) labels = state . lines ; else if ( coord . labels instanceof Function ) { labels = coord . labels ( state ) ; } else if ( Array . isArray ( coord . labels ) ) { labels = coord . labels ; } else if ( isObj ( coord . labels ) ) { labels = coord . labels ; } else { labels = Array ( state . lines . length ) . fill ( null ) ; } state . labels = labels ; if ( isObj ( ticks ) ) { state . ticks = Array ( lines . length ) . fill ( 0 ) ; } if ( isObj ( labels ) ) { state . labels = Array ( lines . length ) . fill ( null ) ; } if ( isObj ( ticks ) ) { Object . keys ( ticks ) . forEach ( ( value , tick ) => { state . ticks . push ( tick ) ; state . lines . push ( parseFloat ( value ) ) ; state . lineColors . push ( null ) ; state . labels . push ( null ) ; } ) ; } if ( isObj ( labels ) ) { Object . keys ( labels ) . forEach ( ( label , value ) => { state . labels . push ( label ) ; state . lines . push ( parseFloat ( value ) ) ; state . lineColors . push ( null ) ; state . ticks . push ( null ) ; } ) ; } return state ; }
get state object with calculated params, ready for rendering
get state object with calculated params ready for rendering
// calculate real offset/range // calc style // get padding // calc font // get lines stops, including joined list of values // calc colors // calc ticks // calc labels // convert hashmap ticks/labels to lines + colors // eslint-disable-next-line guard-for-in