How to use the d3-time-format.timeParse function in d3-time-format

To help you get started, we’ve selected a few d3-time-format 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 Jacwutang / CryptoEngineX / client / src / components / Chart / utils.js View on Github external
import { tsvParse, csvParse } from 'd3-dsv';
import { timeParse } from 'd3-time-format';
import axios from 'axios';
import ccxt from 'ccxt';

// const parseDateTime = timeParse('%Y-%m-%dT%H:%M:%S.%LZ');
const parseDateTime = timeParse('%Q');

// function parseData(ticker) {
//   let d = {};
//   d.date = parseDateTime(ticker.datetime);
//   d.close = ticker.close;
//   d.high = ticker.high;
//   d.low = ticker.low;
//   d.volume = parseFloat(ticker.info.volume);
//
//   return d;
// }

const timeframeToMSHash = {
  '1m': 1000 * 60,
  '1h': 1000 * 60 * 60,
  '1M': 2629742 * 1000,
github hshoff / vx / packages / vx-demo / src / components / tiles / threshold.js View on Github external
import React from 'react';
import { Group } from '@vx/group';
import { curveBasis } from '@vx/curve';
import { LinePath } from '@vx/shape';
import { Threshold } from '@vx/threshold';
import { scaleTime, scaleLinear } from '@vx/scale';
import { AxisLeft, AxisBottom } from '@vx/axis';
import { GridRows, GridColumns } from '@vx/grid';
import { cityTemperature as data } from '@vx/mock-data';
import { timeParse } from 'd3-time-format';

const parseDate = timeParse('%Y%m%d');

// accessors
const date = d => parseDate(d.date);
const ny = d => d['New York'];
const sf = d => d['San Francisco'];

// scales
const xScale = scaleTime({
  domain: [Math.min(...data.map(date)), Math.max(...data.map(date))],
});
const yScale = scaleLinear({
  domain: [
    Math.min(...data.map(d => Math.min(ny(d), sf(d)))),
    Math.max(...data.map(d => Math.max(ny(d), sf(d)))),
  ],
  nice: true,
github rrag / react-stockcharts / docs / documentation.js View on Github external
import React from "react";
import ReactDOM from "react-dom";

import { csvParse, tsvParse } from  "d3-dsv";
import { merge } from "d3-array";
import { timeParse } from "d3-time-format";

const parseDate = timeParse("%Y-%m-%d");
const parseDateTime = timeParse("%Y-%m-%d %H:%M:%S");


import { TypeChooser } from "react-stockcharts/lib/helper";
import "stylesheets/re-stock";

import Nav from "lib/navbar";
import Sidebar from "lib/sidebar";
import MainContainer from "lib/main-container";
import MenuGroup from "lib/menu-group";
import MenuItem from "lib/MenuItem";

const DOCUMENTATION = {
	head: "Documentation",
	pages: [
		// require("./lib/page/GettingStartedPage").default,
github nteract / nteract / packages / transform-dataresource / src / types / date.js View on Github external
export function castDate(format, value) {
  if (!lodash.isDate(value)) {
    if (!lodash.isString(value)) {
      return ERROR;
    }
    try {
      if (format === "default") {
        value = moment(timeParse(_DEFAULT_PATTERN)(value));
      } else if (format === "any") {
        value = moment(value);
      } else {
        if (format.startsWith("fmt:")) {
          console.warn(
            `Format "fmt:
github hpcc-systems / Visualization / packages / form / src / Slider.ts View on Github external
enter(domNode, element) {
        super.enter(domNode, element);
        this.resize({ width: this.width(), height: 50 });

        this.xScale = d3ScaleLinear()
            .clamp(true);

        this.slider = element.append("g")
            .attr("class", "slider")
            ;
        if (this.low() === null && this.high() === null) {
            if (this.lowDatetime() !== null && this.highDatetime() !== null) {
                const time_parser = d3TimeParse(this.timePattern() ? this.timePattern() : "%Q");
                this.low(time_parser(this.lowDatetime()).getTime());
                this.high(time_parser(this.highDatetime()).getTime());
            }
        }
        this.slider.append("line")
            .attr("class", "track")
            .select(function () { return this.parentNode.appendChild(this.cloneNode(true)); })
            .attr("class", "track-inset")
            .select(function () { return this.parentNode.appendChild(this.cloneNode(true)); })
            .attr("class", "track-overlay")
            .call(d3Drag()
                .on("start", () => {
                    this.moveStartPos = d3Event.x;
                    this.handleLeftStartPos = this.handleLeftPos;
                    this.handleRightStartPos = this.handleRightPos;
                    if (this.allowRange() && this.handleLeftPos <= d3Event.x && d3Event.x <= this.handleRightPos) {
github lineupjs / lineupjs / src / model / DatesMapColumn.ts View on Github external
constructor(id: string, desc: Readonly) {
    super(id, desc);
    this.format = timeFormat(desc.dateFormat || '%x');
    this.parse = desc.dateParse ? timeParse(desc.dateParse) : timeParse(desc.dateFormat || '%x');
    this.setDefaultRenderer('default');
  }
github orbiting / crowdfunding-frontend / lib / team.js View on Github external
sylke,
  carlos,
  andrea
]

const admin = [
  susanne,
  nadja,
  laurent,
  francois,
  nadine,
  philipp,
  sylvie
]

const parseDob = timeParse('%d.%m.%Y')
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
}

team.forEach(person => {
  person.age = person.dob ? age(person.dob) : person.age
})
team.sort((a, b) => descending(a.age, b.age) || ascending(a.name, b.name))
github globeandmail / chart-tool / meteor / imports / modules / utils.js View on Github external
export function standardizeDates(data, oldFormat, newFormat, isScatterplot) {

  const stdFormat = timeFormat(newFormat),
    currFormat = timeParse(oldFormat);

  const jsonData = Papa.parse(data, { delimiter: ',' });

  for (let i = 1; i < jsonData.data.length; i++) {
    const date = currFormat(jsonData.data[i][isScatterplot ? 1 : 0]);
    if (date !== null) {
      jsonData.data[i][isScatterplot ? 1 : 0] = stdFormat(date);
    } else {
      throw new Meteor.Error('Incompatible date formatting', "Make sure your data's date style matches the formatting dropdown.");
    }
  }

  const csvOptions = {
    delimiter: ',',
    newline: '\n'
  };
github frictionlessdata / tableschema-js / src / types.js View on Github external
castFmt(value) {
    const date = timeParse(this.format.replace(/^fmt:/, ''))(value)
    if (date == null) {
      throw new Error()
    }
    return date
  }
}
github hpcc-systems / Visualization / packages / other / src / CalendarHeatMap.ts View on Github external
calendarData() {
        if (this.fields().length === 0 || this.data().length === 0) {
            return [];
        }
        const dateParser = d3TimeParse(this.datePattern());
        const valueFormatter = this.aggrDeltaColumn() ? d3Format(".1%") : d3Format("s");
        if (this._prevDateColumn !== this.dateColumn() ||
            this._prevAggrType !== this.aggrType() ||
            this._prevAggrColumn !== this.aggrColumn() ||
            this._prevAggrDeltaColumn !== this.aggrDeltaColumn()) {
            this._prevDateColumn = this.dateColumn();
            this._prevAggrType = this.aggrType();
            this._prevAggrColumn = this.aggrColumn();
            this._prevAggrDeltaColumn = this.aggrDeltaColumn();
            this._view = this._db.aggregateView([this.dateColumn()], this.aggrType(), this.aggrColumn(), this.aggrDeltaColumn());
        }
        return this._view.entries().map(function (row) {
            row.dateKey = dateParser(row.key);
            row.formattedValues = valueFormatter(row.value.aggregate);
            row.origRows = row.value;
            return row;