import React from 'react'; import { withContentRect } from 'react-measure' import { filter, range, map, pipe } from 'rambda'; import { ScatterChart, Scatter, XAxis, YAxis, CartesianGrid, Brush, Label } from 'recharts'; import Job from './Job'; import { maxTime, minTime } from '../ganttUtils'; import theme from '../theme'; class Gannt extends React.PureComponent { constructor(props) { super(props); this.state = { startTime: minTime(props.data), endTime: maxTime(props.data) }; } render() { const { data, measureRef, contentRect: { bounds: dimensions } } = this.props; const { startTime } = this.state; const endTime = this.state.endTime === startTime ? startTime + 1 : this.state.endTime; const scopeData = map(processorData => pipe( filter(datum => (datum.startTime >= startTime || (datum.startTime < startTime && datum.endTime >= startTime) ) && datum.startTime <= endTime ), map(datum => { let newDatum = datum; if (newDatum.startTime < startTime) { newDatum = { ...newDatum, startTime, formerStartTime: newDatum.startTime }; } if (newDatum.endTime > endTime) { newDatum = { ...newDatum, endTime, formerEndTime: newDatum.endTime }; } return newDatum; }) )(processorData), data ); const processors = range(1, data.length + 1); const scopeMinTime = minTime(scopeData); const scopeMaxTime = maxTime(scopeData); const ticksCountX = scopeMinTime + scopeMaxTime; const width = Math.max(theme.gantt.maxWidth, dimensions.width); const height = 100 + 1.75 * theme.gantt.job.height * processors.length; const horizontalGuideLines = map( i => theme.gantt.margin.top + i * 1.75 * theme.gantt.job.height - i * 10, range(0, processors.length) ); return (

Ganttov diagram

this.setState({ startTime: startIndex + 1, endTime: endIndex + 1 }) } /> {scopeData.map((processorData, i) => ( } /> ))}
); } } export default withContentRect('bounds')(Gannt);