UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

117 lines 5.58 kB
"use strict"; 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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var create_react_class_1 = __importDefault(require("create-react-class")); var lodash_1 = __importDefault(require("lodash")); var react_1 = __importStar(require("react")); var index_1 = require("../../../index"); var initialCustomSpendDataPoints = [ { x: '12 AM', y: 0, ref: react_1.default.createRef() }, { x: '1 AM', y: 1, ref: react_1.default.createRef() }, { x: '2 AM', y: 1.5, ref: react_1.default.createRef() }, { x: '3 AM', y: 2, ref: react_1.default.createRef() }, { x: '4 AM', y: 3.8, ref: react_1.default.createRef() }, { x: '5 AM', y: 3.66, ref: react_1.default.createRef() }, { x: '6 AM', y: 5, ref: react_1.default.createRef() }, { x: '7 AM', y: 10, ref: react_1.default.createRef() }, { x: '8 AM', y: 5, ref: react_1.default.createRef() }, { x: '9 AM', y: 5, ref: react_1.default.createRef() }, { x: '10 AM', y: 5, ref: react_1.default.createRef() }, { x: '11 AM', y: 5, ref: react_1.default.createRef() }, ]; var style = { paddingTop: '4rem', }; var DataInput = function (_a) { var xValue = _a.xValue, yValue = _a.yValue, myRef = _a.myRef, changeHandler = _a.changeHandler; var onChange = react_1.useCallback(function (newYValue) { changeHandler(newYValue, xValue); }, [changeHandler, xValue]); return (react_1.default.createElement("div", { style: { width: '70%', margin: 'auto' } }, react_1.default.createElement(index_1.TextFieldValidated, { value: yValue || 0, onBlur: onChange, tabIndex: 0, ref: myRef }), react_1.default.createElement("div", { style: { margin: 'auto', textAlign: 'center', width: '95%', marginTop: '15px', } }, xValue))); }; exports.default = create_react_class_1.default({ getInitialState: function () { return { customSpendDataPoints: initialCustomSpendDataPoints, }; }, onDragHandler: function (newYValue, xValue, fromOnChangeHandler) { var cleanedYValue = fromOnChangeHandler ? newYValue : +Number(newYValue).toFixed(0); var newCustomSpendDataPoints = lodash_1.default.map(this.state.customSpendDataPoints, function (dataPoint) { return dataPoint.x === xValue ? __assign(__assign({}, dataPoint), { y: cleanedYValue }) : dataPoint; }); this.setState({ customSpendDataPoints: newCustomSpendDataPoints }); return newCustomSpendDataPoints; }, onChangeHandler: function (newYValue, xValue) { var currentIndex = lodash_1.default.findIndex(this.state.customSpendDataPoints, [ 'x', xValue, ]); var currentYValue = this.state.customSpendDataPoints[currentIndex].y; var nextValue = +Number(newYValue).toFixed(0); if (currentYValue !== nextValue) { var newCustomSpendDataPoints = this.onDragHandler(newYValue, xValue, true); var nextIndex = currentIndex >= newCustomSpendDataPoints.length - 1 ? 0 : currentIndex + 1; var myRef_1 = newCustomSpendDataPoints[nextIndex].ref; setTimeout(function () { return myRef_1.current.focus(); }, 1); } }, getRenderProp: function (_a, _b) { var onChangeHandler = _a.onChangeHandler; var x = _b.x, y = _b.y, ref = _b.ref; return (react_1.default.createElement(DataInput, { xValue: x, yValue: y, myRef: ref, changeHandler: onChangeHandler })); }, render: function () { var customSpendDataPoints = this.state.customSpendDataPoints; var renderProp = lodash_1.default.partial(this.getRenderProp, { onChangeHandler: this.onChangeHandler, }); return (react_1.default.createElement("div", { style: style }, react_1.default.createElement(index_1.DraggableLineChart, { data: customSpendDataPoints, width: 900, dataIsCentered: true, onDragEnd: this.onDragHandler, xAxisRenderProp: renderProp, yAxisFormatter: function (value) { return value + "%"; } }))); }, }); //# sourceMappingURL=05.ExampleWithYAxisFormatter.js.map