@gooddata/react-components
Version:
GoodData.UI - A powerful JavaScript library for building analytical applications
159 lines • 9.64 kB
JavaScript
"use strict";
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) 2019-2020 GoodData Corporation
var cloneDeep = require("lodash/cloneDeep");
var get = require("lodash/get");
var set = require("lodash/set");
var without = require("lodash/without");
var BucketNames = require("../../../../constants/bucketNames");
var bucketConfig_1 = require("../../../utils/bucketConfig");
var PluggableBaseChart_1 = require("../baseChart/PluggableBaseChart");
var bucket_1 = require("../../../constants/bucket");
var bucketHelper_1 = require("../../../utils/bucketHelper");
var comboChartUiConfigHelper_1 = require("../../../utils/uiConfigHelpers/comboChartUiConfigHelper");
var sort_1 = require("../../../utils/sort");
var axis_1 = require("../../../constants/axis");
var supportedProperties_1 = require("../../../constants/supportedProperties");
var uiConfig_1 = require("../../../constants/uiConfig");
var propertiesHelper_1 = require("../../../utils/propertiesHelper");
var properties_1 = require("../../../constants/properties");
var visualizationTypes_1 = require("../../../../constants/visualizationTypes");
var bucketRules_1 = require("../../../utils/bucketRules");
var common_1 = require("../../../../components/visualizations/utils/common");
var PluggableComboChart = /** @class */ (function (_super) {
__extends(PluggableComboChart, _super);
function PluggableComboChart(props) {
var _this = _super.call(this, props) || this;
_this.primaryChartType = visualizationTypes_1.VisualizationTypes.COLUMN;
_this.type = visualizationTypes_1.VisualizationTypes.COMBO;
_this.axis = axis_1.AXIS.DUAL;
_this.secondaryAxis = axis_1.AXIS_NAME.SECONDARY_Y;
_this.primaryChartType = get(props.visualizationProperties, properties_1.PROPERTY_CONTROLS_PRIMARY_CHART_TYPE, visualizationTypes_1.VisualizationTypes.COLUMN);
_this.supportedPropertiesList = _this.getSupportedPropertiesList();
_this.defaultControlsProperties = {
stackMeasures: _this.isStackMeasuresByDefault(),
};
_this.initializeProperties(props.visualizationProperties);
return _this;
}
PluggableComboChart.prototype.getSupportedPropertiesList = function () {
return supportedProperties_1.COMBO_CHART_SUPPORTED_PROPERTIES[this.axis] || [];
};
PluggableComboChart.prototype.getUiConfig = function () {
return cloneDeep(__assign({}, uiConfig_1.COMBO_CHART_UICONFIG, { optionalStacking: {
supported: true,
disabled: common_1.isLineChart(this.primaryChartType),
stackMeasures: this.isStackMeasuresByDefault(),
} }));
};
PluggableComboChart.prototype.getExtendedReferencePoint = function (referencePoint) {
var clonedReferencePoint = cloneDeep(referencePoint);
var properties = this.configureChartTypes(clonedReferencePoint);
this.primaryChartType = get(properties, "controls.primaryChartType", visualizationTypes_1.VisualizationTypes.COLUMN);
var newReferencePoint = __assign({}, clonedReferencePoint, { properties: properties, uiConfig: this.getUiConfig() });
this.defaultControlsProperties = {
stackMeasures: this.isStackMeasuresByDefault(),
};
this.configureBuckets(newReferencePoint);
newReferencePoint = propertiesHelper_1.setSecondaryMeasures(newReferencePoint, this.secondaryAxis);
this.axis = get(newReferencePoint, uiConfig_1.UICONFIG_AXIS, axis_1.AXIS.PRIMARY);
this.supportedPropertiesList = this.getSupportedPropertiesList();
newReferencePoint = comboChartUiConfigHelper_1.setComboChartUiConfig(newReferencePoint, this.intl, this.type);
newReferencePoint = bucketConfig_1.configurePercent(newReferencePoint, this.isPercentDisabled(newReferencePoint));
newReferencePoint = bucketConfig_1.configureOverTimeComparison(newReferencePoint, !!this.featureFlags.enableWeekFilters);
newReferencePoint = propertiesHelper_1.getReferencePointWithSupportedProperties(newReferencePoint, this.supportedPropertiesList);
newReferencePoint = bucketHelper_1.applyUiConfig(newReferencePoint);
newReferencePoint = sort_1.removeSort(newReferencePoint);
return Promise.resolve(bucketHelper_1.sanitizeFilters(newReferencePoint));
};
PluggableComboChart.prototype.isStackMeasuresByDefault = function () {
return common_1.isAreaChart(this.primaryChartType);
};
PluggableComboChart.prototype.configureBuckets = function (extReferencePoint) {
var buckets = get(extReferencePoint, bucket_1.BUCKETS, []);
var attributes = bucketHelper_1.getAllAttributeItemsWithPreference(buckets, [
BucketNames.TREND,
BucketNames.VIEW,
]).slice(0, 1);
var measures = [];
var secondaryMeasures = [];
// ref. point has both my buckets -> reuse them fully
if (bucketHelper_1.hasBucket(buckets, BucketNames.MEASURES) && bucketHelper_1.hasBucket(buckets, BucketNames.SECONDARY_MEASURES)) {
measures = bucketHelper_1.getBucketItemsByType(buckets, BucketNames.MEASURES, [bucket_1.METRIC]);
secondaryMeasures = bucketHelper_1.getBucketItemsByType(buckets, BucketNames.SECONDARY_MEASURES, [bucket_1.METRIC]);
var restMeasures = bucketHelper_1.getBucketItemsWithExcludeByType(buckets, [BucketNames.MEASURES, BucketNames.SECONDARY_MEASURES], [bucket_1.METRIC]);
secondaryMeasures = secondaryMeasures.concat(restMeasures);
}
else {
// transform from dual axis chart to combo chart
var allMeasures = bucketHelper_1.getMeasureItems(buckets);
secondaryMeasures = bucketHelper_1.getAllMeasuresShowOnSecondaryAxis(buckets);
measures = without.apply(void 0, [allMeasures].concat(secondaryMeasures));
}
var isDualAxisEnabled = propertiesHelper_1.isDualAxisOrSomeSecondaryAxisMeasure(extReferencePoint, secondaryMeasures);
set(extReferencePoint, properties_1.PROPERTY_CONTROLS_DUAL_AXIS, isDualAxisEnabled);
var primaryChartType = get(extReferencePoint, properties_1.PROPERTY_CONTROLS_PRIMARY_CHART_TYPE, visualizationTypes_1.VisualizationTypes.COLUMN);
var secondaryChartType = get(extReferencePoint, properties_1.PROPERTY_CONTROLS_SECONDARY_CHART_TYPE, visualizationTypes_1.VisualizationTypes.LINE);
set(extReferencePoint, bucket_1.BUCKETS, [
{
localIdentifier: BucketNames.MEASURES,
items: bucketHelper_1.setMeasuresShowOnSecondaryAxis(measures, false),
chartType: primaryChartType,
},
{
localIdentifier: BucketNames.SECONDARY_MEASURES,
items: bucketHelper_1.setMeasuresShowOnSecondaryAxis(secondaryMeasures, isDualAxisEnabled),
chartType: secondaryChartType,
},
{
localIdentifier: BucketNames.VIEW,
items: attributes,
},
]);
};
PluggableComboChart.prototype.configureChartTypes = function (referencePoint) {
var buckets = get(referencePoint, bucket_1.BUCKETS, []);
var controls = get(referencePoint, properties_1.PROPERTY_CONTROLS, {});
var primaryChartType = get(bucketHelper_1.findBucket(buckets, BucketNames.MEASURES), "chartType", controls.primaryChartType || visualizationTypes_1.VisualizationTypes.COLUMN);
var secondaryChartType = get(bucketHelper_1.findBucket(buckets, BucketNames.SECONDARY_MEASURES), "chartType", controls.secondaryChartType || visualizationTypes_1.VisualizationTypes.LINE);
return __assign({}, referencePoint.properties, { controls: __assign({}, controls, { primaryChartType: primaryChartType,
secondaryChartType: secondaryChartType }) });
};
PluggableComboChart.prototype.isPercentDisabled = function (extReferencePoint) {
if (this.axis === axis_1.AXIS.DUAL) {
return false;
}
var buckets = get(extReferencePoint, bucket_1.BUCKETS, []);
var primaryMasterMeasures = bucketRules_1.getMasterMeasuresCount(buckets, BucketNames.MEASURES);
var secondaryMasterMeasures = bucketRules_1.getMasterMeasuresCount(buckets, BucketNames.SECONDARY_MEASURES);
// disable percent if there is more than one measure on primary/secondary y-axis
return primaryMasterMeasures + secondaryMasterMeasures > 1;
};
return PluggableComboChart;
}(PluggableBaseChart_1.PluggableBaseChart));
exports.PluggableComboChart = PluggableComboChart;
//# sourceMappingURL=PluggableComboChart.js.map