mdt-charts 1.12.10 → 1.12.14

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.
Files changed (58) hide show
  1. package/lib/config/config.d.ts +2 -2
  2. package/lib/designer/designerConfig.d.ts +1 -1
  3. package/lib/engine/features/axis/axis.js +1 -1
  4. package/lib/engine/features/axis/axisLabelDomHelper.js +1 -1
  5. package/lib/model/chartStyleModel/TwoDimensionalChartStyleModel.js +1 -1
  6. package/lib/model/dataManagerModel/dataManagerModel.d.ts +2 -0
  7. package/lib/model/dataManagerModel/dataManagerModel.js +10 -5
  8. package/lib/model/featuresModel/axisModel.js +1 -1
  9. package/lib/model/featuresModel/legendModel/legendCanvasModel.d.ts +0 -1
  10. package/lib/model/featuresModel/legendModel/legendCanvasModel.js +0 -25
  11. package/lib/model/featuresModel/legendModel/legendModel.d.ts +2 -6
  12. package/lib/model/featuresModel/legendModel/legendModel.js +4 -47
  13. package/lib/model/featuresModel/legendModel/polarMarginCalculator.d.ts +2 -5
  14. package/lib/model/featuresModel/legendModel/polarMarginCalculator.js +12 -29
  15. package/lib/model/featuresModel/legendModel/twoDimLegendModel.d.ts +7 -0
  16. package/lib/model/featuresModel/legendModel/twoDimLegendModel.js +24 -0
  17. package/lib/model/featuresModel/otherComponents.d.ts +0 -2
  18. package/lib/model/featuresModel/otherComponents.js +1 -1
  19. package/lib/model/featuresModel/scaleModel/scaleAxisRecalcer.js +3 -1
  20. package/lib/model/featuresModel/scaleModel/scaleModel.d.ts +2 -2
  21. package/lib/model/featuresModel/scaleModel/scaleModel.js +6 -6
  22. package/lib/model/{modelHelper.d.ts → helpers/modelHelper.d.ts} +1 -1
  23. package/lib/model/{modelHelper.js → helpers/modelHelper.js} +0 -0
  24. package/lib/model/helpers/unitsFromConfigReader.d.ts +2 -0
  25. package/lib/model/helpers/unitsFromConfigReader.js +7 -0
  26. package/lib/model/helpers/unitsReader.d.ts +5 -0
  27. package/lib/model/helpers/unitsReader.js +15 -0
  28. package/lib/model/margin/marginModel.d.ts +11 -0
  29. package/lib/model/margin/marginModel.js +26 -0
  30. package/lib/model/margin/twoDim/twoDimMarginModel.d.ts +14 -0
  31. package/lib/model/margin/twoDim/twoDimMarginModel.js +69 -0
  32. package/lib/model/model.d.ts +2 -2
  33. package/lib/model/modelBuilder.d.ts +0 -1
  34. package/lib/model/modelBuilder.js +7 -12
  35. package/lib/model/notations/intervalModel.d.ts +3 -3
  36. package/lib/model/notations/intervalModel.js +6 -6
  37. package/lib/model/notations/polar/donut/donutAggregatorService.d.ts +1 -0
  38. package/lib/model/notations/polar/donut/donutAggregatorService.js +19 -4
  39. package/lib/model/notations/polar/donut/donutThicknessService.d.ts +0 -2
  40. package/lib/model/notations/polar/donut/donutThicknessService.js +4 -16
  41. package/lib/model/notations/twoDimensionalModel.d.ts +2 -2
  42. package/lib/model/notations/twoDimensionalModel.js +4 -3
  43. package/lib/style/charts-main.css +2 -0
  44. package/lib/style/charts-main.less +2 -0
  45. package/package.json +1 -1
  46. package/tsconfig.production.json +2 -1
  47. package/lib/engine/features/tolltip/newTooltip/newTooltip.test.d.ts +0 -1
  48. package/lib/engine/features/tolltip/newTooltip/newTooltip.test.js +0 -186
  49. package/lib/engine/twoDimensionalNotation/bar/stackedData/dataStacker.test.d.ts +0 -1
  50. package/lib/engine/twoDimensionalNotation/bar/stackedData/dataStacker.test.js +0 -199
  51. package/lib/model/featuresModel/scaleModel.d.ts +0 -19
  52. package/lib/model/featuresModel/scaleModel.js +0 -115
  53. package/lib/model/marginModel.d.ts +0 -18
  54. package/lib/model/marginModel.js +0 -110
  55. package/lib/model/modelInstance/dataModel.d.ts +0 -11
  56. package/lib/model/modelInstance/dataModel.js +0 -23
  57. package/lib/model/notations/polarModel.d.ts +0 -15
  58. package/lib/model/notations/polarModel.js +0 -59
