<commit_before>'use strict';
var React = require('react'),
	d3 = require('d3');

var HistogramSeries = require('./HistogramSeries');

class MACDSeries extends React.Component {
	constructor(props) {
		super(props);
		this.getMACDLine = this.getMACDLine.bind(this);
		this.getSignalLine = this.getSignalLine.bind(this);
		this.getHistogram = this.getHistogram.bind(this);
	}
	getMACDLine() {
		var dataSeries = d3.svg.line()
			.defined((d, i) => this.context.yAccessor(d) !== undefined)
			.x((d) => this.context.xScale(this.context.xAccessor(d)))
			.y((d) => this.context.yScale(this.context.yAccessor(d).MACDLine));

		return dataSeries(this.context.plotData);
	}
	getSignalLine() {
		var dataSeries = d3.svg.line()
			.defined((d, i) => this.context.yAccessor(d) !== undefined)
			.x((d) => this.context.xScale(this.context.xAccessor(d)))
			.y((d) => this.context.yScale(this.context.yAccessor(d).signalLine));

		return dataSeries(this.context.plotData);
	}
	getHistogram() {
		var dataSeries = d3.svg.line()
			.defined((d, i) => this.context.yAccessor(d) !== undefined)
			.x((d) => this.context.xScale(this.context.xAccessor(d)))
			.y((d) => this.context.yScale(this.context.yAccessor(d).histogram));

		return dataSeries(this.context.plotData);
	}
	getChildContext() {
		var yAccess = this.context.yAccessor
		return {
			yAccessor: (d) => yAccess(d).histogram,
		}
	}
	getHorizontalLine() {
		var first = this.context.xAccessor(this.context.plotData[0]);
		var last = this.context.xAccessor(this.context.plotData[this.context.plotData.length - 1]);

		return <line x1={this.context.xScale(first)}
			y1={this.context.yScale(0)}
			x2={this.context.xScale(last)}
			y2={this.context.yScale(0)} className="horizontal" />;
	}
	render() {
		return (
			<g className="macd-series">
				<path d={this.getMACDLine()} className="macdline" />
				<path d={this.getSignalLine()} className="signalline" />
				<HistogramSeries baseAt={this.context.yScale(0)} />
				{this.getHorizontalLine()}
			</g>
		);
	}
};
// baseAt={this.context.yScale(this.context.yScale(0))} 
MACDSeries.contextTypes = {
		xScale: React.PropTypes.func.isRequired,<commit_msg>fix MACD bug when value is undefined, the signal line disappears<commit_after>'use strict';
var React = require('react'),
	d3 = require('d3');

var HistogramSeries = require('./HistogramSeries');

class MACDSeries extends React.Component {
	constructor(props) {
		super(props);
		this.getMACDLine = this.getMACDLine.bind(this);
		this.getSignalLine = this.getSignalLine.bind(this);
		this.getHorizontalLine = this.getHorizontalLine.bind(this);
	}
	getMACDLine() {
		var dataSeries = d3.svg.line()
			.defined((d, i) => (this.context.yAccessor(d) && this.context.yAccessor(d).MACDLine) !== undefined)
			.x((d) => this.context.xScale(this.context.xAccessor(d)))
			.y((d) => this.context.yScale(this.context.yAccessor(d).MACDLine));

		return dataSeries(this.context.plotData);
	}
	getSignalLine() {
		var dataSeries = d3.svg.line()
			.defined((d, i) => (this.context.yAccessor(d) && this.context.yAccessor(d).signalLine) !== undefined)
			.x((d) => this.context.xScale(this.context.xAccessor(d)))
			.y((d) => this.context.yScale(this.context.yAccessor(d).signalLine));

		return dataSeries(this.context.plotData);
	}
	getChildContext() {
		var yAccess = this.context.yAccessor
		return {
			yAccessor: (d) => yAccess(d) && yAccess(d).histogram,
		}
	}
	getHorizontalLine() {
		var first = this.context.xAccessor(this.context.plotData[0]);
		var last = this.context.xAccessor(this.context.plotData[this.context.plotData.length - 1]);

		return <line x1={this.context.xScale(first)}
			y1={this.context.yScale(0)}
			x2={this.context.xScale(last)}
			y2={this.context.yScale(0)} className="horizontal" />;
	}
	render() {
		return (
			<g className="macd-series">
				<path d={this.getMACDLine()} className="macdline" />
				<path d={this.getSignalLine()} className="signalline" />
				<HistogramSeries baseAt={this.context.yScale(0)} />
				{this.getHorizontalLine()}
			</g>
		);
	}
};

MACDSeries.contextTypes = {
		xScale: React.PropTypes.func.isRequired,
{'fraction_non_alphanumeric': 0.18126520681265207, 'fraction_numerical': 0.006812652068126521, 'mean_word_length': 4.585597826086956, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4786742', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1468, 'n_words': 207}