import _ from 'underscore';
+import d3 from 'd3';
import moment from 'moment';
import React from 'react';
renderHorizontalGrid (xScale, yScale) {
let ticks = yScale.ticks(4);
+ if (!ticks.length) {
+ ticks.push(yScale.domain()[1]);
+ }
let grid = ticks.map(tick => {
let opts = {
x: xScale.range()[0],
let availableHeight = this.state.height - this.props.padding[0] - this.props.padding[2];
let xScale = d3.time.scale()
- .domain(d3.extent(this.props.data, d => d.x))
+ .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)])
+ .domain([0, d3.max(this.props.data, d => d.y || 0)])
.nice();
return <svg className="line-chart" width={this.state.width} height={this.state.height}>
--- /dev/null
+import { expect } from 'chai';
+import React from 'react';
+import TestUtils from 'react-addons-test-utils';
+
+import { Timeline } from '../../../../src/main/js/apps/overview/components/timeline-chart';
+
+
+const ZERO_DATA = [
+ { x: new Date(2015, 0, 1), y: 0 },
+ { x: new Date(2015, 0, 2), y: 0 },
+ { x: new Date(2015, 0, 3), y: 0 },
+ { x: new Date(2015, 0, 4), y: 0 }
+];
+
+const NULL_DATA = [
+ { x: new Date(2015, 0, 1), y: null },
+ { x: new Date(2015, 0, 2) },
+ { x: new Date(2015, 0, 3), y: null },
+ { x: new Date(2015, 0, 4) }
+];
+
+const FORMAT = (tick) => tick;
+
+
+describe('TimelineChart', function () {
+ it('should display the zero Y tick if all values are zero', function () {
+ let timeline = <Timeline width={100} height={100} data={ZERO_DATA} events={[]} formatYTick={FORMAT}/>;
+ let output = TestUtils.renderIntoDocument(timeline);
+ let tick = TestUtils.findRenderedDOMComponentWithClass(output, 'line-chart-tick-x');
+ expect(tick.textContent).to.equal('0');
+ });
+
+ it('should display the zero Y tick if all values are undefined', function () {
+ let timeline = <Timeline width={100} height={100} data={NULL_DATA} events={[]} formatYTick={FORMAT}/>;
+ let output = TestUtils.renderIntoDocument(timeline);
+ let tick = TestUtils.findRenderedDOMComponentWithClass(output, 'line-chart-tick-x');
+ expect(tick.textContent).to.equal('0');
+ });
+});