How to use the d3-time.timeYear.count function in d3-time

To help you get started, we’ve selected a few d3-time 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 orbiting / republik-frontend / lib / team.js View on Github external
const age = (dob) => {
  const dateOfBirth = parseDob(dob)
  const now = new Date()
  let age = timeYear.count(dateOfBirth, now)
  var months = now.getMonth() - dateOfBirth.getMonth()
  if (months < 0 || (months === 0 && now.getDate() < dateOfBirth.getDate())) {
    age -= 1
  }
  return age
}
github orbiting / crowdfunding-frontend / lib / team.js View on Github external
const age = (dob) => {
  const dateOfBirth = parseDob(dob)
  const now = new Date()
  let age = timeYear.count(dateOfBirth, now)
  var months = now.getMonth() - dateOfBirth.getMonth()
  if (months < 0 || (months === 0 && now.getDate() < dateOfBirth.getDate())) {
    age -= 1
  }
  return age
}
github orbiting / styleguide / src / components / Chart / Lines.js View on Github external
}
  }

  const columnWidth = Math.floor(width / columns) - 1
  const innerWidth = columnWidth - paddingLeft - paddingRight

  const xValues = data.map(xAccessor)
  let x
  let xTicks
  let xFormat = d => d
  if (props.xScale === 'time') {
    xFormat = timeFormat(props.timeFormat)
    const xTimes = xValues.map(d => d.getTime())
    const domainTime = [min(xTimes), max(xTimes)]
    const domain = domainTime.map(d => new Date(d))
    let yearInteval = Math.round(timeYear.count(domain[0], domain[1]) / 3)

    let time1 = timeYear.offset(domain[0], yearInteval).getTime()
    let time2 = timeYear.offset(domain[1], -yearInteval).getTime()

    x = scaleTime().domain(domain)
    xTicks = [
      domainTime[0],
      sortBy(xTimes, d => Math.abs(d - time1))[0],
      sortBy(xTimes, d => Math.abs(d - time2))[0],
      domainTime[1]
    ]
      .filter(deduplicate)
      .map(d => new Date(d))
  } else {
    let domain = xValues.filter(deduplicate)
    x = scalePoint().domain(domain)
github newamericafoundation / teddy / packages / timeline / src / Timeline / TimelineControl.js View on Github external
constructor(props) {
    super(props);
    this.state = { xDragPos: 0, dragging: false, instructionsHidden: false };
    this.width = null;
    this.count = timeYear.count(this.props.minDate, this.props.maxDate);
    this.scrubberWidth = this.props.divisionWidth * this.count;
    this.scale = scaleTime({
      domain: [this.props.minDate, this.props.maxDate],
      range: [20, this.scrubberWidth - 20]
    });
    this._data = dodge(this.props.data, 14, d => d.date, this.scale);
    this.lastActiveX = this._data[this.props.activePoint].x;
    this.showTooltipDebounced = debounce(this.handleMouseOver, 300);
    this.dragStarted = this.dragStarted.bind(this);
    this.dragEnded = this.dragEnded.bind(this);
  }