@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
219 lines (218 loc) • 10.6 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 (Object.prototype.hasOwnProperty.call(b, 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);
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
import { computed } from 'mobx';
import { find, get, includes } from 'lodash';
import { colorMap } from '@qn-pandora/pandora-app-component/es/components/LegendColorPanel';
import bind from '../../../../utils/bind';
import BaseBarChartStore from '../../BarChart/store';
import { updateSeriesDataByBound, toOverlapLineSeries, getBaseLineBar2Series } from '../../LineChart/transform';
import { toBarSeries } from '../../BarChart/transform';
var LineBarY2ChartStore = /** @class */ (function (_super) {
__extends(LineBarY2ChartStore, _super);
function LineBarY2ChartStore() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(LineBarY2ChartStore.prototype, "showingSeries", {
get: function () {
var currentMetrics = this.chartStyleService.crossAxis1.fields;
var series = this.notFormatSeries.series || [];
var currentMetricNames = currentMetrics;
return series.filter(function (e) {
if (e.isOverlap) {
// 非柱状图的所有metrics允许渲染,例如叠加折线
return true;
}
// 柱状图只渲染当前指标中选中的值(metric)
return includes(currentMetricNames, e.metricName);
});
},
enumerable: false,
configurable: true
});
Object.defineProperty(LineBarY2ChartStore.prototype, "barCrossAxis2Options", {
get: function () {
return this.crossAxis2Options;
},
enumerable: false,
configurable: true
});
LineBarY2ChartStore.prototype.getOptions = function () {
var currentLineMetrics = this.chartStyleService.crossAxis2.fields;
var crossAxisOptions = __spread([
this.barCrossAxis1Options
], (currentLineMetrics.length > 0 ? [this.barCrossAxis2Options] : []));
var baseBarOption = _super.prototype.getOptions.call(this);
var option = __assign(__assign({}, baseBarOption), { yAxis: crossAxisOptions });
return option;
};
Object.defineProperty(LineBarY2ChartStore.prototype, "notFormatSeries", {
get: function () {
var _a = this.chartStyleService, y1Scale = _a.crossAxis1.scale, _b = _a.crossAxis2, y2EmptyValueMode = _b.yEmptyValueMode, y2Scale = _b.scale, isCompareEnable = _a.compare.isCompareEnable, stack = _a.stack;
var data = this.baseSeries;
var data2 = this.overlapLineSeries;
var barSeries = toBarSeries(data);
var lineSeries = toOverlapLineSeries(data2, y2EmptyValueMode === "0" /* Zero */);
if (y1Scale === "log" /* Log */) {
this.processSeriesForLog(barSeries);
}
if (y2Scale === "log" /* Log */) {
this.processSeriesForLog(lineSeries);
}
if (stack) {
barSeries.forEach(function (sery, index) {
// 设置堆叠模式
if (isCompareEnable) {
sery['stack'] = index % 2 === 0 ? 'current' : 'compare';
}
else {
sery['stack'] = 'stacked';
}
});
}
var series = __spread(barSeries, lineSeries);
return { series: series };
},
enumerable: false,
configurable: true
});
Object.defineProperty(LineBarY2ChartStore.prototype, "series", {
get: function () {
var _this = this;
var _a = this.chartStyleService, unitTransformer = _a.crossAxis1.unitTransformer, showBarLabel = _a.showBarLabel, baseLine = _a.baseLine, useCrossAxis2 = _a.useCrossAxis2, _b = _a.mainAxis, field = _b.field, type = _b.type, y1EmptyValueMode = _a.crossAxis1.yEmptyValueMode, y2EmptyValueMode = _a.crossAxis2.yEmptyValueMode, colorMode = _a.colorMode;
var lineThemeOption = get(this.themeOption, 'line');
var showingSeries = this.showingSeries;
var themeColors = get(this.themeOption, 'color');
var typeColors = get(this.themeOption, ['bar', 'color']) || [];
var displayColors = this.chartStyleService.displayColors;
var colorModeColors = get(colorMap, colorMode);
var defaultColors = colorModeColors || typeColors || themeColors;
showingSeries.forEach(function (sery, index) {
// 设置颜色
var displayColor = find(displayColors, function (displayColor) { return displayColor.name === sery.name; });
sery['itemStyle'] = {
normal: {
color: displayColor
? displayColor.color
: defaultColors[index % defaultColors.length]
}
};
if (sery.type === 'line') {
_this.handleLineSeries(sery, lineThemeOption, useCrossAxis2);
}
else if (sery.type === 'bar') {
// 设置label
var labelPosition = showBarLabel === true ? 'inside' : showBarLabel;
sery['showSymbol'] = showBarLabel;
sery['label'] = {
position: labelPosition,
distance: 0,
show: !!showBarLabel,
color: labelPosition === 'inside' ? '#fff' : 'inherit',
formatter: function (params) { return unitTransformer(params.value); }
};
// 设置柱状图最大宽度
sery['barMaxWidth'] = 40;
//设置鼠标样式
sery['cursor'] = _this.chartCanClick ? 'pointer' : 'default';
sery['silent'] = _this.chartCanClick ? false : true;
}
});
if (baseLine.length) {
var _c = getBaseLineBar2Series(baseLine, this.chartContainerService.chartConditionService.originDataset, get(this.themeOption, ['bar', 'thresholdColor']), field, y1EmptyValueMode === "0" /* Zero */, y2EmptyValueMode === "0" /* Zero */, type === "time" /* Time */), numberRightSeries = _c.numberRightSeries, numberLeftSeries = _c.numberLeftSeries, dynamicSeries = _c.dynamicSeries;
updateSeriesDataByBound(showingSeries, baseLine, dynamicSeries, function (data, matchLine) {
return __assign(__assign({}, data), { itemStyle: {
color: matchLine.color
} });
});
var currentLineMetrics = this.chartStyleService.crossAxis2.fields;
return currentLineMetrics.length > 0
? __spread(showingSeries, [
numberLeftSeries,
numberRightSeries
], dynamicSeries) : __spread(showingSeries, [numberLeftSeries], dynamicSeries);
}
return __spread(showingSeries);
},
enumerable: false,
configurable: true
});
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], LineBarY2ChartStore.prototype, "showingSeries", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], LineBarY2ChartStore.prototype, "barCrossAxis2Options", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], LineBarY2ChartStore.prototype, "getOptions", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], LineBarY2ChartStore.prototype, "notFormatSeries", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], LineBarY2ChartStore.prototype, "series", null);
return LineBarY2ChartStore;
}(BaseBarChartStore));
export default LineBarY2ChartStore;