@hn3000/react-stockcharts
Version:
Highly customizable stock charts with ReactJS and d3 (tmp fork by @hn3000)
79 lines (73 loc) • 1.97 kB
JavaScript
"use strict";
import React from "react";
import PropTypes from "prop-types";
import { hexToRGBA, functor } from "../utils";
function SvgLoader(props) {
var className = props.className,
stroke = props.stroke,
strokeWidth = props.strokeWidth,
opacity = props.opacity,
fill = props.fill,
point = props.point,
width = props.width;
var w = functor(width)(point.datum);
var x = point.x - w / 2;
var y = point.y - w / 2;
return React.createElement("rect", {
className: className,
x: x,
y: y,
stroke: stroke,
strokeWidth: strokeWidth,
fillOpacity: opacity,
fill: fill,
width: w,
height: w
});
}
SvgLoader.propTypes = {
stroke: PropTypes.string,
fill: PropTypes.string.isRequired,
opacity: PropTypes.number.isRequired,
point: PropTypes.shape({
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired,
datum: PropTypes.object.isRequired
}).isRequired,
className: PropTypes.string,
strokeWidth: PropTypes.number,
path: PropTypes.string,
width: PropTypes.oneOfType([PropTypes.number, PropTypes.func]).isRequired
};
SvgLoader.defaultProps = {
stroke: "#4682B4",
strokeWidth: 1,
opacity: 0.5,
fill: "#4682B4",
className: "react-stockcharts-marker-svg",
path: ''
};
SvgLoader.drawOnCanvas = function (props, point, ctx) {
var stroke = props.stroke,
fill = props.fill,
opacity = props.opacity,
strokeWidth = props.strokeWidth;
ctx.strokeStyle = stroke;
ctx.lineWidth = strokeWidth;
if (fill !== "none") {
ctx.fillStyle = hexToRGBA(fill, opacity);
}
SvgLoader.drawOnCanvasWithNoStateChange(props, point, ctx);
};
SvgLoader.drawOnCanvasWithNoStateChange = function (props, point, ctx) {
var width = props.width;
var w = functor(width)(point.datum);
var x = point.x - w / 2;
var y = point.y - w / 2;
var p = new Path2D(props.path);
ctx.transform(1, 0, 0, 1, x, y);
ctx.fill(p);
ctx.restore();
};
export default SvgLoader;
//# sourceMappingURL=SvgLoaderMarker.js.map