lucid-ui
Version:
A UI component library from AppNexus.
126 lines • 7.94 kB
JavaScript
"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Point = exports.Kind = void 0;
var lodash_1 = __importDefault(require("lodash"));
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("react-peek/prop-types"));
var style_helpers_1 = require("../../util/style-helpers");
var component_types_1 = require("../../util/component-types");
var chart_helpers_1 = require("../../util/chart-helpers");
var chartConstants = __importStar(require("../../constants/charts"));
var cx = style_helpers_1.lucidClassNames.bind('&-Point');
var number = prop_types_1.default.number, bool = prop_types_1.default.bool, string = prop_types_1.default.string, object = prop_types_1.default.object;
// These were originally built in a 12x12 grid, except triangles which were
// 14x12 cause triangles are poo.
var PATHS = [
'M6,12 C2.686,12 0,9.314 0,6 C0,2.686 2.686,0 6,0 C9.314,-0 12,2.686 12,6 C12,9.314 9.314,12 6,12 z',
'M6,12 C0,12 0,12 0,6 C0,0 -0,0 6,0 C12,0 12,0 12,6 C12,12 12,12 6,12 z',
'M6.034,1.656 C7,0 7,0 7.966,1.656 L13.034,10.344 C14,12 13,12 12,12 L2,12 C1,12 0,12 0.966,10.344 L6.034,1.656 z',
'M7.966,10.344 C7,12 7,12 6.034,10.344 L0.966,1.656 C-0,0 1,0 2,0 L12,0 C13,0 14,0 13.034,1.656 L7.966,10.344 z',
'M2.594,9.406 C-0.812,6 -0.812,6 2.594,2.594 C6,-0.812 6,-0.812 9.406,2.594 C12.812,6 12.812,6 9.406,9.406 C6,12.812 6,12.812 2.594,9.406 z',
];
var Kind;
(function (Kind) {
Kind[Kind["Circle"] = 0] = "Circle";
Kind[Kind["Square"] = 1] = "Square";
Kind[Kind["TriangleUp"] = 2] = "TriangleUp";
Kind[Kind["TriangleDown"] = 3] = "TriangleDown";
Kind[Kind["Diamond"] = 4] = "Diamond";
})(Kind = exports.Kind || (exports.Kind = {}));
var defaultProps = {
x: 0,
y: 0,
kind: 0,
color: chartConstants.COLOR_0,
hasStroke: false,
scale: 1,
};
var Point = function (props) {
var _a;
var color = props.color, hasStroke = props.hasStroke, kind = props.kind, x = props.x, y = props.y, scale = props.scale, className = props.className, style = props.style, passThroughs = __rest(props, ["color", "hasStroke", "kind", "x", "y", "scale", "className", "style"]);
var kindIndex = kind % 5;
var isCustomColor = lodash_1.default.startsWith(color, '#');
var colorStyle = isCustomColor ? { fill: color } : null;
// These transforms are used to center the icon on the x y coordinate
// provided.
var transforms = [
chart_helpers_1.transformFromCenter(x, y, 6, 6, scale),
chart_helpers_1.transformFromCenter(x, y, 6, 6, scale),
chart_helpers_1.transformFromCenter(x, y, 7, 6, scale),
chart_helpers_1.transformFromCenter(x, y, 7, 6, scale),
chart_helpers_1.transformFromCenter(x, y, 6, 6, scale),
];
return (react_1.default.createElement("path", __assign({}, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(exports.Point.propTypes)), { style: __assign(__assign({}, style), colorStyle), className: cx(className, '&', (_a = {
'&-has-stroke': hasStroke
},
_a["&-" + color] = !isCustomColor,
_a)), transform: transforms[kindIndex], d: PATHS[kindIndex] })));
};
exports.Point = Point;
exports.Point.defaultProps = defaultProps;
exports.Point.displayName = 'Point';
exports.Point.peek = {
description: "\n\t\t\t\t*For use within an `svg`*\n\n\t\t\t\tPoints are typically used for scatter plots or overlaying shapes on\n\t\t\t\tlines.\n\t\t\t",
categories: ['visualizations', 'geoms'],
};
exports.Point.propTypes = {
style: object(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\t\tPassed through to the root element.\n\t\t"], ["\n\t\t\tPassed through to the root element.\n\t\t"]))),
className: string(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\t\t\tAppended to the component-specific class names set on the root element.\n\t\t"], ["\n\t\t\tAppended to the component-specific class names set on the root element.\n\t\t"]))),
hasStroke: bool(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\t\tDetermines if the point has a white stroke around it.\n\t\t"], ["\n\t\t\tDetermines if the point has a white stroke around it.\n\t\t"]))),
x: number(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n\t\t\tx coordinate\n\t\t"], ["\n\t\t\tx coordinate\n\t\t"]))),
y: number(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n\t\t\ty coordinate\n\t\t"], ["\n\t\t\ty coordinate\n\t\t"]))),
kind: number(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n\t\t\tZero-based set of shapes. It's recommended that you pass the index of\n\t\t\tyour array for shapes.\n\t\t"], ["\n\t\t\tZero-based set of shapes. It's recommended that you pass the index of\n\t\t\tyour array for shapes.\n\t\t"]))),
color: string(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n\t\t\tStrings should match an existing color class unless they start with a '#'\n\t\t\tfor specific colors. E.g.:\n\n\t\t\t- `COLOR_0`\n\t\t\t- `COLOR_GOOD`\n\t\t\t- `'#123abc'`\n\t\t"], ["\n\t\t\tStrings should match an existing color class unless they start with a '#'\n\t\t\tfor specific colors. E.g.:\n\n\t\t\t- \\`COLOR_0\\`\n\t\t\t- \\`COLOR_GOOD\\`\n\t\t\t- \\`'#123abc'\\`\n\t\t"]))),
scale: number(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n\t\t\tScale up the size of the symbol. 2 would be double the original size.\n\t\t"], ["\n\t\t\tScale up the size of the symbol. 2 would be double the original size.\n\t\t"]))),
};
exports.default = exports.Point;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8;
//# sourceMappingURL=Point.js.map