react-sparklines-typescript
Version:
react-sparklines rewritten in typescript and modern react patterns
26 lines • 1.26 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 lastDirection = function (points) {
Math.sign =
Math.sign ||
function (x) {
return x > 0 ? 1 : -1;
};
return points.length < 2
? 0
: Math.sign(points[points.length - 2].y - points[points.length - 1].y);
};
var SparklinesSpots = function (props) {
var _a = props.points, points = _a === void 0 ? [] : _a, size = props.size, style = props.style, _b = props.spotColors, spotColors = _b === void 0 ? [] : _b;
var startSpot = (react_1.default.createElement("circle", { cx: points[0].x, cy: points[0].y, r: size, style: style }));
var endSpot = (react_1.default.createElement("circle", { cx: points[points.length - 1].x, cy: points[points.length - 1].y, r: size, style: style || { fill: spotColors[lastDirection(points)] } }));
return (react_1.default.createElement("g", null,
style && startSpot,
endSpot));
};
exports.default = SparklinesSpots;
//# sourceMappingURL=SparklinesSpots.js.map