UNPKG

lucid-ui

Version:

A UI component library from Xandr.

149 lines 6.95 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); 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 }); var lodash_1 = require("lodash"); var d3Selection = __importStar(require("d3-selection")); var react_1 = __importDefault(require("react")); var style_helpers_1 = require("../../util/style-helpers"); var DraggableLineChartD3_1 = __importDefault(require("./DraggableLineChartD3")); var cx = style_helpers_1.lucidClassNames.bind('&-DraggableLineChart'); var getEmptyRenderProp = function (preSelectText) { return (react_1.default.createElement("div", { style: { height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', } }, react_1.default.createElement("div", { className: cx('&-empty-info') }, preSelectText))); }; var getCleanData = function (data) { return data.map(function (_a) { var x = _a.x, y = _a.y; return ({ x: x, y: Number.isFinite(y) ? y : 0 }); }); }; var draggableLineChartDefaultProps = { height: 315, width: 1000, margin: { top: 65, right: 80, bottom: 65, left: 80 }, }; /** TODO: Remove this constant when the component is converted to a functional component */ var nonPassThroughs = [ 'height', 'width', 'margin', 'data', 'onDragEnd', 'xAxisTicksVertical', 'dataIsCentered', 'yAxisMin', 'xAxisRenderProp', 'onPreselect', 'preSelectText', 'yAxisFormatter', ].concat(['initialState', 'callbackId']); var DraggableLineChart = /** @class */ (function (_super) { __extends(DraggableLineChart, _super); function DraggableLineChart(props) { var _this = _super.call(this, props) || this; _this.ref = react_1.default.createRef(); _this.d3LineChart = null; return _this; } DraggableLineChart.prototype.componentDidUpdate = function () { this.d3LineChart.updateLineChart(this.props.data); }; DraggableLineChart.prototype.componentDidMount = function () { var svg = d3Selection.select(this.ref); var _a = this.props, height = _a.height, width = _a.width, margin = _a.margin, data = _a.data, onDragEnd = _a.onDragEnd, xAxisTicksVertical = _a.xAxisTicksVertical, dataIsCentered = _a.dataIsCentered, _b = _a.yAxisMin, yAxisMin = _b === void 0 ? 0 : _b, xAxisRenderProp = _a.xAxisRenderProp, onPreselect = _a.onPreselect, preSelectText = _a.preSelectText, _c = _a.yAxisFormatter, yAxisFormatter = _c === void 0 ? null : _c; var emptyRenderProp = onPreselect && preSelectText ? function () { return getEmptyRenderProp(preSelectText); } : undefined; this.d3LineChart = new DraggableLineChartD3_1.default(svg, { height: height || draggableLineChartDefaultProps.height, width: width || draggableLineChartDefaultProps.width, margin: margin || draggableLineChartDefaultProps.margin, data: getCleanData(data), onDragEnd: onDragEnd, xAxisTicksVertical: xAxisTicksVertical, dataIsCentered: dataIsCentered, yAxisMin: yAxisMin, yAxisFormatter: yAxisFormatter, xAxisRenderProp: xAxisRenderProp, emptyRenderProp: emptyRenderProp, cx: cx, onPreselect: onPreselect, }); this.d3LineChart.renderLineChart(); }; DraggableLineChart.prototype.render = function () { var _this = this; var _a = this.props, height = _a.height, width = _a.width, className = _a.className, passThroughs = __rest(_a, ["height", "width", "className"]); return (react_1.default.createElement("svg", __assign({}, (0, lodash_1.omit)(passThroughs, nonPassThroughs), { ref: function (ref) { return (_this.ref = ref); }, className: cx('&', className), width: width, height: height }))); }; DraggableLineChart.displayName = 'DraggableLineChart'; DraggableLineChart.peek = { description: "The `DraggableLineChart` is a single-lined line chart where the points on the line are draggable and will update the data real-time.", categories: ['visualizations', 'charts'], }; DraggableLineChart.defaultProps = draggableLineChartDefaultProps; return DraggableLineChart; }(react_1.default.Component)); exports.default = DraggableLineChart; //# sourceMappingURL=DraggableLineChart.js.map