|
| 1 | +// @flow |
| 2 | + |
| 3 | +import React, { Component } from 'react' |
| 4 | +import { Table } from 'react-bootstrap' |
| 5 | +import moment from 'moment' |
| 6 | + |
| 7 | +import type { FeedVersion } from '../../../types' |
| 8 | + |
| 9 | +type Props = { |
| 10 | + activeVersion: FeedVersion, |
| 11 | + activeVersionIndex: number, |
| 12 | + comparedVersion: FeedVersion, |
| 13 | + comparedVersionIndex: number |
| 14 | +} |
| 15 | + |
| 16 | +const FeedSpan = ({ relativeLength, relativeOffset, ...props }) => { |
| 17 | + return ( |
| 18 | + <div {...props} style={{...props.style, height: '1em', position: 'relative'}}> |
| 19 | + <div className='label-success' style={{height: '100%', left: `${relativeOffset * 100}%`, position: 'absolute', width: `${relativeLength * 100}%`}} /> |
| 20 | + </div> |
| 21 | + ) |
| 22 | +} |
| 23 | + |
| 24 | +export default class TripsChart extends Component<Props> { |
| 25 | + _renderFeedSpan = () => { |
| 26 | + } |
| 27 | + |
| 28 | + render () { |
| 29 | + const { activeVersion, comparedVersion, comparedVersionIndex } = this.props |
| 30 | + |
| 31 | + const activeVersionStartDate = moment(activeVersion.validationSummary.startDate) |
| 32 | + const activeVersionEndDate = moment(activeVersion.validationSummary.endDate) |
| 33 | + const comparedVersionStartDate = moment(comparedVersion.validationSummary.startDate) |
| 34 | + const comparedVersionEndDate = moment(comparedVersion.validationSummary.endDate) |
| 35 | + |
| 36 | + const firstDate = moment.min(activeVersionStartDate, comparedVersionStartDate) |
| 37 | + const lastDate = moment.max(activeVersionEndDate, comparedVersionEndDate) |
| 38 | + |
| 39 | + const numDays = lastDate.diff(firstDate, 'days') |
| 40 | + const activeVersionOffset = activeVersionStartDate.diff(firstDate, 'days') |
| 41 | + const activeVersionLength = activeVersionEndDate.diff(activeVersionStartDate, 'days') |
| 42 | + const comparedVersionOffset = comparedVersionStartDate.diff(firstDate, 'days') |
| 43 | + const comparedVersionLength = comparedVersionEndDate.diff(comparedVersionStartDate, 'days') |
| 44 | + /* |
| 45 | + const data = dailyTripCounts |
| 46 | + .slice(0, maxDaysToShow) |
| 47 | + .map((count, index) => [firstDate.clone().add(index, 'days'), count]) |
| 48 | + const graphHeight = 30 |
| 49 | + const spacing = 8 |
| 50 | + const leftMargin = 50 |
| 51 | + const rightMargin = 50 |
| 52 | + const bottomMargin = 75 |
| 53 | + const svgWidth = leftMargin + rightMargin + (data.length * spacing) |
| 54 | + const svgHeight = graphHeight + bottomMargin |
| 55 | + const maxTrips = Math.max.apply(Math, data.map(d => d[1])) |
| 56 | + const yAxisMax = getChartMax(maxTrips) |
| 57 | + const rowHeight = 20 |
| 58 | +
|
| 59 | + const yAxisLabels = [ |
| 60 | + `Version ${activeVersionIndex}`, |
| 61 | + `Version ${comparedVersionIndex}` |
| 62 | + ] |
| 63 | +*/ |
| 64 | + return ( |
| 65 | + <Table bordered condensed> |
| 66 | + <tbody> |
| 67 | + <tr> |
| 68 | + <td>This version</td> |
| 69 | + <td>{activeVersion.validationSummary.startDate}</td> |
| 70 | + <td><FeedSpan relativeLength={activeVersionLength / numDays} relativeOffset={activeVersionOffset / numDays} style={{width: '200px'}} /></td> |
| 71 | + <td>{activeVersion.validationSummary.endDate}</td> |
| 72 | + </tr> |
| 73 | + <tr> |
| 74 | + <td>Version {comparedVersionIndex}</td> |
| 75 | + <td>{comparedVersion.validationSummary.startDate}</td> |
| 76 | + <td><FeedSpan relativeLength={comparedVersionLength / numDays} relativeOffset={comparedVersionOffset / numDays} style={{width: '200px'}} /></td> |
| 77 | + <td>{comparedVersion.validationSummary.endDate}</td> |
| 78 | + </tr> |
| 79 | + </tbody> |
| 80 | + </Table> |
| 81 | + ) |
| 82 | + } |
| 83 | +} |
0 commit comments