mdt-charts 1.27.2 → 1.27.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/engine/features/valueLabels/valueLabels.d.ts +3 -2
- package/lib/engine/features/valueLabels/valueLabels.js +9 -7
- package/lib/model/featuresModel/scaleModel/scaleModel.js +1 -1
- package/lib/model/margin/twoDim/twoDimMarginModel.js +4 -6
- package/lib/model/modelInstance/configReader.d.ts +0 -4
- package/lib/model/modelInstance/configReader.js +0 -14
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Block } from "../../../engine/block/block";
|
|
2
|
-
import { OptionsModelData, Orient, TwoDimensionalChartModel, TwoDimensionalValueLabels, ValueLabelAnchor, ValueLabelDominantBaseline, ValueLabelsStyleModel } from "../../../model/model";
|
|
2
|
+
import { OptionsModelData, Orient, TwoDimChartValueLabelsOptions, TwoDimensionalChartModel, TwoDimensionalValueLabels, ValueLabelAnchor, ValueLabelDominantBaseline, ValueLabelsStyleModel } from "../../../model/model";
|
|
3
3
|
import { MdtChartsDataRow, MdtChartsDataSource } from "../../../config/config";
|
|
4
4
|
import { Scales, ScalesWithSecondary } from "../../../engine/features/scale/scale";
|
|
5
5
|
export interface ValueLabelsOptions {
|
|
@@ -27,9 +27,10 @@ export declare class ChartValueLabels {
|
|
|
27
27
|
static readonly valueLabelClass: string;
|
|
28
28
|
private readonly renderPipeline;
|
|
29
29
|
private readonly attrsProvider;
|
|
30
|
+
private options;
|
|
30
31
|
constructor(globalOptions: ValueLabelsOptions, chart: TwoDimensionalChartModel);
|
|
31
32
|
render(scales: Scales, data: MdtChartsDataRow[]): void;
|
|
32
|
-
update(scales: Scales, newData: MdtChartsDataRow[]): Promise<void[]>;
|
|
33
|
+
update(scales: Scales, newData: MdtChartsDataRow[], updatedOptions: TwoDimChartValueLabelsOptions): Promise<void[]>;
|
|
33
34
|
private renderByGroupIndex;
|
|
34
35
|
private updateByGroupIndex;
|
|
35
36
|
private getAllValueLabelsOfChart;
|
|
@@ -13,6 +13,7 @@ export class ChartValueLabels {
|
|
|
13
13
|
this.chart = chart;
|
|
14
14
|
this.renderPipeline = new Pipeline();
|
|
15
15
|
this.attrsProvider = new ValueLabelsAttrsProvider();
|
|
16
|
+
this.options = chart.valueLabels;
|
|
16
17
|
this.renderPipeline.push((valueLabels, { style }) => {
|
|
17
18
|
valueLabels.attr("fill", "currentColor").style("font-size", style.fontSize).style("color", style.color);
|
|
18
19
|
if (style.cssClassName)
|
|
@@ -33,8 +34,9 @@ export class ChartValueLabels {
|
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
|
-
update(scales, newData) {
|
|
37
|
+
update(scales, newData, updatedOptions) {
|
|
37
38
|
const updatePromises = [];
|
|
39
|
+
this.options = updatedOptions;
|
|
38
40
|
if (this.chart.isSegmented) {
|
|
39
41
|
const preparedData = getStackedData(newData, this.chart);
|
|
40
42
|
preparedData.forEach((segment, segmentIndex) => {
|
|
@@ -53,21 +55,21 @@ export class ChartValueLabels {
|
|
|
53
55
|
renderByGroupIndex(scales, groupIndex, data, valueFieldName, datumField, dataRowAccessor) {
|
|
54
56
|
let valueLabels = this.getAllValueLabelsOfChart(groupIndex).data(data).enter().append("text");
|
|
55
57
|
valueLabels = this.renderPipeline.execute(valueLabels, { style: this.globalOptions.canvas.style });
|
|
56
|
-
const attrs = this.attrsProvider.getAttrs(this.globalOptions, this.
|
|
57
|
-
this.setAttrs(valueLabels, attrs, valueFieldName, this.
|
|
58
|
+
const attrs = this.attrsProvider.getAttrs(this.globalOptions, this.options, scales, datumField, dataRowAccessor);
|
|
59
|
+
this.setAttrs(valueLabels, attrs, valueFieldName, this.options.format, dataRowAccessor);
|
|
58
60
|
this.setClasses(valueLabels, this.chart.cssClasses, groupIndex);
|
|
59
61
|
}
|
|
60
62
|
updateByGroupIndex(scales, groupIndex, data, valueFieldName, datumField, dataRowAccessor) {
|
|
61
63
|
return new Promise((resolve) => {
|
|
62
64
|
const valueLabels = this.getAllValueLabelsOfChart(groupIndex).data(data);
|
|
63
65
|
valueLabels.exit().remove();
|
|
64
|
-
const attrs = this.attrsProvider.getAttrs(this.globalOptions, this.
|
|
66
|
+
const attrs = this.attrsProvider.getAttrs(this.globalOptions, this.options, scales, datumField, dataRowAccessor);
|
|
65
67
|
let newValueLabels = valueLabels.enter().append("text");
|
|
66
68
|
newValueLabels = this.renderPipeline.execute(newValueLabels, { style: this.globalOptions.canvas.style });
|
|
67
69
|
const mergedValueLabels = newValueLabels.merge(valueLabels);
|
|
68
|
-
this.setAttrs(newValueLabels, attrs, valueFieldName, this.
|
|
70
|
+
this.setAttrs(newValueLabels, attrs, valueFieldName, this.options.format, dataRowAccessor);
|
|
69
71
|
this.setClasses(mergedValueLabels, this.chart.cssClasses, groupIndex);
|
|
70
|
-
this.setAttrs(valueLabels, attrs, valueFieldName, this.
|
|
72
|
+
this.setAttrs(valueLabels, attrs, valueFieldName, this.options.format, dataRowAccessor, true, resolve);
|
|
71
73
|
});
|
|
72
74
|
}
|
|
73
75
|
getAllValueLabelsOfChart(vfIndex) {
|
|
@@ -129,7 +131,7 @@ export class CanvasValueLabels {
|
|
|
129
131
|
this.toggleOldValueLabelsVisibility();
|
|
130
132
|
const chartsUpdatePromises = chartsWithLabels.map((chart, index) => {
|
|
131
133
|
const chartScales = this.getChartScales(scales, chart);
|
|
132
|
-
return this.chartsValueLabels[index].update(chartScales, data[dataOptions.dataSource]);
|
|
134
|
+
return this.chartsValueLabels[index].update(chartScales, data[dataOptions.dataSource], chart.valueLabels);
|
|
133
135
|
});
|
|
134
136
|
Promise.all(chartsUpdatePromises).then(() => {
|
|
135
137
|
const newValueLabels = this.getAllValueLabels();
|
|
@@ -37,7 +37,7 @@ export class ScaleModel {
|
|
|
37
37
|
getScaleSecondaryLinear(dataRows, configReader) {
|
|
38
38
|
var _a;
|
|
39
39
|
return {
|
|
40
|
-
domain: getScaleLinearDomain(this.options.axis.
|
|
40
|
+
domain: getScaleLinearDomain(this.options.axis.valueSecondary.domain, dataRows, this.options, "secondary"),
|
|
41
41
|
range: {
|
|
42
42
|
start: 0,
|
|
43
43
|
end: getScaleValueRangePeek(this.options.orientation, this.canvasModel)
|
|
@@ -56,13 +56,13 @@ export class TwoDimMarginModel {
|
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
58
|
const scaleModel = new ScaleModel(this.configReader.options, modelInstance.canvasModel).getScaleLinear(modelInstance.dataModel.repository.getRawRows(), this.configReader);
|
|
59
|
-
labelsTexts = this.getValueAxisLabels(scaleModel
|
|
59
|
+
labelsTexts = this.getValueAxisLabels(scaleModel).map((v) => this.configReader.getAxisLabelFormatter()(v).toString());
|
|
60
60
|
}
|
|
61
61
|
return AxisModel.getLabelSize(this.designerConfig.canvas.axisLabel.maxSize.main, labelsTexts);
|
|
62
62
|
}
|
|
63
63
|
getMaxLabelSizeSecondary(modelInstance) {
|
|
64
64
|
const scaleModel = new ScaleModel(this.configReader.options, modelInstance.canvasModel).getScaleSecondaryLinear(modelInstance.dataModel.repository.getRawRows(), this.configReader);
|
|
65
|
-
const labelsTexts = this.getValueAxisLabels(scaleModel
|
|
65
|
+
const labelsTexts = this.getValueAxisLabels(scaleModel).map((v) => this.configReader.getSecondaryAxisLabelFormatter()(v).toString());
|
|
66
66
|
return AxisModel.getLabelSize(this.designerConfig.canvas.axisLabel.maxSize.main, labelsTexts);
|
|
67
67
|
}
|
|
68
68
|
recalcVerticalMarginByAxisLabelHeight(labelHeight, canvasModel) {
|
|
@@ -112,16 +112,14 @@ export class TwoDimMarginModel {
|
|
|
112
112
|
};
|
|
113
113
|
canvasModel.increaseMarginSide(axisMarginMapping[keyAxisOrient], valueLabelFontSize + OFFSET_SIZE_PX);
|
|
114
114
|
}
|
|
115
|
-
getValueAxisLabels(scaleModel
|
|
115
|
+
getValueAxisLabels(scaleModel) {
|
|
116
116
|
const scale = Scale.getScaleValue(scaleModel);
|
|
117
117
|
const ticksPolicy = AxisModel.getTickAmountPolicy(this.configReader.options.orientation, this.configReader.options.axis.value, scaleModel);
|
|
118
|
-
let outputValues;
|
|
118
|
+
let outputValues = [];
|
|
119
119
|
if (ticksPolicy.type === "constant")
|
|
120
120
|
outputValues = ticksPolicy.values;
|
|
121
121
|
else if (ticksPolicy.type === "amount")
|
|
122
122
|
outputValues = scale.ticks(ticksPolicy.amount);
|
|
123
|
-
else
|
|
124
|
-
outputValues = this.configReader.getBiggestValueAndDecremented(modelInstance.dataModel.repository);
|
|
125
123
|
return outputValues;
|
|
126
124
|
}
|
|
127
125
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AxisLabelFormatter, MdtChartsConfig, MdtChartsField, MdtChartsFieldName, MdtChartsTwoDimensionalOptions, TwoDimensionalChartType, TwoDimensionalValueGroup, ValueLabelsFormatter } from "../../config/config";
|
|
2
2
|
import { DesignerConfig } from "../../designer/designerConfig";
|
|
3
|
-
import { DataRepositoryModel } from "../../model/modelInstance/dataModel/dataRepository";
|
|
4
3
|
import { ValueLabelsStyleModel } from "../model";
|
|
5
4
|
interface BaseConfigReader {
|
|
6
5
|
getValueFields(): MdtChartsField[];
|
|
@@ -11,8 +10,6 @@ export declare class TwoDimConfigReader implements BaseConfigReader {
|
|
|
11
10
|
readonly options: MdtChartsTwoDimensionalOptions;
|
|
12
11
|
constructor(config: MdtChartsConfig, designerConfig: DesignerConfig);
|
|
13
12
|
getValueFields(): MdtChartsField[];
|
|
14
|
-
getBiggestValueAndDecremented(repository: DataRepositoryModel): number[];
|
|
15
|
-
getBiggestValueAndDecrementedSecondary(repository: DataRepositoryModel): number[];
|
|
16
13
|
getFieldsBySegments(valueGroup: TwoDimensionalValueGroup): MdtChartsFieldName[][];
|
|
17
14
|
getAxisLabelFormatter(): AxisLabelFormatter;
|
|
18
15
|
getSecondaryAxisLabelFormatter(): AxisLabelFormatter;
|
|
@@ -26,7 +23,6 @@ export declare class TwoDimConfigReader implements BaseConfigReader {
|
|
|
26
23
|
areValueLabelsOn(): boolean;
|
|
27
24
|
areValueLabelsNeedIncreaseMargin(): boolean;
|
|
28
25
|
getValueLabelsStyleModel(): ValueLabelsStyleModel;
|
|
29
|
-
private calculateBiggestValueAndDecremented;
|
|
30
26
|
private calculateAxisLabelFormatter;
|
|
31
27
|
}
|
|
32
28
|
export declare class PolarConfigReader implements BaseConfigReader {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getResolvedDomain } from "../../model/featuresModel/scaleModel/scaleDomainService";
|
|
2
1
|
export function getConfigReader(config, designerConfig) {
|
|
3
2
|
if (config.options.type === "2d")
|
|
4
3
|
return new TwoDimConfigReader(config, designerConfig);
|
|
@@ -18,12 +17,6 @@ export class TwoDimConfigReader {
|
|
|
18
17
|
});
|
|
19
18
|
return fields;
|
|
20
19
|
}
|
|
21
|
-
getBiggestValueAndDecremented(repository) {
|
|
22
|
-
return this.calculateBiggestValueAndDecremented(repository, this.options.axis.value.domain, this.getFieldsBySegments("main"));
|
|
23
|
-
}
|
|
24
|
-
getBiggestValueAndDecrementedSecondary(repository) {
|
|
25
|
-
return this.calculateBiggestValueAndDecremented(repository, this.options.axis.valueSecondary.domain, this.getFieldsBySegments("secondary"));
|
|
26
|
-
}
|
|
27
20
|
getFieldsBySegments(valueGroup) {
|
|
28
21
|
const segments = [];
|
|
29
22
|
const valueGroupCharts = this.options.charts.filter((chart) => { var _a; return ((_a = chart.data.valueGroup) !== null && _a !== void 0 ? _a : "main") === valueGroup; });
|
|
@@ -90,13 +83,6 @@ export class TwoDimConfigReader {
|
|
|
90
83
|
cssClassName: (_h = (_g = this.options.valueLabels) === null || _g === void 0 ? void 0 : _g.style) === null || _h === void 0 ? void 0 : _h.cssClassName
|
|
91
84
|
};
|
|
92
85
|
}
|
|
93
|
-
calculateBiggestValueAndDecremented(repository, domain, fields) {
|
|
94
|
-
const resolvedDomain = getResolvedDomain(domain, repository.getRawRows());
|
|
95
|
-
if (resolvedDomain && resolvedDomain.end !== -1) {
|
|
96
|
-
return [resolvedDomain.end, resolvedDomain.end - 1];
|
|
97
|
-
}
|
|
98
|
-
return repository.getBiggestValueAndDecremented(fields);
|
|
99
|
-
}
|
|
100
86
|
calculateAxisLabelFormatter(axisValue) {
|
|
101
87
|
var _a, _b;
|
|
102
88
|
if ((_a = axisValue.labels) === null || _a === void 0 ? void 0 : _a.format)
|