From: Stas Vilchik Date: Fri, 13 Nov 2015 16:40:16 +0000 (+0100) Subject: SONAR-6331 make it possible to display a timeline on RATING and LEVEL measures X-Git-Tag: 5.3-RC1~294 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=814378a88f0b75f943d043e48d2a61488d83f134;p=sonarqube.git SONAR-6331 make it possible to display a timeline on RATING and LEVEL measures --- diff --git a/server/sonar-web/src/main/js/apps/overview/components/domain-timeline.js b/server/sonar-web/src/main/js/apps/overview/components/domain-timeline.js index 62d4ab1f9f9..f58e536ddaf 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/domain-timeline.js +++ b/server/sonar-web/src/main/js/apps/overview/components/domain-timeline.js @@ -133,6 +133,7 @@ export const DomainTimeline = React.createClass({ return
d.y || 0)]) + .nice(); + } + }, + renderHorizontalGrid (xScale, yScale) { - let ticks = yScale.ticks(4); + let hasTicks = typeof yScale.ticks === 'function'; + let ticks = hasTicks ? yScale.ticks(4) : yScale.domain(); if (!ticks.length) { ticks.push(yScale.domain()[1]); } @@ -69,9 +95,9 @@ export const Timeline = React.createClass({ } let opts = { x: xScale(this.props.leakPeriodDate), - y: yScale.range()[1], + y: _.last(yScale.range()), width: xScale.range()[1] - xScale(this.props.leakPeriodDate), - height: yScale.range()[0] - yScale.range()[1], + height: _.first(yScale.range()) - _.last(yScale.range()), fill: '#fffae7' }; return ; @@ -118,10 +144,7 @@ export const Timeline = React.createClass({ .domain(d3.extent(this.props.data, d => d.x || 0)) .range([0, availableWidth]) .clamp(true); - let yScale = d3.scale.linear() - .range([availableHeight, 0]) - .domain([0, d3.max(this.props.data, d => d.y || 0)]) - .nice(); + let yScale = this.getYScale(availableHeight); return diff --git a/server/sonar-web/tests/apps/overview/components/timeline-chart-test.js b/server/sonar-web/tests/apps/overview/components/timeline-chart-test.js index 82d7d66a593..3aae4e12c64 100644 --- a/server/sonar-web/tests/apps/overview/components/timeline-chart-test.js +++ b/server/sonar-web/tests/apps/overview/components/timeline-chart-test.js @@ -23,6 +23,44 @@ const FORMAT = (tick) => tick; describe('TimelineChart', function () { + it('should work with LEVEL', function () { + const DATA = [ + { x: new Date(2015, 0, 1), y: 'OK' }, + { x: new Date(2015, 0, 2), y: 'WARN' }, + { x: new Date(2015, 0, 3), y: 'ERROR' }, + { x: new Date(2015, 0, 4), y: 'WARN' } + ]; + + let timeline = ; + let output = TestUtils.renderIntoDocument(timeline); + let ticks = TestUtils.scryRenderedDOMComponentsWithClass(output, 'line-chart-tick-x'); + expect(ticks).to.have.length(3); + expect(ticks[0].textContent).to.equal('ERROR'); + expect(ticks[1].textContent).to.equal('WARN'); + expect(ticks[2].textContent).to.equal('OK'); + }); + + it('should work with RATING', function () { + const DATA = [ + { x: new Date(2015, 0, 1), y: 1 }, + { x: new Date(2015, 0, 2), y: 3 }, + { x: new Date(2015, 0, 3), y: 1 }, + { x: new Date(2015, 0, 4), y: 4 } + ]; + + let timeline = ; + let output = TestUtils.renderIntoDocument(timeline); + let ticks = TestUtils.scryRenderedDOMComponentsWithClass(output, 'line-chart-tick-x'); + expect(ticks).to.have.length(5); + expect(ticks[0].textContent).to.equal('5'); + expect(ticks[1].textContent).to.equal('4'); + expect(ticks[2].textContent).to.equal('3'); + expect(ticks[3].textContent).to.equal('2'); + expect(ticks[4].textContent).to.equal('1'); + }); + it('should display the zero Y tick if all values are zero', function () { let timeline = ; let output = TestUtils.renderIntoDocument(timeline);