mdt-charts 1.38.4 → 1.38.5
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.js +3 -2
- package/lib/engine/features/scale/scale.d.ts +4 -4
- package/lib/engine/features/scale/scale.js +26 -21
- package/lib/engine/twoDimensionalNotation/area/areaHelper.js +4 -2
- package/lib/engine/twoDimensionalNotation/bar/barHelper.js +1 -1
- package/lib/engine/twoDimensionalNotation/twoDimensionalManager.js +2 -2
- package/lib/model/featuresModel/scaleModel/scaleAxisRecalcer.js +3 -3
- package/lib/model/featuresModel/scaleModel/scaleDomainService.d.ts +4 -1
- package/lib/model/featuresModel/scaleModel/scaleDomainService.js +11 -2
- package/lib/model/featuresModel/scaleModel/scaleModel.js +6 -2
- package/lib/model/model.d.ts +2 -1
- package/lib/model/notations/twoDimensionalModel.js +1 -1
- package/package.json +1 -1
|
@@ -37,8 +37,9 @@ export class GridLineHelper {
|
|
|
37
37
|
};
|
|
38
38
|
const scaledStart = scaleValue(scaleValue.domain()[0]);
|
|
39
39
|
const scaledEnd = scaleValue(scaleValue.domain()[1]);
|
|
40
|
-
const
|
|
41
|
-
const
|
|
40
|
+
const minScaledValue = scaleValue(Math.min(...scaleValue.domain()));
|
|
41
|
+
const minCoord = min([scaledStart, scaledEnd]) - minScaledValue;
|
|
42
|
+
const maxCoord = max([scaledStart, scaledEnd]) - minScaledValue;
|
|
42
43
|
if (axis.orient === "left" || axis.orient === "right") {
|
|
43
44
|
attributes.x1 = minCoord;
|
|
44
45
|
attributes.x2 = maxCoord;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ScaleBand, ScaleLinear } from "d3-scale";
|
|
2
2
|
import { AxisScale } from "d3-axis";
|
|
3
|
-
import {
|
|
3
|
+
import { ScaleBandModel, ScaleKeyModel, ScaleValueModel } from "../../../model/model";
|
|
4
4
|
export interface Scales {
|
|
5
5
|
key: AxisScale<any>;
|
|
6
6
|
value: AxisScale<any>;
|
|
@@ -9,13 +9,13 @@ export interface ScalesWithSecondary extends Scales {
|
|
|
9
9
|
valueSecondary: AxisScale<any>;
|
|
10
10
|
}
|
|
11
11
|
export declare class Scale {
|
|
12
|
-
static
|
|
13
|
-
static getScalesWithSecondary(scaleKey: ScaleKeyModel, scaleValue: ScaleValueModel, scaleValueSecondary: ScaleValueModel, bandSettings: BarChartSettings): ScalesWithSecondary;
|
|
12
|
+
static getScalesWithSecondary(scaleKey: ScaleKeyModel, scaleValue: ScaleValueModel, scaleValueSecondary: ScaleValueModel): ScalesWithSecondary;
|
|
14
13
|
static getScaleValue(scaleValue: ScaleValueModel): ScaleLinear<number, number, number>;
|
|
15
14
|
static getScaleBandWidth(scale: AxisScale<any>): number;
|
|
16
15
|
static getScaleStep(scale: AxisScale<any>): number;
|
|
17
16
|
static getScaledValueOnMiddleOfItem(scale: AxisScale<any>, value: any): number;
|
|
18
|
-
static
|
|
17
|
+
static getScaleBand(scaleKey: ScaleBandModel): ScaleBand<string>;
|
|
18
|
+
private static getScales;
|
|
19
19
|
private static getScaleLinear;
|
|
20
20
|
private static getScalePoint;
|
|
21
21
|
}
|
|
@@ -1,25 +1,12 @@
|
|
|
1
1
|
import { scaleBand, scaleLinear, scalePoint } from "d3-scale";
|
|
2
2
|
//TODO: incapulate in model
|
|
3
3
|
export class Scale {
|
|
4
|
-
static
|
|
5
|
-
const scales =
|
|
6
|
-
key: null,
|
|
7
|
-
value: null
|
|
8
|
-
};
|
|
9
|
-
if (scaleKey.type === "band")
|
|
10
|
-
// scales.key = this.getScaleBand(scaleKey.domain, scaleKey.range, bandSettings, scaleKey.elementsAmount);
|
|
11
|
-
scales.key = this.getScaleBandNew(scaleKey);
|
|
12
|
-
else if (scaleKey.type === "point")
|
|
13
|
-
scales.key = this.getScalePoint(scaleKey.domain, scaleKey.range);
|
|
14
|
-
scales.value = this.getScaleValue(scaleValue);
|
|
15
|
-
return scales;
|
|
16
|
-
}
|
|
17
|
-
static getScalesWithSecondary(scaleKey, scaleValue, scaleValueSecondary, bandSettings) {
|
|
18
|
-
const scales = this.getScales(scaleKey, scaleValue, bandSettings);
|
|
4
|
+
static getScalesWithSecondary(scaleKey, scaleValue, scaleValueSecondary) {
|
|
5
|
+
const scales = this.getScales(scaleKey, scaleValue);
|
|
19
6
|
return Object.assign(Object.assign({}, scales), (scaleValueSecondary && { valueSecondary: this.getScaleValue(scaleValueSecondary) }));
|
|
20
7
|
}
|
|
21
8
|
static getScaleValue(scaleValue) {
|
|
22
|
-
return this.getScaleLinear(scaleValue.domain, scaleValue.range);
|
|
9
|
+
return this.getScaleLinear(scaleValue.domain, scaleValue.range, scaleValue.rootValue);
|
|
23
10
|
}
|
|
24
11
|
static getScaleBandWidth(scale) {
|
|
25
12
|
if (scale.bandwidth && scale.bandwidth() !== 0) {
|
|
@@ -40,16 +27,34 @@ export class Scale {
|
|
|
40
27
|
}
|
|
41
28
|
return scale(value);
|
|
42
29
|
}
|
|
43
|
-
static
|
|
30
|
+
static getScaleBand(scaleKey) {
|
|
31
|
+
// Formulas from d3-scale source code: https://github.com/d3/d3-scale/blob/main/src/band.js
|
|
32
|
+
const paddingInner = 1 - scaleKey.sizes.bandSize / scaleKey.sizes.recalculatedStepSize;
|
|
33
|
+
const paddingOuter = (Math.abs(scaleKey.range.end - scaleKey.range.start) / scaleKey.sizes.recalculatedStepSize -
|
|
34
|
+
scaleKey.domain.length +
|
|
35
|
+
paddingInner) /
|
|
36
|
+
2;
|
|
44
37
|
return scaleBand()
|
|
45
38
|
.domain(scaleKey.domain)
|
|
46
39
|
.range([scaleKey.range.start, scaleKey.range.end])
|
|
47
|
-
.paddingInner(
|
|
48
|
-
.paddingOuter(
|
|
40
|
+
.paddingInner(paddingInner)
|
|
41
|
+
.paddingOuter(paddingOuter);
|
|
42
|
+
}
|
|
43
|
+
static getScales(scaleKey, scaleValue) {
|
|
44
|
+
const scales = {
|
|
45
|
+
key: null,
|
|
46
|
+
value: null
|
|
47
|
+
};
|
|
48
|
+
if (scaleKey.type === "band")
|
|
49
|
+
scales.key = this.getScaleBand(scaleKey);
|
|
50
|
+
else if (scaleKey.type === "point")
|
|
51
|
+
scales.key = this.getScalePoint(scaleKey.domain, scaleKey.range);
|
|
52
|
+
scales.value = this.getScaleValue(scaleValue);
|
|
53
|
+
return scales;
|
|
49
54
|
}
|
|
50
|
-
static getScaleLinear(domain, range) {
|
|
55
|
+
static getScaleLinear(domain, range, rootValue) {
|
|
51
56
|
const scale = scaleLinear().domain(domain).range([range.start, range.end]);
|
|
52
|
-
scale.unknown(scale(
|
|
57
|
+
scale.unknown(scale(rootValue));
|
|
53
58
|
return scale;
|
|
54
59
|
}
|
|
55
60
|
static getScalePoint(domain, range) {
|
|
@@ -19,10 +19,12 @@ export class AreaGeneratorFactory {
|
|
|
19
19
|
]
|
|
20
20
|
});
|
|
21
21
|
if (keyAxisOrient === "bottom" || keyAxisOrient === "top") {
|
|
22
|
-
return generator.getVertical((d) => Scale.getScaledValueOnMiddleOfItem(scales.key, d[keyFieldName]) + margin.left, (d) => scales.value(
|
|
22
|
+
return generator.getVertical((d) => Scale.getScaledValueOnMiddleOfItem(scales.key, d[keyFieldName]) + margin.left, (d) => scales.value(undefined) + margin.top, //TODO: need a clearer way to use rootValue
|
|
23
|
+
(d) => scales.value(d[valueFieldName]) + margin.top);
|
|
23
24
|
}
|
|
24
25
|
if (keyAxisOrient === "left" || keyAxisOrient === "right") {
|
|
25
|
-
return generator.getHorizontal((d) => scales.value(
|
|
26
|
+
return generator.getHorizontal((d) => scales.value(undefined) + margin.left, //TODO: need a clearer way to use rootValue
|
|
27
|
+
(d) => scales.value(d[valueFieldName]) + margin.left, (d) => Scale.getScaledValueOnMiddleOfItem(scales.key, d[keyFieldName]) + margin.top);
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
getSegmentedAreaGenerator() {
|
|
@@ -47,7 +47,7 @@ export class BarHelper {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
static getBandItemValueStretch(scaleValue, valueFieldName) {
|
|
50
|
-
return (d) => Math.abs(scaleValue(d[valueFieldName]) - scaleValue(
|
|
50
|
+
return (d) => Math.abs(scaleValue(d[valueFieldName]) - scaleValue(undefined)); //TODO: need a clearer way to use rootValue
|
|
51
51
|
}
|
|
52
52
|
static setGroupedBandStartCoordinateAttr(attrs, keyAxisOrient, scaleValue, margin, valueFieldName) {
|
|
53
53
|
if (keyAxisOrient === "top") {
|
|
@@ -20,7 +20,7 @@ import { GroupLines } from "../features/groupLines/groupLines";
|
|
|
20
20
|
export class TwoDimensionalManager {
|
|
21
21
|
render(engine, model) {
|
|
22
22
|
const options = model.options;
|
|
23
|
-
const scales = Scale.getScalesWithSecondary(options.scale.key, options.scale.value, options.scale.valueSecondary
|
|
23
|
+
const scales = Scale.getScalesWithSecondary(options.scale.key, options.scale.value, options.scale.valueSecondary);
|
|
24
24
|
engine.block.scales = scales;
|
|
25
25
|
engine.block.svg.render(model.blockCanvas.size);
|
|
26
26
|
Axis.render(engine.block, scales, options.scale, options.axis, model.blockCanvas.size);
|
|
@@ -95,7 +95,7 @@ export class TwoDimensionalManager {
|
|
|
95
95
|
Tooltip.hide(block);
|
|
96
96
|
const options = model.options;
|
|
97
97
|
ElementHighlighter.remove2DChartsFullHighlighting(block, options.charts);
|
|
98
|
-
const scales = Scale.getScalesWithSecondary(options.scale.key, options.scale.value, options.scale.valueSecondary
|
|
98
|
+
const scales = Scale.getScalesWithSecondary(options.scale.key, options.scale.value, options.scale.valueSecondary);
|
|
99
99
|
const keyDomainEquality = Helper.checkDomainsEquality(block.scales.key.domain(), scales.key.domain());
|
|
100
100
|
block.scales = scales;
|
|
101
101
|
Axis.update(block, scales, options.scale, options.axis, model.blockCanvas.size, keyDomainEquality);
|
|
@@ -9,12 +9,12 @@ export class ScaleAxisRecalcer {
|
|
|
9
9
|
this.generateScaleLinear = generateScaleLinear;
|
|
10
10
|
}
|
|
11
11
|
recalculateMargin(canvasModel, chartOrientation, keyAxis) {
|
|
12
|
-
const { scaleFn: scaleValueFn } = this.getScaleValue();
|
|
12
|
+
const { scaleFn: scaleValueFn, scale } = this.getScaleValue();
|
|
13
13
|
const coordinateOnChartBlock = keyAxis.position === "start"
|
|
14
|
-
? scaleValueFn(
|
|
14
|
+
? scaleValueFn(scale.rootValue)
|
|
15
15
|
: (chartOrientation === "vertical"
|
|
16
16
|
? canvasModel.getChartBlockHeight()
|
|
17
|
-
: canvasModel.getChartBlockWidth()) - scaleValueFn(
|
|
17
|
+
: canvasModel.getChartBlockWidth()) - scaleValueFn(scale.rootValue);
|
|
18
18
|
const key = chartOrientation === "vertical" ? keyAxisLabelVerticalLog : keyAxisLabelHorizontalLog;
|
|
19
19
|
const logInfo = canvasModel.marginService.getDataByKey(key);
|
|
20
20
|
if (logInfo) {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { AxisNumberDomain, MdtChartsDataRow, MdtChartsTwoDimensionalChart, MdtChartsTwoDimensionalOptions, TwoDimensionalValueGroup } from "../../../config/config";
|
|
2
2
|
export declare function getResolvedDomain(domain: AxisNumberDomain, dataRows: MdtChartsDataRow[]): import("../../../config/config").NumberDomain;
|
|
3
|
-
export declare function getScaleLinearDomain(configDomain: AxisNumberDomain, dataRows: MdtChartsDataRow[], configOptions: MdtChartsTwoDimensionalOptions, valueGroup?: TwoDimensionalValueGroup):
|
|
3
|
+
export declare function getScaleLinearDomain(configDomain: AxisNumberDomain, dataRows: MdtChartsDataRow[], configOptions: MdtChartsTwoDimensionalOptions, valueGroup?: TwoDimensionalValueGroup): {
|
|
4
|
+
domain: [number, number];
|
|
5
|
+
rootValue: number;
|
|
6
|
+
};
|
|
4
7
|
export declare class ScaleDomainCalculator {
|
|
5
8
|
getScaleMinValue(charts: MdtChartsTwoDimensionalChart[], dataRows: MdtChartsDataRow[]): number;
|
|
6
9
|
getScaleMaxValue(charts: MdtChartsTwoDimensionalChart[], dataRows: MdtChartsDataRow[]): number;
|
|
@@ -18,9 +18,18 @@ export function getScaleLinearDomain(configDomain, dataRows, configOptions, valu
|
|
|
18
18
|
domainPeekMax = calculator.getScaleMaxValue(charts, dataRows);
|
|
19
19
|
else
|
|
20
20
|
domainPeekMax = resolvedConfigDomain.end;
|
|
21
|
+
let rootValue = 0;
|
|
22
|
+
if (domainPeekMin === 0 || domainPeekMax === 0)
|
|
23
|
+
rootValue = 0;
|
|
24
|
+
else if (domainPeekMin < 0 && domainPeekMax > 0)
|
|
25
|
+
rootValue = 0;
|
|
26
|
+
else if (domainPeekMax > 0 && domainPeekMin > 0)
|
|
27
|
+
rootValue = Math.min(domainPeekMin, domainPeekMax);
|
|
28
|
+
else if (domainPeekMin < 0 && domainPeekMax < 0)
|
|
29
|
+
rootValue = Math.max(domainPeekMin, domainPeekMax);
|
|
21
30
|
if (configOptions.axis.key.position === "start")
|
|
22
|
-
return [domainPeekMin, domainPeekMax];
|
|
23
|
-
return [domainPeekMax, domainPeekMin];
|
|
31
|
+
return { domain: [domainPeekMin, domainPeekMax], rootValue };
|
|
32
|
+
return { domain: [domainPeekMax, domainPeekMin], rootValue };
|
|
24
33
|
}
|
|
25
34
|
export class ScaleDomainCalculator {
|
|
26
35
|
getScaleMinValue(charts, dataRows) {
|
|
@@ -31,8 +31,10 @@ export class ScaleModel {
|
|
|
31
31
|
}
|
|
32
32
|
getScaleLinear(dataRows, configReader) {
|
|
33
33
|
var _a;
|
|
34
|
+
const { domain, rootValue } = getScaleLinearDomain(this.options.axis.value.domain, dataRows, this.options);
|
|
34
35
|
return {
|
|
35
|
-
domain
|
|
36
|
+
domain,
|
|
37
|
+
rootValue,
|
|
36
38
|
range: {
|
|
37
39
|
start: 0,
|
|
38
40
|
end: getScaleValueRangePeek(this.options.orientation, this.canvasModel)
|
|
@@ -43,8 +45,10 @@ export class ScaleModel {
|
|
|
43
45
|
}
|
|
44
46
|
getScaleSecondaryLinear(dataRows, configReader) {
|
|
45
47
|
var _a;
|
|
48
|
+
const { domain, rootValue } = getScaleLinearDomain(this.options.axis.valueSecondary.domain, dataRows, this.options, "secondary");
|
|
46
49
|
return {
|
|
47
|
-
domain
|
|
50
|
+
domain,
|
|
51
|
+
rootValue,
|
|
48
52
|
range: {
|
|
49
53
|
start: 0,
|
|
50
54
|
end: getScaleValueRangePeek(this.options.orientation, this.canvasModel)
|
package/lib/model/model.d.ts
CHANGED
|
@@ -145,7 +145,8 @@ export interface ScalePointModel extends BaseScaleKeyModel {
|
|
|
145
145
|
type: "point";
|
|
146
146
|
}
|
|
147
147
|
export interface ScaleValueModel {
|
|
148
|
-
domain:
|
|
148
|
+
domain: number[];
|
|
149
|
+
rootValue: number;
|
|
149
150
|
range: RangeModel;
|
|
150
151
|
type: ScaleValueType;
|
|
151
152
|
formatter: ((v: number) => string) | null;
|
|
@@ -33,7 +33,7 @@ export class TwoDimensionalModel {
|
|
|
33
33
|
secondaryScaleMarginRecalcer.recalculateMargin(canvasModel, options.orientation, options.axis.key);
|
|
34
34
|
secondaryScaleValueInfo = secondaryScaleMarginRecalcer.getScaleValue();
|
|
35
35
|
}
|
|
36
|
-
const keyAxis = AxisModel.getKeyAxis(options, modelInstance.dataModel.repository.getScopedFullSource(), designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () => scaleValueInfo.scaleFn(
|
|
36
|
+
const keyAxis = AxisModel.getKeyAxis(options, modelInstance.dataModel.repository.getScopedFullSource(), designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () => scaleValueInfo.scaleFn(scaleValueInfo.scale.rootValue));
|
|
37
37
|
const keyScale = scaleModel.getScaleKey(modelInstance.dataModel.getAllowableKeys());
|
|
38
38
|
const charts = this.getChartsModel(options.charts, configReader, options.orientation, designerConfig, modelInstance.dataModel.repository, keyAxis.orient, canvasModel, options.data.keyField.name, modelInstance, keyScale);
|
|
39
39
|
const titleConfig = TitleConfigReader.create(options.title, modelInstance);
|