mdt-charts 1.17.2 → 1.18.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.
@@ -130,6 +130,7 @@ export interface NumberDomain {
130
130
  }
131
131
  export interface NumberAxisLabel {
132
132
  format: (v: number) => string;
133
+ stepSize?: number;
133
134
  }
134
135
  export declare type AxisLabelFormatter = (v: number) => string;
135
136
  export interface DiscreteAxisOptions extends AxisOptions {
@@ -31,7 +31,7 @@ export class Axis {
31
31
  static renderAxis(block, scale, scaleOptions, axisOptions, blockSize) {
32
32
  const axisGenerator = AxisHelper.getBaseAxisGenerator(axisOptions, scale);
33
33
  if (axisOptions.type === 'value' && (scaleOptions.type === 'linear' || scaleOptions.type === 'datetime'))
34
- AxisHelper.setValueAxisLabelsSettings(axisGenerator, scale.range(), scaleOptions);
34
+ AxisHelper.setValueAxisLabelsSettings(axisGenerator, scale.range(), scaleOptions, axisOptions.labels);
35
35
  else
36
36
  axisGenerator.tickFormat(axisOptions.labels.showTick);
37
37
  const axisElement = block.getSvg()
@@ -60,7 +60,7 @@ export class Axis {
60
60
  }
61
61
  static updateValueAxis(block, scaleValue, scaleOptions, axisOptions) {
62
62
  const axisGenerator = AxisHelper.getBaseAxisGenerator(axisOptions, scaleValue);
63
- AxisHelper.setValueAxisLabelsSettings(axisGenerator, scaleValue.range(), scaleOptions);
63
+ AxisHelper.setValueAxisLabelsSettings(axisGenerator, scaleValue.range(), scaleOptions, axisOptions.labels);
64
64
  const axisElement = block.getSvg().select(`g.${axisOptions.cssClass}`);
65
65
  AxisDomHelper.updateAxisElement(axisGenerator, axisElement, axisOptions.translate, block.transitionManager.durations.chartUpdate)
66
66
  .then(() => {
@@ -1,8 +1,8 @@
1
1
  import { AxisScale, Axis as IAxis } from 'd3-axis';
2
- import { AxisModelOptions, Orient, ScaleValueModel } from "../../../model/model";
2
+ import { AxisLabelModel, AxisModelOptions, Orient, ScaleValueModel } from "../../../model/model";
3
3
  export declare class AxisHelper {
4
4
  static getAxisByOrient(orient: Orient, scale: AxisScale<any>): IAxis<any>;
5
- static setValueAxisLabelsSettings(axisGenerator: IAxis<any>, range: number[], scaleOptions: ScaleValueModel): void;
5
+ static setValueAxisLabelsSettings(axisGenerator: IAxis<any>, range: number[], scaleOptions: ScaleValueModel, labelsOptions: AxisLabelModel): void;
6
6
  static getBaseAxisGenerator(axisOptions: AxisModelOptions, scale: AxisScale<any>): IAxis<any>;
7
7
  private static removeTicks;
8
8
  private static setNumTickFormat;
@@ -1,8 +1,6 @@
1
1
  import { axisTop, axisBottom, axisLeft, axisRight } from 'd3-axis';
2
- import { max, min } from 'd3-array';
3
2
  import { format } from 'd3-format';
4
3
  import { AxisLabelHelper } from './axisLabelDomHelper';
5
- const MINIMAL_STEP_SIZE = 60;
6
4
  export class AxisHelper {
7
5
  static getAxisByOrient(orient, scale) {
8
6
  if (orient === 'top')
@@ -14,18 +12,14 @@ export class AxisHelper {
14
12
  if (orient === 'right')
15
13
  return axisRight(scale);
16
14
  }
17
- static setValueAxisLabelsSettings(axisGenerator, range, scaleOptions) {
15
+ static setValueAxisLabelsSettings(axisGenerator, range, scaleOptions, labelsOptions) {
18
16
  const axisLength = range[1] - range[0];
19
- let ticksAmount;
20
- if (axisLength / 10 < MINIMAL_STEP_SIZE) {
21
- if (Math.floor(axisLength / MINIMAL_STEP_SIZE) > 2) {
22
- ticksAmount = Math.floor(axisLength / MINIMAL_STEP_SIZE);
23
- axisGenerator.ticks(Math.floor(axisLength / MINIMAL_STEP_SIZE));
24
- }
25
- else {
26
- ticksAmount = 2;
27
- axisGenerator.tickValues([min(scaleOptions.domain), max(scaleOptions.domain)]);
28
- }
17
+ const minimalStepSize = labelsOptions.linearTickStep;
18
+ if (Math.floor(axisLength / minimalStepSize) > 2) {
19
+ axisGenerator.ticks(Math.floor(axisLength / minimalStepSize));
20
+ }
21
+ else {
22
+ axisGenerator.ticks(1);
29
23
  }
30
24
  if (scaleOptions.type === 'linear') {
31
25
  this.setNumTickFormat(axisGenerator, scaleOptions.formatter);
@@ -11,6 +11,7 @@ export declare class AxisLabelHelper {
11
11
  static hideLabels(axisElement: Selection<SVGGElement, unknown, BaseType, unknown>): void;
12
12
  static alignLabelsInKeyAxis(axisOptions: AxisModelOptions, axisElement: Selection<SVGGElement, unknown, HTMLElement, any>): void;
13
13
  private static alignLabelsInVerticalAxis;
14
+ static alignHorizontalAxisLastLabel(block: Block, maxLabelSize: number, axisOptions: AxisModelOptions, blockSize: Size, crop: boolean): void;
14
15
  private static cropAndAlignExtremeLabels;
15
16
  private static getTranslateNumber;
16
17
  static wrapHandler(textBlocks: Selection<SVGGElement, unknown, BaseType, any>, maxWidth: number): void;
@@ -46,7 +46,7 @@ export class AxisLabelHelper {
46
46
  else
47
47
  maxLabelSize = ((_c = (_b = (_a = scale).step) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : Infinity) - 4;
48
48
  DomHelper.cropSvgLabels(axisTextBlocks, maxLabelSize);
49
- if (scaleOptions.type === 'point' && axisOptions.labels.position === 'straight' && (axisOptions.orient === 'top' || axisOptions.orient === 'bottom')) {
49
+ if (axisOptions.labels.position === 'straight' && (axisOptions.orient === 'top' || axisOptions.orient === 'bottom')) {
50
50
  this.cropAndAlignExtremeLabels(block, maxLabelSize, axisOptions, blockSize);
51
51
  }
52
52
  }
@@ -72,7 +72,7 @@ export class AxisLabelHelper {
72
72
  spans.attr('x', AXIS_VERTICAL_LABEL_PADDING);
73
73
  }
74
74
  }
75
- static cropAndAlignExtremeLabels(block, maxLabelSize, axisOptions, blockSize) {
75
+ static alignHorizontalAxisLastLabel(block, maxLabelSize, axisOptions, blockSize, crop) {
76
76
  const lastTick = block.getSvg().select(`.${axisOptions.cssClass}`).select('.tick:last-of-type');
77
77
  const lastLabel = lastTick.select('text');
78
78
  if (lastTick.size() === 0 || lastLabel.size() === 0)
@@ -82,8 +82,12 @@ export class AxisLabelHelper {
82
82
  if (tickTranslateX + lastLabel.node().getBBox().width + axisOptions.translate.translateX > blockSize.width) {
83
83
  lastLabel.attr('text-anchor', 'start');
84
84
  lastLabel.attr('transform', `translate(${this.getTranslateNumber(maxLabelSize, lastLabel, marginRight)}, 0)`);
85
- DomHelper.cropSvgLabels(lastLabel, maxLabelSize / 2 + marginRight);
85
+ if (crop)
86
+ DomHelper.cropSvgLabels(lastLabel, maxLabelSize / 2 + marginRight);
86
87
  }
88
+ }
89
+ static cropAndAlignExtremeLabels(block, maxLabelSize, axisOptions, blockSize) {
90
+ this.alignHorizontalAxisLastLabel(block, maxLabelSize, axisOptions, blockSize, true);
87
91
  const firstLabel = block.getSvg()
88
92
  .select(`.${axisOptions.cssClass}`)
89
93
  .select('.tick:first-of-type')
@@ -23,6 +23,8 @@ export class MarkDot {
23
23
  .selectAll(`.${this.markerDotClass}${Helper.getCssClassesLine(chart.cssClasses)}.chart-element-${vfIndex}`)
24
24
  .data(newData);
25
25
  dots.exit().remove();
26
+ if (chart.markersOptions.show)
27
+ dots.classed(this.hiddenDotClass, false);
26
28
  const attrs = MarkDotHelper.getDotAttrs(keyAxisOrient, scales, margin, keyField, valueFieldName, chart.isSegmented);
27
29
  const newDots = dots
28
30
  .enter()
@@ -7,6 +7,8 @@ export interface LabelSize {
7
7
  width: number;
8
8
  height: number;
9
9
  }
10
+ export declare const MINIMAL_VERTICAL_STEP_SIZE = 60;
11
+ export declare const MINIMAL_HORIZONTAL_STEP_SIZE = 100;
10
12
  export declare class AxisModel {
11
13
  private static service;
12
14
  static getKeyAxis(options: MdtChartsTwoDimensionalOptions, data: MdtChartsDataSource, labelConfig: AxisLabelCanvas, canvasModel: CanvasModel, tooltipSettings: TooltipSettings, getZeroCoordinate?: () => number): AxisModelOptions;
@@ -3,6 +3,8 @@ import { AxisType, CLASSES } from "../modelBuilder";
3
3
  import { DataManagerModel } from "../dataManagerModel/dataManagerModel";
4
4
  import { TwoDimensionalModel } from "../notations/twoDimensionalModel";
5
5
  import { AxisModelService, AxisModelTickCalculator, showAllTicks } from "./axisModelService";
6
+ export const MINIMAL_VERTICAL_STEP_SIZE = 60;
7
+ export const MINIMAL_HORIZONTAL_STEP_SIZE = 100;
6
8
  export class AxisModel {
7
9
  static getKeyAxis(options, data, labelConfig, canvasModel, tooltipSettings, getZeroCoordinate) {
8
10
  var _a;
@@ -21,12 +23,14 @@ export class AxisModel {
21
23
  position: AxisModel.getKeyAxisLabelPosition(canvasModel, DataManagerModel.getDataValuesByKeyField(data, dataOptions.dataSource, dataOptions.keyField.name).length, axisConfig),
22
24
  visible: !TwoDimensionalModel.getChartsEmbeddedLabelsFlag(charts, orientation),
23
25
  defaultTooltip: tooltipSettings.position === 'fixed',
24
- showTick: tickCalculator.createFunctionCalculator(this.getAxisLength(orientation, canvasModel))
26
+ showTick: tickCalculator.createFunctionCalculator(this.getAxisLength(orientation, canvasModel)),
27
+ linearTickStep: MINIMAL_HORIZONTAL_STEP_SIZE
25
28
  },
26
29
  visibility: axisConfig.visibility
27
30
  };
28
31
  }
29
32
  static getValueAxis(orient, axisConfig, labelConfig, canvasModel) {
33
+ var _a, _b;
30
34
  return {
31
35
  type: 'value',
32
36
  orient: AxisModel.getAxisOrient(AxisType.Value, orient, axisConfig.position),
@@ -41,7 +45,8 @@ export class AxisModel {
41
45
  position: 'straight',
42
46
  visible: true,
43
47
  defaultTooltip: true,
44
- showTick: showAllTicks
48
+ showTick: showAllTicks,
49
+ linearTickStep: (_b = (_a = axisConfig.labels) === null || _a === void 0 ? void 0 : _a.stepSize) !== null && _b !== void 0 ? _b : (orient === "horizontal" ? MINIMAL_HORIZONTAL_STEP_SIZE : MINIMAL_VERTICAL_STEP_SIZE)
45
50
  },
46
51
  visibility: axisConfig.visibility
47
52
  };
@@ -123,6 +123,7 @@ export interface AxisLabelModel {
123
123
  visible: boolean;
124
124
  defaultTooltip: boolean;
125
125
  showTick: ShowTickFn;
126
+ linearTickStep: number;
126
127
  }
127
128
  export interface AdditionalElementsOptions {
128
129
  gridLine: GridLineOptions;
@@ -9,11 +9,9 @@ export class TwoDimensionalModel {
9
9
  static getOptions(configReader, designerConfig, modelInstance) {
10
10
  const options = configReader.options;
11
11
  const canvasModel = modelInstance.canvasModel;
12
- const dataModelRep = modelInstance.dataModel.repository;
13
- const dataRows = dataModelRep.getRawRows();
14
- const resolvedTitle = getResolvedTitle(options.title, dataRows);
12
+ const resolvedTitle = getResolvedTitle(options.title, modelInstance.dataModel.repository.getRawRows());
15
13
  const scaleModel = new ScaleModel();
16
- const scaleMarginRecalcer = new ScaleAxisRecalcer(() => scaleModel.getScaleLinear(options, dataModelRep.getScopedRows(), canvasModel, configReader));
14
+ const scaleMarginRecalcer = new ScaleAxisRecalcer(() => scaleModel.getScaleLinear(options, modelInstance.dataModel.repository.getScopedRows(), canvasModel, configReader));
17
15
  scaleMarginRecalcer.recalculateMargin(canvasModel, options.orientation, options.axis.key);
18
16
  const scaleValueInfo = scaleMarginRecalcer.getScaleValue();
19
17
  return {
@@ -26,12 +24,12 @@ export class TwoDimensionalModel {
26
24
  value: scaleValueInfo.scale
27
25
  },
28
26
  axis: {
29
- key: AxisModel.getKeyAxis(options, dataModelRep.getScopedFullSource(), designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () => scaleValueInfo.scaleFn(0)),
27
+ key: AxisModel.getKeyAxis(options, modelInstance.dataModel.repository.getScopedFullSource(), designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () => scaleValueInfo.scaleFn(0)),
30
28
  value: AxisModel.getValueAxis(options.orientation, options.axis.value, designerConfig.canvas.axisLabel, canvasModel)
31
29
  },
32
30
  type: options.type,
33
31
  data: Object.assign({}, options.data),
34
- charts: this.getChartsModel(options.charts, options.orientation, designerConfig),
32
+ charts: this.getChartsModel(options.charts, options.orientation, designerConfig, modelInstance.dataModel.repository),
35
33
  additionalElements: this.getAdditionalElements(options),
36
34
  tooltip: options.tooltip,
37
35
  chartSettings: this.getChartsSettings(designerConfig.canvas.chartOptions, options.orientation)
@@ -59,7 +57,7 @@ export class TwoDimensionalModel {
59
57
  lineLike: { shape: parseShape(chartOrientation, (_a = chartOptions.line) === null || _a === void 0 ? void 0 : _a.shape) }
60
58
  };
61
59
  }
62
- static getChartsModel(charts, chartOrientation, designerConfig) {
60
+ static getChartsModel(charts, chartOrientation, designerConfig, dataModelRep) {
63
61
  const styleModel = new TwoDimensionalChartStyleModel(charts, designerConfig.chartStyle);
64
62
  this.sortCharts(charts);
65
63
  const chartsModel = [];
@@ -74,7 +72,7 @@ export class TwoDimensionalModel {
74
72
  style: styleModel.getChartStyle(chart, index),
75
73
  embeddedLabels: this.getEmbeddedLabelType(chart, chartOrientation),
76
74
  markersOptions: {
77
- show: chart.markers.show,
75
+ show: dataModelRep.getScopedRows().length === 1 ? true : chart.markers.show,
78
76
  styles: {
79
77
  highlighted: {
80
78
  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' }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.17.2",
3
+ "version": "1.18.0",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {