GithubHelp home page GithubHelp logo

react-d3-axis's People

Contributors

shauns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-d3-axis's Issues

Move x axis to the bottom

Probably this will sound as a really dumb question, but how do I move the x axis to the bottom of a chart?

I tried to use style={{ orient: BOTTOM }}, but that affects only the ticks, not the <g> element of the axis.

<Axis {...axisPropsFromBandedScale(widthScale)} style={{ orient: BOTTOM }} />

Are there any props I can pass to translate the <g> element?

By the way, cool library, I was looking for a way to avoid using refs for d3 axes.

react native svg axis

Since we cant use the d3-axis in react native, since it uses div' etc - have you thought of supporting react-native-svg components? It should be a simple fix - maybe it can switch between them - ill make a test mysql now..

Conflict in axisPropsFromTickScale with scaleTime on Next.js

Description of the issue: When calling axisPropsFromTickScale with scaleTime, Next.js returns the error: Warning: Did not expect server HTML to contain a <g> in <g>, pointing to a mismatch between the client and server-side rendered HTML trees. This doesn't happen with other scales such as scaleLinear.

Sample code used for the component:

import {scaleLinear, scaleTime} from 'd3-scale';
import {Axis, axisPropsFromTickScale, axisPropsFromBandedScale, LEFT, TOP, RIGHT, BOTTOM} from 'react-d3-axis';
import {extent, histogram} from 'd3-array';

const HistogramChart = (props) => {

  var width = 650;
  var height = 650;

  let xDomain = extent(props.data, d => d.sales_order_date);
  let yDomain = extent(props.data, d => d.sales_order_ammount);

  let xScale = scaleTime()
  .domain(xDomain)
  .rangeRound([0, width]);

  let yScale = scaleLinear()
    .range([height, 0])
    .domain(yDomain);

  let setBarHeight = d => (height - yScale(d.sales_order_ammount))

  let setRectY = d => (yScale(d.sales_order_ammount))

  var transformBar = (d, i) => ("translate("+ i * width/props.data.length + ",0)");
  return (
    <svg>
      <g transform="translate(40,20)">
        {props.data.map((d, i) => {
          return <g key={i} className="bar" transform={transformBar(d, i)} >
            <rect width={width/props.data.length} height={setBarHeight(d)} y={setRectY(d)} fill="#4b5320"/>
          </g>
        })}
      </g>
      <g transform={"translate(40," + (height + 20) + ")"} fill="#FFF">
        <Axis {...axisPropsFromTickScale(xScale, 5)} style={{orient: BOTTOM}} />
      </g>
      <g transform="translate(40,20)">
        <Axis {...axisPropsFromTickScale(yScale, 15)} style={{orient: LEFT}} />
      </g>
    </svg>
  )
}

export default HistogramChart;

Sample data passed to the component as props:

sampleData = [{ sales_order_date: 2018-08-14T03:22:59.000Z,
       sales_order_ammount: 1003.39,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2018-08-02T01:32:46.000Z,
       sales_order_ammount: 0,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2018-08-14T22:29:45.000Z,
       sales_order_ammount: 1423.68,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2018-05-23T19:58:17.000Z,
       sales_order_ammount: 3646.87,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2018-07-17T06:57:32.000Z,
       sales_order_ammount: 3478.84,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2018-08-15T00:46:19.000Z,
       sales_order_ammount: 2904.56,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2017-08-23T02:33:33.000Z,
       sales_order_ammount: 2821.32,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2018-04-04T20:45:54.000Z,
       sales_order_ammount: 3773.35,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2018-07-05T00:58:22.000Z,
       sales_order_ammount: 3339.32,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2018-07-13T02:53:41.000Z,
       sales_order_ammount: 3298.85,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2018-07-17T03:19:28.000Z,
       sales_order_ammount: 3292.26,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2018-07-14T06:03:37.000Z,
       sales_order_ammount: 3283.27,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2018-08-15T05:18:38.000Z,
       sales_order_ammount: 3285.05,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2017-11-20T01:33:27.000Z,
       sales_order_ammount: 3068.21,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2017-08-01T07:55:37.000Z,
       sales_order_ammount: 1758.5,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2017-09-05T22:49:44.000Z,
       sales_order_ammount: 1725.66,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2017-09-24T01:22:37.000Z,
       sales_order_ammount: 1706.49,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2017-08-28T09:09:16.000Z,
       sales_order_ammount: 1703.8,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2017-08-30T03:38:59.000Z,
       sales_order_ammount: 1732.68,
       sales_order_currency: 'MXN' },
     { sales_order_date: 2017-11-30T22:53:49.000Z,
       sales_order_ammount: 1745.27,
       sales_order_currency: 'MXN' }]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.