@gooddata/react-components
Version:
GoodData.UI - A powerful JavaScript library for building analytical applications
117 lines • 5.96 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
// (C) 2020 GoodData Corporation
var React = require("react");
var invariant = require("invariant");
var geoChart_1 = require("../../../constants/geoChart");
var common_1 = require("../../../helpers/geoChart/common");
var data_1 = require("../../../helpers/geoChart/data");
var color_1 = require("../../visualizations/utils/color");
var colorStrategy_1 = require("../../../helpers/geoChart/colorStrategy");
var MappingHeader_1 = require("../../../interfaces/MappingHeader");
var BaseVisualization_1 = require("../base/BaseVisualization");
var GeoChartInner_1 = require("./GeoChartInner");
var fixEmptyHeaderItems_1 = require("../base/utils/fixEmptyHeaderItems");
var GeoChartOptionsWrapper = /** @class */ (function (_super) {
__extends(GeoChartOptionsWrapper, _super);
function GeoChartOptionsWrapper(props) {
var _this = _super.call(this, props) || this;
_this.buildGeoChartOptions = function (geoData, props) {
var segment = geoData.segment;
var _a = props.config, colors = _a.colors, colorPalette = _a.colorPalette, colorMapping = _a.colorMapping, dataSource = props.dataSource, execution = props.execution;
var palette = color_1.getValidColorPalette(colors, colorPalette);
var colorStrategy = colorStrategy_1.getColorStrategy(palette, colorMapping, geoData, execution, dataSource.getAfm());
var categoryItems = [];
if (segment) {
categoryItems = _this.getCategoryLegendItems(colorStrategy);
}
return {
geoData: geoData,
categoryItems: categoryItems,
colorStrategy: colorStrategy,
colorPalette: palette,
};
};
_this.validateData = function (geoData, props) {
if (!props.execution) {
return;
}
var _a = props.config.limit, limit = _a === void 0 ? geoChart_1.DEFAULT_DATA_POINTS_LIMIT : _a, executionResult = props.execution.executionResult;
return {
isDataTooLarge: !common_1.isDataOfReasonableSize(executionResult, geoData, limit),
};
};
_this.emptyHeaderString = _this.getEmptyHeaderString();
return _this;
}
GeoChartOptionsWrapper.prototype.renderVisualization = function () {
var sanitizedProps = this.sanitizeProperties();
var mdObject = sanitizedProps.config.mdObject, execution = sanitizedProps.execution, onDataTooLarge = sanitizedProps.onDataTooLarge;
var buckets = data_1.getGeoBucketsFromMdObject(mdObject);
var geoData = data_1.getGeoData(buckets, execution);
var isDataTooLarge = this.validateData(geoData, sanitizedProps).isDataTooLarge;
if (isDataTooLarge) {
invariant(onDataTooLarge, "GeoChart's onDataTooLarge callback is missing.");
onDataTooLarge();
return null;
}
var geoChartOptions = this.buildGeoChartOptions(geoData, sanitizedProps);
return React.createElement(GeoChartInner_1.GeoChartInner, __assign({}, sanitizedProps, { geoChartOptions: geoChartOptions }));
};
GeoChartOptionsWrapper.prototype.getCategoryLegendItems = function (colorStrategy) {
var _this = this;
var colorAssignment = colorStrategy.getColorAssignment();
return colorAssignment.map(function (item, legendIndex) {
var _a = MappingHeader_1.isMappingHeaderAttributeItem(item.headerItem)
? item.headerItem.attributeHeaderItem
: { name: _this.emptyHeaderString, uri: _this.emptyHeaderString }, name = _a.name, uri = _a.uri;
var color = colorStrategy.getColorByIndex(legendIndex);
return {
uri: uri,
name: name,
color: color,
legendIndex: legendIndex,
isVisible: true,
};
});
};
GeoChartOptionsWrapper.prototype.sanitizeProperties = function () {
var _a = this.props.execution, executionResult = _a.executionResult, executionResponse = _a.executionResponse;
var executionResultWithResolvedEmptyValues = fixEmptyHeaderItems_1.fixEmptyHeaderItems(executionResult, this.emptyHeaderString);
return __assign({}, this.props, { execution: {
executionResponse: executionResponse,
executionResult: executionResultWithResolvedEmptyValues,
} });
};
GeoChartOptionsWrapper.prototype.getEmptyHeaderString = function () {
return "(" + this.props.intl.formatMessage({ id: "visualization.emptyValue" }) + ")";
};
GeoChartOptionsWrapper.defaultProps = GeoChartInner_1.GeoChartInner.defaultProps;
return GeoChartOptionsWrapper;
}(BaseVisualization_1.BaseVisualization));
exports.GeoChartOptionsWrapper = GeoChartOptionsWrapper;
//# sourceMappingURL=GeoChartOptionsWrapper.js.map