function _extends(){return _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a},_extends.apply(this,arguments)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _inheritsLoose(a,b){a.prototype=Object.create(b.prototype),a.prototype.constructor=a,a.__proto__=b}/* eslint-disable react/require-default-props */ /* eslint-disable react/no-unused-prop-types */ /* eslint-disable react/forbid-prop-types */ /* eslint-disable react/no-access-state-in-setstate */ /* eslint-disable compat/compat */ /* eslint-disable react/destructuring-assignment */ /* eslint-disable react/jsx-handler-names */ /* eslint-disable react/no-unsafe */ /* eslint-disable react/sort-comp */ /* eslint-disable camelcase */ /* eslint-disable no-prototype-builtins */ /* eslint-disable sort-keys */ /* eslint-disable no-eq-null */ /* eslint-disable no-magic-numbers */ /**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */ /* eslint no-underscore-dangle: ["error", { "allow": ["", "__timestamp"] }] */import React from"react";import PropTypes from"prop-types";import{CategoricalColorNamespace}from"@superset-ui/color";import AnimatableDeckGLContainer from"./AnimatableDeckGLContainer";import Legend from"./components/Legend";import{hexToRGB}from"./utils/colors";import{getPlaySliderParams}from"./utils/time";import sandboxedEval from"./utils/sandbox";import{fitViewport}from"./layers/common";var getScale=CategoricalColorNamespace.getScale;function getCategories(a,b){var e=a.color_picker||{r:0,g:0,b:0,a:1},c=[e.r,e.g,e.b,255*e.a],f=getScale(a.color_scheme),g={};return b.forEach(function(b){if(null!=b.cat_color&&!g.hasOwnProperty(b.cat_color)){var d;d=a.dimension?hexToRGB(f(b.cat_color),255*e.a):c,g[b.cat_color]={color:d,enabled:!0}}}),g}var propTypes={formData:PropTypes.object.isRequired,mapboxApiKey:PropTypes.string.isRequired,setControlValue:PropTypes.func.isRequired,viewport:PropTypes.object.isRequired,getLayer:PropTypes.func.isRequired,getPoints:PropTypes.func.isRequired,payload:PropTypes.object.isRequired,onAddFilter:PropTypes.func,setTooltip:PropTypes.func},CategoricalDeckGLContainer=/*#__PURE__*/function(a){/*
   * A Deck.gl container that handles categories.
   *
   * The container will have an interactive legend, populated from the
   * categories present in the data.
   */function b(b){var c;return c=a.call(this,b)||this,c.state=c.getStateFromProps(b),c.getLayers=c.getLayers.bind(_assertThisInitialized(c)),c.onValuesChange=c.onValuesChange.bind(_assertThisInitialized(c)),c.onViewportChange=c.onViewportChange.bind(_assertThisInitialized(c)),c.toggleCategory=c.toggleCategory.bind(_assertThisInitialized(c)),c.showSingleCategory=c.showSingleCategory.bind(_assertThisInitialized(c)),c}_inheritsLoose(b,a);var c=b.prototype;return c.UNSAFE_componentWillReceiveProps=function UNSAFE_componentWillReceiveProps(a){a.payload.form_data!==this.state.formData&&this.setState(_extends({},this.getStateFromProps(a)))},c.onValuesChange=function onValuesChange(a){this.setState({values:Array.isArray(a)?a:[a,a+this.state.getStep(a)]})},c.onViewportChange=function onViewportChange(a){this.setState({viewport:a})},c.getStateFromProps=function getStateFromProps(a,b){var c=a.payload.data.features||[],d=c.map(function(a){return a.__timestamp}),e=getCategories(a.formData,c);// the state is computed only from the payload; if it hasn't changed, do
// not recompute state since this would reset selections and/or the play
// slider position due to changes in form controls
if(b&&a.payload.form_data===b.formData)return _extends({},b,{categories:e});// the granularity has to be read from the payload form_data, not the
// props formData which comes from the instantaneous controls state
var f=a.payload.form_data.time_grain_sqla||a.payload.form_data.granularity||"P1D",g=getPlaySliderParams(d,f),h=g.start,i=g.end,j=g.getStep,k=g.values,l=g.disabled,m=a.formData.autozoom?fitViewport(a.viewport,a.getPoints(c)):a.viewport;return{start:h,end:i,getStep:j,values:k,disabled:l,viewport:m,selected:[],lastClick:0,formData:a.payload.form_data,categories:e}},c.getLayers=function getLayers(a){var b=this.props,c=b.getLayer,d=b.payload,e=b.formData,f=b.onAddFilter,g=b.setTooltip,h=d.data.features?[].concat(d.data.features):[];// Apply user defined data mutator if defined
if(h=this.addColor(h,e),e.js_data_mutator){var k=sandboxedEval(e.js_data_mutator);h=k(h)}// Filter by time
h=a[0]===a[1]||a[1]===this.end?h.filter(function(b){return b.__timestamp>=a[0]&&b.__timestamp<=a[1]}):h.filter(function(b){return b.__timestamp>=a[0]&&b.__timestamp<a[1]});// Show only categories selected in the legend
var i=this.state.categories;e.dimension&&(h=h.filter(function(a){return i[a.cat_color]&&i[a.cat_color].enabled}));var j=_extends({},d,{data:_extends({},d.data,{features:h})});return[c(e,j,f,g)]},c.addColor=function addColor(a,b){var e=b.color_picker||{r:0,g:0,b:0,a:1},c=getScale(b.color_scheme);return a.map(function(a){var d;return b.dimension?(d=hexToRGB(c(a.cat_color),255*e.a),_extends({},a,{color:d})):a})},c.toggleCategory=function toggleCategory(a){var b,c=this.state.categories[a],d=_extends({},this.state.categories,(b={},b[a]=_extends({},c,{enabled:!c.enabled}),b));Object.values(d).every(function(a){return!a.enabled})&&Object.values(d).forEach(function(a){a.enabled=!0}),this.setState({categories:d})},c.showSingleCategory=function showSingleCategory(a){var b=_extends({},this.state.categories);/* eslint-disable no-param-reassign */Object.values(b).forEach(function(a){a.enabled=!1}),b[a].enabled=!0,this.setState({categories:b})},c.render=function render(){return React.createElement("div",{style:{position:"relative"}},React.createElement(AnimatableDeckGLContainer,{getLayers:this.getLayers,start:this.state.start,end:this.state.end,getStep:this.state.getStep,values:this.state.values,onValuesChange:this.onValuesChange,disabled:this.state.disabled,viewport:this.state.viewport,onViewportChange:this.onViewportChange,mapboxApiAccessToken:this.props.mapboxApiKey,mapStyle:this.props.formData.mapbox_style,setControlValue:this.props.setControlValue},React.createElement(Legend,{categories:this.state.categories,toggleCategory:this.toggleCategory,showSingleCategory:this.showSingleCategory,position:this.props.formData.legend_position,format:this.props.formData.legend_format})))},b}(React.PureComponent);export{CategoricalDeckGLContainer as default};CategoricalDeckGLContainer.propTypes=propTypes;