@gooddata/react-components
Version:
GoodData.UI - A powerful JavaScript library for building analytical applications
126 lines • 6.75 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 React = require("react");
var cloneDeep = require("lodash/cloneDeep");
var get = require("lodash/get");
var set = require("lodash/set");
var BucketNames = require("../../../../constants/bucketNames");
var react_dom_1 = require("react-dom");
var bucketConfig_1 = require("../../../utils/bucketConfig");
var PluggableBaseChart_1 = require("../baseChart/PluggableBaseChart");
var uiConfig_1 = require("../../../constants/uiConfig");
var bucket_1 = require("../../../constants/bucket");
var bucketHelper_1 = require("../../../utils/bucketHelper");
var LineChartBasedConfigurationPanel_1 = require("../../configurationPanels/LineChartBasedConfigurationPanel");
var lineChartUiConfigHelper_1 = require("../../../utils/uiConfigHelpers/lineChartUiConfigHelper");
var sort_1 = require("../../../utils/sort");
var propertiesHelper_1 = require("../../../utils/propertiesHelper");
var supportedProperties_1 = require("../../../constants/supportedProperties");
var axis_1 = require("../../../constants/axis");
var visualizationTypes_1 = require("../../../../constants/visualizationTypes");
var PluggableLineChart = /** @class */ (function (_super) {
__extends(PluggableLineChart, _super);
function PluggableLineChart(props) {
var _this = _super.call(this, props) || this;
// set default to DUAL to get the full supported props list
// and will be updated in getExtendedReferencePoint
_this.axis = axis_1.AXIS.DUAL;
_this.type = visualizationTypes_1.VisualizationTypes.LINE;
_this.supportedPropertiesList = _this.getSupportedPropertiesList();
_this.initializeProperties(props.visualizationProperties);
return _this;
}
PluggableLineChart.prototype.getSupportedPropertiesList = function () {
return supportedProperties_1.LINE_CHART_SUPPORTED_PROPERTIES[this.axis];
};
PluggableLineChart.prototype.getExtendedReferencePoint = function (referencePoint) {
var clonedReferencePoint = cloneDeep(referencePoint);
var newReferencePoint = __assign({}, clonedReferencePoint, { uiConfig: cloneDeep(uiConfig_1.DEFAULT_LINE_UICONFIG) });
var buckets = get(clonedReferencePoint, bucket_1.BUCKETS, []);
var measures = bucketHelper_1.getMeasureItems(buckets);
var masterMeasures = bucketHelper_1.filterOutDerivedMeasures(measures);
var attributes = [];
var stacks = bucketHelper_1.getStackItems(buckets);
var dateItems = bucketHelper_1.getDateItems(buckets);
var allAttributes = bucketHelper_1.getAllAttributeItemsWithPreference(buckets, [
BucketNames.LOCATION,
BucketNames.TREND,
BucketNames.VIEW,
BucketNames.SEGMENT,
BucketNames.STACK,
]);
if (dateItems.length) {
attributes = dateItems.slice(0, 1);
stacks =
masterMeasures.length <= 1 && allAttributes.length > 1
? allAttributes
.filter(function (attribute) { return !bucketHelper_1.isDateBucketItem(attribute); })
.slice(0, 1)
: stacks;
}
else {
if (masterMeasures.length <= 1 &&
allAttributes.length > 1 &&
!bucketHelper_1.isDateBucketItem(get(allAttributes, "1"))) {
stacks = allAttributes.slice(1, 2);
}
attributes = bucketHelper_1.getAttributeItemsWithoutStacks(buckets).slice(0, 1);
}
set(newReferencePoint, bucket_1.BUCKETS, [
{
localIdentifier: BucketNames.MEASURES,
items: bucketHelper_1.getFilteredMeasuresForStackedCharts(buckets),
},
{
localIdentifier: BucketNames.TREND,
items: attributes,
},
{
localIdentifier: BucketNames.SEGMENT,
items: stacks,
},
]);
newReferencePoint = propertiesHelper_1.setSecondaryMeasures(newReferencePoint, axis_1.AXIS_NAME.SECONDARY_Y);
this.axis = get(newReferencePoint, uiConfig_1.UICONFIG_AXIS, axis_1.AXIS.PRIMARY);
this.supportedPropertiesList = this.getSupportedPropertiesList();
newReferencePoint = lineChartUiConfigHelper_1.setLineChartUiConfig(newReferencePoint, this.intl, this.type);
newReferencePoint = bucketConfig_1.configurePercent(newReferencePoint, false);
newReferencePoint = bucketConfig_1.configureOverTimeComparison(newReferencePoint, !!this.featureFlags.enableWeekFilters);
newReferencePoint = propertiesHelper_1.getReferencePointWithSupportedProperties(newReferencePoint, this.supportedPropertiesList);
newReferencePoint = sort_1.removeSort(newReferencePoint);
return Promise.resolve(bucketHelper_1.sanitizeFilters(newReferencePoint));
};
PluggableLineChart.prototype.renderConfigurationPanel = function () {
if (document.querySelector(this.configPanelElement)) {
react_dom_1.render(React.createElement(LineChartBasedConfigurationPanel_1.default, { locale: this.locale, references: this.references, properties: this.visualizationProperties, propertiesMeta: this.propertiesMeta, mdObject: this.mdObject, colors: this.colors, pushData: this.handlePushData, type: this.type, isError: this.isError, isLoading: this.isLoading, featureFlags: this.featureFlags, axis: this.axis }), document.querySelector(this.configPanelElement));
}
};
return PluggableLineChart;
}(PluggableBaseChart_1.PluggableBaseChart));
exports.PluggableLineChart = PluggableLineChart;
//# sourceMappingURL=PluggableLineChart.js.map