mdt-charts 1.12.4 → 1.12.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.
@@ -1,3 +1,4 @@
1
+ import { ScaleLinear, ScaleTime } from 'd3-scale';
1
2
  import { AxisScale } from 'd3-axis';
2
3
  import { BarChartSettings, ScaleKeyModel, ScaleValueModel } from '../../../model/model';
3
4
  export interface Scales {
@@ -6,6 +7,7 @@ export interface Scales {
6
7
  }
7
8
  export declare class Scale {
8
9
  static getScales(scaleKey: ScaleKeyModel, scaleValue: ScaleValueModel, bandSettings: BarChartSettings): Scales;
10
+ static getScaleValue(scaleValue: ScaleValueModel): ScaleLinear<number, number, never> | ScaleTime<number, number, never>;
9
11
  static getScaleBandWidth(scale: AxisScale<any>): number;
10
12
  static getScaleStep(scale: AxisScale<any>): number;
11
13
  static getScaledValue(scale: AxisScale<any>, value: any): number;
@@ -9,11 +9,14 @@ export class Scale {
9
9
  scales.key = this.getScaleBand(scaleKey.domain, scaleKey.range, bandSettings, scaleKey.elementsAmount);
10
10
  else if (scaleKey.type === 'point')
11
11
  scales.key = this.getScalePoint(scaleKey.domain, scaleKey.range);
12
+ scales.value = this.getScaleValue(scaleValue);
13
+ return scales;
14
+ }
15
+ static getScaleValue(scaleValue) {
12
16
  if (scaleValue.type === 'linear')
13
- scales.value = this.getScaleLinear(scaleValue.domain, scaleValue.range);
17
+ return this.getScaleLinear(scaleValue.domain, scaleValue.range);
14
18
  else if (scaleValue.type === 'datetime')
15
- scales.value = this.getScaleTime(scaleValue.domain, scaleValue.range);
16
- return scales;
19
+ return this.getScaleTime(scaleValue.domain, scaleValue.range);
17
20
  }
18
21
  static getScaleBandWidth(scale) {
19
22
  if (scale.bandwidth && scale.bandwidth() !== 0) {
@@ -5,11 +5,11 @@ export class AreaHelper {
5
5
  if (keyAxisOrient === 'bottom' || keyAxisOrient === 'top')
6
6
  return area()
7
7
  .x(d => Scale.getScaledValue(scales.key, d[keyFieldName]) + margin.left)
8
- .y0(d => this.getZeroCoordinate(keyAxisOrient, margin, blockSize))
8
+ .y0(d => scales.value(0) + margin.top)
9
9
  .y1(d => scales.value(d[valueFieldName]) + margin.top);
10
10
  if (keyAxisOrient === 'left' || keyAxisOrient === 'right')
11
11
  return area()
12
- .x0(d => this.getZeroCoordinate(keyAxisOrient, margin, blockSize))
12
+ .x0(d => scales.value(0) + margin.left)
13
13
  .x1(d => scales.value(d[valueFieldName]) + margin.left)
14
14
  .y(d => Scale.getScaledValue(scales.key, d[keyFieldName]) + margin.top);
15
15
  }
@@ -171,15 +171,15 @@ export class Bar {
171
171
  resolve('');
172
172
  return;
173
173
  }
174
- let barsHander = bars;
174
+ let barsHandler = bars;
175
175
  if (transitionDuration > 0) {
176
- barsHander = barsHander
176
+ barsHandler = barsHandler
177
177
  .interrupt()
178
178
  .transition()
179
179
  .duration(transitionDuration)
180
180
  .on('end', () => resolve(''));
181
181
  }
182
- barsHander.attr('x', d => barAttrs.x(d))
182
+ barsHandler.attr('x', d => barAttrs.x(d))
183
183
  .attr('y', d => barAttrs.y(d))
184
184
  .attr('height', d => barAttrs.height(d))
185
185
  .attr('width', d => barAttrs.width(d));
@@ -66,20 +66,20 @@ export class BarHelper {
66
66
  }
67
67
  static setGroupedBarAttrsByValue(attrs, keyAxisOrient, margin, scaleValue, valueFieldName, blockSize) {
68
68
  if (keyAxisOrient === 'top') {
69
- attrs.y = d => margin.top;
70
- attrs.height = d => Helper.getValueOrZero(scaleValue(d[valueFieldName]));
69
+ attrs.y = d => scaleValue(Math.min(d[valueFieldName], 0)) + margin.top;
70
+ attrs.height = d => Math.abs(scaleValue(d[valueFieldName]) - scaleValue(0));
71
71
  }
72
72
  if (keyAxisOrient === 'bottom') {
73
- attrs.y = d => scaleValue(d[valueFieldName]) + margin.top;
74
- attrs.height = d => Helper.getValueOrZero(blockSize.height - margin.top - margin.bottom - scaleValue(d[valueFieldName]));
73
+ attrs.y = d => scaleValue(Math.max(d[valueFieldName], 0)) + margin.top;
74
+ attrs.height = d => Math.abs(scaleValue(d[valueFieldName]) - scaleValue(0));
75
75
  }
76
76
  if (keyAxisOrient === 'left') {
77
- attrs.x = d => margin.left + 1;
78
- attrs.width = d => Helper.getValueOrZero(scaleValue(d[valueFieldName]));
77
+ attrs.x = d => scaleValue(Math.min(d[valueFieldName], 0)) + margin.left;
78
+ attrs.width = d => Math.abs(scaleValue(d[valueFieldName]) - scaleValue(0));
79
79
  }
80
80
  if (keyAxisOrient === 'right') {
81
- attrs.x = d => scaleValue(d[valueFieldName]) + margin.left;
82
- attrs.width = d => Helper.getValueOrZero(blockSize.width - margin.left - margin.right - scaleValue(d[valueFieldName]));
81
+ attrs.x = d => scaleValue(Math.max(d[valueFieldName], 0)) + margin.left;
82
+ attrs.width = d => Math.abs(scaleValue(d[valueFieldName]) - scaleValue(0));
83
83
  }
84
84
  }
85
85
  static setSegmentedBarAttrsByValue(attrs, keyAxisOrient, scaleValue, margin, blockSize) {
@@ -9,7 +9,7 @@ export interface LabelSize {
9
9
  }
10
10
  export declare class AxisModel {
11
11
  private static service;
12
- static getKeyAxis(options: MdtChartsTwoDimensionalOptions, data: MdtChartsDataSource, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, tooltipSettings: TooltipSettings): AxisModelOptions;
12
+ static getKeyAxis(options: MdtChartsTwoDimensionalOptions, data: MdtChartsDataSource, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, tooltipSettings: TooltipSettings, getZeroCoordinate?: () => number): AxisModelOptions;
13
13
  static getValueAxis(orient: ChartOrientation, axisConfig: NumberAxisOptions, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel): AxisModelOptions;
14
14
  static getAxisLength(chartOrientation: ChartOrientation, canvasModel: CanvasModel): number;
15
15
  static getAxisOrient(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition): Orient;
@@ -17,4 +17,5 @@ export declare class AxisModel {
17
17
  static getAxisTranslateY(axisType: AxisType, chartOrientation: ChartOrientation, axisPosition: AxisPosition, canvasModel: CanvasModel): number;
18
18
  static getKeyAxisLabelPosition(canvasModel: CanvasModel, scopedDataLength: number, axisConfig?: DiscreteAxisOptions): AxisLabelPosition;
19
19
  static getLabelSize(labelMaxWidth: number, labelTexts: any[]): LabelSize;
20
+ private static getKeyAxisTranslateModel;
20
21
  }
@@ -4,16 +4,14 @@ import { DataManagerModel } from "../dataManagerModel/dataManagerModel";
4
4
  import { TwoDimensionalModel } from "../notations/twoDimensionalModel";
5
5
  import { AxisModelService } from "./axisModelService";
6
6
  export class AxisModel {
7
- static getKeyAxis(options, data, labelConfig, canvasModel, tooltipSettings) {
7
+ static getKeyAxis(options, data, labelConfig, canvasModel, tooltipSettings, getZeroCoordinate) {
8
8
  const { charts, orientation, data: dataOptions } = options;
9
9
  const axisConfig = options.axis.key;
10
+ const translate = this.getKeyAxisTranslateModel(orientation, axisConfig.position, canvasModel, getZeroCoordinate);
10
11
  return {
11
12
  type: 'key',
12
13
  orient: AxisModel.getAxisOrient(AxisType.Key, orientation, axisConfig.position),
13
- translate: {
14
- translateX: AxisModel.getAxisTranslateX(AxisType.Key, orientation, axisConfig.position, canvasModel),
15
- translateY: AxisModel.getAxisTranslateY(AxisType.Key, orientation, axisConfig.position, canvasModel)
16
- },
14
+ translate,
17
15
  cssClass: 'key-axis',
18
16
  ticks: axisConfig.ticks,
19
17
  labels: {
@@ -109,5 +107,22 @@ export class AxisModel {
109
107
  textBlock.remove();
110
108
  return labelSize;
111
109
  }
110
+ static getKeyAxisTranslateModel(chartOrientation, axisPosition, canvasModel, getZeroCoordinate) {
111
+ let translateY;
112
+ let translateX;
113
+ if (chartOrientation === "vertical") {
114
+ translateY = getZeroCoordinate() + canvasModel.getMarginSide("top");
115
+ translateX = AxisModel.getAxisTranslateX(AxisType.Key, chartOrientation, axisPosition, canvasModel);
116
+ }
117
+ else {
118
+ translateX = getZeroCoordinate() + canvasModel.getMarginSide("left");
119
+ translateY = AxisModel.getAxisTranslateY(AxisType.Key, chartOrientation, axisPosition, canvasModel);
120
+ }
121
+ console.log(translateX, translateY);
122
+ return {
123
+ translateX,
124
+ translateY
125
+ };
126
+ }
112
127
  }
113
128
  AxisModel.service = new AxisModelService();
@@ -1,5 +1,5 @@
1
1
  import { ScaleKeyModel, ScaleKeyType, ScaleValueModel, ScaleValueType } from "../model";
2
- import { AxisPosition, NumberDomain, IntervalChart, MdtChartsTwoDimensionalChart, MdtChartsTwoDimensionalOptions, ChartOrientation, MdtChartsDataSource } from "../../config/config";
2
+ import { AxisPosition, NumberDomain, IntervalChart, MdtChartsTwoDimensionalChart, MdtChartsTwoDimensionalOptions, ChartOrientation, MdtChartsDataSource, MdtChartsDataRow } from "../../config/config";
3
3
  import { CanvasModel } from "../modelInstance/canvasModel/canvasModel";
4
4
  export declare enum ScaleType {
5
5
  Key = 0,
@@ -14,5 +14,6 @@ export declare class ScaleModel {
14
14
  static getScaleKeyType(charts: MdtChartsTwoDimensionalChart[]): ScaleKeyType;
15
15
  static getScaleValueType(charts: MdtChartsTwoDimensionalChart[] | IntervalChart[]): ScaleValueType;
16
16
  static getElementsAmount(barCharts: MdtChartsTwoDimensionalChart[]): number;
17
- static getScaleMaxValue(charts: MdtChartsTwoDimensionalChart[], dataSource: string, data: MdtChartsDataSource): number;
17
+ static getScaleMaxValue(charts: MdtChartsTwoDimensionalChart[], dataRows: MdtChartsDataRow[]): number;
18
+ static getScaleMinValue(charts: MdtChartsTwoDimensionalChart[], dataRows: MdtChartsDataRow[]): number;
18
19
  }
@@ -47,11 +47,11 @@ export class ScaleModel {
47
47
  let domainPeekMin;
48
48
  let domainPeekMax;
49
49
  if (configDomain.start === -1)
50
- domainPeekMin = 0;
50
+ domainPeekMin = this.getScaleMinValue(configOptions.charts, data[configOptions.data.dataSource]);
51
51
  else
52
52
  domainPeekMin = configDomain.start;
53
53
  if (configDomain.end === -1)
54
- domainPeekMax = this.getScaleMaxValue(configOptions.charts, configOptions.data.dataSource, data);
54
+ domainPeekMax = this.getScaleMaxValue(configOptions.charts, data[configOptions.data.dataSource]);
55
55
  else
56
56
  domainPeekMax = configDomain.end;
57
57
  if (configOptions.axis.key.position === 'start')
@@ -80,10 +80,10 @@ export class ScaleModel {
80
80
  });
81
81
  return barsAmount;
82
82
  }
83
- static getScaleMaxValue(charts, dataSource, data) {
83
+ static getScaleMaxValue(charts, dataRows) {
84
84
  let max = 0;
85
85
  charts.forEach(chart => {
86
- data[dataSource].forEach(dataRow => {
86
+ dataRows.forEach(dataRow => {
87
87
  let sumInRow = 0;
88
88
  chart.data.valueFields.forEach(field => {
89
89
  if (chart.isSegmented)
@@ -97,4 +97,19 @@ export class ScaleModel {
97
97
  });
98
98
  return max;
99
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
+ }
100
115
  }
@@ -1,13 +1,12 @@
1
1
  import { MdtChartsConfig, MdtChartsDataSource } from "../config/config";
2
2
  import { DesignerConfig } from "../designer/designerConfig";
3
- import { DataScope, LegendBlockModel, Orient, OtherCommonComponents, PolarOptionsModel } from "./model";
3
+ import { DataScope, LegendBlockModel, Orient, OtherCommonComponents } from "./model";
4
4
  import { ModelInstance } from "./modelInstance/modelInstance";
5
5
  import { CanvasModel } from "./modelInstance/canvasModel/canvasModel";
6
6
  export declare const AXIS_HORIZONTAL_LABEL_PADDING = 15;
7
7
  export declare const AXIS_VERTICAL_LABEL_PADDING = 10;
8
8
  export declare class MarginModel {
9
9
  static initMargin(designerConfig: DesignerConfig, config: MdtChartsConfig, otherComponents: OtherCommonComponents, data: MdtChartsDataSource, modelInstance: ModelInstance): void;
10
- static recalcPolarMarginWithScopedData(modelInstance: ModelInstance, designerConfig: DesignerConfig, config: MdtChartsConfig, legendBlockModel: LegendBlockModel, dataScope: DataScope, options: PolarOptionsModel): void;
11
10
  static recalcMarginByVerticalAxisLabel(modelInstance: ModelInstance, config: MdtChartsConfig, designerConfig: DesignerConfig, dataScope: DataScope): void;
12
11
  private static getHorizontalMarginByAxisLabels;
13
12
  private static recalcVerticalMarginByAxisLabelHeight;
@@ -15,6 +14,5 @@ export declare class MarginModel {
15
14
  private static recalcMarginWithLegend;
16
15
  private static getLegendItemsContent;
17
16
  static appendToGlobalMarginValuesLegendMargin(canvasModel: CanvasModel, position: Orient, legendBlockModel: LegendBlockModel): void;
18
- private static clearMarginByLegendBlockPosition;
19
17
  private static recalcMarginByTitle;
20
18
  }
@@ -3,7 +3,6 @@ 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 { PolarModel } from "./notations/polar/polarModel";
7
6
  export const AXIS_HORIZONTAL_LABEL_PADDING = 15;
8
7
  export const AXIS_VERTICAL_LABEL_PADDING = 10;
9
8
  export class MarginModel {
@@ -24,21 +23,6 @@ export class MarginModel {
24
23
  this.recalcHorizontalMarginByAxisLabelWidth(labelSize, canvasModel, config.options.orientation, config.options.axis, showingFlag);
25
24
  }
26
25
  }
27
- static recalcPolarMarginWithScopedData(modelInstance, designerConfig, config, legendBlockModel, dataScope, options) {
28
- const canvasModel = modelInstance.canvasModel;
29
- let position = canvasModel.legendCanvas.getPosition();
30
- if (position !== 'off') {
31
- position = PolarModel.getLegendPositionByBlockSize(canvasModel); // reset position
32
- this.clearMarginByLegendBlockPosition(canvasModel, legendBlockModel);
33
- let allowableKeys = [...dataScope.allowableKeys];
34
- if (dataScope.hidedRecordsAmount !== 0 && position === 'bottom')
35
- allowableKeys.push('1'); // Если есть спрятанные записи, то в массив добавляется объект, чтобы выделить место в легенде для индикатора переполнения
36
- const legendSize = LegendModel.getLegendSize(config.options.type, position, allowableKeys, designerConfig.canvas.legendBlock.maxWidth, config.canvas.size, legendBlockModel);
37
- canvasModel.increaseMarginSide(position, legendSize + legendBlockModel.coordinate[position].margin[position]);
38
- legendBlockModel.coordinate[position].size = legendSize;
39
- options.legend.position = position;
40
- }
41
- }
42
26
  static recalcMarginByVerticalAxisLabel(modelInstance, config, designerConfig, dataScope) {
43
27
  if ((config.options.type === '2d' || config.options.type === 'interval') && config.options.orientation === 'vertical') {
44
28
  const axisLabelSize = AxisModel.getLabelSize(designerConfig.canvas.axisLabel.maxSize.main, dataScope.allowableKeys);
@@ -117,15 +101,6 @@ export class MarginModel {
117
101
  else
118
102
  canvasModel.increaseMarginSide(position, legendCoordinate[position].margin.top + legendCoordinate[position].margin.bottom);
119
103
  }
120
- static clearMarginByLegendBlockPosition(canvasModel, legendBlockModel) {
121
- const legendCoordinate = legendBlockModel.coordinate;
122
- ['left', 'right', 'top', 'bottom'].forEach((position) => {
123
- const decreaseByValue = legendCoordinate[position].size === 0
124
- ? 0
125
- : legendCoordinate[position].size + legendCoordinate[position].margin[position];
126
- canvasModel.descreaseMarginSide(position, decreaseByValue);
127
- });
128
- }
129
104
  static recalcMarginByTitle(canvasModel, titleBlockModel) {
130
105
  canvasModel.increaseMarginSide("top", titleBlockModel.margin.top + titleBlockModel.size + titleBlockModel.margin.bottom);
131
106
  }
@@ -1,3 +1,4 @@
1
+ import { Scale } from "../../engine/features/scale/scale";
1
2
  import { ChartStyleModelService } from "../chartStyleModel/chartStyleModel";
2
3
  import { TwoDimensionalChartStyleModel } from "../chartStyleModel/TwoDimensionalChartStyleModel";
3
4
  import { AxisModel } from "../featuresModel/axisModel";
@@ -5,17 +6,22 @@ import { ScaleModel } from "../featuresModel/scaleModel";
5
6
  export class TwoDimensionalModel {
6
7
  static getOptions(options, designerConfig, data, modelInstance) {
7
8
  const canvasModel = modelInstance.canvasModel;
9
+ const scaleKey = ScaleModel.getScaleKey(modelInstance.dataModel.getAllowableKeys(), options.orientation, canvasModel, options.charts, this.getChartsByType(options.charts, 'bar'));
10
+ const scaleValue = ScaleModel.getScaleLinear(options, data, canvasModel);
11
+ const chartSettings = this.getChartsSettings(designerConfig.canvas.chartOptions.bar);
12
+ //TODO: rm import from engine
13
+ const scaleValueFn = Scale.getScaleValue(scaleValue);
8
14
  return {
9
15
  legend: canvasModel.legendCanvas.getModel(),
10
16
  title: options.title,
11
17
  selectable: !!options.selectable,
12
18
  orient: options.orientation,
13
19
  scale: {
14
- key: ScaleModel.getScaleKey(modelInstance.dataModel.getAllowableKeys(), options.orientation, canvasModel, options.charts, this.getChartsByType(options.charts, 'bar')),
15
- value: ScaleModel.getScaleLinear(options, data, canvasModel)
20
+ key: scaleKey,
21
+ value: scaleValue
16
22
  },
17
23
  axis: {
18
- key: AxisModel.getKeyAxis(options, data, designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip),
24
+ key: AxisModel.getKeyAxis(options, data, designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () => scaleValueFn(0)),
19
25
  value: AxisModel.getValueAxis(options.orientation, options.axis.value, designerConfig.canvas.axisLabel, canvasModel)
20
26
  },
21
27
  type: options.type,
@@ -23,7 +29,7 @@ export class TwoDimensionalModel {
23
29
  charts: this.getChartsModel(options.charts, options.orientation, designerConfig.chartStyle),
24
30
  additionalElements: this.getAdditionalElements(options),
25
31
  tooltip: options.tooltip,
26
- chartSettings: this.getChartsSettings(designerConfig.canvas.chartOptions.bar)
32
+ chartSettings
27
33
  };
28
34
  }
29
35
  static getChartsEmbeddedLabelsFlag(charts, chartOrientation) {
@@ -58,6 +58,7 @@
58
58
  .legend-item {
59
59
  cursor: default;
60
60
  transition: opacity 0.1s;
61
+ line-height: 1;
61
62
  /* will-change: opacity; */
62
63
  }
63
64
  .legend-block-column .legend-item:not(:first-of-type) {
@@ -58,6 +58,7 @@
58
58
  .legend-item {
59
59
  cursor: default;
60
60
  transition: opacity 0.1s;
61
+ line-height: 1;
61
62
  /* will-change: opacity; */
62
63
  }
63
64
  .legend-block-column .legend-item:not(:first-of-type) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.12.4",
3
+ "version": "1.12.5",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {