Liferay.Loader.define("portal-workflow-metrics-web@2.0.46/js/components/process-metrics/completion-velocity/VelocityChart.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/charts', 'frontend-js-react-web$react', '../../../shared/components/chart/TooltipChart.es', '../../../shared/util/moment.es', '../../AppContext.es', './util/chart.es', './util/chartConstants.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

    var _charts = _interopRequireDefault(require("@frontend-taglib-clay$clayui/charts"));

    var _react = _interopRequireWildcard(require("frontend-js-react-web$react"));

    var _TooltipChart = _interopRequireDefault(require("../../../shared/components/chart/TooltipChart.es"));

    var _moment = _interopRequireDefault(require("../../../shared/util/moment.es"));

    var _AppContext = require("../../AppContext.es");

    var _chart = require("./util/chart.es");

    var _chartConstants = require("./util/chartConstants.es");

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (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;
    }

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

    function _toConsumableArray(arr) {
      return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
    }

    function _nonIterableSpread() {
      throw new TypeError("Invalid attempt to spread non-iterable instance");
    }

    function _iterableToArray(iter) {
      if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
    }

    function _arrayWithoutHoles(arr) {
      if (Array.isArray(arr)) {
        for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
          arr2[i] = arr[i];
        }return arr2;
      }
    }

    var VelocityChart = function VelocityChart(_ref) {
      var timeRange = _ref.timeRange,
          _ref$velocityData = _ref.velocityData,
          velocityData = _ref$velocityData === void 0 ? {} : _ref$velocityData,
          velocityUnit = _ref.velocityUnit;

      var _useContext = (0, _react.useContext)(_AppContext.AppContext),
          isAmPm = _useContext.isAmPm;

      var unitKey = velocityUnit.key,
          unitName = velocityUnit.name;
      var _velocityData$histogr = velocityData.histograms,
          histograms = _velocityData$histogr === void 0 ? [] : _velocityData$histogr;
      var keys = histograms.map(function (item) {
        return _moment.default.utc(item.key).toDate();
      });
      var dataValues = [_toConsumableArray(histograms.map(function (item) {
        return item.value;
      }))];

      var _getAxisMeasuresFromD = (0, _chart.getAxisMeasuresFromData)(dataValues),
          intervals = _getAxisMeasuresFromD.intervals,
          maxValue = _getAxisMeasuresFromD.maxValue;

      var data = {
        columns: [['x'].concat(_toConsumableArray(keys)), ['data_1'].concat(_toConsumableArray(histograms.map(function (item) {
          return item.value;
        })))],
        x: 'x'
      };
      var dataX = [];

      if (keys.length) {
        dataX = (0, _chart.getXAxisIntervals)(timeRange, keys, unitKey);
      }

      return (/*#__PURE__*/_react.default.createElement("div", {
          className: "velocity-chart"
        }, histograms.length > 0 && /*#__PURE__*/_react.default.createElement(_charts.default, {
          axis: {
            x: {
              padding: {
                left: 0,
                right: 0
              },
              tick: {
                centered: false,
                fit: true,
                format: function format(date) {
                  return (0, _chart.formatXAxisDate)(date, isAmPm, unitKey, timeRange);
                },
                outer: false,
                values: dataX
              },
              type: 'timeseries'
            },
            y: {
              inner: false,
              inverted: false,
              max: maxValue,
              min: 0,
              padding: {
                bottom: 0,
                top: 0
              },
              show: true,
              tick: {
                outer: false,
                values: intervals
              }
            }
          },
          data: data,
          grid: {
            lines: {
              front: false
            },
            x: {
              lines: dataX.map(function (key) {
                return {
                  value: key
                };
              })
            }
          },
          height: 190,
          legend: {
            show: false
          },
          line: {
            classes: ['bb-line', 'bb-line-dashed-4-4']
          },
          padding: {
            top: 0
          },
          point: {
            focus: {
              expand: {
                enabled: true,
                r: 5
              }
            },
            pattern: ['circle'],
            r: 0.01,
            select: {
              r: 5
            }
          },
          resize: {
            auto: true
          },
          tooltip: {
            contents: VelocityChart.Tooltip(isAmPm, timeRange, unitKey, unitName)
          }
        }))
      );
    };

    var Tooltip = function Tooltip(isAmPm, timeRange, unitKey, unitName) {
      return function (dataPoints) {
        var isValidDate = function isValidDate(date) {
          if (date instanceof Date && !isNaN(date.getTime())) {
            return true;
          }

          return false;
        };

        var formatTooltipDate = function formatTooltipDate(date, isAmPm, timeRange, unitKey) {
          var datePattern = Liferay.Language.get('ddd-mmm-d');

          var dateUTC = _moment.default.utc(date);

          if (unitKey === _chartConstants.HOURS) {
            if (isAmPm) {
              datePattern = Liferay.Language.get('mmm-dd-hh-mm-a');
            } else {
              datePattern = Liferay.Language.get('mmm-dd-hh-mm');
            }

            return dateUTC.format(datePattern);
          } else if (unitKey === _chartConstants.WEEKS) {
            return (0, _chart.formatWeekDateWithYear)(date, timeRange);
          } else if (unitKey === _chartConstants.MONTHS) {
            return (0, _chart.formatMonthDate)(date, timeRange);
          } else if (unitKey === _chartConstants.YEARS) {
            return (0, _chart.formatYearDate)(date, timeRange);
          }

          return dateUTC.format(datePattern);
        };

        var selectedDataPoint = dataPoints[0];
        var currentPeriodTitle = function getDateTitle(date, isAmPm, timeRange, unitKey) {
          if (!isValidDate(date)) {
            return '';
          }

          return formatTooltipDate(date, isAmPm, timeRange, unitKey);
        }(selectedDataPoint.x, isAmPm, timeRange, unitKey);
        var header = [{
          label: currentPeriodTitle,
          weight: 'semibold',
          width: 160
        }].filter(Boolean);
        var rows = [{
          columns: [{
            label: "".concat(selectedDataPoint.value, " ").concat(unitName),
            weight: 'normal'
          }].filter(Boolean)
        }].filter(Boolean);
        return (0, _TooltipChart.default)({
          header: header,
          rows: rows
        });
      };
    };

    VelocityChart.Tooltip = Tooltip;
    var _default = VelocityChart;
    exports.default = _default;
    //# sourceMappingURL=VelocityChart.es.js.map
  }
});
//# sourceMappingURL=VelocityChart.es.js.map