*/
// @flow
import React from 'react';
-import { map } from 'lodash';
+import { minBy } from 'lodash';
import { AutoSizer } from 'react-virtualized';
import { generateSeries, GRAPHS_METRICS_DISPLAYED } from '../../projectActivity/utils';
import { getGraph } from '../../../helpers/storage';
import type { History, Metric } from '../types';
type Props = {
- history: History,
+ history: ?History,
metrics: Array<Metric>,
project: string,
router: { replace: ({ pathname: string, query?: {} }) => void }
return metrics;
};
- getSeries = (history: History, graph: string, metricsType: string) => {
- const measureHistory = map(history, (item, key) => ({
- metric: key,
- history: item.filter(p => p.value != null)
+ getSeries = (history: ?History, graph: string, metricsType: string) => {
+ const myHistory = history;
+ if (!myHistory) {
+ return [];
+ }
+ const metrics = this.getDisplayedMetrics(graph);
+ const firstValid = minBy(
+ metrics.map(metric => myHistory[metric].find(p => p.value || p.value === 0)),
+ 'date'
+ );
+ const measureHistory = metrics.map(metric => ({
+ metric,
+ history: firstValid
+ ? myHistory[metric].filter(p => p.date >= firstValid.date)
+ : myHistory[metric]
}));
- return generateSeries(measureHistory, graph, metricsType, this.getDisplayedMetrics(graph));
+ return generateSeries(measureHistory, graph, metricsType, metrics);
};
getMetricType = (metrics: Array<Metric>, graph: string) => {
this.setState({ selectedDate, tooltipXPos, tooltipIdx });
render() {
- const { graph, selectedDate, tooltipIdx, tooltipXPos } = this.state;
+ const { graph, selectedDate, series, tooltipIdx, tooltipXPos } = this.state;
return (
<div
className="overview-analysis-graph big-spacer-bottom spacer-top"
interpolate="linear"
metricType={this.state.metricsType}
padding={GRAPH_PADDING}
- series={this.state.series}
+ series={series}
showAreas={['coverage', 'duplications'].includes(graph)}
updateTooltip={this.updateTooltip}
/>
graphWidth={width}
metrics={this.props.metrics}
selectedDate={selectedDate}
- series={this.state.series}
+ series={series}
tooltipIdx={tooltipIdx}
tooltipPos={tooltipXPos}
/>}