mdt-charts 1.14.0 → 1.15.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.
@@ -20,6 +20,7 @@ interface Canvas {
20
20
  chartBlockMargin: BlockMargin;
21
21
  legendBlock: LegendBlockCanvas;
22
22
  chartOptions: ChartOptionsCanvas;
23
+ markers?: MarkerCanvas;
23
24
  }
24
25
  export interface AxisLabelCanvas {
25
26
  maxSize: AxisLabelSize;
@@ -33,6 +34,15 @@ interface BlockMargin {
33
34
  left: number;
34
35
  right: number;
35
36
  }
37
+ interface MarkerCanvas {
38
+ highlighted?: {
39
+ radius?: number;
40
+ };
41
+ normal?: {
42
+ radius?: number;
43
+ borderSize?: number;
44
+ };
45
+ }
36
46
  export interface LegendBlockCanvas {
37
47
  maxWidth: number | string;
38
48
  static?: StaticLegendBlockCanvas;
@@ -2,7 +2,7 @@ import { Selection, BaseType } from 'd3-selection';
2
2
  import { PieArcDatum } from 'd3-shape';
3
3
  import { BlockMargin, TwoDimensionalChartModel } from "../../model/model";
4
4
  import { Block } from "../block/block";
5
- import { MdtChartsDataRow, Size, TwoDimensionalChartType } from '../../config/config';
5
+ import { MdtChartsDataRow, Size } from '../../config/config';
6
6
  export declare class ElementHighlighter {
7
7
  private static inactiveElemClass;
8
8
  static toggleActivityStyle(elementSelection: Selection<BaseType, unknown, BaseType, unknown>, isActive: boolean): void;
@@ -21,7 +21,7 @@ export declare class ElementHighlighter {
21
21
  static toggleMarkDotVisible(markDots: Selection<BaseType, any, BaseType, any>, isHighlight: boolean): void;
22
22
  static remove2DChartsFullHighlighting(block: Block, charts: TwoDimensionalChartModel[], transitionDuration?: number): void;
23
23
  static removeUnselected2DHighlight(block: Block, keyFieldName: string, charts: TwoDimensionalChartModel[], transitionDuration: number): void;
24
- static toggle2DElements(elemSelection: Selection<BaseType, any, BaseType, any>, isHighlight: boolean, chartType: TwoDimensionalChartType, transitionDuration: number): void;
24
+ static toggle2DElements(elemSelection: Selection<BaseType, any, BaseType, any>, isHighlight: boolean, chart: TwoDimensionalChartModel, transitionDuration: number): void;
25
25
  private static makeArcClone;
26
26
  private static makeArcShadow;
27
27
  private static renderDonutSegmentClone;
@@ -94,7 +94,7 @@ export class ElementHighlighter {
94
94
  const elems = DomHelper.get2DChartElements(block, chart);
95
95
  if (chart.type !== 'bar' && !chart.markersOptions.show)
96
96
  elems.classed(MarkDot.hiddenDotClass, true);
97
- this.toggle2DElements(elems, false, chart.type, transitionDuration);
97
+ this.toggle2DElements(elems, false, chart, transitionDuration);
98
98
  this.toggleActivityStyle(elems, true);
99
99
  });
100
100
  }
@@ -104,14 +104,14 @@ export class ElementHighlighter {
104
104
  const selectedElems = DomHelper.getChartElementsByKeys(elems, chart.isSegmented, keyFieldName, block.filterEventManager.getSelectedKeys(), SelectionCondition.Exclude);
105
105
  if (chart.type !== 'bar' && !chart.markersOptions.show)
106
106
  selectedElems.classed(MarkDot.hiddenDotClass, true);
107
- this.toggle2DElements(selectedElems, false, chart.type, transitionDuration);
107
+ this.toggle2DElements(selectedElems, false, chart, transitionDuration);
108
108
  if (block.filterEventManager.getSelectedKeys().length > 0)
109
109
  this.toggleActivityStyle(selectedElems, false);
110
110
  });
111
111
  }
