text: "use strict";exports.__esModule=!0,exports.renderTooltipFactory=renderTooltipFactory,exports.default=void 0;var _react=_interopRequireDefault(require("react")),_propTypes=_interopRequireDefault(require("prop-types")),_shortid=_interopRequireDefault(require("shortid")),_xyChart=require("@data-ui/xy-chart"),_color=require("@superset-ui/color"),_timeFormat=require("@superset-ui/time-format"),_dimension=require("@superset-ui/dimension");require("./BigNumber.css");function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _inheritsLoose(a,b){a.prototype=Object.create(b.prototype),a.prototype.constructor=a,a.__proto__=b}var CHART_MARGIN={top:4,right:4,bottom:4,left:4},PROPORTION={HEADER:.3,SUBHEADER:.125,TRENDLINE:.3};function renderTooltipFactory(a){function b(b){var c=b.datum,d=c.x,e=c.y,f=(0,_timeFormat.smartDateVerboseFormatter)(d),g=a(e);return _react.default.createElement("div",{style:{padding:"4px 8px"}},f,_react.default.createElement("br",null),_react.default.createElement("strong",null,g))}return b.propTypes={datum:_propTypes.default.shape({x:_propTypes.default.instanceOf(Date),y:_propTypes.default.number}).isRequired},b}function identity(a){return a}var propTypes={className:_propTypes.default.string,width:_propTypes.default.number.isRequired,height:_propTypes.default.number.isRequired,bigNumber:_propTypes.default.number.isRequired,formatBigNumber:_propTypes.default.func,headerFontSize:_propTypes.default.number,subheader:_propTypes.default.string,subheaderFontSize:_propTypes.default.number,showTrendLine:_propTypes.default.bool,startYAxisAtZero:_propTypes.default.bool,trendLineData:_propTypes.default.array,mainColor:_propTypes.default.string,renderTooltip:_propTypes.default.func},defaultProps={className:"",formatBigNumber:identity,headerFontSize:PROPORTION.HEADER,subheader:"",subheaderFontSize:PROPORTION.SUBHEADER,showTrendLine:!1,startYAxisAtZero:!0,trendLineData:null,mainColor:_color.BRAND_COLOR,renderTooltip:renderTooltipFactory(identity)},BigNumberVis=/*#__PURE__*/function(a){function b(b){var c;return c=a.call(this,b)||this,c.gradientId=_shortid.default.generate(),c}_inheritsLoose(b,a);var c=b.prototype;return c.getClassName=function getClassName(){var a=this.props,b=a.className,c=a.showTrendLine,d="superset-legacy-chart-big-number "+b;return c?d:d+" no-trendline"},c.createTemporaryContainer=function createTemporaryContainer(){var a=document.createElement("div");// and not visible
  return a.className=this.getClassName(),a.style.position="absolute",a.style.opacity=0,a},c.renderHeader=function renderHeader(a){var b=this.props,c=b.bigNumber,d=b.formatBigNumber,e=b.width,f=d(c),g=this.createTemporaryContainer();document.body.appendChild(g);var h=(0,_dimension.computeMaxFontSize)({text:f,maxWidth:Math.floor(e),maxHeight:a,className:"header-line",container:g});return document.body.removeChild(g),_react.default.createElement("div",{className:"header-line",style:{fontSize:h,height:a}},_react.default.createElement("span",null,f))},c.renderSubheader=function renderSubheader(a){var b=this.props,c=b.subheader,d=b.width,e=0;if(c){var f=this.createTemporaryContainer();document.body.appendChild(f),e=(0,_dimension.computeMaxFontSize)({text:c,maxWidth:Math.floor(d),maxHeight:a,className:"subheader-line",container:f}),document.body.removeChild(f)}return _react.default.createElement("div",{className:"subheader-line",style:{fontSize:e,height:a}},c)},c.renderTrendline=function renderTrendline(a){var b=this.props,c=b.width,d=b.trendLineData,e=b.mainColor,f=b.subheader,g=b.renderTooltip,h=b.startYAxisAtZero;return _react.default.createElement(_xyChart.XYChart,{ariaLabel:"Big number visualization "+f,xScale:{type:"timeUtc"},yScale:{type:"linear",includeZero:h},width:Math.floor(c),height:a,margin:CHART_MARGIN,renderTooltip:g,snapTooltipToDataX:!0},_react.default.createElement(_xyChart.LinearGradient,{id:this.gradientId,from:e,to:"#fff"}),_react.default.createElement(_xyChart.AreaSeries,{data:d,fill:"url(#"+this.gradientId+")",stroke:e}),_react.default.createElement(_xyChart.CrossHair,{stroke:e,circleFill:e,circleStroke:"#fff",showHorizontalLine:!1,fullHeight:!0,strokeDasharray:"5,2"}))},c.render=function render(){var a=this.props,b=a.showTrendLine,c=a.height,d=a.headerFontSize,e=a.subheaderFontSize,f=this.getClassName();if(b){var g=Math.floor(PROPORTION.TRENDLINE*c);return _react.default.createElement("div",{className:f},_react.default.createElement("div",{className:"text-container",style:{height:c-g}},this.renderHeader(Math.ceil(d*(1-PROPORTION.TRENDLINE)*c)),this.renderSubheader(Math.ceil(e*(1-PROPORTION.TRENDLINE)*c))),this.renderTrendline(g))}return _react.default.createElement("div",{className:f,style:{height:c}},this.renderHeader(Math.ceil(d*c)),this.renderSubheader(Math.ceil(e*c)))},b}(_react.default.PureComponent);BigNumberVis.propTypes=propTypes,BigNumberVis.defaultProps=defaultProps;var _default=BigNumberVis;exports.default=_default;