mdt-charts 1.12.5 → 1.12.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/engine/features/gridLine/gidLineHelper.d.ts +2 -0
- package/lib/engine/features/gridLine/gidLineHelper.js +22 -0
- package/lib/engine/features/gridLine/gridLine.d.ts +5 -3
- package/lib/engine/features/gridLine/gridLine.js +16 -17
- package/lib/engine/intervalNotation/intervalManager.js +1 -1
- package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +2 -2
- package/lib/model/featuresModel/axisModel.js +0 -1
- package/lib/model/featuresModel/scaleModel/scaleAxisRecalcer.d.ts +20 -0
- package/lib/model/featuresModel/scaleModel/scaleAxisRecalcer.js +31 -0
- package/lib/model/featuresModel/scaleModel/scaleModel.d.ts +19 -0
- package/lib/model/featuresModel/scaleModel/scaleModel.js +115 -0
- package/lib/model/marginModel.js +7 -4
- package/lib/model/modelInstance/canvasModel/canvasModel.d.ts +5 -4
- package/lib/model/modelInstance/canvasModel/canvasModel.js +6 -2
- package/lib/model/modelInstance/canvasModel/marginModelService.d.ts +11 -0
- package/lib/model/modelInstance/canvasModel/marginModelService.js +26 -0
- package/lib/model/notations/intervalModel.js +1 -1
- package/lib/model/notations/twoDimensionalModel.js +9 -11
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AxisScale } from "d3-axis";
|
|
1
2
|
import { Size } from "../../../config/config";
|
|
2
3
|
import { AxisModelOptions, BlockMargin } from "../../../model/model";
|
|
3
4
|
export declare type GridLineType = 'key' | 'value';
|
|
@@ -10,4 +11,5 @@ export interface GridLineAttributes {
|
|
|
10
11
|
export declare class GridLineHelper {
|
|
11
12
|
static getGridLineLength(gridLineType: GridLineType, keyAxis: AxisModelOptions, valueAxis: AxisModelOptions, blockSize: Size, margin: BlockMargin): number;
|
|
12
13
|
static getLineAttributes(axis: AxisModelOptions, lineLength: number): GridLineAttributes;
|
|
14
|
+
static getKeyLineAttributes(axis: AxisModelOptions, scaleValue: AxisScale<any>): GridLineAttributes;
|
|
13
15
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { max, min } from "d3-array";
|
|
1
2
|
export class GridLineHelper {
|
|
2
3
|
static getGridLineLength(gridLineType, keyAxis, valueAxis, blockSize, margin) {
|
|
3
4
|
let axis;
|
|
@@ -27,4 +28,25 @@ export class GridLineHelper {
|
|
|
27
28
|
attributes.y2 = lineLength;
|
|
28
29
|
return attributes;
|
|
29
30
|
}
|
|
31
|
+
static getKeyLineAttributes(axis, scaleValue) {
|
|
32
|
+
const attributes = {
|
|
33
|
+
x1: 0,
|
|
34
|
+
y1: 0,
|
|
35
|
+
x2: 0,
|
|
36
|
+
y2: 0
|
|
37
|
+
};
|
|
38
|
+
const scaledStart = scaleValue(scaleValue.domain()[0]);
|
|
39
|
+
const scaledEnd = scaleValue(scaleValue.domain()[1]);
|
|
40
|
+
const minCoord = min([scaledStart, scaledEnd]) - scaleValue(0);
|
|
41
|
+
const maxCoord = max([scaledStart, scaledEnd]) - scaleValue(0);
|
|
42
|
+
if (axis.orient === 'left' || axis.orient === 'right') {
|
|
43
|
+
attributes.x1 = minCoord;
|
|
44
|
+
attributes.x2 = maxCoord;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
attributes.y1 = minCoord;
|
|
48
|
+
attributes.y2 = maxCoord;
|
|
49
|
+
}
|
|
50
|
+
return attributes;
|
|
51
|
+
}
|
|
30
52
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Size } from "../../../config/config";
|
|
2
|
-
import { BlockMargin, GridLineFlag, IAxisModel
|
|
2
|
+
import { BlockMargin, GridLineFlag, IAxisModel } from "../../../model/model";
|
|
3
3
|
import { Block } from "../../block/block";
|
|
4
|
+
import { Scales } from "../scale/scale";
|
|
4
5
|
export declare class GridLine {
|
|
5
6
|
private static readonly gridLineClass;
|
|
6
|
-
static render(block: Block, gridLineFlag: GridLineFlag, axes: IAxisModel, blockSize: Size, margin: BlockMargin,
|
|
7
|
-
static update(block: Block, gridLineFlag: GridLineFlag, axes: IAxisModel, blockSize: Size, margin: BlockMargin,
|
|
7
|
+
static render(block: Block, gridLineFlag: GridLineFlag, axes: IAxisModel, blockSize: Size, margin: BlockMargin, scales: Scales): void;
|
|
8
|
+
static update(block: Block, gridLineFlag: GridLineFlag, axes: IAxisModel, blockSize: Size, margin: BlockMargin, scales: Scales): void;
|
|
8
9
|
private static renderLine;
|
|
9
10
|
private static clear;
|
|
10
11
|
private static removeGridLinesOnAxes;
|
|
12
|
+
private static rmGridLineOnTick;
|
|
11
13
|
}
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import { GridLineHelper } from "./gidLineHelper";
|
|
2
2
|
export class GridLine {
|
|
3
|
-
static render(block, gridLineFlag, axes, blockSize, margin,
|
|
3
|
+
static render(block, gridLineFlag, axes, blockSize, margin, scales) {
|
|
4
4
|
if (gridLineFlag.value) {
|
|
5
5
|
const lineLength = GridLineHelper.getGridLineLength('value', axes.key, axes.value, blockSize, margin);
|
|
6
6
|
const lineAttributes = GridLineHelper.getLineAttributes(axes.value, lineLength);
|
|
7
7
|
this.renderLine(block, axes.value, lineAttributes);
|
|
8
8
|
}
|
|
9
9
|
if (gridLineFlag.key) {
|
|
10
|
-
const
|
|
11
|
-
const lineAttributes = GridLineHelper.getLineAttributes(axes.key, lineLength);
|
|
10
|
+
const lineAttributes = GridLineHelper.getKeyLineAttributes(axes.key, scales.value);
|
|
12
11
|
this.renderLine(block, axes.key, lineAttributes);
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
this.removeGridLinesOnAxes(block, axes.key, axes.value, false);
|
|
16
|
-
else if (gridLineFlag.key || gridLineFlag.value)
|
|
17
|
-
this.removeGridLinesOnAxes(block, axes.key, axes.value, true);
|
|
13
|
+
this.removeGridLinesOnAxes(block, axes.key, axes.value, true);
|
|
18
14
|
}
|
|
19
|
-
static update(block, gridLineFlag, axes, blockSize, margin,
|
|
15
|
+
static update(block, gridLineFlag, axes, blockSize, margin, scales) {
|
|
20
16
|
this.clear(block, axes.key.cssClass, axes.value.cssClass);
|
|
21
|
-
this.render(block, gridLineFlag, axes, blockSize, margin,
|
|
17
|
+
this.render(block, gridLineFlag, axes, blockSize, margin, scales);
|
|
22
18
|
}
|
|
23
19
|
static renderLine(block, axis, lineAttributes) {
|
|
24
20
|
block
|
|
@@ -51,17 +47,20 @@ export class GridLine {
|
|
|
51
47
|
tickOnValueAxisSelector = ':last-of-type';
|
|
52
48
|
if (keyAxis.orient === 'bottom' || keyAxis.orient === 'right')
|
|
53
49
|
tickOnKeyAxisSelector = ':last-of-type';
|
|
54
|
-
block.getSvg()
|
|
50
|
+
const tickOnKey = block.getSvg()
|
|
55
51
|
.select(`.${valueAxis.cssClass}`)
|
|
56
|
-
.select(`g.tick${tickOnKeyAxisSelector}`)
|
|
52
|
+
.select(`g.tick${tickOnKeyAxisSelector}`);
|
|
53
|
+
const tickOnValue = block.getSvg()
|
|
54
|
+
.select(`.${keyAxis.cssClass}`)
|
|
55
|
+
.select(`g.tick${tickOnValueAxisSelector}`);
|
|
56
|
+
// this.rmGridLineOnTick(tickOnKey);
|
|
57
|
+
// if (!excludeKey)
|
|
58
|
+
// this.rmGridLineOnTick(tickOnValue);
|
|
59
|
+
}
|
|
60
|
+
static rmGridLineOnTick(tick) {
|
|
61
|
+
tick
|
|
57
62
|
.select(`.${this.gridLineClass}`)
|
|
58
63
|
.remove();
|
|
59
|
-
if (!excludeKey)
|
|
60
|
-
block.getSvg()
|
|
61
|
-
.select(`.${keyAxis.cssClass}`)
|
|
62
|
-
.select(`g.tick${tickOnValueAxisSelector}`)
|
|
63
|
-
.select(`.${this.gridLineClass}`)
|
|
64
|
-
.remove();
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
66
|
GridLine.gridLineClass = 'grid-line';
|
|
@@ -11,7 +11,7 @@ export class IntervalManager {
|
|
|
11
11
|
block.renderSvg(model.blockCanvas.size);
|
|
12
12
|
const scales = Scale.getScales(options.scale.key, options.scale.value, options.chartSettings.bar);
|
|
13
13
|
Axis.render(block, scales, options.scale, options.axis, model.blockCanvas.size);
|
|
14
|
-
GridLine.render(block, options.additionalElements.gridLine.flag, options.axis, model.blockCanvas.size, model.chartBlock.margin,
|
|
14
|
+
GridLine.render(block, options.additionalElements.gridLine.flag, options.axis, model.blockCanvas.size, model.chartBlock.margin, scales);
|
|
15
15
|
this.renderCharts(block, options.charts, scales, data, options.data, model.chartBlock.margin, options.axis.key.orient, options.chartSettings);
|
|
16
16
|
Title.render(block, options.title, model.otherComponents.titleBlock, model.blockCanvas.size);
|
|
17
17
|
Legend.render(block, data, options, model);
|
|
@@ -20,7 +20,7 @@ export class TwoDimensionalManager {
|
|
|
20
20
|
engine.block.scales = scales;
|
|
21
21
|
engine.block.renderSvg(model.blockCanvas.size);
|
|
22
22
|
Axis.render(engine.block, scales, options.scale, options.axis, model.blockCanvas.size);
|
|
23
|
-
GridLine.render(engine.block, options.additionalElements.gridLine.flag, options.axis, model.blockCanvas.size, model.chartBlock.margin,
|
|
23
|
+
GridLine.render(engine.block, options.additionalElements.gridLine.flag, options.axis, model.blockCanvas.size, model.chartBlock.margin, scales);
|
|
24
24
|
this.renderCharts(engine.block, options.charts, scales, engine.data, options.data, model.chartBlock.margin, options.axis.key.orient, options.chartSettings.bar, model.blockCanvas.size);
|
|
25
25
|
engine.block.filterEventManager.registerEventFor2D(scales.key, model.chartBlock.margin, model.blockCanvas.size, options);
|
|
26
26
|
engine.block.filterEventManager.event2DUpdate(options);
|
|
@@ -49,7 +49,7 @@ export class TwoDimensionalManager {
|
|
|
49
49
|
const keyDomainEquality = Helper.checkDomainsEquality(block.scales.key.domain(), scales.key.domain());
|
|
50
50
|
block.scales = scales;
|
|
51
51
|
Axis.update(block, scales, options.scale, options.axis, model.blockCanvas.size, keyDomainEquality);
|
|
52
|
-
GridLine.update(block, options.additionalElements.gridLine.flag, options.axis, model.blockCanvas.size, model.chartBlock.margin,
|
|
52
|
+
GridLine.update(block, options.additionalElements.gridLine.flag, options.axis, model.blockCanvas.size, model.chartBlock.margin, scales);
|
|
53
53
|
const promises = this.updateCharts(block, options.charts, scales, data, model.options.data, model.chartBlock.margin, options.axis.key.orient, model.blockCanvas.size, options.chartSettings.bar);
|
|
54
54
|
Promise.all(promises)
|
|
55
55
|
.then(() => {
|
|
@@ -118,7 +118,6 @@ export class AxisModel {
|
|
|
118
118
|
translateX = getZeroCoordinate() + canvasModel.getMarginSide("left");
|
|
119
119
|
translateY = AxisModel.getAxisTranslateY(AxisType.Key, chartOrientation, axisPosition, canvasModel);
|
|
120
120
|
}
|
|
121
|
-
console.log(translateX, translateY);
|
|
122
121
|
return {
|
|
123
122
|
translateX,
|
|
124
123
|
translateY
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ScaleLinear, ScaleTime } from "d3-scale";
|
|
2
|
+
import { ChartOrientation, DiscreteAxisOptions } from "../../../config/config";
|
|
3
|
+
import { ScaleValueModel } from "../../model";
|
|
4
|
+
import { CanvasModel } from "../../modelInstance/canvasModel/canvasModel";
|
|
5
|
+
export declare const keyAxisLabelVerticalLog = "keyAxisLabel_vertical_margin_log";
|
|
6
|
+
export declare const keyAxisLabelHorizontalLog = "keyAxisLabel_horizontal_margin_log";
|
|
7
|
+
interface ScaleInfo {
|
|
8
|
+
scale: ScaleValueModel;
|
|
9
|
+
scaleFn: ScaleLinear<number, number, never> | ScaleTime<number, number, never>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Предназначен для получения нового scaleValue и уменьшения globalMargin, если ось ключей находится где-то внутри chartBlock, а не на его границе
|
|
13
|
+
*/
|
|
14
|
+
export declare class ScaleAxisRecalcer {
|
|
15
|
+
private generateScaleLinear;
|
|
16
|
+
constructor(generateScaleLinear: () => ScaleValueModel);
|
|
17
|
+
recalculateMargin(canvasModel: CanvasModel, chartOrientation: ChartOrientation, keyAxis: DiscreteAxisOptions): void;
|
|
18
|
+
getScaleValue(): ScaleInfo;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Scale } from "../../../engine/features/scale/scale";
|
|
2
|
+
export const keyAxisLabelVerticalLog = "keyAxisLabel_vertical_margin_log";
|
|
3
|
+
export const keyAxisLabelHorizontalLog = "keyAxisLabel_horizontal_margin_log";
|
|
4
|
+
/**
|
|
5
|
+
* Предназначен для получения нового scaleValue и уменьшения globalMargin, если ось ключей находится где-то внутри chartBlock, а не на его границе
|
|
6
|
+
*/
|
|
7
|
+
export class ScaleAxisRecalcer {
|
|
8
|
+
constructor(generateScaleLinear) {
|
|
9
|
+
this.generateScaleLinear = generateScaleLinear;
|
|
10
|
+
}
|
|
11
|
+
recalculateMargin(canvasModel, chartOrientation, keyAxis) {
|
|
12
|
+
const scaleValue = this.generateScaleLinear();
|
|
13
|
+
//TODO: rm import from engine
|
|
14
|
+
const scaleValueFn = Scale.getScaleValue(scaleValue);
|
|
15
|
+
const coordinateOnChartBlock = (keyAxis.position === "start"
|
|
16
|
+
? scaleValueFn(0)
|
|
17
|
+
: (chartOrientation === "vertical"
|
|
18
|
+
? canvasModel.getChartBlockHeight()
|
|
19
|
+
: canvasModel.getChartBlockWidth()) - scaleValueFn(0));
|
|
20
|
+
const key = chartOrientation === "vertical" ? keyAxisLabelVerticalLog : keyAxisLabelHorizontalLog;
|
|
21
|
+
const logInfo = canvasModel.marginService.getDataByKey(key);
|
|
22
|
+
canvasModel.decreaseMarginSide(logInfo.side, logInfo.byValue - coordinateOnChartBlock < 0 ? logInfo.byValue : coordinateOnChartBlock);
|
|
23
|
+
}
|
|
24
|
+
getScaleValue() {
|
|
25
|
+
const scale = this.generateScaleLinear();
|
|
26
|
+
return {
|
|
27
|
+
scale,
|
|
28
|
+
scaleFn: Scale.getScaleValue(scale)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ScaleKeyModel, ScaleKeyType, ScaleValueModel, ScaleValueType } from "../../model";
|
|
2
|
+
import { AxisPosition, NumberDomain, IntervalChart, MdtChartsTwoDimensionalChart, MdtChartsTwoDimensionalOptions, ChartOrientation, MdtChartsDataSource, MdtChartsDataRow } from "../../../config/config";
|
|
3
|
+
import { CanvasModel } from "../../modelInstance/canvasModel/canvasModel";
|
|
4
|
+
export declare enum ScaleType {
|
|
5
|
+
Key = 0,
|
|
6
|
+
Value = 1
|
|
7
|
+
}
|
|
8
|
+
export declare class ScaleModel {
|
|
9
|
+
static getScaleKey(allowableKeys: string[], orient: ChartOrientation, canvasModel: CanvasModel, charts: MdtChartsTwoDimensionalChart[], barCharts: MdtChartsTwoDimensionalChart[]): ScaleKeyModel;
|
|
10
|
+
static getScaleLinear(options: MdtChartsTwoDimensionalOptions, data: MdtChartsDataSource, canvasModel: CanvasModel): ScaleValueModel;
|
|
11
|
+
static getRangePeek(scaleType: ScaleType, chartOrientation: string, canvasModel: CanvasModel): number;
|
|
12
|
+
static getDateValueDomain(data: MdtChartsDataSource, chart: IntervalChart, keyAxisPosition: AxisPosition, dataSource: string): [Date, Date];
|
|
13
|
+
static getLinearDomain(configDomain: NumberDomain, data: MdtChartsDataSource, configOptions: MdtChartsTwoDimensionalOptions): [number, number];
|
|
14
|
+
static getScaleKeyType(charts: MdtChartsTwoDimensionalChart[]): ScaleKeyType;
|
|
15
|
+
static getScaleValueType(charts: MdtChartsTwoDimensionalChart[] | IntervalChart[]): ScaleValueType;
|
|
16
|
+
static getElementsAmount(barCharts: MdtChartsTwoDimensionalChart[]): number;
|
|
17
|
+
static getScaleMaxValue(charts: MdtChartsTwoDimensionalChart[], dataRows: MdtChartsDataRow[]): number;
|
|
18
|
+
static getScaleMinValue(charts: MdtChartsTwoDimensionalChart[], dataRows: MdtChartsDataRow[]): number;
|
|
19
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { ModelHelper } from "../../modelHelper";
|
|
2
|
+
export var ScaleType;
|
|
3
|
+
(function (ScaleType) {
|
|
4
|
+
ScaleType[ScaleType["Key"] = 0] = "Key";
|
|
5
|
+
ScaleType[ScaleType["Value"] = 1] = "Value";
|
|
6
|
+
})(ScaleType || (ScaleType = {}));
|
|
7
|
+
export class ScaleModel {
|
|
8
|
+
static getScaleKey(allowableKeys, orient, canvasModel, charts, barCharts) {
|
|
9
|
+
return {
|
|
10
|
+
domain: allowableKeys,
|
|
11
|
+
range: {
|
|
12
|
+
start: 0,
|
|
13
|
+
end: ScaleModel.getRangePeek(ScaleType.Key, orient, canvasModel)
|
|
14
|
+
},
|
|
15
|
+
type: ScaleModel.getScaleKeyType(charts),
|
|
16
|
+
elementsAmount: this.getElementsAmount(barCharts)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
static getScaleLinear(options, data, canvasModel) {
|
|
20
|
+
return {
|
|
21
|
+
domain: ScaleModel.getLinearDomain(options.axis.value.domain, data, options),
|
|
22
|
+
range: {
|
|
23
|
+
start: 0,
|
|
24
|
+
end: ScaleModel.getRangePeek(ScaleType.Value, options.orientation, canvasModel)
|
|
25
|
+
},
|
|
26
|
+
type: ScaleModel.getScaleValueType(options.charts)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
static getRangePeek(scaleType, chartOrientation, canvasModel) {
|
|
30
|
+
if (chartOrientation === 'vertical')
|
|
31
|
+
return scaleType === ScaleType.Key
|
|
32
|
+
? canvasModel.getChartBlockWidth()
|
|
33
|
+
: canvasModel.getChartBlockHeight();
|
|
34
|
+
return scaleType === ScaleType.Key
|
|
35
|
+
? canvasModel.getChartBlockHeight()
|
|
36
|
+
: canvasModel.getChartBlockWidth();
|
|
37
|
+
}
|
|
38
|
+
static getDateValueDomain(data, chart, keyAxisPosition, dataSource) {
|
|
39
|
+
const minMax = ModelHelper.getMinAndMaxOfIntervalData(data, dataSource, chart);
|
|
40
|
+
let domainPeekMin = minMax[0];
|
|
41
|
+
let domainPeekMax = minMax[1];
|
|
42
|
+
if (keyAxisPosition === 'start')
|
|
43
|
+
return [domainPeekMin, domainPeekMax];
|
|
44
|
+
return [domainPeekMax, domainPeekMin];
|
|
45
|
+
}
|
|
46
|
+
static getLinearDomain(configDomain, data, configOptions) {
|
|
47
|
+
let domainPeekMin;
|
|
48
|
+
let domainPeekMax;
|
|
49
|
+
if (configDomain.start === -1)
|
|
50
|
+
domainPeekMin = this.getScaleMinValue(configOptions.charts, data[configOptions.data.dataSource]);
|
|
51
|
+
else
|
|
52
|
+
domainPeekMin = configDomain.start;
|
|
53
|
+
if (configDomain.end === -1)
|
|
54
|
+
domainPeekMax = this.getScaleMaxValue(configOptions.charts, data[configOptions.data.dataSource]);
|
|
55
|
+
else
|
|
56
|
+
domainPeekMax = configDomain.end;
|
|
57
|
+
if (configOptions.axis.key.position === 'start')
|
|
58
|
+
return [domainPeekMin, domainPeekMax];
|
|
59
|
+
return [domainPeekMax, domainPeekMin];
|
|
60
|
+
}
|
|
61
|
+
static getScaleKeyType(charts) {
|
|
62
|
+
if (charts.findIndex((chart) => chart.type === 'bar') === -1)
|
|
63
|
+
return 'point';
|
|
64
|
+
return 'band';
|
|
65
|
+
}
|
|
66
|
+
static getScaleValueType(charts) {
|
|
67
|
+
if (charts.findIndex((chart) => chart.type === 'gantt') !== -1)
|
|
68
|
+
return 'datetime';
|
|
69
|
+
return 'linear';
|
|
70
|
+
}
|
|
71
|
+
static getElementsAmount(barCharts) {
|
|
72
|
+
if (barCharts.length === 0)
|
|
73
|
+
return 1;
|
|
74
|
+
let barsAmount = 0;
|
|
75
|
+
barCharts.forEach(chart => {
|
|
76
|
+
if (chart.isSegmented)
|
|
77
|
+
barsAmount += 1; // Если бар сегментированный, то все valueFields являются частями одного бара
|
|
78
|
+
else
|
|
79
|
+
barsAmount += chart.data.valueFields.length;
|
|
80
|
+
});
|
|
81
|
+
return barsAmount;
|
|
82
|
+
}
|
|
83
|
+
static getScaleMaxValue(charts, dataRows) {
|
|
84
|
+
let max = 0;
|
|
85
|
+
charts.forEach(chart => {
|
|
86
|
+
dataRows.forEach(dataRow => {
|
|
87
|
+
let sumInRow = 0;
|
|
88
|
+
chart.data.valueFields.forEach(field => {
|
|
89
|
+
if (chart.isSegmented)
|
|
90
|
+
sumInRow += dataRow[field.name];
|
|
91
|
+
else if (dataRow[field.name] > sumInRow)
|
|
92
|
+
sumInRow = dataRow[field.name];
|
|
93
|
+
});
|
|
94
|
+
if (max < sumInRow)
|
|
95
|
+
max = sumInRow;
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
return max;
|
|
99
|
+
}
|
|
100
|
+
static getScaleMinValue(charts, dataRows) {
|
|
101
|
+
let min = 0;
|
|
102
|
+
charts.forEach(chart => {
|
|
103
|
+
dataRows.forEach(dataRow => {
|
|
104
|
+
let sumInRow = 0;
|
|
105
|
+
chart.data.valueFields.forEach(field => {
|
|
106
|
+
if (dataRow[field.name] < sumInRow)
|
|
107
|
+
sumInRow = dataRow[field.name];
|
|
108
|
+
});
|
|
109
|
+
if (min > sumInRow)
|
|
110
|
+
min = sumInRow;
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
return min;
|
|
114
|
+
}
|
|
115
|
+
}
|
package/lib/model/marginModel.js
CHANGED
|
@@ -3,6 +3,7 @@ import { DataManagerModel } from "./dataManagerModel/dataManagerModel";
|
|
|
3
3
|
import { LegendModel } from "./featuresModel/legendModel/legendModel";
|
|
4
4
|
import { AxisType } from "./modelBuilder";
|
|
5
5
|
import { TwoDimensionalModel } from "./notations/twoDimensionalModel";
|
|
6
|
+
import { keyAxisLabelHorizontalLog, keyAxisLabelVerticalLog } from "./featuresModel/scaleModel/scaleAxisRecalcer";
|
|
6
7
|
export const AXIS_HORIZONTAL_LABEL_PADDING = 15;
|
|
7
8
|
export const AXIS_VERTICAL_LABEL_PADDING = 10;
|
|
8
9
|
export class MarginModel {
|
|
@@ -28,8 +29,10 @@ export class MarginModel {
|
|
|
28
29
|
const axisLabelSize = AxisModel.getLabelSize(designerConfig.canvas.axisLabel.maxSize.main, dataScope.allowableKeys);
|
|
29
30
|
const axisConfig = AxisModel.getKeyAxisLabelPosition(modelInstance.canvasModel, dataScope.allowableKeys.length, config.options.axis.key);
|
|
30
31
|
const marginOrient = config.options.axis.key.position === 'end' ? 'bottom' : 'top';
|
|
31
|
-
if (axisConfig === 'rotated')
|
|
32
|
-
modelInstance.canvasModel.
|
|
32
|
+
if (axisConfig === 'rotated') {
|
|
33
|
+
modelInstance.canvasModel.decreaseMarginSide(marginOrient, axisLabelSize.height);
|
|
34
|
+
modelInstance.canvasModel.increaseMarginSide(marginOrient, axisLabelSize.width, keyAxisLabelVerticalLog);
|
|
35
|
+
}
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
static getHorizontalMarginByAxisLabels(labelsMaxWidth, axis, data, options) {
|
|
@@ -48,7 +51,7 @@ export class MarginModel {
|
|
|
48
51
|
const valueAxisOrient = AxisModel.getAxisOrient(AxisType.Value, orientation, axis.value.position);
|
|
49
52
|
if ((keyAxisOrient === 'bottom' || keyAxisOrient === 'top')) {
|
|
50
53
|
if (axis.key.visibility)
|
|
51
|
-
canvasModel.increaseMarginSide(keyAxisOrient, labelSize.height + AXIS_HORIZONTAL_LABEL_PADDING);
|
|
54
|
+
canvasModel.increaseMarginSide(keyAxisOrient, labelSize.height + AXIS_HORIZONTAL_LABEL_PADDING, keyAxisLabelVerticalLog);
|
|
52
55
|
}
|
|
53
56
|
else if (axis.value.visibility)
|
|
54
57
|
canvasModel.increaseMarginSide(valueAxisOrient, labelSize.height + AXIS_HORIZONTAL_LABEL_PADDING);
|
|
@@ -57,7 +60,7 @@ export class MarginModel {
|
|
|
57
60
|
const keyAxisOrient = AxisModel.getAxisOrient(AxisType.Key, orientation, axis.key.position);
|
|
58
61
|
const valueAxisOrient = AxisModel.getAxisOrient(AxisType.Value, orientation, axis.value.position);
|
|
59
62
|
if ((keyAxisOrient === 'left' || keyAxisOrient === 'right') && isShow && axis.key.visibility) {
|
|
60
|
-
canvasModel.increaseMarginSide(keyAxisOrient, labelSize.width + AXIS_VERTICAL_LABEL_PADDING);
|
|
63
|
+
canvasModel.increaseMarginSide(keyAxisOrient, labelSize.width + AXIS_VERTICAL_LABEL_PADDING, keyAxisLabelHorizontalLog);
|
|
61
64
|
}
|
|
62
65
|
else if ((valueAxisOrient === 'left' || valueAxisOrient === 'right') && axis.value.visibility) {
|
|
63
66
|
canvasModel.increaseMarginSide(valueAxisOrient, labelSize.width + AXIS_VERTICAL_LABEL_PADDING);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Size } from "../../../config/config";
|
|
2
2
|
import { BlockMargin } from "../../model";
|
|
3
3
|
import { LegendCanvasModelInstance } from "./legendCanvasModel";
|
|
4
|
+
import { MarginModelService } from "./marginModelService";
|
|
4
5
|
import { TitleCanvasModel } from "./titleCanvas";
|
|
5
|
-
declare type MarginSide = keyof BlockMargin;
|
|
6
|
+
export declare type MarginSide = keyof BlockMargin;
|
|
6
7
|
export declare class CanvasModel {
|
|
7
8
|
titleCanvas: TitleCanvasModel;
|
|
8
9
|
legendCanvas: LegendCanvasModelInstance;
|
|
10
|
+
marginService: MarginModelService;
|
|
9
11
|
private blockSize;
|
|
10
12
|
private margin;
|
|
11
13
|
constructor();
|
|
@@ -13,12 +15,11 @@ export declare class CanvasModel {
|
|
|
13
15
|
getMargin(): BlockMargin;
|
|
14
16
|
getMarginSide(side: MarginSide): number;
|
|
15
17
|
setMarginSide(side: MarginSide, size: number): void;
|
|
16
|
-
increaseMarginSide(side: MarginSide, byValue: number): void;
|
|
17
|
-
|
|
18
|
+
increaseMarginSide(side: MarginSide, byValue: number, key?: string): void;
|
|
19
|
+
decreaseMarginSide(side: MarginSide, byValue: number): void;
|
|
18
20
|
roundMargin(): void;
|
|
19
21
|
initBlockSize(blockSize: Size): void;
|
|
20
22
|
getBlockSize(): Size;
|
|
21
23
|
getChartBlockWidth(): number;
|
|
22
24
|
getChartBlockHeight(): number;
|
|
23
25
|
}
|
|
24
|
-
export {};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { LegendCanvasModelInstance } from "./legendCanvasModel";
|
|
2
|
+
import { MarginModelService } from "./marginModelService";
|
|
2
3
|
import { TitleCanvasModel } from "./titleCanvas";
|
|
3
4
|
export class CanvasModel {
|
|
4
5
|
constructor() {
|
|
5
6
|
this.titleCanvas = new TitleCanvasModel();
|
|
6
7
|
this.legendCanvas = new LegendCanvasModelInstance();
|
|
8
|
+
this.marginService = new MarginModelService();
|
|
7
9
|
}
|
|
8
10
|
initMargin(margin) {
|
|
9
11
|
this.margin = margin;
|
|
@@ -17,10 +19,12 @@ export class CanvasModel {
|
|
|
17
19
|
setMarginSide(side, size) {
|
|
18
20
|
this.margin[side] = size;
|
|
19
21
|
}
|
|
20
|
-
increaseMarginSide(side, byValue) {
|
|
22
|
+
increaseMarginSide(side, byValue, key) {
|
|
21
23
|
this.margin[side] += byValue;
|
|
24
|
+
if (key)
|
|
25
|
+
this.marginService.appendLog(key, side, byValue);
|
|
22
26
|
}
|
|
23
|
-
|
|
27
|
+
decreaseMarginSide(side, byValue) {
|
|
24
28
|
this.margin[side] -= byValue;
|
|
25
29
|
}
|
|
26
30
|
roundMargin() {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MarginSide } from "./canvasModel";
|
|
2
|
+
export interface MarginLogData {
|
|
3
|
+
side: MarginSide;
|
|
4
|
+
byValue: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class MarginModelService {
|
|
7
|
+
private log;
|
|
8
|
+
appendLog(key: string, side: MarginSide, byValue: number): void;
|
|
9
|
+
getDataByKey(key: string): MarginLogData;
|
|
10
|
+
private findLogByKey;
|
|
11
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class MarginModelService {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.log = [];
|
|
4
|
+
}
|
|
5
|
+
appendLog(key, side, byValue) {
|
|
6
|
+
const log = this.findLogByKey(key);
|
|
7
|
+
if (log) {
|
|
8
|
+
log.data = { side, byValue };
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
this.log.push({
|
|
12
|
+
key,
|
|
13
|
+
data: {
|
|
14
|
+
side,
|
|
15
|
+
byValue
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
getDataByKey(key) {
|
|
20
|
+
var _a;
|
|
21
|
+
return (_a = this.findLogByKey(key)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22
|
+
}
|
|
23
|
+
findLogByKey(key) {
|
|
24
|
+
return this.log.find(l => l.key === key);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -2,7 +2,7 @@ import { AxisModel } from "../featuresModel/axisModel";
|
|
|
2
2
|
import { ChartStyleModelService } from "../chartStyleModel/chartStyleModel";
|
|
3
3
|
import { DataManagerModel } from "../dataManagerModel/dataManagerModel";
|
|
4
4
|
import { AxisType } from "../modelBuilder";
|
|
5
|
-
import { ScaleModel, ScaleType } from "../featuresModel/scaleModel";
|
|
5
|
+
import { ScaleModel, ScaleType } from "../featuresModel/scaleModel/scaleModel";
|
|
6
6
|
import { TwoDimensionalModel } from "./twoDimensionalModel";
|
|
7
7
|
export class IntervalModel {
|
|
8
8
|
static getOptions(config, designerConfig, margin, dataScope, data, modelInstance) {
|
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import { Scale } from "../../engine/features/scale/scale";
|
|
2
1
|
import { ChartStyleModelService } from "../chartStyleModel/chartStyleModel";
|
|
3
2
|
import { TwoDimensionalChartStyleModel } from "../chartStyleModel/TwoDimensionalChartStyleModel";
|
|
4
3
|
import { AxisModel } from "../featuresModel/axisModel";
|
|
5
|
-
import {
|
|
4
|
+
import { ScaleAxisRecalcer } from "../featuresModel/scaleModel/scaleAxisRecalcer";
|
|
5
|
+
import { ScaleModel } from "../featuresModel/scaleModel/scaleModel";
|
|
6
6
|
export class TwoDimensionalModel {
|
|
7
7
|
static getOptions(options, designerConfig, data, modelInstance) {
|
|
8
8
|
const canvasModel = modelInstance.canvasModel;
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
//TODO: rm import from engine
|
|
13
|
-
const scaleValueFn = Scale.getScaleValue(scaleValue);
|
|
9
|
+
const scaleMarginRecalcer = new ScaleAxisRecalcer(() => ScaleModel.getScaleLinear(options, data, canvasModel));
|
|
10
|
+
scaleMarginRecalcer.recalculateMargin(canvasModel, options.orientation, options.axis.key);
|
|
11
|
+
const scaleValueInfo = scaleMarginRecalcer.getScaleValue();
|
|
14
12
|
return {
|
|
15
13
|
legend: canvasModel.legendCanvas.getModel(),
|
|
16
14
|
title: options.title,
|
|
17
15
|
selectable: !!options.selectable,
|
|
18
16
|
orient: options.orientation,
|
|
19
17
|
scale: {
|
|
20
|
-
key:
|
|
21
|
-
value:
|
|
18
|
+
key: ScaleModel.getScaleKey(modelInstance.dataModel.getAllowableKeys(), options.orientation, canvasModel, options.charts, this.getChartsByType(options.charts, 'bar')),
|
|
19
|
+
value: scaleValueInfo.scale
|
|
22
20
|
},
|
|
23
21
|
axis: {
|
|
24
|
-
key: AxisModel.getKeyAxis(options, data, designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () =>
|
|
22
|
+
key: AxisModel.getKeyAxis(options, data, designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () => scaleValueInfo.scaleFn(0)),
|
|
25
23
|
value: AxisModel.getValueAxis(options.orientation, options.axis.value, designerConfig.canvas.axisLabel, canvasModel)
|
|
26
24
|
},
|
|
27
25
|
type: options.type,
|
|
@@ -29,7 +27,7 @@ export class TwoDimensionalModel {
|
|
|
29
27
|
charts: this.getChartsModel(options.charts, options.orientation, designerConfig.chartStyle),
|
|
30
28
|
additionalElements: this.getAdditionalElements(options),
|
|
31
29
|
tooltip: options.tooltip,
|
|
32
|
-
chartSettings
|
|
30
|
+
chartSettings: this.getChartsSettings(designerConfig.canvas.chartOptions.bar)
|
|
33
31
|
};
|
|
34
32
|
}
|
|
35
33
|
static getChartsEmbeddedLabelsFlag(charts, chartOrientation) {
|