@gooddata/react-components
Version:
GoodData.UI - A powerful JavaScript library for building analytical applications
129 lines • 6.16 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) 2007-2020 GoodData Corporation
var React = require("react");
var react_measure_1 = require("react-measure");
var cx = require("classnames");
var isEmpty = require("lodash/isEmpty");
var FluidLegend_1 = require("./FluidLegend");
var StaticLegend_1 = require("./StaticLegend");
var common_1 = require("../../utils/common");
var HeatmapLegend_1 = require("./HeatmapLegend");
var IntlWrapper_1 = require("../../../core/base/IntlWrapper");
var TranslationsProvider_1 = require("../../../core/base/TranslationsProvider");
var helpers_1 = require("./helpers");
var common_2 = require("../../../../helpers/geoChart/common");
var Legend = /** @class */ (function (_super) {
__extends(Legend, _super);
function Legend(props) {
var _this = _super.call(this, props) || this;
_this.onItemClick = _this.onItemClick.bind(_this);
return _this;
}
Legend.prototype.onItemClick = function (item) {
this.props.onItemClick(item);
};
Legend.prototype.getSeries = function () {
var _a = this.props, series = _a.series, legendItemsEnabled = _a.legendItemsEnabled, chartType = _a.chartType;
var seriesWithVisibility = series.map(function (seriesItem) {
var isVisible = legendItemsEnabled[seriesItem.legendIndex];
return __assign({}, seriesItem, { isVisible: isVisible });
});
if (common_1.isComboChart(chartType)) {
return helpers_1.getComboChartSeries(seriesWithVisibility);
}
return helpers_1.transformToDualAxesSeries(seriesWithVisibility, chartType);
};
Legend.prototype.renderFluid = function () {
var _this = this;
var chartType = this.props.chartType;
return (React.createElement(react_measure_1.default, { client: true }, function (_a) {
var measureRef = _a.measureRef, contentRect = _a.contentRect;
var usedWidth = contentRect.client && contentRect.client.width
? Math.floor(contentRect.client.width)
: 0;
return (React.createElement("div", { className: "viz-fluid-legend-wrap", ref: measureRef },
React.createElement(FluidLegend_1.default, { series: _this.getSeries(), chartType: chartType, onItemClick: _this.onItemClick, containerWidth: usedWidth })));
}));
};
Legend.prototype.renderStatic = function () {
var _this = this;
var _a = this.props, chartType = _a.chartType, position = _a.position, height = _a.height, format = _a.format, locale = _a.locale, responsive = _a.responsive;
var classNames = cx("viz-static-legend-wrap", "position-" + position);
var props = {
series: this.getSeries(),
chartType: chartType,
onItemClick: this.onItemClick,
position: position,
format: format,
locale: locale,
responsive: responsive,
};
return (React.createElement(react_measure_1.default, { client: true }, function (_a) {
var measureRef = _a.measureRef, contentRect = _a.contentRect;
var measuredHeight = contentRect.client && contentRect.client.height
? Math.floor(contentRect.client.height)
: 0;
var usedHeight = height || measuredHeight;
if (!isEmpty(contentRect.client)) {
_this.props.validateOverHeight(contentRect.client);
}
return (React.createElement("div", { className: classNames, ref: measureRef },
React.createElement(StaticLegend_1.default, __assign({}, props, { containerHeight: usedHeight }))));
}));
};
Legend.prototype.render = function () {
var responsive = this.props.responsive;
var showFluidLegend = this.props.showFluidLegend;
var isFluidLegend = common_2.isFluidLegendEnabled(responsive, showFluidLegend);
if (common_1.isHeatmap(this.props.chartType)) {
return this.renderHeatmapLegend();
}
if (isFluidLegend) {
return this.renderFluid();
}
return this.renderStatic();
};
Legend.prototype.renderHeatmapLegend = function () {
var _a = this.props, locale = _a.locale, format = _a.format, responsive = _a.responsive, position = _a.position;
var showFluidLegend = this.props.showFluidLegend;
var series = this.getSeries();
var isSmall = responsive && showFluidLegend;
return (React.createElement(IntlWrapper_1.IntlWrapper, { locale: locale },
React.createElement(TranslationsProvider_1.IntlTranslationsProvider, null, function (props) { return (React.createElement(HeatmapLegend_1.default, { series: series, format: format, isSmall: isSmall, numericSymbols: props.numericSymbols, position: position })); })));
};
Legend.defaultProps = {
responsive: false,
legendItemsEnabled: [],
height: 0,
showFluidLegend: false,
isLegendOverHeight: false,
};
return Legend;
}(React.PureComponent));
exports.default = Legend;
//# sourceMappingURL=Legend.js.map