Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ Desktop.ini
npm-debug.log*
yarn-debug.log*
yarn-error.log*

/examples
3 changes: 2 additions & 1 deletion examples/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import BoxPlot from './Components/BoxPlot';
import GanttChart from './Components/GanttChart';
import LineChart from './Components/LineChart';

import '@hh.ru/react-d3-chart-graphs/styles.css';
// import '@hh.ru/react-d3-chart-graphs/styles.css';
import './dist/styles.css';

class App extends Component {
render() {
Expand Down
3 changes: 2 additions & 1 deletion examples/src/Components/BarChart.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import {BarChart} from '@hh.ru/react-d3-chart-graphs';
// import {BarChart} from '@hh.ru/react-d3-chart-graphs';
import {BarChart} from '../dist/index.js';

const items = [
{
Expand Down
3 changes: 2 additions & 1 deletion examples/src/Components/BoxPlot.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import {BoxPlot} from '@hh.ru/react-d3-chart-graphs';
// import {BoxPlot} from '@hh.ru/react-d3-chart-graphs';
import {BoxPlot} from '../dist/index.js';

const items = [
{
Expand Down
10 changes: 8 additions & 2 deletions examples/src/Components/GanttChart.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import {GanttChart} from '@hh.ru/react-d3-chart-graphs';
// import {GanttChart} from '@hh.ru/react-d3-chart-graphs';
import {GanttChart} from '../dist/index.js';
import {timeFormat} from 'd3-time-format';

const data = [
Expand Down Expand Up @@ -44,8 +45,12 @@ const axesProps = {
yAxis: 5,
},
tickFormat: {
xAxis: timeFormat('%d %B %y'),
// xAxis: timeFormat('%d %B %y'),
xAxis: timeFormat('%-I:%M:%S %p')
},
ticksCount: {
xAxis: 50
}
};

const stackColors = {
Expand All @@ -70,6 +75,7 @@ export default () => {

return (
<GanttChart
manualAxes={true}
axesProps={axesProps}
data={data}
handleBarHover={handleBarHover}
Expand Down
3 changes: 2 additions & 1 deletion examples/src/Components/LineChart.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import {LineChartTime} from '@hh.ru/react-d3-chart-graphs';
// import {LineChartTime} from '@hh.ru/react-d3-chart-graphs';
import {LineChartTime} from '../dist/index.js';
import {timeFormat} from 'd3-time-format';

const items = [
Expand Down
3 changes: 2 additions & 1 deletion examples/src/Components/StackedBarChart.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import {StackedBarChart} from '@hh.ru/react-d3-chart-graphs';
// import {StackedBarChart} from '@hh.ru/react-d3-chart-graphs';
import {StackedBarChart} from '../dist/index.js';

const data = [
{
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@hh.ru/react-d3-chart-graphs",
"name": "react-d3-chart-graphs",
"version": "6.0.2",
"description": "A javascript library for building charts components made with React.js and D3.js",
"main": "dist/index.j",
"description": "A javascript library for building charts components made with React.js and D3.js. Fork by @hh.ru/react-d3-chart-graphs",
"main": "dist/index.js",
"style": "dist/styles.css",
"files": [
"dist/styles.css",
Expand All @@ -17,7 +17,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/hhru/react-d3-chart-graphs"
"url": "https://github.com/Gorgy/react-d3-chart-graphs"
},
"private": false,
"keywords": [
Expand All @@ -30,8 +30,8 @@
"stacked-bar-chart"
],
"author": {
"name": "Andrei Gladkov",
"email": "andrewgladkovlz@gmail.com"
"name": "Andrei Gladkov/Alexei Belov",
"email": "lcf-trane@live.ru"
},
"license": "MIT",
"devDependencies": {
Expand Down
13 changes: 8 additions & 5 deletions src/GanttChart/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Chart extends Component {
}),
render: PropTypes.func,
parentWidth: PropTypes.number,
manualAxes: PropTypes.bool
};

handleBarHover = this.props.handleBarHover ? this.props.handleBarHover.bind(null) : () => {};
Expand All @@ -55,7 +56,7 @@ class Chart extends Component {
};

render() {
const { data, axesProps, margins, stackColors, paddingMultiplier, fillOpacity, render } = this.props;
const { data, axesProps, margins, stackColors, paddingMultiplier, fillOpacity, render, manualAxes } = this.props;
const { legend, padding, tickFormat, ticksCount } = axesProps;
const defaultMargins = { top: 10, right: 10, bottom: 150, left: 80 };
const canvasMargins = margins || defaultMargins;
Expand All @@ -75,11 +76,13 @@ class Chart extends Component {
const yDomain = data.map((item) => item.titleBar);
const datesDomain = d3extent(datePlainList, (d) => new Date(d));

const calcTicksCount =
Math.floor((datesDomain[1] - datesDomain[0]) / (1000 * 60 * 60 * 24)) <= 2
? Math.floor((datesDomain[1] - datesDomain[0]) / (1000 * 60 * 60))
: Math.floor((datesDomain[1] - datesDomain[0]) / (1000 * 60 * 60 * 24));

const AxesTicksCount = {
xAxis: Math.min(
Math.floor((datesDomain[1] - datesDomain[0]) / (1000 * 60 * 60 * 24)),
(ticksCount && ticksCount.xAxis) || 30
),
xAxis: manualAxes ? ticksCount.xAxis : Math.min(calcTicksCount, (ticksCount && ticksCount.xAxis) || 30),
yAxis: (ticksCount && ticksCount.yAxis) || data.length,
};

Expand Down