mdt-charts 1.12.3 → 1.12.4

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.
@@ -6,7 +6,7 @@ export interface AggregatorInfo {
6
6
  name: string;
7
7
  value: number | string;
8
8
  format: DataType;
9
- margin: number;
9
+ marginInPercent: number;
10
10
  }
11
11
  export declare class Aggregator {
12
12
  static readonly aggregatorValueClass = "aggregator-value";
@@ -15,26 +15,28 @@ export class Aggregator {
15
15
  name: settings.content.title,
16
16
  value: settings.content.value,
17
17
  format: valueField.format,
18
- margin: settings.margin
18
+ marginInPercent: settings.margin
19
19
  };
20
20
  }
21
21
  static renderText(block, innerRadius, aggregatorInfo, fontSize, translate) {
22
- if (innerRadius > 40) {
22
+ if (innerRadius > 30) {
23
23
  const aggregatorObject = this.renderAggregatorObject(block, innerRadius, translate);
24
24
  const wrapper = this.renderWrapper(aggregatorObject);
25
25
  wrapper
26
26
  .append('div')
27
27
  .attr('class', this.aggregatorValueClass)
28
+ .attr('title', this.formatValue(aggregatorInfo.format, aggregatorInfo.value))
28
29
  .style('text-align', 'center')
29
30
  .style('font-size', `${fontSize}px`)
30
31
  .text(this.formatValue(aggregatorInfo.format, aggregatorInfo.value));
31
- wrapper
32
+ const titleBlock = wrapper
32
33
  .append('div')
33
34
  .attr('class', this.aggregatorTitleClass)
34
35
  .attr('title', aggregatorInfo.name)
35
36
  .style('text-align', 'center')
36
37
  .text(aggregatorInfo.name);
37
- this.reCalculateAggregatorFontSize(aggregatorObject.node().getBoundingClientRect().width, block, aggregatorInfo.margin);
38
+ this.setTitleFontSize(titleBlock, innerRadius);
39
+ this.reCalculateAggregatorFontSize(aggregatorObject.node().getBoundingClientRect().width, block, aggregatorInfo.marginInPercent);
38
40
  }
39
41
  }
40
42
  static formatValue(format, value) {
@@ -63,26 +65,25 @@ export class Aggregator {
63
65
  const interpolateFunc = interpolateNumber(oldValue, newValue);
64
66
  return t => {
65
67
  this.textContent = thisClass.formatValue(newAggregator.format, parseFloat((interpolateFunc(t)).toFixed(precision)));
66
- thisClass.reCalculateAggregatorFontSize(aggregatorObject.node().getBoundingClientRect().width, block, newAggregator.margin);
68
+ thisClass.reCalculateAggregatorFontSize(aggregatorObject.node().getBoundingClientRect().width, block, newAggregator.marginInPercent);
67
69
  };
68
70
  });
69
71
  }
