mdt-charts 1.36.0 → 1.37.0
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 +19 -0
- package/lib/engine/block/blockSvg.js +1 -1
- package/lib/engine/features/scale/scale.js +1 -1
- package/lib/engine/twoDimensionalNotation/bar/barHelper.d.ts +1 -1
- package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +2 -0
- package/lib/model/featuresModel/grouping/{groupingCanvasCalculator/groupingCanvasCalculator.d.ts → groupingDataAmountCalculator/groupingDataAmountCalculator.d.ts} +2 -8
- package/lib/model/featuresModel/grouping/groupingDataAmountCalculator/groupingDataAmountCalculator.js +22 -0
- package/lib/model/featuresModel/grouping/groupingEdgeLines/groupingEdgeLinesGenerator.d.ts +1 -0
- package/lib/model/featuresModel/grouping/groupingEdgeLines/groupingEdgeLinesGenerator.js +8 -8
- package/lib/model/featuresModel/grouping/groupingLabels/groupingLabelsCoordinateHandlers.d.ts +2 -2
- package/lib/model/featuresModel/grouping/groupingLabels/groupingLabelsCoordinateHandlers.js +3 -4
- package/lib/model/featuresModel/grouping/groupingLabels/groupingLabelsScaler.d.ts +4 -9
- package/lib/model/featuresModel/grouping/groupingLabels/groupingLabelsScaler.js +4 -5
- package/lib/model/featuresModel/grouping/groupingLabels/staticCoordinateCalculator.d.ts +2 -2
- package/lib/model/featuresModel/grouping/groupingLabels/staticCoordinateCalculator.js +3 -4
- package/lib/model/featuresModel/grouping/groupingSplitLines/groupingSplitLines.d.ts +4 -2
- package/lib/model/featuresModel/grouping/groupingSplitLines/groupingSplitLines.js +4 -6
- package/lib/model/featuresModel/scaleModel/scaleModel.js +4 -5
- package/lib/model/featuresModel/scaleModel/sizaCalculators/keyTotalSpaceCalculator.d.ts +11 -0
- package/lib/model/featuresModel/scaleModel/sizaCalculators/keyTotalSpaceCalculator.js +16 -0
- package/lib/model/featuresModel/scaleModel/sizaCalculators/scaleCanvasSizesCalculator.d.ts +14 -0
- package/lib/model/featuresModel/scaleModel/sizaCalculators/scaleCanvasSizesCalculator.js +25 -0
- package/lib/model/model.d.ts +6 -10
- package/lib/model/modelInstance/canvasModel/canvasModel.d.ts +1 -1
- package/lib/model/modelInstance/configReader/twoDimConfigReader/groupingConfigReader/groupingConfigReader.d.ts +1 -0
- package/lib/model/modelInstance/configReader/twoDimConfigReader/groupingConfigReader/groupingConfigReader.js +3 -0
- package/lib/model/notations/twoDimensionalModel.js +30 -20
- package/package.json +1 -1
- package/lib/model/featuresModel/grouping/groupingCanvasCalculator/groupingCanvasCalculator.js +0 -41
package/lib/config/config.d.ts
CHANGED
|
@@ -54,6 +54,25 @@ export interface MdtChartsTwoDimensionalOptions extends GraphicNotationOptions {
|
|
|
54
54
|
orientation: ChartOrientation;
|
|
55
55
|
valueLabels?: MdtChartsTwoDimensionalValueLabels;
|
|
56
56
|
grouping?: TwoDimGroupingOptions;
|
|
57
|
+
events?: TwoDimensionalEvents;
|
|
58
|
+
}
|
|
59
|
+
interface TwoDimensionalEvents {
|
|
60
|
+
drawComplete?: (event: TwoDimensionalDrawCompleteEvent) => void;
|
|
61
|
+
}
|
|
62
|
+
interface TwoDimensionalDrawCompleteEvent {
|
|
63
|
+
canvas: {
|
|
64
|
+
keyItems: CanvasKeyItemOptions[];
|
|
65
|
+
plotAreaMargin: BlockMargin;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export interface BlockMargin {
|
|
69
|
+
top: number;
|
|
70
|
+
bottom: number;
|
|
71
|
+
left: number;
|
|
72
|
+
right: number;
|
|
73
|
+
}
|
|
74
|
+
export interface CanvasKeyItemOptions {
|
|
75
|
+
totalSize: number;
|
|
57
76
|
}
|
|
58
77
|
export interface MdtChartsPolarOptions extends GraphicNotationOptions {
|
|
59
78
|
type: "polar";
|
|
@@ -4,7 +4,7 @@ import { HatchPatternDef } from "./defs/hatchPattern";
|
|
|
4
4
|
export class BlockSvg {
|
|
5
5
|
constructor(options) {
|
|
6
6
|
this.hatchPatternDef = new HatchPatternDef();
|
|
7
|
-
this.chartBlockClass = "
|
|
7
|
+
this.chartBlockClass = "plot-area";
|
|
8
8
|
this.chartGroupClass = "chart-group";
|
|
9
9
|
this.svgCssClasses = options.svgCssClasses;
|
|
10
10
|
this.parentBlockId = options.parentBlockId;
|
|
@@ -44,7 +44,7 @@ export class Scale {
|
|
|
44
44
|
return scaleBand()
|
|
45
45
|
.domain(scaleKey.domain)
|
|
46
46
|
.range([scaleKey.range.start, scaleKey.range.end])
|
|
47
|
-
.paddingInner(scaleKey.sizes.paddingInner / scaleKey.sizes.
|
|
47
|
+
.paddingInner(scaleKey.sizes.paddingInner / scaleKey.sizes.oneKeyTotalSpace)
|
|
48
48
|
.paddingOuter(scaleKey.sizes.paddingOuter / scaleKey.sizes.recalculatedStepSize);
|
|
49
49
|
}
|
|
50
50
|
//TODO: remove after tests of new way to create scale band
|
|
@@ -26,7 +26,7 @@ export declare class DotChartSettingsStore implements BandLikeChartSettingsStore
|
|
|
26
26
|
getBandItemSize(): number;
|
|
27
27
|
getBandItemPad(): number;
|
|
28
28
|
}
|
|
29
|
-
export declare class BarSettingsStore {
|
|
29
|
+
export declare class BarSettingsStore implements BandLikeChartSettingsStore {
|
|
30
30
|
private readonly modelSettings;
|
|
31
31
|
private readonly canvasConfig;
|
|
32
32
|
constructor(modelSettings: BarChartSettings, canvasConfig: {
|
|
@@ -85,6 +85,7 @@ export class TwoDimensionalManager {
|
|
|
85
85
|
this.linearGradientDef = new LinearGradientDef();
|
|
86
86
|
this.linearGradientDef.render(engine.block.svg.ensureDefsRendered(), options.defs.gradients);
|
|
87
87
|
}
|
|
88
|
+
model.options.canvasEvents.drawCompleted();
|
|
88
89
|
}
|
|
89
90
|
updateData(block, model, data) {
|
|
90
91
|
var _a, _b;
|
|
@@ -109,6 +110,7 @@ export class TwoDimensionalManager {
|
|
|
109
110
|
block.filterEventManager.event2DUpdate(options);
|
|
110
111
|
block.filterEventManager.registerEventFor2D(scales.key, model.chartBlock.margin, model.blockCanvas.size, options);
|
|
111
112
|
Tooltip.render(block, model, model.otherComponents.tooltipBlock, scales);
|
|
113
|
+
model.options.canvasEvents.drawCompleted();
|
|
112
114
|
});
|
|
113
115
|
RecordOverflowAlertCore.update(block, options.recordOverflowAlert);
|
|
114
116
|
if (this.canvasValueLabels)
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { MdtChartsBaseField, MdtChartsDataRow } from "../../../../config/config";
|
|
2
|
-
import { GroupingLabelKey
|
|
3
|
-
import { KeyScaleInfoForGroupingLabelsScaler } from "../groupingLabels/groupingLabelsScaler";
|
|
2
|
+
import { GroupingLabelKey } from "../../../model";
|
|
4
3
|
interface GroupingCanvasCalculatorOptions {
|
|
5
|
-
keyScaleInfo: KeyScaleInfoForGroupingLabelsScaler;
|
|
6
4
|
dataRows: MdtChartsDataRow[];
|
|
7
5
|
field: MdtChartsBaseField;
|
|
8
|
-
range: RangeModel;
|
|
9
6
|
}
|
|
10
|
-
export declare class
|
|
7
|
+
export declare class GroupingDataAmountCalculator {
|
|
11
8
|
private readonly options;
|
|
12
9
|
constructor(options: GroupingCanvasCalculatorOptions);
|
|
13
10
|
calculate(): {
|
|
14
11
|
rowsCountsPerGroups: number[];
|
|
15
|
-
oneShareSize: number;
|
|
16
|
-
keyAxisOuterPadding: number;
|
|
17
|
-
keyAxisInnerPadding: number;
|
|
18
12
|
groupDomain: GroupingLabelKey[];
|
|
19
13
|
};
|
|
20
14
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class GroupingDataAmountCalculator {
|
|
2
|
+
constructor(options) {
|
|
3
|
+
this.options = options;
|
|
4
|
+
}
|
|
5
|
+
calculate() {
|
|
6
|
+
const domainWithRowsCount = new Map();
|
|
7
|
+
this.options.dataRows.forEach((row) => {
|
|
8
|
+
const key = row[this.options.field.name];
|
|
9
|
+
if (key) {
|
|
10
|
+
if (domainWithRowsCount.has(key))
|
|
11
|
+
domainWithRowsCount.set(key, domainWithRowsCount.get(key) + 1);
|
|
12
|
+
else
|
|
13
|
+
domainWithRowsCount.set(key, 1);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const rowsCounts = Array.from(domainWithRowsCount.values());
|
|
17
|
+
return {
|
|
18
|
+
rowsCountsPerGroups: rowsCounts,
|
|
19
|
+
groupDomain: Array.from(domainWithRowsCount.keys())
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -5,6 +5,7 @@ interface GroupingEdgeLinesGeneratorOptions {
|
|
|
5
5
|
orients: Iterable<Orient>;
|
|
6
6
|
staticCoordinateCalculator: GroupingStaticCoordinateCalculator;
|
|
7
7
|
canvasModel: CanvasModel;
|
|
8
|
+
lineWidth: number;
|
|
8
9
|
}
|
|
9
10
|
export declare class GroupingEdgeLinesGenerator {
|
|
10
11
|
private readonly options;
|
|
@@ -11,8 +11,8 @@ export class GroupingEdgeLinesGenerator {
|
|
|
11
11
|
const leftX = this.options.canvasModel.getMarginSide("left");
|
|
12
12
|
const rightX = this.options.canvasModel.getBlockSize().width - this.options.canvasModel.getMarginSide("right");
|
|
13
13
|
edgeLines = edgeLines.concat([
|
|
14
|
-
{ x1: leftX, x2: leftX, y1, y2 },
|
|
15
|
-
{ x1: rightX, x2: rightX, y1, y2 }
|
|
14
|
+
{ x1: leftX + this.options.lineWidth / 2, x2: leftX + this.options.lineWidth / 2, y1, y2 },
|
|
15
|
+
{ x1: rightX - this.options.lineWidth / 2, x2: rightX - this.options.lineWidth / 2, y1, y2 }
|
|
16
16
|
]);
|
|
17
17
|
}
|
|
18
18
|
if (orient === "bottom") {
|
|
@@ -21,8 +21,8 @@ export class GroupingEdgeLinesGenerator {
|
|
|
21
21
|
const leftX = this.options.canvasModel.getMarginSide("left");
|
|
22
22
|
const rightX = this.options.canvasModel.getBlockSize().width - this.options.canvasModel.getMarginSide("right");
|
|
23
23
|
edgeLines = edgeLines.concat([
|
|
24
|
-
{ x1: leftX, x2: leftX, y1, y2 },
|
|
25
|
-
{ x1: rightX, x2: rightX, y1, y2 }
|
|
24
|
+
{ x1: leftX + this.options.lineWidth / 2, x2: leftX + this.options.lineWidth / 2, y1, y2 },
|
|
25
|
+
{ x1: rightX - this.options.lineWidth / 2, x2: rightX - this.options.lineWidth / 2, y1, y2 }
|
|
26
26
|
]);
|
|
27
27
|
}
|
|
28
28
|
if (orient === "left") {
|
|
@@ -31,8 +31,8 @@ export class GroupingEdgeLinesGenerator {
|
|
|
31
31
|
const topY = this.options.canvasModel.getMarginSide("top");
|
|
32
32
|
const bottomY = this.options.canvasModel.getBlockSize().height - this.options.canvasModel.getMarginSide("bottom");
|
|
33
33
|
edgeLines = edgeLines.concat([
|
|
34
|
-
{ x1, x2, y1: topY, y2: topY },
|
|
35
|
-
{ x1, x2, y1: bottomY, y2: bottomY }
|
|
34
|
+
{ x1, x2, y1: topY + this.options.lineWidth / 2, y2: topY + this.options.lineWidth / 2 },
|
|
35
|
+
{ x1, x2, y1: bottomY - this.options.lineWidth / 2, y2: bottomY - this.options.lineWidth / 2 }
|
|
36
36
|
]);
|
|
37
37
|
}
|
|
38
38
|
if (orient === "right") {
|
|
@@ -41,8 +41,8 @@ export class GroupingEdgeLinesGenerator {
|
|
|
41
41
|
const topY = this.options.canvasModel.getMarginSide("top");
|
|
42
42
|
const bottomY = this.options.canvasModel.getBlockSize().height - this.options.canvasModel.getMarginSide("bottom");
|
|
43
43
|
edgeLines = edgeLines.concat([
|
|
44
|
-
{ x1, x2, y1: topY, y2: topY },
|
|
45
|
-
{ x1, x2, y1: bottomY, y2: bottomY }
|
|
44
|
+
{ x1, x2, y1: topY + this.options.lineWidth / 2, y2: topY + this.options.lineWidth / 2 },
|
|
45
|
+
{ x1, x2, y1: bottomY - this.options.lineWidth / 2, y2: bottomY - this.options.lineWidth / 2 }
|
|
46
46
|
]);
|
|
47
47
|
}
|
|
48
48
|
}
|
package/lib/model/featuresModel/grouping/groupingLabels/groupingLabelsCoordinateHandlers.d.ts
CHANGED
|
@@ -5,12 +5,12 @@ interface GroupingLabelsCoordinateHandlerOptions {
|
|
|
5
5
|
orient: Orient;
|
|
6
6
|
sideIndex: number;
|
|
7
7
|
staticCoordinateCalculator: GroupingStaticCoordinateCalculator;
|
|
8
|
+
canvasModel: CanvasModel;
|
|
8
9
|
}
|
|
9
10
|
export declare class GroupingLabelsCoordinateHandler {
|
|
10
|
-
private readonly canvasModel;
|
|
11
11
|
private readonly options;
|
|
12
12
|
private readonly staticCoordinate;
|
|
13
|
-
constructor(
|
|
13
|
+
constructor(options: GroupingLabelsCoordinateHandlerOptions);
|
|
14
14
|
handleX(scaledCoordinate: number): number;
|
|
15
15
|
handleY(scaledCoordinate: number): number;
|
|
16
16
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
export class GroupingLabelsCoordinateHandler {
|
|
2
|
-
constructor(
|
|
3
|
-
this.canvasModel = canvasModel;
|
|
2
|
+
constructor(options) {
|
|
4
3
|
this.options = options;
|
|
5
4
|
this.staticCoordinate = this.options.staticCoordinateCalculator.calculate(this.options.orient, this.options.sideIndex);
|
|
6
5
|
}
|
|
7
6
|
handleX(scaledCoordinate) {
|
|
8
7
|
let x;
|
|
9
8
|
if (this.options.orient === "top" || this.options.orient === "bottom")
|
|
10
|
-
x = scaledCoordinate + this.canvasModel.getMarginSide("left");
|
|
9
|
+
x = scaledCoordinate + this.options.canvasModel.getMarginSide("left");
|
|
11
10
|
else
|
|
12
11
|
x = this.staticCoordinate;
|
|
13
12
|
return x;
|
|
@@ -15,7 +14,7 @@ export class GroupingLabelsCoordinateHandler {
|
|
|
15
14
|
handleY(scaledCoordinate) {
|
|
16
15
|
let y;
|
|
17
16
|
if (this.options.orient === "left" || this.options.orient === "right")
|
|
18
|
-
y = scaledCoordinate + this.canvasModel.getMarginSide("top");
|
|
17
|
+
y = scaledCoordinate + this.options.canvasModel.getMarginSide("top");
|
|
19
18
|
else
|
|
20
19
|
y = this.staticCoordinate;
|
|
21
20
|
return y;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { GroupingLabelKey } from "../../../model";
|
|
2
|
-
import {
|
|
2
|
+
import { GroupingDataAmountCalculator } from "../groupingDataAmountCalculator/groupingDataAmountCalculator";
|
|
3
|
+
import { ScaleCanvasSizesCalculator } from "../../scaleModel/sizaCalculators/scaleCanvasSizesCalculator";
|
|
3
4
|
interface GroupingLabelsCoordinateScalerOptions {
|
|
4
|
-
|
|
5
|
+
dataAmountCalculator: GroupingDataAmountCalculator;
|
|
6
|
+
sizesCalculator: ScaleCanvasSizesCalculator;
|
|
5
7
|
}
|
|
6
|
-
export declare type KeyScaleInfoForGroupingLabelsScaler = {
|
|
7
|
-
type: "band";
|
|
8
|
-
keyAxisOuterPadding: number;
|
|
9
|
-
keyAxisInnerPadding: number;
|
|
10
|
-
} | {
|
|
11
|
-
type: "point";
|
|
12
|
-
};
|
|
13
8
|
export declare class GroupingLabelsCoordinateScaler {
|
|
14
9
|
private readonly options;
|
|
15
10
|
private readonly scaleFn;
|
|
@@ -2,15 +2,14 @@ import { scaleOrdinal } from "d3-scale";
|
|
|
2
2
|
export class GroupingLabelsCoordinateScaler {
|
|
3
3
|
constructor(options) {
|
|
4
4
|
this.options = options;
|
|
5
|
-
const {
|
|
5
|
+
const { innerPadding, oneKeyPureSize, outerPadding } = this.options.sizesCalculator.calculate();
|
|
6
|
+
const { rowsCountsPerGroups, groupDomain } = this.options.dataAmountCalculator.calculate();
|
|
6
7
|
let previousTotalShares = 0;
|
|
7
8
|
const coordinates = [];
|
|
8
9
|
for (let rowIndex = 0; rowIndex < rowsCountsPerGroups.length; rowIndex++) {
|
|
9
10
|
const rowsAmount = rowsCountsPerGroups[rowIndex];
|
|
10
|
-
let previousShift = previousTotalShares * (
|
|
11
|
-
const centerOfDomainItem = previousShift +
|
|
12
|
-
(rowsAmount * oneShareSize + (rowsAmount - 1) * keyAxisInnerPadding) / 2 +
|
|
13
|
-
keyAxisOuterPadding;
|
|
11
|
+
let previousShift = previousTotalShares * (oneKeyPureSize + innerPadding);
|
|
12
|
+
const centerOfDomainItem = previousShift + (rowsAmount * oneKeyPureSize + (rowsAmount - 1) * innerPadding) / 2 + outerPadding;
|
|
14
13
|
coordinates.push(centerOfDomainItem);
|
|
15
14
|
previousTotalShares += rowsAmount;
|
|
16
15
|
}
|
|
@@ -7,11 +7,11 @@ interface GroupingStaticCoordinateCalculatorOptions {
|
|
|
7
7
|
legendTotalNeededSpace: number;
|
|
8
8
|
};
|
|
9
9
|
groupingItemSizes: GroupingItemSize[];
|
|
10
|
+
canvasModel: CanvasModel;
|
|
10
11
|
}
|
|
11
12
|
export declare class GroupingStaticCoordinateCalculator {
|
|
12
|
-
private readonly canvasModel;
|
|
13
13
|
private readonly options;
|
|
14
|
-
constructor(
|
|
14
|
+
constructor(options: GroupingStaticCoordinateCalculatorOptions);
|
|
15
15
|
calculate(orient: Orient, sideIndex: number): number;
|
|
16
16
|
}
|
|
17
17
|
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export class GroupingStaticCoordinateCalculator {
|
|
2
|
-
constructor(
|
|
3
|
-
this.canvasModel = canvasModel;
|
|
2
|
+
constructor(options) {
|
|
4
3
|
this.options = options;
|
|
5
4
|
}
|
|
6
5
|
calculate(orient, sideIndex) {
|
|
@@ -13,13 +12,13 @@ export class GroupingStaticCoordinateCalculator {
|
|
|
13
12
|
staticCoordinate = this.options.otherComponentSizes.titleTotalNeededSpace + prevSlicesSizes * sideIndex;
|
|
14
13
|
if (orient === "bottom")
|
|
15
14
|
staticCoordinate =
|
|
16
|
-
this.canvasModel.getBlockSize().height -
|
|
15
|
+
this.options.canvasModel.getBlockSize().height -
|
|
17
16
|
this.options.otherComponentSizes.legendTotalNeededSpace -
|
|
18
17
|
prevSlicesSizes * sideIndex;
|
|
19
18
|
if (orient === "left")
|
|
20
19
|
staticCoordinate = prevSlicesSizes * sideIndex;
|
|
21
20
|
if (orient === "right")
|
|
22
|
-
staticCoordinate = this.canvasModel.getBlockSize().width - prevSlicesSizes * sideIndex;
|
|
21
|
+
staticCoordinate = this.options.canvasModel.getBlockSize().width - prevSlicesSizes * sideIndex;
|
|
23
22
|
if (staticCoordinate === undefined) {
|
|
24
23
|
throw new Error(`Static coordinate for orient ${orient} and sideIndex ${sideIndex} is undefined`);
|
|
25
24
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { GroupingSplitLineAttributes, Orient } from "../../../model";
|
|
2
2
|
import { CanvasModel } from "../../../modelInstance/canvasModel/canvasModel";
|
|
3
|
-
import {
|
|
3
|
+
import { ScaleCanvasSizesCalculator } from "../../scaleModel/sizaCalculators/scaleCanvasSizesCalculator";
|
|
4
|
+
import { GroupingDataAmountCalculator } from "../groupingDataAmountCalculator/groupingDataAmountCalculator";
|
|
4
5
|
import { GroupingStaticCoordinateCalculator } from "../groupingLabels/staticCoordinateCalculator";
|
|
5
6
|
interface GroupingSplitLinesGeneratorOptions {
|
|
6
|
-
|
|
7
|
+
dataAmountCalculator: GroupingDataAmountCalculator;
|
|
8
|
+
sizesCalculator: ScaleCanvasSizesCalculator;
|
|
7
9
|
orient: Orient;
|
|
8
10
|
sideIndex: number;
|
|
9
11
|
staticCoordinateCalculator: GroupingStaticCoordinateCalculator;
|
|
@@ -5,14 +5,12 @@ export class GroupingSplitLinesGenerator {
|
|
|
5
5
|
generate() {
|
|
6
6
|
let previousTotalShares = 0;
|
|
7
7
|
const coordinates = [];
|
|
8
|
-
const {
|
|
8
|
+
const { innerPadding, outerPadding, oneKeyPureSize } = this.options.sizesCalculator.calculate();
|
|
9
|
+
const { rowsCountsPerGroups } = this.options.dataAmountCalculator.calculate();
|
|
9
10
|
for (let rowIndex = 0; rowIndex < rowsCountsPerGroups.length - 1; rowIndex++) {
|
|
10
11
|
const rowsAmount = rowsCountsPerGroups[rowIndex];
|
|
11
|
-
let previousShift = previousTotalShares * (
|
|
12
|
-
const coordinate = previousShift +
|
|
13
|
-
keyAxisOuterPadding +
|
|
14
|
-
rowsAmount * (oneShareSize + keyAxisInnerPadding) -
|
|
15
|
-
keyAxisInnerPadding / 2;
|
|
12
|
+
let previousShift = previousTotalShares * (oneKeyPureSize + innerPadding);
|
|
13
|
+
const coordinate = previousShift + outerPadding + rowsAmount * (oneKeyPureSize + innerPadding) - innerPadding / 2;
|
|
16
14
|
coordinates.push(coordinate);
|
|
17
15
|
previousTotalShares += rowsAmount;
|
|
18
16
|
}
|
|
@@ -25,8 +25,7 @@ export class ScaleModel {
|
|
|
25
25
|
return Object.assign(Object.assign({}, baseModel), { type: "point" });
|
|
26
26
|
}
|
|
27
27
|
if (type === "band") {
|
|
28
|
-
|
|
29
|
-
return Object.assign(Object.assign({}, baseModel), { type: "band", elementsAmount: elementsInGroupAmount, sizes: this.getBandScaleSizeParams(baseModel.domain, baseModel.range, elementsInGroupAmount) });
|
|
28
|
+
return Object.assign(Object.assign({}, baseModel), { type: "band", sizes: this.getBandScaleSizeParams(baseModel.domain, baseModel.range, getElementsAmountForScale(bandLikeCharts)) });
|
|
30
29
|
}
|
|
31
30
|
throw new Error("Unknown scale key type");
|
|
32
31
|
}
|
|
@@ -61,8 +60,8 @@ export class ScaleModel {
|
|
|
61
60
|
};
|
|
62
61
|
const getStepSize = () => (Math.abs(range.end - range.start) + paddings.inner - 2 * paddings.outer) / domainValues.length;
|
|
63
62
|
const getBandSize = () => getStepSize() - paddings.inner;
|
|
64
|
-
const
|
|
65
|
-
if (this.barCanvas.groupMinDistance <
|
|
63
|
+
const oneKeyTotalSpace = getBandSize();
|
|
64
|
+
if (this.barCanvas.groupMinDistance < oneKeyTotalSpace) {
|
|
66
65
|
paddings.inner = this.barCanvas.groupMinDistance;
|
|
67
66
|
paddings.outer = this.barCanvas.groupMinDistance / 2;
|
|
68
67
|
}
|
|
@@ -84,7 +83,7 @@ export class ScaleModel {
|
|
|
84
83
|
return {
|
|
85
84
|
paddingInner: paddings.inner,
|
|
86
85
|
paddingOuter: paddings.outer,
|
|
87
|
-
|
|
86
|
+
oneKeyTotalSpace,
|
|
88
87
|
recalculatedStepSize: getStepSize()
|
|
89
88
|
};
|
|
90
89
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CanvasKeyItemOptions } from "../../../../config/config";
|
|
2
|
+
import { ScaleCanvasSizesCalculator } from "./scaleCanvasSizesCalculator";
|
|
3
|
+
interface KeyTotalSpaceCalculatorOptions {
|
|
4
|
+
scaleSizesCalculator: ScaleCanvasSizesCalculator;
|
|
5
|
+
}
|
|
6
|
+
export declare class KeyTotalSpaceCalculator {
|
|
7
|
+
private readonly options;
|
|
8
|
+
constructor(options: KeyTotalSpaceCalculatorOptions);
|
|
9
|
+
calculate(): CanvasKeyItemOptions[];
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class KeyTotalSpaceCalculator {
|
|
2
|
+
constructor(options) {
|
|
3
|
+
this.options = options;
|
|
4
|
+
}
|
|
5
|
+
calculate() {
|
|
6
|
+
const sizes = this.options.scaleSizesCalculator.calculate();
|
|
7
|
+
const items = new Array(sizes.keysAmount);
|
|
8
|
+
for (let i = 0; i < sizes.keysAmount; i++) {
|
|
9
|
+
if (i === 0 || i === sizes.keysAmount - 1)
|
|
10
|
+
items[i] = { totalSize: sizes.outerPadding + sizes.oneKeyPureSize + sizes.innerPadding / 2 };
|
|
11
|
+
else
|
|
12
|
+
items[i] = { totalSize: sizes.oneKeyPureSize + sizes.innerPadding };
|
|
13
|
+
}
|
|
14
|
+
return items;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ScaleKeyModel } from "../../../model";
|
|
2
|
+
export interface KeyScaleCanvasSizes {
|
|
3
|
+
innerPadding: number;
|
|
4
|
+
outerPadding: number;
|
|
5
|
+
oneKeyPureSize: number;
|
|
6
|
+
keysAmount: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class ScaleCanvasSizesCalculator {
|
|
9
|
+
private readonly options;
|
|
10
|
+
constructor(options: {
|
|
11
|
+
keyScale: ScaleKeyModel;
|
|
12
|
+
});
|
|
13
|
+
calculate(): KeyScaleCanvasSizes;
|
|
14
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class ScaleCanvasSizesCalculator {
|
|
2
|
+
constructor(options) {
|
|
3
|
+
this.options = options;
|
|
4
|
+
}
|
|
5
|
+
calculate() {
|
|
6
|
+
if (this.options.keyScale.type === "band") {
|
|
7
|
+
const rangeOfKeyAxis = Math.abs(this.options.keyScale.range.end - this.options.keyScale.range.start) -
|
|
8
|
+
this.options.keyScale.sizes.paddingOuter * 2 -
|
|
9
|
+
this.options.keyScale.sizes.paddingInner * (this.options.keyScale.domain.length - 1);
|
|
10
|
+
return {
|
|
11
|
+
innerPadding: this.options.keyScale.sizes.paddingInner,
|
|
12
|
+
outerPadding: this.options.keyScale.sizes.paddingOuter,
|
|
13
|
+
oneKeyPureSize: rangeOfKeyAxis / this.options.keyScale.domain.length,
|
|
14
|
+
keysAmount: this.options.keyScale.domain.length
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
innerPadding: (this.options.keyScale.range.end - this.options.keyScale.range.start) /
|
|
19
|
+
(this.options.keyScale.domain.length - 1),
|
|
20
|
+
outerPadding: 0,
|
|
21
|
+
oneKeyPureSize: 0,
|
|
22
|
+
keysAmount: this.options.keyScale.domain.length
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
package/lib/model/model.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChartOrientation, MdtChartsColorField, PolarChartType, Size, TwoDimensionalChartType, AxisLabelPosition, ShowTickFn, MdtChartsDataRow, TwoDimensionalValueGroup, ValueLabelsCollisionMode, ValueLabelsRotationOptions, ValueLabelsHandleElement, MdtChartsFieldName } from "../config/config";
|
|
1
|
+
import { ChartOrientation, MdtChartsColorField, PolarChartType, Size, TwoDimensionalChartType, AxisLabelPosition, ShowTickFn, MdtChartsDataRow, TwoDimensionalValueGroup, ValueLabelsCollisionMode, ValueLabelsRotationOptions, ValueLabelsHandleElement, MdtChartsFieldName, BlockMargin as ConfigBlockMargin } from "../config/config";
|
|
2
2
|
import { DataType, DonutOptionsCanvas, Formatter, StaticLegendBlockCanvas, TooltipSettings, Transitions } from "../designer/designerConfig";
|
|
3
3
|
import { BoundingRect } from "../engine/features/valueLabelsCollision/valueLabelsCollision";
|
|
4
4
|
declare type AxisType = "key" | "value";
|
|
@@ -30,12 +30,7 @@ export interface BlockCanvas {
|
|
|
30
30
|
export interface ChartBlockModel {
|
|
31
31
|
margin: BlockMargin;
|
|
32
32
|
}
|
|
33
|
-
export
|
|
34
|
-
top: number;
|
|
35
|
-
bottom: number;
|
|
36
|
-
left: number;
|
|
37
|
-
right: number;
|
|
38
|
-
}
|
|
33
|
+
export declare type BlockMargin = ConfigBlockMargin;
|
|
39
34
|
export interface TooltipBasicModel {
|
|
40
35
|
getContent: (keyFieldValue: string) => TooltipContent;
|
|
41
36
|
}
|
|
@@ -81,6 +76,9 @@ export interface TwoDimensionalOptionsModel extends GraphicNotationOptionsModel
|
|
|
81
76
|
chartSettings: TwoDimChartElementsSettings;
|
|
82
77
|
valueLabels: TwoDimensionalValueLabels;
|
|
83
78
|
grouping: TwoDimGroupingModel;
|
|
79
|
+
canvasEvents: {
|
|
80
|
+
drawCompleted: () => void;
|
|
81
|
+
};
|
|
84
82
|
}
|
|
85
83
|
export interface PolarOptionsModel extends GraphicNotationOptionsModel {
|
|
86
84
|
type: "polar";
|
|
@@ -135,13 +133,11 @@ export declare type ScaleKeyModel = ScaleBandModel | ScalePointModel;
|
|
|
135
133
|
export interface ScaleBandModel extends BaseScaleKeyModel {
|
|
136
134
|
type: "band";
|
|
137
135
|
sizes: ScaleBandModelSizeParams;
|
|
138
|
-
/** @deprecated Use sizes instead */
|
|
139
|
-
elementsAmount: number;
|
|
140
136
|
}
|
|
141
137
|
export interface ScaleBandModelSizeParams {
|
|
142
138
|
paddingOuter: number;
|
|
143
139
|
paddingInner: number;
|
|
144
|
-
|
|
140
|
+
oneKeyTotalSpace: number;
|
|
145
141
|
recalculatedStepSize: number;
|
|
146
142
|
}
|
|
147
143
|
export interface ScalePointModel extends BaseScaleKeyModel {
|
|
@@ -13,7 +13,7 @@ export declare class CanvasModel implements CanvasMarginModel, CanvasSizesModel
|
|
|
13
13
|
private margin;
|
|
14
14
|
constructor();
|
|
15
15
|
initMargin(margin: BlockMargin): void;
|
|
16
|
-
getMargin(): BlockMargin;
|
|
16
|
+
getMargin(): import("../../../config/config").BlockMargin;
|
|
17
17
|
getMarginSide(side: MarginSide): number;
|
|
18
18
|
setMarginSide(side: MarginSide, size: number): void;
|
|
19
19
|
increaseMarginSide(side: MarginSide, byValue: number, key?: string): void;
|
|
@@ -11,6 +11,7 @@ export declare class GroupingConfigReader {
|
|
|
11
11
|
private readonly maxLabelSize;
|
|
12
12
|
constructor(keyAxisOptions: DiscreteAxisOptions, chartOrientation: ChartOrientation, groupingOptions?: TwoDimGroupingOptions);
|
|
13
13
|
isEnabled(): boolean;
|
|
14
|
+
getLineWidth(): number;
|
|
14
15
|
getUsingOrients(): Set<Orient>;
|
|
15
16
|
getSlicesSizesByOrients(dataRows: MdtChartsDataRow[]): GroupingItemSize[];
|
|
16
17
|
getPreparedOptions(scopedDatasourceRows: MdtChartsDataRow[]): {
|
|
@@ -15,7 +15,9 @@ import { GroupingLabelsCoordinateScaler } from "../featuresModel/grouping/groupi
|
|
|
15
15
|
import { GroupingStaticCoordinateCalculator } from "../featuresModel/grouping/groupingLabels/staticCoordinateCalculator";
|
|
16
16
|
import { GroupingEdgeLinesGenerator } from "../featuresModel/grouping/groupingEdgeLines/groupingEdgeLinesGenerator";
|
|
17
17
|
import { GroupingSplitLinesGenerator } from "../featuresModel/grouping/groupingSplitLines/groupingSplitLines";
|
|
18
|
-
import {
|
|
18
|
+
import { GroupingDataAmountCalculator } from "../featuresModel/grouping/groupingDataAmountCalculator/groupingDataAmountCalculator";
|
|
19
|
+
import { ScaleCanvasSizesCalculator } from "../featuresModel/scaleModel/sizaCalculators/scaleCanvasSizesCalculator";
|
|
20
|
+
import { KeyTotalSpaceCalculator } from "../featuresModel/scaleModel/sizaCalculators/keyTotalSpaceCalculator";
|
|
19
21
|
export class TwoDimensionalModel {
|
|
20
22
|
static getOptions(configReader, designerConfig, modelInstance) {
|
|
21
23
|
const options = configReader.options;
|
|
@@ -35,7 +37,8 @@ export class TwoDimensionalModel {
|
|
|
35
37
|
const titleConfig = TitleConfigReader.create(options.title, modelInstance);
|
|
36
38
|
const keyScale = scaleModel.getScaleKey(modelInstance.dataModel.getAllowableKeys());
|
|
37
39
|
const isHorizontal = options.orientation === "horizontal";
|
|
38
|
-
const groupingStaticCoordinateCalculator = new GroupingStaticCoordinateCalculator(
|
|
40
|
+
const groupingStaticCoordinateCalculator = new GroupingStaticCoordinateCalculator({
|
|
41
|
+
canvasModel,
|
|
39
42
|
otherComponentSizes: {
|
|
40
43
|
titleTotalNeededSpace: canvasModel.titleCanvas.getAllNeededSpace(),
|
|
41
44
|
legendTotalNeededSpace: canvasModel.legendCanvas.getAllNeededSpace()
|
|
@@ -45,10 +48,24 @@ export class TwoDimensionalModel {
|
|
|
45
48
|
const groupingEdgeLinesGenerator = new GroupingEdgeLinesGenerator({
|
|
46
49
|
canvasModel,
|
|
47
50
|
orients: configReader.grouping.getUsingOrients(),
|
|
48
|
-
staticCoordinateCalculator: groupingStaticCoordinateCalculator
|
|
51
|
+
staticCoordinateCalculator: groupingStaticCoordinateCalculator,
|
|
52
|
+
lineWidth: configReader.grouping.getLineWidth()
|
|
49
53
|
});
|
|
54
|
+
const scaleSizesCalculator = new ScaleCanvasSizesCalculator({ keyScale });
|
|
55
|
+
const keyTotalSpaceCalculator = new KeyTotalSpaceCalculator({ scaleSizesCalculator });
|
|
50
56
|
return {
|
|
51
57
|
legend: canvasModel.legendCanvas.getModel(),
|
|
58
|
+
canvasEvents: {
|
|
59
|
+
drawCompleted: () => {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
(_b = (_a = options.events) === null || _a === void 0 ? void 0 : _a.drawComplete) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
62
|
+
canvas: {
|
|
63
|
+
plotAreaMargin: canvasModel.getMargin(),
|
|
64
|
+
keyItems: keyTotalSpaceCalculator.calculate()
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
},
|
|
52
69
|
title: {
|
|
53
70
|
textContent: titleConfig.getTextContent(),
|
|
54
71
|
fontSize: titleConfig.getFontSize()
|
|
@@ -59,24 +76,16 @@ export class TwoDimensionalModel {
|
|
|
59
76
|
items: configReader.grouping
|
|
60
77
|
.getPreparedOptions(modelInstance.dataModel.repository.getScopedRows())
|
|
61
78
|
.map((prepared) => {
|
|
62
|
-
|
|
63
|
-
if (keyScale.type === "band") {
|
|
64
|
-
keyScaleInfo = {
|
|
65
|
-
type: keyScale.type,
|
|
66
|
-
keyAxisOuterPadding: keyScale.sizes.paddingOuter,
|
|
67
|
-
keyAxisInnerPadding: keyScale.sizes.paddingInner
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
else
|
|
71
|
-
keyScaleInfo = { type: "point" };
|
|
72
|
-
const groupingCanvasCalculator = new GroupingCanvasCalculator({
|
|
79
|
+
const groupingDataAmountCalculator = new GroupingDataAmountCalculator({
|
|
73
80
|
dataRows: modelInstance.dataModel.repository.getScopedRows(),
|
|
74
|
-
field: prepared.field
|
|
75
|
-
keyScaleInfo,
|
|
76
|
-
range: keyScale.range
|
|
81
|
+
field: prepared.field
|
|
77
82
|
});
|
|
78
|
-
const scaler = new GroupingLabelsCoordinateScaler({
|
|
79
|
-
|
|
83
|
+
const scaler = new GroupingLabelsCoordinateScaler({
|
|
84
|
+
dataAmountCalculator: groupingDataAmountCalculator,
|
|
85
|
+
sizesCalculator: scaleSizesCalculator
|
|
86
|
+
});
|
|
87
|
+
const coordinateHandler = new GroupingLabelsCoordinateHandler({
|
|
88
|
+
canvasModel,
|
|
80
89
|
orient: prepared.orient,
|
|
81
90
|
sideIndex: prepared.sideIndex,
|
|
82
91
|
staticCoordinateCalculator: groupingStaticCoordinateCalculator
|
|
@@ -86,7 +95,8 @@ export class TwoDimensionalModel {
|
|
|
86
95
|
orient: prepared.orient,
|
|
87
96
|
sideIndex: prepared.sideIndex,
|
|
88
97
|
staticCoordinateCalculator: groupingStaticCoordinateCalculator,
|
|
89
|
-
|
|
98
|
+
dataAmountCalculator: groupingDataAmountCalculator,
|
|
99
|
+
sizesCalculator: scaleSizesCalculator
|
|
90
100
|
});
|
|
91
101
|
return {
|
|
92
102
|
labels: {
|
package/package.json
CHANGED
package/lib/model/featuresModel/grouping/groupingCanvasCalculator/groupingCanvasCalculator.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export class GroupingCanvasCalculator {
|
|
2
|
-
constructor(options) {
|
|
3
|
-
this.options = options;
|
|
4
|
-
}
|
|
5
|
-
calculate() {
|
|
6
|
-
let keyAxisInnerPadding = 0;
|
|
7
|
-
let keyAxisOuterPadding = 0;
|
|
8
|
-
if (this.options.keyScaleInfo.type === "band") {
|
|
9
|
-
keyAxisInnerPadding = this.options.keyScaleInfo.keyAxisInnerPadding;
|
|
10
|
-
keyAxisOuterPadding = this.options.keyScaleInfo.keyAxisOuterPadding;
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
keyAxisInnerPadding =
|
|
14
|
-
(this.options.range.end - this.options.range.start) / (this.options.dataRows.length - 1);
|
|
15
|
-
keyAxisOuterPadding = 0;
|
|
16
|
-
}
|
|
17
|
-
const domainWithRowsCount = new Map();
|
|
18
|
-
this.options.dataRows.forEach((row) => {
|
|
19
|
-
const key = row[this.options.field.name];
|
|
20
|
-
if (key) {
|
|
21
|
-
if (domainWithRowsCount.has(key))
|
|
22
|
-
domainWithRowsCount.set(key, domainWithRowsCount.get(key) + 1);
|
|
23
|
-
else
|
|
24
|
-
domainWithRowsCount.set(key, 1);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
const rangeOfKeyAxis = Math.abs(this.options.range.end - this.options.range.start) -
|
|
28
|
-
keyAxisOuterPadding * 2 -
|
|
29
|
-
keyAxisInnerPadding * (this.options.dataRows.length - 1);
|
|
30
|
-
const totalShares = Array.from(domainWithRowsCount.values()).reduce((acc, curr) => acc + curr, 0);
|
|
31
|
-
const oneShareSize = rangeOfKeyAxis / totalShares;
|
|
32
|
-
const rowsCounts = Array.from(domainWithRowsCount.values());
|
|
33
|
-
return {
|
|
34
|
-
rowsCountsPerGroups: rowsCounts,
|
|
35
|
-
oneShareSize,
|
|
36
|
-
keyAxisInnerPadding,
|
|
37
|
-
keyAxisOuterPadding,
|
|
38
|
-
groupDomain: Array.from(domainWithRowsCount.keys())
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
}
|