/*
* SonarQube
* Copyright (C) 2009-2017 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import $ from 'jquery';
import moment from 'moment';
import React from 'react';
import { extent, max } from 'd3-array';
import { scaleLinear, scaleOrdinal, scaleTime } from 'd3-scale';
import { line as d3Line } from 'd3-shape';
import { ResizeMixin } from '../mixins/resize-mixin';
import { TooltipsMixin } from '../mixins/tooltips-mixin';
const Timeline = React.createClass({
propTypes: {
data: React.PropTypes.arrayOf(React.PropTypes.object).isRequired,
padding: React.PropTypes.arrayOf(React.PropTypes.number),
height: React.PropTypes.number,
interpolate: React.PropTypes.string
},
mixins: [ResizeMixin, TooltipsMixin],
getDefaultProps() {
return {
padding: [10, 10, 10, 10],
interpolate: 'basis'
};
},
getInitialState() {
return {
width: this.props.width,
height: this.props.height
};
},
getRatingScale(availableHeight) {
return scaleOrdinal().domain([5, 4, 3, 2, 1]).rangePoints([availableHeight, 0]);
},
getLevelScale(availableHeight) {
return scaleOrdinal().domain(['ERROR', 'WARN', 'OK']).rangePoints([availableHeight, 0]);
},
getYScale(availableHeight) {
if (this.props.metricType === 'RATING') {
return this.getRatingScale(availableHeight);
} else if (this.props.metricType === 'LEVEL') {
return this.getLevelScale(availableHeight);
} else {
return scaleLinear()
.range([availableHeight, 0])
.domain([0, max(this.props.data, d => d.y || 0)])
.nice();
}
},
handleEventMouseEnter(event) {
$(`.js-event-circle-${event.date.getTime()}`).tooltip('show');
},
handleEventMouseLeave(event) {
$(`.js-event-circle-${event.date.getTime()}`).tooltip('hide');
},
renderHorizontalGrid(xScale, yScale) {
const hasTicks = typeof yScale.ticks === 'function';
const ticks = hasTicks ? yScale.ticks(4) : yScale.domain();
if (!ticks.length) {
ticks.push(yScale.domain()[1]);
}
const grid = ticks.map(tick => {
const opts = {
x: xScale.range()[0],
y: yScale(tick)
};
return (
');
return (