mdt-charts 1.15.4 → 1.15.6
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/config/config.d.ts +2 -1
- package/lib/engine/features/axis/axisLabelDomHelper.js +2 -1
- package/lib/model/featuresModel/axisModel.js +1 -1
- package/lib/model/helpers/modelHelper.js +10 -4
- package/lib/model/margin/twoDim/twoDimMarginModel.js +2 -1
- package/lib/model/modelInstance/configReader.d.ts +2 -1
- package/lib/model/modelInstance/configReader.js +10 -0
- package/lib/model/modelInstance/dataModel/dataRepository.d.ts +2 -2
- package/lib/model/modelInstance/dataModel/dataRepository.js +9 -2
- package/package.json +1 -1
package/lib/config/config.d.ts
CHANGED
|
@@ -86,8 +86,9 @@ export interface DataOptions {
|
|
|
86
86
|
keyField: MdtChartsField;
|
|
87
87
|
maxRecordsAmount?: number;
|
|
88
88
|
}
|
|
89
|
+
export declare type MdtChartsFieldName = string;
|
|
89
90
|
export interface MdtChartsField {
|
|
90
|
-
name:
|
|
91
|
+
name: MdtChartsFieldName;
|
|
91
92
|
format: DataType;
|
|
92
93
|
}
|
|
93
94
|
export interface MdtChartsValueField extends MdtChartsField {
|
|
@@ -38,12 +38,13 @@ export class AxisLabelHelper {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
static cropLabels(block, scale, scaleOptions, axisOptions, blockSize) {
|
|
41
|
+
var _a, _b, _c;
|
|
41
42
|
const axisTextBlocks = block.getSvg().select(`.${axisOptions.cssClass}`).selectAll('text');
|
|
42
43
|
let maxLabelSize;
|
|
43
44
|
if ((axisOptions.orient === 'left' || axisOptions.orient === 'right') || (axisOptions.type === 'key' && axisOptions.labels.position === 'rotated'))
|
|
44
45
|
maxLabelSize = axisOptions.labels.maxSize;
|
|
45
46
|
else
|
|
46
|
-
maxLabelSize = scale.step() - 4;
|
|
47
|
+
maxLabelSize = ((_c = (_b = (_a = scale).step) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : Infinity) - 4;
|
|
47
48
|
DomHelper.cropSvgLabels(axisTextBlocks, maxLabelSize);
|
|
48
49
|
if (scaleOptions.type === 'point' && axisOptions.labels.position === 'straight' && (axisOptions.orient === 'top' || axisOptions.orient === 'bottom')) {
|
|
49
50
|
this.cropAndAlignExtremeLabels(block, maxLabelSize, axisOptions, blockSize);
|
|
@@ -82,7 +82,7 @@ export class AxisModel {
|
|
|
82
82
|
}
|
|
83
83
|
static getLabelSize(labelMaxWidth, labelTexts) {
|
|
84
84
|
const LABEL_ELEMENT_HEIGHT_PX = 17;
|
|
85
|
-
const ONE_UPPER_SYMBOL_WIDTH_PX = 8
|
|
85
|
+
const ONE_UPPER_SYMBOL_WIDTH_PX = 8;
|
|
86
86
|
const longestLabelLength = Math.max(...labelTexts.map(t => ModelHelper.getStringScore(t)));
|
|
87
87
|
const longestLabelWidth = ONE_UPPER_SYMBOL_WIDTH_PX * longestLabelLength;
|
|
88
88
|
return {
|
|
@@ -29,12 +29,18 @@ export class ModelHelper {
|
|
|
29
29
|
// Number width == lower case letter width
|
|
30
30
|
let score = 0;
|
|
31
31
|
const upperLetterScore = 1;
|
|
32
|
-
const lowerLetterScore = 0.
|
|
32
|
+
const lowerLetterScore = 0.8;
|
|
33
|
+
const digitAndSymbolScore = 0.67;
|
|
34
|
+
const specialSmallSymbols = [",", ".", " "];
|
|
33
35
|
for (let i = 0; i < word.length; i++) {
|
|
34
|
-
if (word[i].
|
|
35
|
-
|
|
36
|
+
if (parseFloat(word[i]).toString() !== word[i] && !specialSmallSymbols.includes(word[i]) && word[i].trim().length > 0) {
|
|
37
|
+
if (word[i].toUpperCase() === word[i])
|
|
38
|
+
score += upperLetterScore;
|
|
39
|
+
else
|
|
40
|
+
score += lowerLetterScore;
|
|
41
|
+
}
|
|
36
42
|
else
|
|
37
|
-
score +=
|
|
43
|
+
score += digitAndSymbolScore;
|
|
38
44
|
}
|
|
39
45
|
return score;
|
|
40
46
|
}
|
|
@@ -43,7 +43,8 @@ export class TwoDimMarginModel {
|
|
|
43
43
|
labelsTexts = modelInstance.dataModel.repository.getValuesByKeyField();
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
|
-
labelsTexts = modelInstance.dataModel.repository.getBiggestValueAndDecremented(
|
|
46
|
+
labelsTexts = modelInstance.dataModel.repository.getBiggestValueAndDecremented(this.configReader.getFieldsBySegments())
|
|
47
|
+
.map(v => this.configReader.getAxisLabelFormatter()(v));
|
|
47
48
|
}
|
|
48
49
|
return AxisModel.getLabelSize(this.designerConfig.canvas.axisLabel.maxSize.main, labelsTexts);
|
|
49
50
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AxisLabelFormatter, MdtChartsConfig, MdtChartsField, MdtChartsTwoDimensionalOptions, TwoDimensionalChartType } from "../../config/config";
|
|
1
|
+
import { AxisLabelFormatter, MdtChartsConfig, MdtChartsField, MdtChartsFieldName, MdtChartsTwoDimensionalOptions, TwoDimensionalChartType } from "../../config/config";
|
|
2
2
|
import { DesignerConfig } from "../../designer/designerConfig";
|
|
3
3
|
interface BaseConfigReader {
|
|
4
4
|
getValueFields(): MdtChartsField[];
|
|
@@ -9,6 +9,7 @@ export declare class TwoDimConfigReader implements BaseConfigReader {
|
|
|
9
9
|
readonly options: MdtChartsTwoDimensionalOptions;
|
|
10
10
|
constructor(config: MdtChartsConfig, designerConfig: DesignerConfig);
|
|
11
11
|
getValueFields(): MdtChartsField[];
|
|
12
|
+
getFieldsBySegments(): MdtChartsFieldName[][];
|
|
12
13
|
getAxisLabelFormatter(): AxisLabelFormatter;
|
|
13
14
|
getLegendItemInfo(): {
|
|
14
15
|
text: string;
|
|
@@ -17,6 +17,16 @@ export class TwoDimConfigReader {
|
|
|
17
17
|
});
|
|
18
18
|
return fields;
|
|
19
19
|
}
|
|
20
|
+
getFieldsBySegments() {
|
|
21
|
+
const segments = [];
|
|
22
|
+
this.options.charts.forEach(chart => {
|
|
23
|
+
if (!chart.isSegmented)
|
|
24
|
+
segments.push(...chart.data.valueFields.map(vf => [vf.name]));
|
|
25
|
+
else
|
|
26
|
+
segments.push(...[chart.data.valueFields.map(vf => vf.name)]);
|
|
27
|
+
});
|
|
28
|
+
return segments;
|
|
29
|
+
}
|
|
20
30
|
getAxisLabelFormatter() {
|
|
21
31
|
var _a, _b;
|
|
22
32
|
if ((_a = this.options.axis.value.labels) === null || _a === void 0 ? void 0 : _a.format)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataOptions, MdtChartsDataSource, MdtChartsField } from "../../../config/config";
|
|
1
|
+
import { DataOptions, MdtChartsDataSource, MdtChartsField, MdtChartsFieldName } from "../../../config/config";
|
|
2
2
|
export declare class DataRepositoryModel {
|
|
3
3
|
private rawFullSource;
|
|
4
4
|
private scopedFullSource;
|
|
@@ -7,7 +7,7 @@ export declare class DataRepositoryModel {
|
|
|
7
7
|
private valueFields;
|
|
8
8
|
initOptions(options: DataOptions, valueFields: MdtChartsField[]): void;
|
|
9
9
|
getValuesByKeyField(): any[];
|
|
10
|
-
getBiggestValueAndDecremented(): number
|
|
10
|
+
getBiggestValueAndDecremented(segmentedFields?: MdtChartsFieldName[][]): [number, number];
|
|
11
11
|
initRawFullSource(rawSource: MdtChartsDataSource): void;
|
|
12
12
|
getRawRows(): import("../../../config/config").MdtChartsDataRow[];
|
|
13
13
|
getFirstRow(): import("../../../config/config").MdtChartsDataRow;
|
|
@@ -7,10 +7,17 @@ export class DataRepositoryModel {
|
|
|
7
7
|
getValuesByKeyField() {
|
|
8
8
|
return this.getRawRows().map(dataRow => dataRow[this.keyField.name]);
|
|
9
9
|
}
|
|
10
|
-
getBiggestValueAndDecremented() {
|
|
10
|
+
getBiggestValueAndDecremented(segmentedFields) {
|
|
11
11
|
const values = [];
|
|
12
12
|
this.getRawRows().forEach(row => {
|
|
13
|
-
|
|
13
|
+
if (!segmentedFields) {
|
|
14
|
+
this.valueFields.forEach(vf => values.push(row[vf.name]));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
segmentedFields.forEach(fields => {
|
|
18
|
+
const valuesBySegment = fields.reduce((acc, f) => acc + row[f], 0);
|
|
19
|
+
values.push(valuesBySegment);
|
|
20
|
+
});
|
|
14
21
|
});
|
|
15
22
|
const biggest = Math.max(...values);
|
|
16
23
|
return [biggest, biggest - 1];
|