112
- static toggle2DElements(elemSelection, isHighlight, chartType, transitionDuration) {
113
- if (chartType === 'area' || chartType === 'line') {
114
- elemSelection.call(this.toggleDot, isHighlight, transitionDuration);
112
+ static toggle2DElements(elemSelection, isHighlight, chart, transitionDuration) {
113
+ if (chart.type === 'area' || chart.type === 'line') {
114
+ elemSelection.call(this.toggleDot, isHighlight, chart.markersOptions.styles, transitionDuration);
115
115
  }
116
116
  else {
117
117
  this.toggleBar(elemSelection, isHighlight);
@@ -175,7 +175,7 @@ export class ElementHighlighter {
175
175
  });
176
176
  }
177
177
  }
178
- static toggleDot(elementSelection, isScaled, transitionDuration = 0) {
178
+ static toggleDot(elementSelection, isScaled, styles, transitionDuration = 0) {
179
179
  const animationName = 'size-scale';
180
180
  elementSelection.nodes().forEach(node => {
181
181
  interrupt(node, animationName);
@@ -189,8 +189,8 @@ export class ElementHighlighter {
189
189
  .ease(easeLinear);
190
190
  }
191
191
  elementsHandler
192
- .attr('r', isScaled ? 5 : 4)
193
- .style('stroke-width', (isScaled ? 3.5 : 3) + 'px')
192
+ .attr('r', isScaled ? styles.highlighted.size.radius : styles.normal.size.radius)
193
+ .style('stroke-width', isScaled ? styles.highlighted.size.borderSize : styles.normal.size.borderSize)
194
194
  .each(function () {
195
195
  select(this).style('fill', isScaled ? select(this).style('stroke') : 'white');
196
196
  });
@@ -10,7 +10,7 @@ export class SelectHighlighter {
10
10
  const selectedElements = DomHelper.getChartElementsByKeys(DomHelper.get2DChartElements(block, chart), chart.isSegmented, options.data.keyField.name, [keyValue]);
11
11
  const elements = DomHelper.get2DChartElements(block, chart);
12
12
  if (!appendKey) {
13
- ElementHighlighter.toggle2DElements(selectedElements, false, chart.type, block.transitionManager.durations.markerHover);
13
+ ElementHighlighter.toggle2DElements(selectedElements, false, chart, block.transitionManager.durations.markerHover);
14
14
  if (chart.type !== 'bar' && !chart.markersOptions.show)
15
15
  ElementHighlighter.toggleMarkDotVisible(selectedElements, false);
16
16
  if (selectedKeys.length > 0) {
@@ -24,17 +24,17 @@ export class SelectHighlighter {
24
24
  return;
25
25
  }
26
26
  if (multySelection) {
27
- ElementHighlighter.toggle2DElements(selectedElements, true, chart.type, block.transitionManager.durations.markerHover);
27
+ ElementHighlighter.toggle2DElements(selectedElements, true, chart, block.transitionManager.durations.markerHover);
28
28
  ElementHighlighter.toggleActivityStyle(selectedElements, true);
29
29
  ElementHighlighter.toggleActivityStyle(DomHelper.getChartElementsByKeys(elements, chart.isSegmented, options.data.keyField.name, selectedKeys, SelectionCondition.Exclude), false);
30
30
  }
31
31
  else {
32
- ElementHighlighter.toggle2DElements(DomHelper.getChartElementsByKeys(elements, chart.isSegmented, options.data.keyField.name, selectedKeys, SelectionCondition.Exclude), false, chart.type, block.transitionManager.durations.markerHover);
32
+ ElementHighlighter.toggle2DElements(DomHelper.getChartElementsByKeys(elements, chart.isSegmented, options.data.keyField.name, selectedKeys, SelectionCondition.Exclude), false, chart, block.transitionManager.durations.markerHover);
33
33
  ElementHighlighter.toggleActivityStyle(elements, false);
34
34
  if (chart.type !== 'bar' && !chart.markersOptions.show)
35
35
  ElementHighlighter.toggleMarkDotVisible(elements, false);
36
36
  ElementHighlighter.toggleActivityStyle(selectedElements, true);
37
- ElementHighlighter.toggle2DElements(selectedElements, true, chart.type, block.transitionManager.durations.markerHover);
37
+ ElementHighlighter.toggle2DElements(selectedElements, true, chart, block.transitionManager.durations.markerHover);
38
38
  }
39
39
  if (chart.type !== 'bar' && !chart.markersOptions.show)
40
40
  ElementHighlighter.toggleMarkDotVisible(selectedElements, true);
@@ -76,7 +76,7 @@ export class SelectHighlighter {
76
76
  static clear2D(block, options) {
77
77
  options.charts.forEach(chart => {
78
78
  const elements = DomHelper.get2DChartElements(block, chart);
79
- ElementHighlighter.toggle2DElements(elements, false, chart.type, block.transitionManager.durations.markerHover);
79
+ ElementHighlighter.toggle2DElements(elements, false, chart, block.transitionManager.durations.markerHover);
80
80
  ElementHighlighter.toggleActivityStyle(elements, true);
81
81
  if (chart.type !== 'bar' && !chart.markersOptions.show)
82
82
  ElementHighlighter.toggleMarkDotVisible(elements, false);
@@ -90,7 +90,7 @@ export class Legend {
90
90
  .attr('class', options.itemsOptions.labelClass)
91
91
  .text(d => d.textContent);
92
92
  if (options.shouldCropLabels)
93
- LegendDomHelper.cropRowLabels(foreignObject, itemWrappers);
93
+ LegendDomHelper.decreaseRowLabels(foreignObject, itemWrappers, options.blockModel.static);
94
94
  return itemWrappers;
95
95
  }
96
96
  getObject(block) {
@@ -13,7 +13,9 @@ function getNewWidths(collection, wrapper) {
13
13
  let avgExtra = extra / biggerThanAvg.length;
14
14
  biggerThanAvg.forEach((item, index) => {
15
15
  const avgDiff = item.getCurrentWidth() - avgWidth;
16
- const decreaseBy = avgDiff < avgExtra ? avgDiff : avgExtra;
16
+ const decreaseBy = index === biggerThanAvg.length - 1
17
+ ? extra
18
+ : (avgDiff < avgExtra ? avgDiff : avgExtra);
17
19
  item.decreaseBy(decreaseBy);
18
20
  extra -= decreaseBy;
19
21
  avgExtra = extra / (biggerThanAvg.length - index - 1);
@@ -25,7 +27,7 @@ function fixWidthsByLinePos(collection, wrapper) {
25
27
  let currentRow = [];
26
28
  collection.items.forEach((item, i) => {
27
29
  const currentRowSum = currentRow.reduce((acc, i) => acc + i.getCurrentTotalWidth(), 0);
28
- if (currentRowSum + item.getWidthWithoutRightMargin() <= wrapper.getWidthOfOneLine()) {
30
+ if (currentRowSum + item.getCurrentTotalWidth() <= wrapper.getWidthOfOneLine()) {
29
31
  currentRow.push(item);
30
32
  }
31
33
  else {
@@ -43,11 +45,13 @@ function fixWidthsByLinePos(collection, wrapper) {
43
45
  const bottom = byRows[i + 1];
44
46
  const topFreeSpace = wrapper.getWidthOfOneLine() - top.getTotalWidth();
45
47
  const firstOfBottom = bottom.getFirstItem();
46
- if (topFreeSpace / firstOfBottom.getCurrentTotalWidth() > 0.51 || i === byRows.length - 2) {
48
+ if (i === byRows.length - 2)
49
+ top.pushMany(bottom.shiftAll());
50
+ else if (topFreeSpace / firstOfBottom.getCurrentTotalWidth() > 0.5) {
47
51
  const fromBottom = bottom.shift();
48
52
  top.push(fromBottom);
49
- result.push(...getNewWidths(top, new LegendWrapper({ maxRowsAmount: 1, width: wrapper.getWidthOfOneLine() })));
50
53
  }
54
+ result.push(...getNewWidths(top, new LegendWrapper({ maxRowsAmount: 1, width: wrapper.getWidthOfOneLine() })));
51
55
  }
52
56
  return result;
53
57
  }
@@ -80,11 +84,14 @@ class LegendItem {
80
84
  this.width -= by;
81
85
  }
82
86
  getCurrentWidth() {
83
- return this.width;
87
+ return Math.round(this.width * 100) / 100;
84
88
  }
85
89
  getTotalMarginSize() {
86
90
  return this.config.marginLeft + this.config.marginRight;
87
91
  }
92
+ resetWidthToOriginal() {
93
+ this.width = this.config.width;
94
+ }
88
95
  }
89
96
  class LegendItemCollection {
90
97
  constructor(items) {
@@ -113,7 +120,17 @@ class LegendItemCollection {
113
120
  shift() {
114
121
  return this.items.shift();
115
122
  }
123
+ shiftAll() {
124
+ return this.items.splice(0, this.items.length);
125
+ }
116
126
  push(item) {
117
127
  this.items.push(item);
118
128
  }
129
+ pushMany(items) {
130
+ this.items.push(...items);
131
+ }
132
+ resetItemsToOriginalWidth() {
133
+ this.items.forEach(item => item.resetWidthToOriginal());
134
+ return this;
135
+ }
119
136
  }
@@ -10,7 +10,6 @@ export interface DotAttrs {
10
10
  export declare class MarkDot {
11
11
  static readonly markerDotClass: string;
12
12
  static readonly hiddenDotClass: string;
13
- private static dotRadius;
14
13
  static render(block: Block, data: MdtChartsDataRow[], keyAxisOrient: Orient, scales: Scales, margin: BlockMargin, keyFieldName: string, vfIndex: number, valueFieldName: string, chart: TwoDimensionalChartModel): void;
15
14
  static update(block: Block, newData: MdtChartsDataRow[], keyAxisOrient: Orient, scales: Scales, margin: BlockMargin, keyField: string, vfIndex: number, valueFieldName: string, chart: TwoDimensionalChartModel): void;
16
15
  static updateColors(block: Block, chart: TwoDimensionalChartModel, valueFieldIndex: number): void;
@@ -13,7 +13,7 @@ export class MarkDot {
13
13
  .enter();
14
14
  const attrs = MarkDotHelper.getDotAttrs(keyAxisOrient, scales, margin, keyFieldName, valueFieldName, chart.isSegmented);
15
15
  const dots = dotsWrapper.append('circle');
16
- this.setAttrs(block, dots, attrs);
16
+ this.setAttrs(block, dots, attrs, chart.markersOptions.styles);
17
17
  this.setClassesAndStyle(dots, chart.cssClasses, vfIndex, chart.style.elementColors);
18
18
  if (!chart.markersOptions.show)
19
19
  dots.classed(this.hiddenDotClass, true);
@@ -27,7 +27,7 @@ export class MarkDot {
27
27
  const newDots = dots
28
28
  .enter()
29
29
  .append('circle');
30
- this.setAttrs(block, newDots, attrs);
30
+ this.setAttrs(block, newDots, attrs, chart.markersOptions.styles);
31
31
  this.setClassesAndStyle(newDots, chart.cssClasses, vfIndex, chart.style.elementColors);
32
32
  if (!chart.markersOptions.show)
33
33
  newDots.classed(this.hiddenDotClass, true);
@@ -52,17 +52,16 @@ export class MarkDot {
52
52
  DomHelper.setCssClasses(dots, Helper.getCssClassesWithElementIndex(cssClasses, vfIndex));
53
53
  DomHelper.setChartElementColor(dots, elementColors, vfIndex, 'stroke');
54
54
  }
55
- static setAttrs(block, dots, attrs) {
55
+ static setAttrs(block, dots, attrs, styles) {
56
56
  dots
57
57
  .attr('class', this.markerDotClass)
58
58
  .attr('cx', d => attrs.cx(d))
59
59
  .attr('cy', d => attrs.cy(d))
60
- .attr('r', this.dotRadius)
61
- .style('stroke-width', '3px')
60
+ .attr('r', styles.normal.size.radius)
61
+ .style('stroke-width', styles.normal.size.borderSize)
62
62
  .style('fill', 'white')
63
63
  .style('clip-path', `url(#${block.svg.getClipPathId()})`);
64
64
  }
65
65
  }
66
66
  MarkDot.markerDotClass = NamesHelper.getClassName('dot');
67
67
  MarkDot.hiddenDotClass = NamesHelper.getClassName('dot-hidden');
68
- MarkDot.dotRadius = 4;
@@ -100,7 +100,7 @@ export class Tooltip {
100
100
  const oldElements = DomHelper.getChartElementsByKeys(elements, chart.isSegmented, args.dataOptions.keyField.name, [currentKey]);
101
101
  if (chart.type !== 'bar' && !chart.markersOptions.show)
102
102
  ElementHighlighter.toggleMarkDotVisible(oldElements, false);
103
- ElementHighlighter.toggle2DElements(oldElements, false, chart.type, block.transitionManager.durations.markerHover);
103
+ ElementHighlighter.toggle2DElements(oldElements, false, chart, block.transitionManager.durations.markerHover);
104
104
  if (block.filterEventManager.getSelectedKeys().length > 0) {
105
105
  ElementHighlighter.toggleActivityStyle(oldElements, false);
106
106
  }
@@ -110,7 +110,7 @@ export class Tooltip {
110
110
  ElementHighlighter.toggleMarkDotVisible(selectedElements, true);
111
111
  ElementHighlighter.toggleActivityStyle(selectedElements, true);
112
112
  if (block.filterEventManager.getSelectedKeys().length === 0 || block.filterEventManager.isSelected(keyValue)) {
113
- ElementHighlighter.toggle2DElements(selectedElements, true, chart.type, block.transitionManager.durations.markerHover);
113
+ ElementHighlighter.toggle2DElements(selectedElements, true, chart, block.transitionManager.durations.markerHover);
114
114
  }
115
115
  });
116
116
  }
@@ -5,6 +5,7 @@ import { MIN_DONUT_BLOCK_SIZE, PolarModel } from "../notations/polar/polarModel"
5
5
  import { DataManagerModelService } from "./dataManagerModelService";
6
6
  import { LegendPolarMarginCalculator } from "../featuresModel/legendModel/polarMarginCalculator";
7
7
  import { CardsDataManagerModel } from "./notations/cardsDataManagerModel";
8
+ import { styledElementValues } from "../modelBuilder";
8
9
  export class DataManagerModel {
9
10
  static getPreparedData(data, allowableKeys, config) {
10
11
  const scopedData = config.options.type !== "card" ? this.getScopedData(data, allowableKeys, config.options.data) : data;
@@ -83,11 +84,16 @@ export class DataManagerModel {
83
84
  }
84
85
  //TODO: position type
85
86
  static getLegendDataParams(position, keys, legendCanvas, canvasModel, legendBlock) {
87
+ const legendItemContentOptions = keys.map(k => ({
88
+ text: k,
89
+ markerSize: styledElementValues.defaultLegendMarkerSizes,
90
+ wrapperSize: { marginRightPx: styledElementValues.legend.inlineDynamicItemWrapperMarginRightPx }
91
+ }));
86
92
  if (position === 'right') {
87
- return LegendCanvasModel.findElementsAmountByLegendSize(keys, position, this.polarMarginCalculator.getMaxLegendWidth(legendCanvas, canvasModel.getBlockSize().width), canvasModel.getChartBlockHeight() - legendBlock.coordinate.bottom.margin.bottom);
93
+ return LegendCanvasModel.findElementsAmountByLegendSize(legendItemContentOptions, position, this.polarMarginCalculator.getMaxLegendWidth(legendCanvas, canvasModel.getBlockSize().width), canvasModel.getChartBlockHeight() - legendBlock.coordinate.bottom.margin.bottom);
88
94
  }
89
95
  else {
90
- return LegendCanvasModel.findElementsAmountByLegendSize(keys, position, canvasModel.getChartBlockWidth() - legendBlock.coordinate.bottom.margin.left - legendBlock.coordinate.bottom.margin.right, canvasModel.getChartBlockHeight() - legendBlock.coordinate.bottom.margin.bottom - legendBlock.coordinate.bottom.margin.top - MIN_DONUT_BLOCK_SIZE);
96
+ return LegendCanvasModel.findElementsAmountByLegendSize(legendItemContentOptions, position, canvasModel.getChartBlockWidth() - legendBlock.coordinate.bottom.margin.left - legendBlock.coordinate.bottom.margin.right, canvasModel.getChartBlockHeight() - legendBlock.coordinate.bottom.margin.bottom - legendBlock.coordinate.bottom.margin.top - MIN_DONUT_BLOCK_SIZE);
91
97
  }
92
98
  }
93
99
  static getMaximumPossibleScope(keys, dataModel) {
@@ -1,8 +1,19 @@
1
1
  import { DataLegendParams } from "../../dataManagerModel/dataManagerModel";
2
2
  import { LegendPosition } from "../../model";
3
3
  export declare type LegendItemsDirection = 'row' | 'column';
4
+ export interface LegendItemContentOptions {
5
+ text: string;
6
+ markerSize: {
7
+ widthPx: number;
8
+ heightPx: number;
9
+ marginRightPx: number;
10
+ };
11
+ wrapperSize: {
12
+ marginRightPx: number;
13
+ };
14
+ }
4
15
  export declare class LegendCanvasModel {
5
16
  static getLegendItemWidth(text: string): number;
6
- static findElementsAmountByLegendSize(texts: string[], position: LegendPosition, legendBlockWidth: number, legendBlockHeight: number): DataLegendParams;
17
+ static findElementsAmountByLegendSize(items: LegendItemContentOptions[], position: LegendPosition, legendBlockWidth: number, legendBlockHeight: number): DataLegendParams;
7
18
  private static getLegendWrapperEl;
8
19
  }
@@ -18,31 +18,37 @@ export class LegendCanvasModel {
18
18
  itemWrapper.remove();
19
19
  return sumWidth;
20
20
  }
21
- static findElementsAmountByLegendSize(texts, position, legendBlockWidth, legendBlockHeight) {
21
+ //TODO: find better solution
22
+ static findElementsAmountByLegendSize(items, position, legendBlockWidth, legendBlockHeight) {
22
23
  const legendWrapper = this.getLegendWrapperEl(legendBlockWidth, position === "right" ? "column" : "row");
23
24
  document.body.append(legendWrapper);
24
25
  let amount = 0;
25
- for (let i = 0; i < texts.length; i++) {
26
+ for (let i = 0; i < items.length; i++) {
26
27
  const itemWrapper = document.createElement('div');
27
28
  const colorBlock = document.createElement('span');
28
29
  const textBlock = document.createElement('span');
29
30
  itemWrapper.classList.add("legend-item");
30
- if (position === 'bottom') {
31
+ if (position === 'bottom' || position === 'top') {
31
32
  itemWrapper.classList.add('legend-item-inline');
32
33
  textBlock.classList.add('legend-label-nowrap');
33
34
  }
34
35
  else {
35
36
  itemWrapper.classList.add('legend-item-row');
36
37
  }
37
- colorBlock.classList.add(CLASSES.legendColor);
38
+ // colorBlock.classList.add(CLASSES.legendColor);
39
+ colorBlock.style.display = "inline-block";
40
+ colorBlock.style.width = `${items[i].markerSize.widthPx}px`;
41
+ colorBlock.style.height = `${items[i].markerSize.heightPx}px`;
42
+ colorBlock.style.marginRight = `${items[i].markerSize.marginRightPx}px`;
38
43
  textBlock.classList.add(CLASSES.legendLabel);
39
- textBlock.textContent = texts[i];
44
+ textBlock.textContent = items[i].text;
45
+ itemWrapper.style.marginRight = `${items[i].wrapperSize.marginRightPx}px`;
40
46
  itemWrapper.append(colorBlock, textBlock);
41
47
  legendWrapper.append(itemWrapper);
42
48
  amount++;
43
49
  if (legendWrapper.offsetHeight > legendBlockHeight) {
44
50
  itemWrapper.remove();
45
- if (legendBlockHeight - legendWrapper.offsetHeight >= 15 && position !== 'bottom')
51
+ if (legendBlockHeight - legendWrapper.offsetHeight >= 15 && position !== 'bottom' && position !== 'top')
46
52
  amount = amount; //TODO: remove
47
53
  else
48
54
  amount -= 1;
@@ -1,8 +1,11 @@
1
1
  import { Legend } from "../../../config/config";
2
2
  import { LegendBlockModel } from "../../model";
3
+ import { TwoDimConfigReader } from "../../modelInstance/configReader";
3
4
  import { ModelInstance } from "../../modelInstance/modelInstance";
4
5
  export declare class TwoDimLegendModel {
6
+ private configReader;
7
+ constructor(configReader: TwoDimConfigReader);
5
8
  recalcMarginWith2DLegend(modelInstance: ModelInstance, legendBlockModel: LegendBlockModel, legendOptions: Legend): void;
6
- private getLegendSize;
9
+ private getLegendSizeLegacy;
7
10
  private getLegendModel;
8
11
  }
@@ -1,18 +1,29 @@
1
+ import { styledElementValues } from "../../modelBuilder";
2
+ import { getWidthOfLegendMarkerByType } from "../../notations/twoDimensional/styles";
3
+ import { LegendCanvasModel } from "./legendCanvasModel";
1
4
  import { LegendModel } from "./legendModel";
2
5
  export class TwoDimLegendModel {
6
+ constructor(configReader) {
7
+ this.configReader = configReader;
8
+ }
3
9
  recalcMarginWith2DLegend(modelInstance, legendBlockModel, legendOptions) {
4
10
  const canvasModel = modelInstance.canvasModel;
5
11
  const legendPosition = this.getLegendModel(legendOptions).position;
6
12
  modelInstance.canvasModel.legendCanvas.setPosition(legendPosition);
7
13
  if (legendPosition !== 'off') {
8
- const legendSize = this.getLegendSize();
14
+ const legendItemInfo = this.configReader.getLegendItemInfo();
15
+ const legendSize = LegendCanvasModel.findElementsAmountByLegendSize(legendItemInfo.map(i => ({
16
+ text: i.text,
17
+ markerSize: Object.assign(Object.assign({}, styledElementValues.defaultLegendMarkerSizes), { widthPx: getWidthOfLegendMarkerByType(i.chartType) }),
18
+ wrapperSize: { marginRightPx: styledElementValues.legend.inlineItemWrapperMarginRightPx }
19
+ })), 'top', modelInstance.canvasModel.getBlockSize().width, legendBlockModel.static.maxLinesAmount * styledElementValues.legend.inlineLegendOneLineHeightPx).size.height;
9
20
  canvasModel.increaseMarginSide(legendPosition, legendSize);
10
21
  if (legendSize !== 0)
11
22
  LegendModel.appendToGlobalMarginValuesLegendMargin(canvasModel, legendPosition, legendBlockModel);
12
23
  legendBlockModel.coordinate[legendPosition].size = legendSize;
13
24
  }
14
25
  }
15
- getLegendSize() {
26
+ getLegendSizeLegacy() {
16
27
  const heightOfLegendItemWithoutWordWrapping = 20;
17
28
  return heightOfLegendItemWithoutWordWrapping;
18
29
  }
@@ -9,7 +9,7 @@ export class TwoDimMarginModel {
9
9
  constructor(designerConfig, configReader) {
10
10
  this.designerConfig = designerConfig;
11
11
  this.configReader = configReader;
12
- this.twoDimLegendModel = new TwoDimLegendModel();
12
+ this.twoDimLegendModel = new TwoDimLegendModel(this.configReader);
13
13
  }
14
14
  recalcMargin(otherComponents, modelInstance) {
15
15
  const canvasModel = modelInstance.canvasModel;
@@ -265,6 +265,18 @@ export interface ValueField extends Field {
265
265
  }
266
266
  export interface MarkersOptions {
267
267
  show: boolean;
268
+ styles: MarkersStyleOptions;
269
+ }
270
+ export interface MarkersStyleOptions {
271
+ highlighted: MarkerStyle;
272
+ normal: MarkerStyle;
273
+ }
274
+ interface MarkerStyle {
275
+ size: MarkersBaseSizeOptions;
276
+ }
277
+ interface MarkersBaseSizeOptions {
278
+ radius: number;
279
+ borderSize: string;
268
280
  }
269
281
  interface IntervalChartDataModel {
270
282
  valueField1: ValueField;
@@ -11,5 +11,17 @@ export declare const CLASSES: {
11
11
  legendColor: string;
12
12
  legendItem: string;
13
13
  };
14
+ export declare const styledElementValues: {
15
+ defaultLegendMarkerSizes: {
16
+ widthPx: number;
17
+ heightPx: number;
18
+ marginRightPx: number;
19
+ };
20
+ legend: {
21
+ inlineLegendOneLineHeightPx: number;
22
+ inlineItemWrapperMarginRightPx: number;
23
+ inlineDynamicItemWrapperMarginRightPx: number;
24
+ };
25
+ };
14
26
  export declare function assembleModel(config: MdtChartsConfig, data: MdtChartsDataSource, designerConfig: DesignerConfig): Model;
15
27
  export declare function getPreparedData(model: Model, data: MdtChartsDataSource, config: MdtChartsConfig): MdtChartsDataSource;
@@ -2,7 +2,6 @@ import { MarginModel } from './margin/marginModel';
2
2
  import { TwoDimensionalModel } from './notations/twoDimensionalModel';
3
3
  import { PolarModel } from './notations/polar/polarModel';
4
4
  import { DataManagerModel } from './dataManagerModel/dataManagerModel';
5
- import { IntervalModel } from './notations/intervalModel';
6
5
  import { OtherComponentsModel } from './featuresModel/otherComponents';
7
6
  import { ConfigValidator } from './configsValidator/configValidator';
8
7
  import { ModelInstance } from './modelInstance/modelInstance';
@@ -19,6 +18,18 @@ export const CLASSES = {
19
18
  legendColor: 'legend-circle',
20
19
  legendItem: 'legend-item',
21
20
  };
21
+ export const styledElementValues = {
22
+ defaultLegendMarkerSizes: {
23
+ widthPx: 11,
24
+ heightPx: 11,
25
+ marginRightPx: 6
26
+ },
27
+ legend: {
28
+ inlineLegendOneLineHeightPx: 21,
29
+ inlineItemWrapperMarginRightPx: 12,
30
+ inlineDynamicItemWrapperMarginRightPx: 2
31
+ }
32
+ };
22
33
  function getBlockCanvas(config, modelInstance) {
23
34
  const emptyBlockParams = { width: 0, height: 0 };
24
35
  const size = ConfigValidator.validateCanvasSize(modelInstance.canvasModel.getBlockSize()) ? Object.assign({}, modelInstance.canvasModel.getBlockSize()) : emptyBlockParams;
@@ -40,9 +51,6 @@ function getOptions(config, designerConfig, modelInstance) {
40
51
  else if (config.options.type === 'polar') {
41
52
  return PolarModel.getOptions(config.options, designerConfig, modelInstance);
42
53
  }
43
- else if (config.options.type === 'interval') {
44
- return IntervalModel.getOptions(config.options, designerConfig, modelInstance);
45
- }
46
54
  else if (config.options.type === "card") {
47
55
  return CardsModelInstance.getOptions(config.options, modelInstance);
48
56
  }
@@ -1,4 +1,4 @@
1
- import { AxisLabelFormatter, MdtChartsConfig, MdtChartsField, MdtChartsTwoDimensionalOptions } from "../../config/config";
1
+ import { AxisLabelFormatter, MdtChartsConfig, MdtChartsField, MdtChartsTwoDimensionalOptions, TwoDimensionalChartType } from "../../config/config";
2
2
  import { DesignerConfig } from "../../designer/designerConfig";
3
3
  interface BaseConfigReader {
4
4
  getValueFields(): MdtChartsField[];
@@ -10,6 +10,10 @@ export declare class TwoDimConfigReader implements BaseConfigReader {
10
10
  constructor(config: MdtChartsConfig, designerConfig: DesignerConfig);
11
11
  getValueFields(): MdtChartsField[];
12
12
  getAxisLabelFormatter(): AxisLabelFormatter;
13
+ getLegendItemInfo(): {
14
+ text: string;
15
+ chartType: TwoDimensionalChartType;
16
+ }[];
13
17
  }
14
18
  export declare class PolarConfigReader implements BaseConfigReader {
15
19
  private options;
@@ -24,6 +24,16 @@ export class TwoDimConfigReader {
24
24
  const valueFieldFormat = this.options.charts[0].data.valueFields[0].format;
25
25
  return (v) => this.designerConfig.dataFormat.formatters(v, { type: valueFieldFormat });
26
26
  }
27
+ getLegendItemInfo() {
28
+ const info = [];
29
+ this.options.charts.forEach(c => {
30
+ c.data.valueFields.forEach(vf => {
31
+ var _a;
32
+ info.push({ text: (_a = vf.title) !== null && _a !== void 0 ? _a : vf.name, chartType: c.type });
33
+ });
34
+ });
35
+ return info;
36
+ }
27
37
  }
28
38
  export class PolarConfigReader {
29
39
  constructor(config) {
@@ -1,6 +1,7 @@
1
1
  import { ChartLegendModel, LineLikeChartDashOptions, LineLikeChartShapeOptions } from "../../model";
2
- import { ChartOrientation, MdtChartsLineLikeChartDashedStyles, MdtChartsTwoDimensionalChart } from "../../../config/config";
2
+ import { ChartOrientation, MdtChartsLineLikeChartDashedStyles, MdtChartsTwoDimensionalChart, TwoDimensionalChartType } from "../../../config/config";
3
3
  import { MdtChartsLineLikeChartShape } from "../../../designer/designerConfig";
4
4
  export declare function parseShape(chartOrientation: ChartOrientation, configOptions?: MdtChartsLineLikeChartShape): LineLikeChartShapeOptions;
5
5
  export declare function parseDashStyles(configOptions?: MdtChartsLineLikeChartDashedStyles): LineLikeChartDashOptions;
6
6
  export declare function getLegendMarkerOptions(chart: MdtChartsTwoDimensionalChart): ChartLegendModel;
7
+ export declare function getWidthOfLegendMarkerByType(chartType: TwoDimensionalChartType): number;
@@ -1,4 +1,5 @@
1
1
  import { LineCurveType } from "../../model";
2
+ import { styledElementValues } from "../../modelBuilder";
2
3
  export function parseShape(chartOrientation, configOptions) {
3
4
  var _a;
4
5
  const curveType = (_a = configOptions === null || configOptions === void 0 ? void 0 : configOptions.curve) === null || _a === void 0 ? void 0 : _a.type;
@@ -35,7 +36,15 @@ export function getLegendMarkerOptions(chart) {
35
36
  };
36
37
  return {
37
38
  markerShape: shapeByType[chart.type],
38
- barViewOptions: { hatch: { on: (_c = (_b = (_a = chart.barStyles) === null || _a === void 0 ? void 0 : _a.hatch) === null || _b === void 0 ? void 0 : _b.on) !== null && _c !== void 0 ? _c : false }, width: 10 },
39
- lineViewOptions: { dashedStyles: parseDashStyles((_d = chart.lineStyles) === null || _d === void 0 ? void 0 : _d.dash), width: 30 }
39
+ barViewOptions: { hatch: { on: (_c = (_b = (_a = chart.barStyles) === null || _a === void 0 ? void 0 : _a.hatch) === null || _b === void 0 ? void 0 : _b.on) !== null && _c !== void 0 ? _c : false }, width: getWidthOfLegendMarkerByType("bar") },
40
+ lineViewOptions: { dashedStyles: parseDashStyles((_d = chart.lineStyles) === null || _d === void 0 ? void 0 : _d.dash), width: getWidthOfLegendMarkerByType("line") }
40
41
  };
41
42
  }
43
+ export function getWidthOfLegendMarkerByType(chartType) {
44
+ if (chartType === "bar")
45
+ return 10;
46
+ if (chartType === "line")
47
+ return 30;
48
+ if (chartType === "area")
49
+ return styledElementValues.defaultLegendMarkerSizes.widthPx;
50
+ }
@@ -28,7 +28,7 @@ export class TwoDimensionalModel {
28
28
  },
29
29
  type: options.type,
30
30
  data: Object.assign({}, options.data),
31
- charts: this.getChartsModel(options.charts, options.orientation, designerConfig.chartStyle),
31
+ charts: this.getChartsModel(options.charts, options.orientation, designerConfig),
32
32
  additionalElements: this.getAdditionalElements(options),
33
33
  tooltip: options.tooltip,
34
34
  chartSettings: this.getChartsSettings(designerConfig.canvas.chartOptions, options.orientation)
@@ -56,12 +56,12 @@ export class TwoDimensionalModel {
56
56
  lineLike: { shape: parseShape(chartOrientation, (_a = chartOptions.line) === null || _a === void 0 ? void 0 : _a.shape) }
57
57
  };
58
58
  }
59
- static getChartsModel(charts, chartOrientation, chartStyleConfig) {
60
- const styleModel = new TwoDimensionalChartStyleModel(charts, chartStyleConfig);
59
+ static getChartsModel(charts, chartOrientation, designerConfig) {
60
+ const styleModel = new TwoDimensionalChartStyleModel(charts, designerConfig.chartStyle);
61
61
  this.sortCharts(charts);
62
62
  const chartsModel = [];
63
63
  charts.forEach((chart, index) => {
64
- var _a, _b, _c, _d;
64
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
65
65
  chartsModel.push({
66
66
  type: chart.type,
67
67
  isSegmented: chart.isSegmented,
@@ -70,9 +70,22 @@ export class TwoDimensionalModel {
70
70
  cssClasses: ChartStyleModelService.getCssClasses(index),
71
71
  style: styleModel.getChartStyle(chart, index),
72
72
  embeddedLabels: this.getEmbeddedLabelType(chart, chartOrientation),
73
- markersOptions: chart.markers,
74
- lineViewOptions: { dashedStyles: parseDashStyles((_a = chart.lineStyles) === null || _a === void 0 ? void 0 : _a.dash) },
75
- barViewOptions: { hatch: { on: (_d = (_c = (_b = chart.barStyles) === null || _b === void 0 ? void 0 : _b.hatch) === null || _c === void 0 ? void 0 : _c.on) !== null && _d !== void 0 ? _d : false } },
73
+ markersOptions: {
74
+ show: chart.markers.show,
75
+ styles: {
76
+ highlighted: {
77
+ size: { radius: (_c = (_b = (_a = designerConfig.canvas.markers) === null || _a === void 0 ? void 0 : _a.highlighted) === null || _b === void 0 ? void 0 : _b.radius) !== null && _c !== void 0 ? _c : 4, borderSize: '3.5px' }
78
+ },
79
+ normal: {
80
+ size: {
81
+ radius: (_f = (_e = (_d = designerConfig.canvas.markers) === null || _d === void 0 ? void 0 : _d.normal) === null || _e === void 0 ? void 0 : _e.radius) !== null && _f !== void 0 ? _f : 3,
82
+ borderSize: `${(_j = (_h = (_g = designerConfig.canvas.markers) === null || _g === void 0 ? void 0 : _g.normal) === null || _h === void 0 ? void 0 : _h.borderSize) !== null && _j !== void 0 ? _j : 2}px`
83
+ }
84
+ }
85
+ }
86
+ },
87
+ lineViewOptions: { dashedStyles: parseDashStyles((_k = chart.lineStyles) === null || _k === void 0 ? void 0 : _k.dash) },
88
+ barViewOptions: { hatch: { on: (_o = (_m = (_l = chart.barStyles) === null || _l === void 0 ? void 0 : _l.hatch) === null || _m === void 0 ? void 0 : _m.on) !== null && _o !== void 0 ? _o : false } },
76
89
  legend: getLegendMarkerOptions(chart),
77
90
  index
78
91
  });
@@ -69,8 +69,8 @@
69
69
  overflow: hidden;
70
70
  text-overflow: ellipsis;
71
71
  }
72
- .legend-wrapper-without-wrap .legend-item-inline:not(:first-of-type) {
73
- margin-left: 20px;
72
+ .legend-wrapper-without-wrap .legend-item-inline:not(:last-of-type) {
73
+ margin-right: 12px
74
74
  }
75
75
  .legend-wrapper-with-wrap .legend-item-inline {
76
76
  margin: 2px;
@@ -98,7 +98,7 @@
98
98
  text-overflow: ellipsis;
99
99
  }
100
100
  .legend-marker {
101
- margin-right: 8px;
101
+ margin-right: 6px;
102
102
  }
103
103
  .legend-circle {
104
104
  position: relative;
@@ -107,7 +107,7 @@
107
107
  width: 11px;
108
108
  height: 11px;
109
109
  border-radius: 50%;
110
- margin-right: 8px;
110
+ margin-right: 6px;
111
111
  }
112
112
 
113
113
 
@@ -69,8 +69,8 @@
69
69
  overflow: hidden;
70
70
  text-overflow: ellipsis;
71
71
  }
72
- .legend-wrapper-without-wrap .legend-item-inline:not(:first-of-type) {
73
- margin-left: 20px;
72
+ .legend-wrapper-without-wrap .legend-item-inline:not(:last-of-type) {
73
+ margin-right: 12px
74
74
  }
75
75
  .legend-wrapper-with-wrap .legend-item-inline {
76
76
  margin: 2px;
@@ -98,7 +98,7 @@
98
98
  text-overflow: ellipsis;
99
99
  }
100
100
  .legend-marker {
101
- margin-right: 8px;
101
+ margin-right: 6px;
102
102
  }
103
103
  .legend-circle {
104
104
  position: relative;
@@ -107,7 +107,7 @@
107
107
  width: 11px;
108
108
  height: 11px;
109
109
  border-radius: 50%;
110
- margin-right: 8px;
110
+ margin-right: 6px;
111
111
  }
112
112
 
113
113
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {