react-sparklines-typescript
Version:
react-sparklines rewritten in typescript and modern react patterns
18 lines • 1.29 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var SparklinesBars = function (props) {
var _a = props.points, points = _a === void 0 ? [] : _a, _b = props.height, height = _b === void 0 ? 0 : _b, _c = props.style, style = _c === void 0 ? { fill: "slategray" } : _c, barWidth = props.barWidth, margin = props.margin, onMouseMove = props.onMouseMove;
var strokeWidth = 1 * ((style && style.strokeWidth ? +style.strokeWidth : 0) || 0);
var marginWidth = margin ? 2 * margin : 0;
var width = barWidth ||
(points && points.length >= 2
? Math.max(0, points[1].x - points[0].x - strokeWidth - marginWidth)
: 0);
return (react_1.default.createElement("g", { transform: "scale(1,-1)" }, points.map(function (p, i) { return (react_1.default.createElement("rect", { key: i, x: p.x - (width + strokeWidth) / 2, y: -height, width: width, height: Math.max(0, height - p.y), style: style, onMouseMove: onMouseMove && onMouseMove.bind({}, p) })); })));
};
exports.default = SparklinesBars;
//# sourceMappingURL=SparklinesBars.js.map