70
72
  static reCalculateAggregatorFontSize(wrapperSize, block, pad) {
71
73
  const aggregatorValue = block.getSvg()
72
74
  .select(`.${this.aggregatorValueClass}`);
73
- const aggregatorTitle = block.getSvg()
74
- .select(`.${this.aggregatorTitleClass}`);
75
- let fontSize = parseInt(aggregatorValue.style('font-size'));
76
- while (aggregatorValue.node().getBoundingClientRect().width > wrapperSize - pad * 2 && fontSize > 12) {
75
+ const sizeCoefficient = 0.25;
76
+ let fontSize = wrapperSize * sizeCoefficient;
77
+ aggregatorValue.style('font-size', `${fontSize}px`);
78
+ const margin = pad / 100 * wrapperSize;
79
+ while (aggregatorValue.node().getBoundingClientRect().width > wrapperSize - margin * 2 && fontSize > 12) {
77
80
  aggregatorValue.style('font-size', `${fontSize -= 2}px`);
78
81
  }
79
- while (aggregatorValue.node().getBoundingClientRect().width < wrapperSize - pad * 2 && fontSize < 60) {
80
- aggregatorValue.style('font-size', `${fontSize += 2}px`);
81
- }
82
- this.setTitleFontSize(aggregatorTitle, fontSize);
83
82
  }
84
- static setTitleFontSize(aggregatorTitle, valueFontSize) {
85
- aggregatorTitle.style('font-size', `${Math.round(valueFontSize * 0.5)}px`);
83
+ static setTitleFontSize(aggregatorTitle, innerRadius) {
84
+ const sizeCoefficient = 0.15;
85
+ aggregatorTitle.style('font-size', `${Math.round(innerRadius * sizeCoefficient)}px`);
86
+ aggregatorTitle.style('max-height', `${sizeCoefficient * 100}%`);
86
87
  }
87
88
  static renderAggregatorObject(block, innerRadius, translate) {
88
89
  return block.getSvg()
@@ -30,12 +30,12 @@ export class LegendModel {
30
30
  },
31
31
  right: {
32
32
  size: 0,
33
- margin: { top: canvasModel.titleCanvas.getAllNeededSpace(), bottom: mb, left: 10, right: 0 },
33
+ margin: { top: canvasModel.titleCanvas.getAllNeededSpace(), bottom: mb, left: 5, right: 0 },
34
34
  pad: 0
35
35
  },
36
36
  top: {
37
37
  size: 0,
38
- margin: { top: 10, bottom: 10, left: 20, right: 20 },
38
+ margin: { top: 5, bottom: 10, left: 0, right: 0 },
39
39
  pad: canvasModel.titleCanvas.getAllNeededSpace()
40
40
  }
41
41
  },
@@ -4,7 +4,7 @@ export class TitleModel {
4
4
  const pad = titleText ? defaultPads : 0;
5
5
  return {
6
6
  margin: {
7
- bottom: 10,
7
+ bottom: 5,
8
8
  left: 0,
9
9
  right: 0,
10
10
  top: 0
@@ -30,16 +30,16 @@ function getChartBlockModel(modelInstance) {
30
30
  margin: modelInstance.canvasModel.getMargin()
31
31
  };
32
32
  }
33
- function getOptions(config, designerConfig, modelInstance, dataScope, data) {
33
+ function getOptions(config, designerConfig, modelInstance, data) {
34
34
  //TODO: migrate to polymorphism
35
35
  if (config.options.type === '2d') {
36
- return TwoDimensionalModel.getOptions(config.options, designerConfig, dataScope, data, modelInstance);
36
+ return TwoDimensionalModel.getOptions(config.options, designerConfig, data, modelInstance);
37
37
  }
38
38
  else if (config.options.type === 'polar') {
39
- return PolarModel.getOptions(config.options, data, designerConfig, modelInstance);
39
+ return PolarModel.getOptions(config.options, designerConfig, modelInstance);
40
40
  }
41
41
  else if (config.options.type === 'interval') {
42
- return IntervalModel.getOptions(config, designerConfig, modelInstance.canvasModel.getMargin(), dataScope, data, modelInstance);
42
+ return IntervalModel.getOptions(config, designerConfig, modelInstance.canvasModel.getMargin(), modelInstance.dataModel.getScope(), data, modelInstance);
43
43
  }
44
44
  }
45
45
  function getDataSettings(dataScope, designerConfig) {
@@ -57,7 +57,7 @@ function getTransitions(designerConfig) {
57
57
  return designerConfig.transitions;
58
58
  }
59
59
  export function assembleModel(config, data, designerConfig) {
60
- const modelInstance = ModelInstance.create(config);
60
+ const modelInstance = ModelInstance.create(config, data);
61
61
  if (!data || Object.keys(data).length === 0)
62
62
  return {
63
63
  blockCanvas: getBlockCanvas(config, modelInstance),
@@ -71,15 +71,14 @@ export function assembleModel(config, data, designerConfig) {
71
71
  MarginModel.initMargin(designerConfig, config, otherComponents, data, modelInstance);
72
72
  DataManagerModel.initDataScope(config, data, designerConfig, otherComponents.legendBlock, modelInstance);
73
73
  const preparedData = DataManagerModel.getPreparedData(data, modelInstance.dataModel.getAllowableKeys(), config);
74
+ modelInstance.dataModel.repository.initScopedFullSource(preparedData);
74
75
  if (config.options.type === '2d' && config.options.axis.key.visibility)
75
76
  MarginModel.recalcMarginByVerticalAxisLabel(modelInstance, config, designerConfig, modelInstance.dataModel.getScope());
76
77
  const blockCanvas = getBlockCanvas(config, modelInstance);
77
78
  const chartBlock = getChartBlockModel(modelInstance);
78
- const options = getOptions(config, designerConfig, modelInstance, modelInstance.dataModel.getScope(), preparedData);
79
+ const options = getOptions(config, designerConfig, modelInstance, preparedData);
79
80
  const dataSettings = getDataSettings(modelInstance.dataModel.getScope(), designerConfig);
80
81
  const transitions = getTransitions(designerConfig);
81
- // if (options.type === 'polar')
82
- // MarginModel.recalcPolarMarginWithScopedData(modelInstance, designerConfig, config, otherComponents.legendBlock, modelInstance.dataModel.getScope(), options);
83
82
  modelInstance.canvasModel.roundMargin();
84
83
  return {
85
84
  blockCanvas,
@@ -0,0 +1,14 @@
1
+ import { DataScope } from "../../model";
2
+ import { DataRepositoryModel } from "./dataRepository";
3
+ export declare const DEFAULT_MAX_RECORDS_AMOUNT = 50;
4
+ export declare class DataModelInstance {
5
+ repository: DataRepositoryModel;
6
+ constructor();
7
+ private maxRecordsAmount;
8
+ private scope;
9
+ initMaxRecordsAmount(amount: number): void;
10
+ getMaxRecordsAmount(): number;
11
+ initScope(scope: DataScope): void;
12
+ getScope(): DataScope;
13
+ getAllowableKeys(): string[];
14
+ }
@@ -0,0 +1,26 @@
1
+ import { DataRepositoryModel } from "./dataRepository";
2
+ export const DEFAULT_MAX_RECORDS_AMOUNT = 50;
3
+ export class DataModelInstance {
4
+ constructor() {
5
+ //TODO: create dataScopeModel.
6
+ this.maxRecordsAmount = DEFAULT_MAX_RECORDS_AMOUNT;
7
+ this.repository = new DataRepositoryModel();
8
+ }
9
+ initMaxRecordsAmount(amount) {
10
+ if (typeof amount === "number" && amount > 0) {
11
+ this.maxRecordsAmount = amount;
12
+ }
13
+ }
14
+ getMaxRecordsAmount() {
15
+ return this.maxRecordsAmount;
16
+ }
17
+ initScope(scope) {
18
+ this.scope = scope;
19
+ }
20
+ getScope() {
21
+ return this.scope;
22
+ }
23
+ getAllowableKeys() {
24
+ return this.getScope().allowableKeys;
25
+ }
26
+ }
@@ -0,0 +1,12 @@
1
+ import { MdtChartsDataSource } from "../../../config/config";
2
+ export declare class DataRepositoryModel {
3
+ private rawFullSource;
4
+ private scopedFullSource;
5
+ private sourceName;
6
+ initSourceName(sourceName: string): void;
7
+ initRawFullSource(rawSource: MdtChartsDataSource): void;
8
+ getRawRows(): import("../../../config/config").MdtChartsDataRow[];
9
+ initScopedFullSource(scopedSource: MdtChartsDataSource): void;
10
+ getScopedFullSource(): MdtChartsDataSource;
11
+ getScopedRows(): import("../../../config/config").MdtChartsDataRow[];
12
+ }
@@ -0,0 +1,20 @@
1
+ export class DataRepositoryModel {
2
+ initSourceName(sourceName) {
3
+ this.sourceName = sourceName;
4
+ }
5
+ initRawFullSource(rawSource) {
6
+ this.rawFullSource = rawSource;
7
+ }
8
+ getRawRows() {
9
+ return this.rawFullSource[this.sourceName];
10
+ }
11
+ initScopedFullSource(scopedSource) {
12
+ this.scopedFullSource = scopedSource;
13
+ }
14
+ getScopedFullSource() {
15
+ return this.scopedFullSource;
16
+ }
17
+ getScopedRows() {
18
+ return this.scopedFullSource[this.sourceName];
19
+ }
20
+ }
@@ -1,8 +1,8 @@
1
- import { MdtChartsConfig } from "../../main";
1
+ import { MdtChartsConfig, MdtChartsDataSource } from "../../config/config";
2
2
  import { CanvasModel } from "./canvasModel/canvasModel";
3
- import { DataModelInstance } from "./dataModel";
3
+ import { DataModelInstance } from "./dataModel/dataModel";
4
4
  export declare class ModelInstance {
5
- static create(config: MdtChartsConfig): ModelInstance;
5
+ static create(config: MdtChartsConfig, data: MdtChartsDataSource): ModelInstance;
6
6
  private static initInitialParams;
7
7
  canvasModel: CanvasModel;
8
8
  dataModel: DataModelInstance;
@@ -1,17 +1,19 @@
1
1
  import { CanvasModel } from "./canvasModel/canvasModel";
2
- import { DataModelInstance } from "./dataModel";
2
+ import { DataModelInstance } from "./dataModel/dataModel";
3
3
  export class ModelInstance {
4
4
  constructor() {
5
5
  this.canvasModel = new CanvasModel();
6
6
  this.dataModel = new DataModelInstance();
7
7
  }
8
- static create(config) {
8
+ static create(config, data) {
9
9
  const modelInstance = new ModelInstance();
10
- this.initInitialParams(modelInstance, config);
10
+ this.initInitialParams(modelInstance, config, data);
11
11
  return modelInstance;
12
12
  }
13
- static initInitialParams(modelInstance, config) {
13
+ static initInitialParams(modelInstance, config, data) {
14
14
  modelInstance.canvasModel.initBlockSize(config.canvas.size);
15
15
  modelInstance.dataModel.initMaxRecordsAmount(config.options.data.maxRecordsAmount);
16
+ modelInstance.dataModel.repository.initSourceName(config.options.data.dataSource);
17
+ modelInstance.dataModel.repository.initRawFullSource(data);
16
18
  }
17
19
  }
@@ -1,7 +1,7 @@
1
1
  export const AGGREGATOR_DEFAULT_TITLE = "Сумма";
2
2
  export class DonutAggregatorService {
3
3
  getContent(aggregatorOptions, dataOptions) {
4
- if (!(aggregatorOptions === null || aggregatorOptions === void 0 ? void 0 : aggregatorOptions.content))
4
+ if (!(aggregatorOptions === null || aggregatorOptions === void 0 ? void 0 : aggregatorOptions.content) || !dataOptions.rows)
5
5
  return this.generateDefaultContent(dataOptions);
6
6
  const content = aggregatorOptions.content({ data: dataOptions.rows });
7
7
  if (this.doesValueExist(content.value) && content.title)
@@ -19,7 +19,7 @@ export class DonutAggregatorService {
19
19
  generateDefaultContent(dataOptions) {
20
20
  return {
21
21
  title: AGGREGATOR_DEFAULT_TITLE,
22
- value: dataOptions.rows.reduce((acc, row) => acc + row[dataOptions.valueFieldName], 0)
22
+ value: dataOptions.rows ? dataOptions.rows.reduce((acc, row) => acc + row[dataOptions.valueFieldName], 0) : 0
23
23
  };
24
24
  }
25
25
  }
@@ -4,7 +4,7 @@ import { DonutChartSettings } from "../../../model";
4
4
  export declare class DonutModel {
5
5
  private thicknessService;
6
6
  private aggregatorService;
7
- getSettings(settingsFromConfig: DonutOptionsCanvas, chartOptions: PolarChart, dataRows: MdtChartsDataRow[]): DonutChartSettings;
7
+ getSettings(settingsFromConfig: DonutOptionsCanvas, chartOptions: PolarChart, rawDataRows: MdtChartsDataRow[]): DonutChartSettings;
8
8
  private getThicknessOptions;
9
9
  private getAggregatorOptions;
10
10
  }
@@ -5,11 +5,11 @@ export class DonutModel {
5
5
  this.thicknessService = new DonutThicknessService();
6
6
  this.aggregatorService = new DonutAggregatorService();
7
7
  }
8
- getSettings(settingsFromConfig, chartOptions, dataRows) {
8
+ getSettings(settingsFromConfig, chartOptions, rawDataRows) {
9
9
  return {
10
10
  padAngle: settingsFromConfig.padAngle,
11
11
  thickness: this.getThicknessOptions(settingsFromConfig.thickness),
12
- aggregator: this.getAggregatorOptions(settingsFromConfig, chartOptions, dataRows)
12
+ aggregator: this.getAggregatorOptions(settingsFromConfig, chartOptions, rawDataRows)
13
13
  };
14
14
  }
15
15
  getThicknessOptions(settingsFromConfig) {
@@ -20,11 +20,11 @@ export class DonutModel {
20
20
  value: this.thicknessService.valueToNumber(settingsFromConfig.value),
21
21
  };
22
22
  }
23
- getAggregatorOptions(settingsFromConfig, chartOptions, dataRows) {
23
+ getAggregatorOptions(settingsFromConfig, chartOptions, rawDataRows) {
24
24
  return {
25
25
  margin: settingsFromConfig.aggregatorPad,
26
26
  content: this.aggregatorService.getContent(chartOptions.aggregator, {
27
- rows: dataRows,
27
+ rows: rawDataRows,
28
28
  valueFieldName: chartOptions.data.valueField.name
29
29
  })
30
30
  };
@@ -1,13 +1,12 @@
1
- import { MdtChartsDataSource, MdtChartsPolarOptions } from "../../../config/config";
1
+ import { MdtChartsPolarOptions } from "../../../config/config";
2
2
  import { DesignerConfig } from "../../../designer/designerConfig";
3
3
  import { PolarOptionsModel, LegendCoordinate } from "../../model";
4
4
  import { CanvasModel } from "../../modelInstance/canvasModel/canvasModel";
5
5
  import { ModelInstance } from "../../modelInstance/modelInstance";
6
- /** If donut block has width less than this const, legend change postion from "right" to "bottom" */
7
6
  export declare const MIN_DONUT_BLOCK_SIZE = 120;
8
7
  export declare class PolarModel {
9
8
  private static donutModel;
10
- static getOptions(options: MdtChartsPolarOptions, data: MdtChartsDataSource, designerConfig: DesignerConfig, modelInstance: ModelInstance): PolarOptionsModel;
9
+ static getOptions(options: MdtChartsPolarOptions, designerConfig: DesignerConfig, modelInstance: ModelInstance): PolarOptionsModel;
11
10
  static getLegendPositionByBlockSize(canvasModel: CanvasModel): "bottom" | "right";
12
11
  static doesChartBlockHasEnoughWidthForContainsLegend(chartBlockWidth: number, legendWidth: number, legendCoordinate: LegendCoordinate): boolean;
13
12
  static doesChartBlockHasEnoughHeightForContainsLegend(chartBlockHeight: number, legendCoordinate: LegendCoordinate): boolean;
@@ -1,19 +1,17 @@
1
1
  import { ChartStyleModelService } from "../../chartStyleModel/chartStyleModel";
2
2
  import { DonutModel } from "./donut/donutModel";
3
- /** If donut block has width less than this const, legend change postion from "right" to "bottom" */
4
3
  export const MIN_DONUT_BLOCK_SIZE = 120;
5
4
  export class PolarModel {
6
- static getOptions(options, data, designerConfig, modelInstance) {
7
- const dataRows = data[options.data.dataSource];
5
+ static getOptions(options, designerConfig, modelInstance) {
8
6
  return {
9
7
  type: options.type,
10
8
  selectable: !!options.selectable,
11
9
  title: options.title,
12
10
  data: Object.assign({}, options.data),
13
- charts: this.getChartsModel(options.chart, dataRows.length, designerConfig.chartStyle),
11
+ charts: this.getChartsModel(options.chart, modelInstance.dataModel.repository.getScopedRows().length, designerConfig.chartStyle),
14
12
  legend: modelInstance.canvasModel.legendCanvas.getModel(),
15
13
  tooltip: options.tooltip,
16
- chartCanvas: this.getDonutSettings(designerConfig.canvas.chartOptions.donut, options.chart, dataRows)
14
+ chartCanvas: this.getDonutSettings(designerConfig.canvas.chartOptions.donut, options.chart, modelInstance.dataModel.repository.getRawRows())
17
15
  };
18
16
  }
19
17
  //TODO: type for returned value
@@ -1,9 +1,9 @@
1
1
  import { ChartOrientation, MdtChartsDataSource, MdtChartsTwoDimensionalChart, MdtChartsTwoDimensionalOptions } from "../../config/config";
2
2
  import { BarOptionsCanvas, DesignerConfig } from "../../designer/designerConfig";
3
- import { DataScope, TwoDimensionalOptionsModel, TwoDimChartElementsSettings } from "../model";
3
+ import { TwoDimensionalOptionsModel, TwoDimChartElementsSettings } from "../model";
4
4
  import { ModelInstance } from "../modelInstance/modelInstance";
5
5
  export declare class TwoDimensionalModel {
6
- static getOptions(options: MdtChartsTwoDimensionalOptions, designerConfig: DesignerConfig, dataScope: DataScope, data: MdtChartsDataSource, modelInstance: ModelInstance): TwoDimensionalOptionsModel;
6
+ static getOptions(options: MdtChartsTwoDimensionalOptions, designerConfig: DesignerConfig, data: MdtChartsDataSource, modelInstance: ModelInstance): TwoDimensionalOptionsModel;
7
7
  static getChartsEmbeddedLabelsFlag(charts: MdtChartsTwoDimensionalChart[], chartOrientation: ChartOrientation): boolean;
8
8
  /**
9
9
  * Сортирует список чартов в порядке: area - bar - line.
@@ -3,7 +3,7 @@ import { TwoDimensionalChartStyleModel } from "../chartStyleModel/TwoDimensional
3
3
  import { AxisModel } from "../featuresModel/axisModel";
4
4
  import { ScaleModel } from "../featuresModel/scaleModel";
5
5
  export class TwoDimensionalModel {
6
- static getOptions(options, designerConfig, dataScope, data, modelInstance) {
6
+ static getOptions(options, designerConfig, data, modelInstance) {
7
7
  const canvasModel = modelInstance.canvasModel;
8
8
  return {
9
9
  legend: canvasModel.legendCanvas.getModel(),
@@ -11,7 +11,7 @@ export class TwoDimensionalModel {
11
11
  selectable: !!options.selectable,
12
12
  orient: options.orientation,
13
13
  scale: {
14
- key: ScaleModel.getScaleKey(dataScope.allowableKeys, options.orientation, canvasModel, options.charts, this.getChartsByType(options.charts, 'bar')),
14
+ key: ScaleModel.getScaleKey(modelInstance.dataModel.getAllowableKeys(), options.orientation, canvasModel, options.charts, this.getChartsByType(options.charts, 'bar')),
15
15
  value: ScaleModel.getScaleLinear(options, data, canvasModel)
16
16
  },
17
17
  axis: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.12.3",
3
+ "version": "1.12.4",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {