"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GaugeDimensionEditor = GaugeDimensionEditor; var _eui = require("@elastic/eui"); var _react = _interopRequireWildcard(require("react")); var _i18n = require("@kbn/i18n"); var _coloring = require("@kbn/coloring"); var _common = require("@kbn/expression-gauge-plugin/common"); var _public = require("@kbn/expression-gauge-plugin/public"); var _visualizationUiComponents = require("@kbn/visualization-ui-components"); var _utils = require("../../../common/expressions/datatable/utils"); var _shared_components = require("../../shared_components"); var _palette_config = require("./palette_config"); var _utils2 = require("./utils"); require("./dimension_editor.scss"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ function GaugeDimensionEditor(props) { var _frame$activeData; const { state, setState, frame, accessor } = props; const [isPaletteOpen, setIsPaletteOpen] = (0, _react.useState)(false); if ((state === null || state === void 0 ? void 0 : state.metricAccessor) !== accessor) return null; const currentData = (_frame$activeData = frame.activeData) === null || _frame$activeData === void 0 ? void 0 : _frame$activeData[state.layerId]; const [firstRow] = (currentData === null || currentData === void 0 ? void 0 : currentData.rows) || []; if (accessor == null || firstRow == null || !(0, _utils.isNumericFieldForDatatable)(currentData, accessor)) { return null; } const accessors = (0, _utils2.getAccessorsFromState)(state); const hasDynamicColoring = (state === null || state === void 0 ? void 0 : state.colorMode) === 'palette'; const currentMinMax = { min: (0, _public.getMinValue)(firstRow, accessors), max: (0, _public.getMaxValue)(firstRow, accessors) }; const activePalette = (state === null || state === void 0 ? void 0 : state.palette) || { type: 'palette', name: _palette_config.defaultPaletteParams.name, params: { ..._palette_config.defaultPaletteParams, continuity: 'all', colorStops: undefined, stops: undefined, rangeMin: currentMinMax.min, rangeMax: currentMinMax.max * 3 / 4 } }; const displayStops = (0, _shared_components.applyPaletteParams)(props.paletteService, activePalette, currentMinMax); const togglePalette = () => setIsPaletteOpen(!isPaletteOpen); return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_eui.EuiFormRow, { display: "columnCompressed", fullWidth: true, label: _i18n.i18n.translate('xpack.lens.gauge.dynamicColoring.label', { defaultMessage: 'Band colors' }), className: "lnsDynamicColoringRow" }, /*#__PURE__*/_react.default.createElement(_eui.EuiSwitch, { "data-test-subj": "lnsDynamicColoringGaugeSwitch", compressed: true, label: "", showLabel: false, checked: hasDynamicColoring, onChange: e => { const { checked } = e.target; const params = checked ? { palette: { ...activePalette, params: { ...activePalette.params, stops: displayStops } }, ticksPosition: _common.GaugeTicksPositions.BANDS, colorMode: _common.GaugeColorModes.PALETTE } : { ticksPosition: _common.GaugeTicksPositions.AUTO, colorMode: _common.GaugeColorModes.NONE }; setState({ ...state, ...params }); } })), hasDynamicColoring && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_eui.EuiFormRow, { className: "lnsDynamicColoringRow", display: "columnCompressed", fullWidth: true, label: _i18n.i18n.translate('xpack.lens.paletteMetricGradient.label', { defaultMessage: 'Color' }) }, /*#__PURE__*/_react.default.createElement(_eui.EuiFlexGroup, { alignItems: "center", gutterSize: "s", responsive: false, className: "lnsDynamicColoringClickable" }, /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, null, /*#__PURE__*/_react.default.createElement(_eui.EuiColorPaletteDisplay, { "data-test-subj": "lnsGauge_dynamicColoring_palette", palette: displayStops.map(({ color }) => color), type: _coloring.FIXED_PROGRESSION, onClick: togglePalette })), /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, { grow: false }, /*#__PURE__*/_react.default.createElement(_eui.EuiButtonEmpty, { "data-test-subj": "lnsGauge_dynamicColoring_trigger", iconType: "controlsHorizontal", onClick: togglePalette, size: "xs", flush: "both" }, _i18n.i18n.translate('xpack.lens.paletteTableGradient.customize', { defaultMessage: 'Edit' })), /*#__PURE__*/_react.default.createElement(_shared_components.PalettePanelContainer, { siblingRef: props.panelRef, isOpen: isPaletteOpen, handleClose: togglePalette }, /*#__PURE__*/_react.default.createElement(_coloring.CustomizablePalette, { palettes: props.paletteService, activePalette: activePalette, dataBounds: currentMinMax, setPalette: newPalette => { // if the new palette is not custom, replace the rangeMin with the artificial one if (newPalette.name !== _coloring.CUSTOM_PALETTE && newPalette.params && newPalette.params.rangeMin !== currentMinMax.min) { newPalette.params.rangeMin = currentMinMax.min; } setState({ ...state, palette: newPalette }); } }))))), /*#__PURE__*/_react.default.createElement(_eui.EuiFormRow, { display: "columnCompressedSwitch", fullWidth: true, label: /*#__PURE__*/_react.default.createElement(_visualizationUiComponents.TooltipWrapper, { position: "top", tooltipContent: _i18n.i18n.translate('xpack.lens.shared.ticksPositionOptionsTooltip', { defaultMessage: 'Places ticks on each band border instead of distributing them evenly' }), condition: true, delay: "regular" }, /*#__PURE__*/_react.default.createElement("span", null, _i18n.i18n.translate('xpack.lens.shared.ticksPositionOptions', { defaultMessage: 'Ticks on bands' }), /*#__PURE__*/_react.default.createElement(_eui.EuiIcon, { type: "questionInCircle", color: "subdued", size: "s", className: "eui-alignTop" }))) }, /*#__PURE__*/_react.default.createElement(_eui.EuiSwitch, { compressed: true, label: _i18n.i18n.translate('xpack.lens.shared.ticksPositionOptions', { defaultMessage: 'Ticks on bands' }), "data-test-subj": "lens-toolbar-gauge-ticks-position-switch", showLabel: false, checked: state.ticksPosition === _common.GaugeTicksPositions.BANDS, onChange: () => { setState({ ...state, ticksPosition: state.ticksPosition === _common.GaugeTicksPositions.BANDS ? _common.GaugeTicksPositions.AUTO : _common.GaugeTicksPositions.BANDS }); } })))); }