@@ -9,6 +9,7 @@ export declare type EmbeddedLabelTypeModel = "none" | "key" | "value";
9
9
  export declare type DataOptions = {
10
10
  [option: string]: any;
11
11
  };
12
+ export declare type UnitsFromConfig = "%" | "px";
12
13
  export interface Model<O = TwoDimensionalOptionsModel | PolarOptionsModel | IntervalOptionsModel> {
13
14
  blockCanvas: BlockCanvas;
14
15
  chartBlock: ChartBlockModel;
@@ -148,7 +149,7 @@ export interface DonutAggregatorContent {
148
149
  value: string | number;
149
150
  title: string;
150
151
  }
151
- export declare type DonutThicknessUnit = "px" | "%";
152
+ export declare type DonutThicknessUnit = UnitsFromConfig;
152
153
  export interface DonutThicknessOptions {
153
154
  min: number;
154
155
  max: number;
@@ -223,7 +224,6 @@ interface ComponentBlockModel {
223
224
  }
224
225
  export interface LegendBlockModel {
225
226
  coordinate: LegendCoordinate;
226
- standartTooltip: boolean;
227
227
  }
228
228
  export interface LegendCoordinate {
229
229
  top: LegendCanvasCoordinate;
@@ -13,4 +13,3 @@ export declare const CLASSES: {
13
13
  };
14
14
  export declare function assembleModel(config: MdtChartsConfig, data: MdtChartsDataSource, designerConfig: DesignerConfig): Model;
15
15
  export declare function getPreparedData(model: Model, data: MdtChartsDataSource, config: MdtChartsConfig): MdtChartsDataSource;
16
- export declare function getUpdatedModel(config: MdtChartsConfig, data: MdtChartsDataSource, designerConfig: DesignerConfig): Model;
@@ -1,4 +1,4 @@
1
- import { MarginModel } from './marginModel';
1
+ 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';
@@ -30,16 +30,16 @@ function getChartBlockModel(modelInstance) {
30
30
  margin: modelInstance.canvasModel.getMargin()
31
31
  };
32
32
  }
33
- function getOptions(config, designerConfig, modelInstance, data) {
33
+ function getOptions(config, designerConfig, modelInstance) {
34
34
  //TODO: migrate to polymorphism
35
35
  if (config.options.type === '2d') {
36
- return TwoDimensionalModel.getOptions(config.options, designerConfig, data, modelInstance);
36
+ return TwoDimensionalModel.getOptions(config.options, designerConfig, modelInstance);
37
37
  }
38
38
  else if (config.options.type === 'polar') {
39
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(), modelInstance.dataModel.getScope(), data, modelInstance);
42
+ return IntervalModel.getOptions(config.options, designerConfig, modelInstance);
43
43
  }
44
44
  }
45
45
  function getDataSettings(dataScope, designerConfig) {
@@ -67,16 +67,14 @@ export function assembleModel(config, data, designerConfig) {
67
67
  dataSettings: null
68
68
  };
69
69
  resetFalsyValues(data, config.options.data.keyField.name);
70
- const otherComponents = OtherComponentsModel.getOtherComponentsModel({ elementsOptions: designerConfig.elementsOptions, notation: config.options.type, title: config.options.title }, modelInstance);
70
+ const otherComponents = OtherComponentsModel.getOtherComponentsModel({ elementsOptions: designerConfig.elementsOptions, title: config.options.title }, modelInstance);
71
71
  MarginModel.initMargin(designerConfig, config, otherComponents, data, modelInstance);
72
72
  DataManagerModel.initDataScope(config, data, designerConfig, otherComponents.legendBlock, modelInstance);
73
- const preparedData = DataManagerModel.getPreparedData(data, modelInstance.dataModel.getAllowableKeys(), config);
74
- modelInstance.dataModel.repository.initScopedFullSource(preparedData);
75
73
  if (config.options.type === '2d' && config.options.axis.key.visibility)
76
- MarginModel.recalcMarginByVerticalAxisLabel(modelInstance, config, designerConfig, modelInstance.dataModel.getScope());
74
+ MarginModel.recalcMarginByVerticalAxisLabel(modelInstance, config.options, designerConfig);
77
75
  const blockCanvas = getBlockCanvas(config, modelInstance);
78
76
  const chartBlock = getChartBlockModel(modelInstance);
79
- const options = getOptions(config, designerConfig, modelInstance, preparedData);
77
+ const options = getOptions(config, designerConfig, modelInstance);
80
78
  const dataSettings = getDataSettings(modelInstance.dataModel.getScope(), designerConfig);
81
79
  const transitions = getTransitions(designerConfig);
82
80
  modelInstance.canvasModel.roundMargin();
@@ -111,6 +109,3 @@ export function getPreparedData(model, data, config) {
111
109
  const preparedData = DataManagerModel.getPreparedData(data, model.dataSettings.scope.allowableKeys, config);
112
110
  return preparedData;
113
111
  }
114
- export function getUpdatedModel(config, data, designerConfig) {
115
- return assembleModel(config, data, designerConfig);
116
- }
@@ -1,9 +1,9 @@
1
- import { MdtChartsConfig, MdtChartsDataSource, MdtChartsIntervalOptions } from "../../config/config";
1
+ import { MdtChartsIntervalOptions } from "../../config/config";
2
2
  import { DesignerConfig } from "../../designer/designerConfig";
3
- import { AdditionalElementsOptions, BlockMargin, DataScope, IntervalOptionsModel } from "../model";
3
+ import { AdditionalElementsOptions, IntervalOptionsModel } from "../model";
4
4
  import { ModelInstance } from "../modelInstance/modelInstance";
5
5
  export declare class IntervalModel {
6
- static getOptions(config: MdtChartsConfig, designerConfig: DesignerConfig, margin: BlockMargin, dataScope: DataScope, data: MdtChartsDataSource, modelInstance: ModelInstance): IntervalOptionsModel;
6
+ static getOptions(options: MdtChartsIntervalOptions, designerConfig: DesignerConfig, modelInstance: ModelInstance): IntervalOptionsModel;
7
7
  static getAdditionalElements(options: MdtChartsIntervalOptions): AdditionalElementsOptions;
8
8
  private static getChartsModel;
9
9
  }
@@ -5,9 +5,9 @@ import { AxisType } from "../modelBuilder";
5
5
  import { ScaleModel, ScaleType } from "../featuresModel/scaleModel/scaleModel";
6
6
  import { TwoDimensionalModel } from "./twoDimensionalModel";
7
7
  export class IntervalModel {
8
- static getOptions(config, designerConfig, margin, dataScope, data, modelInstance) {
9
- const options = config.options;
8
+ static getOptions(options, designerConfig, modelInstance) {
10
9
  const canvasModel = modelInstance.canvasModel;
10
+ const dataModelRep = modelInstance.dataModel.repository;
11
11
  return {
12
12
  legend: canvasModel.legendCanvas.getModel(),
13
13
  title: options.title,
@@ -15,7 +15,7 @@ export class IntervalModel {
15
15
  orient: options.orientation,
16
16
  scale: {
17
17
  key: {
18
- domain: dataScope.allowableKeys,
18
+ domain: modelInstance.dataModel.getAllowableKeys(),
19
19
  range: {
20
20
  start: 0,
21
21
  end: ScaleModel.getRangePeek(ScaleType.Key, options.orientation, canvasModel)
@@ -24,7 +24,7 @@ export class IntervalModel {
24
24
  elementsAmount: 1
25
25
  },
26
26
  value: {
27
- domain: ScaleModel.getDateValueDomain(data, options.chart, options.axis.key.position, options.data.dataSource),
27
+ domain: ScaleModel.getDateValueDomain(dataModelRep.getScopedFullSource(), options.chart, options.axis.key.position, options.data.dataSource),
28
28
  range: {
29
29
  start: 0,
30
30
  end: ScaleModel.getRangePeek(ScaleType.Value, options.orientation, canvasModel)
@@ -43,8 +43,8 @@ export class IntervalModel {
43
43
  cssClass: 'key-axis',
44
44
  ticks: options.axis.key.ticks,
45
45
  labels: {
46
- maxSize: AxisModel.getLabelSize(designerConfig.canvas.axisLabel.maxSize.main, data[options.data.dataSource].map(d => d[options.data.keyField.name])).width,
47
- position: AxisModel.getKeyAxisLabelPosition(canvasModel, DataManagerModel.getDataValuesByKeyField(data, options.data.dataSource, options.data.keyField.name).length),
46
+ maxSize: AxisModel.getLabelSize(designerConfig.canvas.axisLabel.maxSize.main, dataModelRep.getScopedRows().map(d => d[options.data.keyField.name])).width,
47
+ position: AxisModel.getKeyAxisLabelPosition(canvasModel, DataManagerModel.getDataValuesByKeyField(dataModelRep.getScopedFullSource(), options.data.dataSource, options.data.keyField.name).length),
48
48
  visible: true,
49
49
  defaultTooltip: designerConfig.elementsOptions.tooltip.position === 'fixed'
50
50
  },
@@ -9,4 +9,5 @@ export declare class DonutAggregatorService {
9
9
  getContent(aggregatorOptions: MdtChartsDonutAggregator, dataOptions: AggregatorServiceDataOptions): DonutAggregatorContent;
10
10
  private doesValueExist;
11
11
  private generateDefaultContent;
12
+ private getDefaultValue;
12
13
  }
@@ -4,14 +4,25 @@ export class DonutAggregatorService {
4
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
- if (this.doesValueExist(content.value) && content.title)
8
- return content;
7
+ if (!content || (!this.doesValueExist(content.value) && !content.title))
8
+ return this.generateDefaultContent(dataOptions);
9
+ if (this.doesValueExist(content.value) && content.title) {
10
+ return {
11
+ title: content.title,
12
+ value: content.value
13
+ };
14
+ }
9
15
  if (!content.title && this.doesValueExist(content.value))
10
16
  return {
11
17
  value: content.value,
12
18
  title: AGGREGATOR_DEFAULT_TITLE
13
19
  };
14
- return this.generateDefaultContent(dataOptions);
20
+ if (!this.doesValueExist(content.value) && content.title) {
21
+ return {
22
+ value: this.getDefaultValue(dataOptions),
23
+ title: content.title
24
+ };
25
+ }
15
26
  }
16
27
  doesValueExist(content) {
17
28
  return content != null;
@@ -19,7 +30,11 @@ export class DonutAggregatorService {
19
30
  generateDefaultContent(dataOptions) {
20
31
  return {
21
32
  title: AGGREGATOR_DEFAULT_TITLE,
22
- value: dataOptions.rows ? dataOptions.rows.reduce((acc, row) => acc + row[dataOptions.valueFieldName], 0) : 0
33
+ value: dataOptions.rows ? this.getDefaultValue(dataOptions) : 0
23
34
  };
24
35
  }
36
+ getDefaultValue(dataOptions) {
37
+ const totalSumOfValues = dataOptions.rows.reduce((acc, row) => acc + row[dataOptions.valueFieldName], 0);
38
+ return totalSumOfValues;
39
+ }
25
40
  }
@@ -4,6 +4,4 @@ export declare class DonutThicknessService {
4
4
  private defaultUnit;
5
5
  getUnit(settingsFromConfig: MdtChartsDonutThicknessOptions): DonutThicknessUnit;
6
6
  valueToNumber(value: string | number): number;
7
- private getUnitByValue;
8
- private getLastUnitFromString;
9
7
  }
@@ -1,12 +1,13 @@
1
+ import { getPxPercentUnitByValue } from "../../../helpers/unitsFromConfigReader";
1
2
  export class DonutThicknessService {
2
3
  constructor() {
3
4
  this.defaultUnit = "px";
4
5
  }
5
6
  getUnit(settingsFromConfig) {
6
7
  if (settingsFromConfig.value)
7
- return this.getUnitByValue(settingsFromConfig.value);
8
- const minUnit = this.getUnitByValue(settingsFromConfig.min);
9
- const maxUnit = this.getUnitByValue(settingsFromConfig.max);
8
+ return getPxPercentUnitByValue(settingsFromConfig.value);
9
+ const minUnit = getPxPercentUnitByValue(settingsFromConfig.min);
10
+ const maxUnit = getPxPercentUnitByValue(settingsFromConfig.max);
10
11
  return minUnit === maxUnit ? minUnit : this.defaultUnit;
11
12
  }
12
13
  valueToNumber(value) {
@@ -14,17 +15,4 @@ export class DonutThicknessService {
14
15
  return value;
15
16
  return parseInt(value);
16
17
  }
17
- getUnitByValue(value) {
18
- if (typeof value !== "string")
19
- return this.defaultUnit;
20
- return this.getLastUnitFromString(value);
21
- }
22
- getLastUnitFromString(value) {
23
- let resultUnit = this.defaultUnit;
24
- ["%", "px"].forEach(unit => {
25
- if (value.endsWith(unit))
26
- resultUnit = unit;
27
- });
28
- return resultUnit;
29
- }
30
18
  }
@@ -1,9 +1,9 @@
1
- import { ChartOrientation, MdtChartsDataSource, MdtChartsTwoDimensionalChart, MdtChartsTwoDimensionalOptions } from "../../config/config";
1
+ import { ChartOrientation, MdtChartsTwoDimensionalChart, MdtChartsTwoDimensionalOptions } from "../../config/config";
2
2
  import { BarOptionsCanvas, DesignerConfig } from "../../designer/designerConfig";
3
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, data: MdtChartsDataSource, modelInstance: ModelInstance): TwoDimensionalOptionsModel;
6
+ static getOptions(options: MdtChartsTwoDimensionalOptions, designerConfig: DesignerConfig, modelInstance: ModelInstance): TwoDimensionalOptionsModel;
7
7
  static getChartsEmbeddedLabelsFlag(charts: MdtChartsTwoDimensionalChart[], chartOrientation: ChartOrientation): boolean;
8
8
  /**
9
9
  * Сортирует список чартов в порядке: area - bar - line.
@@ -4,9 +4,10 @@ import { AxisModel } from "../featuresModel/axisModel";
4
4
  import { ScaleAxisRecalcer } from "../featuresModel/scaleModel/scaleAxisRecalcer";
5
5
  import { ScaleModel } from "../featuresModel/scaleModel/scaleModel";
6
6
  export class TwoDimensionalModel {
7
- static getOptions(options, designerConfig, data, modelInstance) {
7
+ static getOptions(options, designerConfig, modelInstance) {
8
8
  const canvasModel = modelInstance.canvasModel;
9
- const scaleMarginRecalcer = new ScaleAxisRecalcer(() => ScaleModel.getScaleLinear(options, data, canvasModel));
9
+ const dataModelRep = modelInstance.dataModel.repository;
10
+ const scaleMarginRecalcer = new ScaleAxisRecalcer(() => ScaleModel.getScaleLinear(options, dataModelRep.getScopedRows(), canvasModel));
10
11
  scaleMarginRecalcer.recalculateMargin(canvasModel, options.orientation, options.axis.key);
11
12
  const scaleValueInfo = scaleMarginRecalcer.getScaleValue();
12
13
  return {
@@ -19,7 +20,7 @@ export class TwoDimensionalModel {
19
20
  value: scaleValueInfo.scale
20
21
  },
21
22
  axis: {
22
- key: AxisModel.getKeyAxis(options, data, designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () => scaleValueInfo.scaleFn(0)),
23
+ key: AxisModel.getKeyAxis(options, dataModelRep.getScopedFullSource(), designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () => scaleValueInfo.scaleFn(0)),
23
24
  value: AxisModel.getValueAxis(options.orientation, options.axis.value, designerConfig.canvas.axisLabel, canvasModel)
24
25
  },
25
26
  type: options.type,
@@ -80,6 +80,8 @@
80
80
  }
81
81
  .legend-item-row > span {
82
82
  display: block;
83
+ overflow: hidden;
84
+ text-overflow: ellipsis;
83
85
  }
84
86
 
85
87
  .legend-label {
@@ -80,6 +80,8 @@
80
80
  }
81
81
  .legend-item-row > span {
82
82
  display: block;
83
+ overflow: hidden;
84
+ text-overflow: ellipsis;
83
85
  }
84
86
 
85
87
  .legend-label {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.12.10",
3
+ "version": "1.12.14",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {
@@ -18,6 +18,7 @@
18
18
  "node_modules",
19
19
  "**/__tests__/*",
20
20
  "src/playground/*",
21
- "**/*Example.ts"
21
+ "**/*Example.ts",
22
+ "**/*.test.ts"
22
23
  ]
23
24
  }
@@ -1,186 +0,0 @@
1
- import { NewTooltipServiceClass } from "./newTooltipService";
2
- const ignoredValue = 0;
3
- const ignoredBigvalue = 1000000;
4
- describe('newTooltipService', () => {
5
- const getIgnoredSize = (big) => {
6
- return {
7
- height: big ? ignoredBigvalue : ignoredValue,
8
- width: big ? ignoredBigvalue : ignoredValue
9
- };
10
- };
11
- const getSizeWithOne = (key, value) => {
12
- const size = getIgnoredSize();
13
- size[key] = value;
14
- return size;
15
- };
16
- const getPosWithOne = (key, value) => {
17
- const coordinate = {
18
- left: ignoredValue,
19
- top: ignoredValue
20
- };
21
- coordinate[key] = value;
22
- return coordinate;
23
- };
24
- const getBoundingWithOne = (key, value) => {
25
- const blockBounding = {
26
- left: ignoredValue,
27
- bottom: ignoredValue,
28
- height: ignoredValue,
29
- top: ignoredValue,
30
- width: ignoredValue
31
- };
32
- blockBounding[key] = value;
33
- return blockBounding;
34
- };
35
- const service = new NewTooltipServiceClass();
36
- describe('getTooltipByWindow with parentBlock', () => {
37
- test('should return left point equal to `-(left of parent block)` if left of tooltip is less', () => {
38
- const tooltipBounding = getIgnoredSize();
39
- const preCoordinate = getPosWithOne("left", -50);
40
- const windowSize = getIgnoredSize(true);
41
- const blockBounding = getBoundingWithOne("left", 10);
42
- const res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize, blockBounding);
43
- expect(res.left).toBe(-blockBounding.left);
44
- });
45
- test('should return left point equal to left of preCoordinate if left of tooltip is less', () => {
46
- const tooltipBounding = getIgnoredSize();
47
- const preCoordinate = getPosWithOne("left", 20);
48
- const windowSize = getIgnoredSize(true);
49
- const blockBounding = getBoundingWithOne("left", 10);
50
- const res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize, blockBounding);
51
- expect(res.left).toBe(preCoordinate.left);
52
- });
53
- test('should return left point equal to `(window width - tooltip width)` if right of tooltip is bigger', () => {
54
- const tooltipBounding = getSizeWithOne("width", 50);
55
- const preCoordinate = getPosWithOne("left", 20);
56
- const windowSize = getSizeWithOne("width", 90);
57
- const blockBounding = getBoundingWithOne("left", 30);
58
- const res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize, blockBounding);
59
- expect(res.left).toBe(-8); // 50 + 20 + 30 > 90 => 90 - 30 - 50 - scrollPad(18)
60
- });
61
- test('should return left point equal to left of preCoordinate if right of tooltip is less than window width', () => {
62
- const tooltipBounding = getSizeWithOne("width", 50);
63
- const preCoordinate = getPosWithOne("left", 20);
64
- const windowSize = getSizeWithOne("width", 200);
65
- const blockBounding = getBoundingWithOne("left", 30);
66
- const res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize, blockBounding);
67
- expect(res.left).toBe(preCoordinate.left); // 50 + 20 + 30 < 200
68
- });
69
- test('should return top point equal to `-(top of parent block)` if top of tooltip is less', () => {
70
- const tooltipBounding = getIgnoredSize();
71
- const preCoordinate = getPosWithOne("top", -40);
72
- const windowSize = getIgnoredSize(true);
73
- const blockBounding = getBoundingWithOne("top", -20);
74
- let res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize, blockBounding);
75
- expect(res.top).toBe(-blockBounding.top);
76
- blockBounding.top = -60;
77
- res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize, blockBounding);
78
- expect(res.top).toBe(-blockBounding.top); // 60 by blockBounding = 0 by window
79
- blockBounding.top = -100;
80
- preCoordinate.top = 20;
81
- res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize, blockBounding);
82
- expect(res.top).toBe(-blockBounding.top);
83
- blockBounding.top = -10;
84
- preCoordinate.top = 5;
85
- res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize, blockBounding);
86
- expect(res.top).toBe(-blockBounding.top);
87
- });
88
- test('should return top point equal top of preCoordinate if top of tooltip is bigger', () => {
89
- const tooltipBounding = getIgnoredSize();
90
- const preCoordinate = getPosWithOne("top", 20);
91
- const windowSize = getIgnoredSize(true);
92
- const blockBounding = getBoundingWithOne("top", 100);
93
- let res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize, blockBounding);
94
- expect(res.top).toBe(preCoordinate.top);
95
- preCoordinate.top = -99;
96
- res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize, blockBounding);
97
- expect(res.top).toBe(preCoordinate.top);
98
- });
99
- test('should return top point equal to `(winHeight - tooltipHeight)` if bottom of tooltip is bigger than window height', () => {
100
- const tooltipBounding = getSizeWithOne("height", 50);
101
- const preCoordinate = getPosWithOne("top", 90);
102
- const windowSize = getSizeWithOne("height", 200);
103
- const blockBounding = {
104
- left: ignoredValue,
105
- bottom: 210,
106
- height: 110,
107
- top: 100,
108
- width: ignoredValue
109
- };
110
- const res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize, blockBounding);
111
- expect(res.top).toBe(50); // 110 - 50 - (210 - 200)
112
- });
113
- test('should return top point equal to top of preCoordinate if bottom of tooltip is less than height of window', () => {
114
- const tooltipBounding = getSizeWithOne("height", 50);
115
- const preCoordinate = getPosWithOne("top", 90);
116
- const windowSize = getSizeWithOne("height", 300);
117
- const blockBounding = {
118
- left: ignoredValue,
119
- bottom: 210,
120
- height: 110,
121
- top: 100,
122
- width: ignoredValue
123
- };
124
- const res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize, blockBounding);
125
- expect(res.top).toBe(preCoordinate.top); // 90 + 50 + 100 < 300
126
- });
127
- });
128
- describe('getTooltipByWindow without parentBlock', () => {
129
- test('should return left point equal to 0 if left of tooltip is less', () => {
130
- const tooltipBounding = getIgnoredSize();
131
- const preCoordinate = getPosWithOne("left", -50);
132
- const windowSize = getIgnoredSize(true);
133
- const res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize);
134
- expect(res.left === 0).toBe(true); // negative zero jest not matching with simple zero
135
- });
136
- test('should return left point equal to left of preCoordinate if left of tooltip is bigger than 0', () => {
137
- const tooltipBounding = getIgnoredSize();
138
- const preCoordinate = getPosWithOne("left", 20);
139
- const windowSize = getIgnoredSize(true);
140
- const res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize);
141
- expect(res.left).toBe(preCoordinate.left);
142
- });
143
- test('should return left point equal to `(window width - tooltip width)` if right of tooltip is bigger', () => {
144
- const tooltipBounding = getSizeWithOne("width", 50);
145
- const preCoordinate = getPosWithOne("left", 60);
146
- const windowSize = getSizeWithOne("width", 100);
147
- const res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize);
148
- expect(res.left).toBe(32); // 60 + 50 > 100 => 100 - 50 - scrollPad(18)
149
- });
150
- test('should return left point equal to left of preCoordinate if right of tooltip is less than window width', () => {
151
- const tooltipBounding = getSizeWithOne("width", 50);
152
- const preCoordinate = getPosWithOne("left", 20);
153
- const windowSize = getSizeWithOne("width", 200);
154
- const res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize);
155
- expect(res.left).toBe(preCoordinate.left); // 50 + 20 < 200
156
- });
157
- test('should return top point equal to 0 if top of tooltip is less than 0', () => {
158
- const tooltipBounding = getIgnoredSize();
159
- const preCoordinate = getPosWithOne("top", -40);
160
- const windowSize = getIgnoredSize(true);
161
- const res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize);
162
- expect(res.top === 0).toBe(true);
163
- });
164
- test('should return top point equal top of preCoordinate if top of tooltip is bigger than 0', () => {
165
- const tooltipBounding = getIgnoredSize();
166
- const preCoordinate = getPosWithOne("top", 20);
167
- const windowSize = getIgnoredSize(true);
168
- const res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize);
169
- expect(res.top).toBe(preCoordinate.top);
170
- });
171
- test('should return top point equal to `(winHeight - tooltipHeight)` if bottom of tooltip is bigger than window height', () => {
172
- const tooltipBounding = getSizeWithOne("height", 50);
173
- const preCoordinate = getPosWithOne("top", 90);
174
- const windowSize = getSizeWithOne("height", 100);
175
- const res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize);
176
- expect(res.top).toBe(50); // 90 + 50 > 100 => 100 - 50
177
- });
178
- test('should return top point equal to top of preCoordinate if bottom of tooltip is less than height of window', () => {
179
- const tooltipBounding = getSizeWithOne("height", 50);
180
- const preCoordinate = getPosWithOne("top", 90);
181
- const windowSize = getSizeWithOne("height", 300);
182
- const res = service.getTooltipByWindow(tooltipBounding, preCoordinate, windowSize);
183
- expect(res.top).toBe(preCoordinate.top); // 90 + 50 < 300
184
- });
185
- });
186
- });