r-d3
Version:
D3 data, React rendering.
54 lines (43 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _react = require('react');
var React = _interopRequireWildcard(_react);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Candlestick = function Candlestick(props) {
var className = props.className,
width = props.width,
x = props.x,
y = props.y;
var date = x(props.date);
var close = y(props.close);
var high = y(props.high);
var low = y(props.low);
var open = y(props.open);
var diff = open - close;
return React.createElement(
'g',
{
className: (0, _classnames2.default)('candlestick', {
'gain': diff > 0,
'loss': diff < 0
}, className) },
React.createElement('line', {
x1: date,
x2: date,
y1: high,
y2: low
}),
React.createElement('rect', {
height: Math.abs(diff) || 1,
width: width,
x: date - width / 2,
y: diff > 0 ? close : open
})
);
};
exports.default = Candlestick;