@datarailsshared/dr_renderer 1.5.159 → 1.5.168

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 (32) hide show
  1. package/.idea/jsLibraryMappings.xml +6 -0
  2. package/.idea/misc.xml +9 -0
  3. package/.nvmrc +1 -0
  4. package/jest.config.js +1 -1
  5. package/package.json +9 -11
  6. package/scripts/check-versions.js +16 -0
  7. package/src/highcharts_renderer.d.ts +2 -2
  8. package/tsconfig.json +1 -1
  9. package/.circleci/config.yml +0 -85
  10. package/.github/workflows/ai-coder-jira.yml +0 -915
  11. package/.github/workflows/ai-coder-n8n-caller.yml +0 -82
  12. package/.github/workflows/release.yml +0 -49
  13. package/tests/__snapshots__/suboptions.test.js.snap +0 -5028
  14. package/tests/dr-renderer-helpers.test.js +0 -228
  15. package/tests/dr_chart_tooltip.test.js +0 -789
  16. package/tests/dr_gauge_chart.test.js +0 -2041
  17. package/tests/errors.test.js +0 -157
  18. package/tests/highcharts_renderer.test.js +0 -9407
  19. package/tests/mock/add-in-dynamic-ranges.json +0 -127
  20. package/tests/mock/add-in-functions.json +0 -410
  21. package/tests/mock/add-in-tables.json +0 -347
  22. package/tests/mock/tables.json +0 -2258
  23. package/tests/mock/widgets.json +0 -401
  24. package/tests/options-builder.test.js +0 -1698
  25. package/tests/pivot-table/freeze-panes/constants.test.js +0 -92
  26. package/tests/pivot-table/freeze-panes/index.test.js +0 -193
  27. package/tests/pivot-table/freeze-panes/sticky-strategy.test.js +0 -542
  28. package/tests/pivot-table/freeze-panes/transform-strategy.test.js +0 -304
  29. package/tests/ptCreateDrillDownSeriesToDrilldownChart.test.js +0 -509
  30. package/tests/seriesPointStyles-helper.test.js +0 -114
  31. package/tests/suboptions.test.js +0 -322
  32. package/tests/value.formatter.test.js +0 -143
@@ -1,789 +0,0 @@
1
- import { DrChartTooltip, DR_TOOLTIP_OPTIONS_DEFAULT } from "../src/dr_chart_tooltip";
2
- const helpers = require("../src/dr-renderer-helpers");
3
-
4
- describe("DrChartTooltip", () => {
5
- let chartMock;
6
- let instance;
7
- let anchorBBoxMock;
8
- let anchorMock;
9
- let positionMock;
10
- let optionsMock;
11
- let tooltipBBoxMock;
12
- let tooltipMock;
13
- let arrowElMock;
14
- let chartBBoxMock;
15
-
16
- beforeEach(() => {
17
- chartBBoxMock = {
18
- x: 0,
19
- y: 0,
20
- width: 800,
21
- height: 600,
22
- };
23
- chartMock = {
24
- renderer: {
25
- text: jest.fn().mockImplementation((content) => ({
26
- attr: jest.fn().mockReturnThis(),
27
- css: jest.fn().mockReturnThis(),
28
- add: jest.fn().mockReturnThis(),
29
- hide: jest.fn().mockReturnThis(),
30
- getBBox: jest.fn().mockReturnValue({ width: 100, height: 50 }),
31
- })),
32
- },
33
- container: {
34
- getBoundingClientRect: jest.fn().mockReturnValue(chartBBoxMock),
35
- clientWidth: 800,
36
- },
37
- chartWidth: 800,
38
- chartHeight: 600,
39
- };
40
-
41
- instance = new DrChartTooltip(chartMock, {
42
- fontSize: 12,
43
- fontFamily: "Arial",
44
- color: "#333",
45
- });
46
-
47
- anchorBBoxMock = { x: 100, y: 100, width: 50, height: 30 };
48
- anchorMock = {
49
- getBBox: jest.fn().mockReturnValue(anchorBBoxMock),
50
- };
51
- positionMock = { x: 60, y: 30, direction: "top" };
52
- optionsMock = {
53
- anchorOffset: 10,
54
- arrowRadius: 3,
55
- arrowSize: 10,
56
- background: "#fff",
57
- border: 1,
58
- borderColor: "#DFE0E3",
59
- borderRadius: 8,
60
- boxShadow: "0px 4px 8px 1px rgba(0, 0, 0, 0.25)",
61
- direction: "top",
62
- followPointer: false,
63
- outerOffset: 8,
64
- paddings: [6, 12],
65
- showArrow: true,
66
- };
67
- arrowElMock = {
68
- setAttribute: jest.fn(),
69
- removeAttribute: jest.fn(),
70
- };
71
- tooltipBBoxMock = { width: 40, height: 50 };
72
- tooltipMock = {
73
- attr: jest.fn(),
74
- getBBox: jest.fn().mockReturnValue(tooltipBBoxMock),
75
- element: {
76
- querySelector: jest.fn().mockReturnValue(arrowElMock),
77
- },
78
- };
79
-
80
- jest.spyOn(helpers, "clamp");
81
- jest.spyOn(helpers, "removeSVGTextCorrection");
82
- });
83
-
84
- afterEach(() => {
85
- jest.clearAllMocks();
86
- });
87
-
88
- it("initializes with default options", () => {
89
- const tooltip = new DrChartTooltip(chartMock);
90
- expect(tooltip.getOptions()).toEqual({ ...DR_TOOLTIP_OPTIONS_DEFAULT });
91
- });
92
-
93
- it("initializes with merged options", () => {
94
- expect(instance).toBeInstanceOf(DrChartTooltip);
95
- expect(instance.getOptions()).toEqual({
96
- ...DR_TOOLTIP_OPTIONS_DEFAULT,
97
- fontSize: 12,
98
- fontFamily: "Arial",
99
- color: "#333",
100
- });
101
- });
102
-
103
- describe("add", () => {
104
- let localOptions;
105
-
106
- beforeEach(() => {
107
- localOptions = instance.getOptions();
108
- });
109
-
110
- it("return false unless content or anchor are provided", () => {
111
- expect(instance.add()).toBe(false);
112
- });
113
-
114
- it("creates and show a tooltip on element mouseover", () => {
115
- const anchor = document.createElement("div");
116
- const content = "Tooltip Content";
117
-
118
- const destroyMock = jest.fn();
119
- const showMock = jest.fn();
120
- instance.create = jest.fn().mockReturnValue({
121
- destroy: destroyMock,
122
- show: showMock,
123
- });
124
-
125
- instance.add(content, anchor);
126
-
127
- anchor.dispatchEvent(new MouseEvent("mouseover", {}));
128
- expect(instance.create).toHaveBeenCalledWith("Tooltip Content", anchor, localOptions);
129
- expect(showMock).toHaveBeenCalled();
130
-
131
- // destroy the previous tooltip
132
- anchor.dispatchEvent(new MouseEvent("mouseover", {}));
133
- expect(destroyMock).toHaveBeenCalled();
134
- });
135
-
136
- it("creates and show a tooltip on point mouseover", () => {
137
- const anchor = document.createElement("div");
138
- const content = "Tooltip Content";
139
-
140
- const showMock = jest.fn();
141
- instance.create = jest.fn().mockReturnValue({
142
- show: showMock,
143
- });
144
-
145
- instance.add(content, anchor, { followPointer: true });
146
- const event = new MouseEvent("mouseover", {});
147
-
148
- anchor.dispatchEvent(event);
149
- expect(instance.create).toHaveBeenCalledWith("Tooltip Content", event, {
150
- ...localOptions,
151
- ...{ followPointer: true },
152
- });
153
- expect(showMock).toHaveBeenCalled();
154
- });
155
-
156
- it("ignore mouseleave event unless tooltip is created", () => {
157
- const anchor = document.createElement("div");
158
- const content = "Tooltip Content";
159
-
160
- const destroyMock = jest.fn();
161
- const showMock = jest.fn();
162
- instance.create = jest.fn().mockReturnValue({
163
- destroy: destroyMock,
164
- show: showMock,
165
- });
166
-
167
- instance.add(content, anchor, { followPointer: true });
168
-
169
- anchor.dispatchEvent(new MouseEvent("mouseleave", {}));
170
- expect(destroyMock).not.toHaveBeenCalled();
171
- });
172
-
173
- it("destroys tooltip on mouseleave", () => {
174
- const anchor = document.createElement("div");
175
- const content = "Tooltip Content";
176
-
177
- const destroyMock = jest.fn();
178
- const showMock = jest.fn();
179
- instance.create = jest.fn().mockReturnValue({
180
- destroy: destroyMock,
181
- show: showMock,
182
- });
183
-
184
- instance.add(content, anchor, { followPointer: true });
185
-
186
- anchor.dispatchEvent(new MouseEvent("mouseover", {}));
187
- anchor.dispatchEvent(new MouseEvent("mouseleave", {}));
188
- expect(destroyMock).toHaveBeenCalled();
189
- });
190
-
191
- it("updates tooltip position on mousemove", () => {
192
- const anchor = document.createElement("div");
193
- const content = "Tooltip Content";
194
-
195
- const showMock = jest.fn();
196
- instance.create = jest.fn().mockReturnValue({
197
- show: showMock,
198
- });
199
- instance.setTooltipPosition = jest.fn();
200
-
201
- instance.add(content, anchor, { followPointer: true });
202
- const event = new MouseEvent("mousemove", {});
203
-
204
- anchor.dispatchEvent(event);
205
- // not call untill tooltip is created
206
- expect(instance.setTooltipPosition).not.toHaveBeenCalled();
207
- anchor.dispatchEvent(new MouseEvent("mouseover", {}));
208
- anchor.dispatchEvent(event);
209
- // update position for the existing tooltip
210
- expect(instance.setTooltipPosition).toHaveBeenCalled();
211
- });
212
- });
213
-
214
- describe("create", () => {
215
- it("creates a tooltip with correct attributes and styles", () => {
216
- const content = "Tooltip Content";
217
- instance.setTooltipPosition = jest.fn();
218
- const options = instance.getOptions();
219
- const tooltip = instance.create(content, null, options);
220
-
221
- expect(chartMock.renderer.text).toHaveBeenCalledWith(expect.stringContaining(content), 0, 0, true);
222
- expect(tooltip.attr).toHaveBeenCalledWith({ class: "dr-renderer-tooltip" });
223
- expect(tooltip.css).toHaveBeenCalledWith(
224
- expect.objectContaining({
225
- background: options.background,
226
- fontFamily: "Arial",
227
- fontSize: "12px",
228
- color: "#333",
229
- border: `${options.border}px solid ${options.borderColor}`,
230
- borderRadius: options.borderRadius + "px",
231
- boxShadow: options.boxShadow,
232
- color: options.color,
233
- display: "flex",
234
- alignItems: "center",
235
- gap: "4px",
236
- fontFamily: options.fontFamily,
237
- fontSize: options.fontSize + "px",
238
- padding: options.paddings.map((p) => `${p}px`).join(" "),
239
- })
240
- );
241
- });
242
-
243
- it("sets a tooltip position", () => {
244
- const options = instance.getOptions();
245
- instance.setTooltipPosition = jest.fn();
246
- instance.create("Tooltip content", null, options);
247
- expect(instance.setTooltipPosition).toHaveBeenCalled();
248
- });
249
-
250
- it("adds an arrow if { showArrow: true }", () => {
251
- const options = instance.getOptions();
252
- instance.setTooltipPosition = jest.fn();
253
- instance.create("Tooltip content", null, options);
254
- expect(chartMock.renderer.text).toHaveBeenCalledWith(
255
- 'Tooltip content<span class="dr-renderer-tooltip_arrow" style="position: absolute"></span>',
256
- 0,
257
- 0,
258
- true
259
- );
260
- });
261
-
262
- it("does not add an arrow if { showArrow: false }", () => {
263
- const options = instance.getOptions();
264
- instance.setTooltipPosition = jest.fn();
265
- instance.create("Tooltip content", null, { ...options, ...{ showArrow: false } });
266
- expect(chartMock.renderer.text).toHaveBeenCalledWith("Tooltip content", 0, 0, true);
267
- });
268
- });
269
-
270
- describe("setTooltipPosition", () => {
271
- beforeEach(() => {
272
- instance.getPosition = jest.fn().mockReturnValue(positionMock);
273
- instance.setArrowPosition = jest.fn();
274
- });
275
-
276
- it("positions the tooltip correctly", () => {
277
- instance.setTooltipPosition(tooltipMock, anchorMock, optionsMock);
278
-
279
- expect(tooltipMock.attr).toHaveBeenCalledWith({
280
- x: positionMock.x,
281
- y: positionMock.y,
282
- class: expect.stringContaining(positionMock.direction),
283
- });
284
- });
285
-
286
- it("positions the tooltip arrow correctly", () => {
287
- instance.setTooltipPosition(tooltipMock, anchorMock, optionsMock);
288
- expect(instance.setArrowPosition).toHaveBeenCalledWith(tooltipMock, positionMock, anchorMock, optionsMock);
289
- });
290
-
291
- it("does not position the tooltip arrow unless the arrows is on", () => {
292
- optionsMock.showArrow = false;
293
- instance.setTooltipPosition(tooltipMock, anchorMock, optionsMock);
294
- expect(instance.setArrowPosition).not.toHaveBeenCalled();
295
- });
296
- });
297
-
298
- describe("setArrowPosition", () => {
299
- let commonStyles;
300
- let arrowBottomBorderStyles;
301
- let arrowTopBorderStyles;
302
- let arrowLeftBorderStyles;
303
- let arrowRightBorderStyles;
304
-
305
- beforeEach(() => {
306
- commonStyles = `position:absolute;display:block;width:${optionsMock.arrowSize}px;height:${optionsMock.arrowSize}px;transform:rotate(-45deg);border-style:solid;border-width:${optionsMock.border}px;background:${optionsMock.background};`;
307
- arrowBottomBorderStyles = `border-color:${optionsMock.borderColor} ${
308
- optionsMock.borderColor
309
- } transparent transparent;border-top-right-radius:${optionsMock.arrowRadius}px;top:-${optionsMock.arrowSize / 2}px;`;
310
- arrowTopBorderStyles = `border-color:transparent transparent ${optionsMock.borderColor} ${
311
- optionsMock.borderColor
312
- };border-bottom-left-radius:${optionsMock.arrowRadius}px;bottom:-${optionsMock.arrowSize / 2}px;`;
313
- arrowLeftBorderStyles = `border-color:transparent ${optionsMock.borderColor} ${
314
- optionsMock.borderColor
315
- } transparent;border-bottom-right-radius:${optionsMock.arrowRadius}px;right:-${optionsMock.arrowSize / 2}px;`;
316
- arrowRightBorderStyles = `border-color:${optionsMock.borderColor} transparent transparent ${
317
- optionsMock.borderColor
318
- };border-top-left-radius:${optionsMock.arrowRadius}px;left:-${optionsMock.arrowSize / 2}px;`;
319
- });
320
-
321
- it("sets a top arrow position (tooltip is bigger than anchor)", () => {
322
- tooltipBBoxMock.width = 100;
323
- tooltipBBoxMock.height = 20;
324
- anchorBBoxMock.width = 50;
325
- anchorBBoxMock.height = 50;
326
- anchorBBoxMock.x = 200;
327
- anchorBBoxMock.y = 200;
328
- positionMock = {
329
- x: 175,
330
- y: 180,
331
- direction: "top",
332
- };
333
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
334
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowTopBorderStyles}left:45px`);
335
- });
336
-
337
- it("sets a top arrow position (tooltip is smaller than anchor)", () => {
338
- tooltipBBoxMock.width = 40;
339
- tooltipBBoxMock.height = 20;
340
- anchorBBoxMock.width = 50;
341
- anchorBBoxMock.height = 50;
342
- anchorBBoxMock.x = 200;
343
- anchorBBoxMock.y = 200;
344
- positionMock = {
345
- x: 205,
346
- y: 180,
347
- direction: "top",
348
- };
349
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
350
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowTopBorderStyles}left:15px`);
351
- });
352
-
353
- it("sets a top arrow position (tooltip is smaller than anchor) on a zoomed chart", () => {
354
- chartMock.container.clientWidth = 1600;
355
- tooltipBBoxMock.width = 40;
356
- tooltipBBoxMock.height = 20;
357
- anchorBBoxMock.width = 50;
358
- anchorBBoxMock.height = 50;
359
- anchorBBoxMock.x = 200;
360
- anchorBBoxMock.y = 200;
361
- positionMock = {
362
- x: 205,
363
- y: 180,
364
- direction: "top",
365
- };
366
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
367
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowTopBorderStyles}left:22px`);
368
- });
369
-
370
- it("sets a top arrow position (clamp left)", () => {
371
- tooltipBBoxMock.width = 100;
372
- tooltipBBoxMock.height = 20;
373
- anchorBBoxMock.width = 20;
374
- anchorBBoxMock.height = 20;
375
- anchorBBoxMock.x = 0;
376
- anchorBBoxMock.y = 200;
377
- positionMock = {
378
- x: 0,
379
- y: 180,
380
- direction: "top",
381
- };
382
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
383
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowTopBorderStyles}left:8px`);
384
- });
385
-
386
- it("sets a top arrow position (clamp right)", () => {
387
- tooltipBBoxMock.width = 100;
388
- tooltipBBoxMock.height = 20;
389
- anchorBBoxMock.width = 20;
390
- anchorBBoxMock.height = 20;
391
- anchorBBoxMock.x = 180;
392
- anchorBBoxMock.y = 200;
393
- positionMock = {
394
- x: 100,
395
- y: 180,
396
- direction: "top",
397
- };
398
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
399
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowTopBorderStyles}left:82px`);
400
- });
401
-
402
- it("sets a bottom arrow position (tooltip is bigger than anchor)", () => {
403
- tooltipBBoxMock.width = 100;
404
- tooltipBBoxMock.height = 20;
405
- anchorBBoxMock.width = 50;
406
- anchorBBoxMock.height = 50;
407
- anchorBBoxMock.x = 200;
408
- anchorBBoxMock.y = 200;
409
- positionMock = {
410
- x: 175,
411
- y: 180,
412
- direction: "bottom",
413
- };
414
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
415
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowBottomBorderStyles}left:45px`);
416
- });
417
-
418
- it("sets a bottom arrow position (tooltip is smaller than anchor)", () => {
419
- tooltipBBoxMock.width = 40;
420
- tooltipBBoxMock.height = 20;
421
- anchorBBoxMock.width = 50;
422
- anchorBBoxMock.height = 50;
423
- anchorBBoxMock.x = 200;
424
- anchorBBoxMock.y = 200;
425
- positionMock = {
426
- x: 205,
427
- y: 180,
428
- direction: "bottom",
429
- };
430
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
431
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowBottomBorderStyles}left:15px`);
432
- });
433
-
434
- it("sets a bottom arrow position (clamp left)", () => {
435
- tooltipBBoxMock.width = 100;
436
- tooltipBBoxMock.height = 20;
437
- anchorBBoxMock.width = 20;
438
- anchorBBoxMock.height = 20;
439
- anchorBBoxMock.x = 0;
440
- anchorBBoxMock.y = 200;
441
- positionMock = {
442
- x: 0,
443
- y: 180,
444
- direction: "bottom",
445
- };
446
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
447
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowBottomBorderStyles}left:8px`);
448
- });
449
-
450
- it("sets a bottom arrow position (clamp right)", () => {
451
- tooltipBBoxMock.width = 100;
452
- tooltipBBoxMock.height = 20;
453
- anchorBBoxMock.width = 20;
454
- anchorBBoxMock.height = 20;
455
- anchorBBoxMock.x = 180;
456
- anchorBBoxMock.y = 200;
457
- positionMock = {
458
- x: 100,
459
- y: 180,
460
- direction: "bottom",
461
- };
462
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
463
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowBottomBorderStyles}left:82px`);
464
- });
465
-
466
- it("sets a left arrow position (tooltip is bigger than anchor)", () => {
467
- tooltipBBoxMock.width = 20;
468
- tooltipBBoxMock.height = 100;
469
- anchorBBoxMock.width = 50;
470
- anchorBBoxMock.height = 50;
471
- anchorBBoxMock.x = 200;
472
- anchorBBoxMock.y = 200;
473
- positionMock = {
474
- x: 180,
475
- y: 175,
476
- direction: "left",
477
- };
478
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
479
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowLeftBorderStyles}top:45px`);
480
- });
481
-
482
- it("sets a left arrow position (tooltip is smaller than anchor)", () => {
483
- tooltipBBoxMock.width = 20;
484
- tooltipBBoxMock.height = 40;
485
- anchorBBoxMock.width = 50;
486
- anchorBBoxMock.height = 50;
487
- anchorBBoxMock.x = 200;
488
- anchorBBoxMock.y = 200;
489
- positionMock = {
490
- x: 180,
491
- y: 205,
492
- direction: "left",
493
- };
494
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
495
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowLeftBorderStyles}top:15px`);
496
- });
497
-
498
- it("sets a left arrow position (tooltip is smaller than anchor) on a zoomed chart", () => {
499
- chartMock.container.clientWidth = 1600;
500
- tooltipBBoxMock.width = 20;
501
- tooltipBBoxMock.height = 40;
502
- anchorBBoxMock.width = 50;
503
- anchorBBoxMock.height = 50;
504
- anchorBBoxMock.x = 200;
505
- anchorBBoxMock.y = 200;
506
- positionMock = {
507
- x: 180,
508
- y: 205,
509
- direction: "left",
510
- };
511
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
512
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowLeftBorderStyles}top:22px`);
513
- });
514
-
515
- it("sets a left arrow position (clamp top)", () => {
516
- tooltipBBoxMock.width = 20;
517
- tooltipBBoxMock.height = 100;
518
- anchorBBoxMock.width = 20;
519
- anchorBBoxMock.height = 20;
520
- anchorBBoxMock.x = 200;
521
- anchorBBoxMock.y = 0;
522
- positionMock = {
523
- x: 180,
524
- y: 0,
525
- direction: "left",
526
- };
527
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
528
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowLeftBorderStyles}top:8px`);
529
- });
530
-
531
- it("sets a left arrow position (clamp bottom)", () => {
532
- tooltipBBoxMock.width = 20;
533
- tooltipBBoxMock.height = 100;
534
- anchorBBoxMock.width = 20;
535
- anchorBBoxMock.height = 20;
536
- anchorBBoxMock.x = 200;
537
- anchorBBoxMock.y = 180;
538
- positionMock = {
539
- x: 180,
540
- y: 10,
541
- direction: "left",
542
- };
543
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
544
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowLeftBorderStyles}top:82px`);
545
- });
546
-
547
- it("sets a right arrow position (tooltip is bigger than anchor)", () => {
548
- tooltipBBoxMock.width = 20;
549
- tooltipBBoxMock.height = 100;
550
- anchorBBoxMock.width = 50;
551
- anchorBBoxMock.height = 50;
552
- anchorBBoxMock.x = 200;
553
- anchorBBoxMock.y = 200;
554
- positionMock = {
555
- x: 180,
556
- y: 175,
557
- direction: "right",
558
- };
559
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
560
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowRightBorderStyles}top:45px`);
561
- });
562
-
563
- it("sets a right arrow position (tooltip is smaller than anchor)", () => {
564
- tooltipBBoxMock.width = 20;
565
- tooltipBBoxMock.height = 40;
566
- anchorBBoxMock.width = 50;
567
- anchorBBoxMock.height = 50;
568
- anchorBBoxMock.x = 200;
569
- anchorBBoxMock.y = 200;
570
- positionMock = {
571
- x: 180,
572
- y: 205,
573
- direction: "right",
574
- };
575
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
576
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowRightBorderStyles}top:15px`);
577
- });
578
-
579
- it("sets a right arrow position (clamp top)", () => {
580
- tooltipBBoxMock.width = 20;
581
- tooltipBBoxMock.height = 100;
582
- anchorBBoxMock.width = 20;
583
- anchorBBoxMock.height = 20;
584
- anchorBBoxMock.x = 200;
585
- anchorBBoxMock.y = 0;
586
- positionMock = {
587
- x: 180,
588
- y: 0,
589
- direction: "right",
590
- };
591
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
592
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowRightBorderStyles}top:8px`);
593
- });
594
-
595
- it("sets a right arrow position (clamp bottom)", () => {
596
- tooltipBBoxMock.width = 20;
597
- tooltipBBoxMock.height = 100;
598
- anchorBBoxMock.width = 20;
599
- anchorBBoxMock.height = 20;
600
- anchorBBoxMock.x = 200;
601
- anchorBBoxMock.y = 180;
602
- positionMock = {
603
- x: 180,
604
- y: 10,
605
- direction: "right",
606
- };
607
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
608
- expect(arrowElMock.setAttribute).toHaveBeenCalledWith("style", `${commonStyles}${arrowRightBorderStyles}top:82px`);
609
- });
610
-
611
- it("removes old styles", () => {
612
- instance.setArrowPosition(tooltipMock, positionMock, anchorMock, optionsMock);
613
- expect(arrowElMock.removeAttribute).toHaveBeenCalledWith("style");
614
- });
615
- });
616
-
617
- describe("getCoords", () => {
618
- beforeEach(() => {
619
- tooltipBBoxMock.width = 100;
620
- tooltipBBoxMock.height = 20;
621
- anchorBBoxMock.width = 50;
622
- anchorBBoxMock.height = 50;
623
- anchorBBoxMock.x = 200;
624
- anchorBBoxMock.y = 200;
625
- });
626
-
627
- it("gets coordinates (top - without correction)", () => {
628
- expect(instance.getCoords("top", tooltipMock, anchorMock, optionsMock)).toEqual({ x: 175, y: 170 });
629
- });
630
-
631
- it("gets coordinates (top - without correction)", () => {
632
- chartMock.container.clientWidth = 1600;
633
- expect(instance.getCoords("top", tooltipMock, anchorMock, optionsMock)).toEqual({ x: 400, y: 370 });
634
- });
635
-
636
- it("gets coordinates (top - bound to the chart - left)", () => {
637
- anchorBBoxMock.x = 0;
638
- expect(instance.getCoords("top", tooltipMock, anchorMock, optionsMock)).toEqual({ x: 8 /* offset */, y: 170 });
639
- });
640
-
641
- it("gets coordinates (top - bound to the chart - right)", () => {
642
- anchorBBoxMock.x = 1000;
643
- expect(instance.getCoords("top", tooltipMock, anchorMock, optionsMock)).toEqual({
644
- x: 692 /* chartWidth - tooltipWidth - offset */,
645
- y: 170,
646
- });
647
- });
648
-
649
- it("gets coordinates (bottom - without correction)", () => {
650
- expect(instance.getCoords("bottom", tooltipMock, anchorMock, optionsMock)).toEqual({ x: 175, y: 260 });
651
- });
652
-
653
- it("gets coordinates (bottom - bound to the chart - left)", () => {
654
- anchorBBoxMock.x = 0;
655
- expect(instance.getCoords("bottom", tooltipMock, anchorMock, optionsMock)).toEqual({ x: 8 /* offset */, y: 260 });
656
- });
657
-
658
- it("gets coordinates (bottom - bound to the chart - right)", () => {
659
- anchorBBoxMock.x = 1000;
660
- expect(instance.getCoords("bottom", tooltipMock, anchorMock, optionsMock)).toEqual({
661
- x: 692 /* chartWidth - tooltipWidth - offset */,
662
- y: 260,
663
- });
664
- });
665
-
666
- it("gets coordinates (left - without correction)", () => {
667
- expect(instance.getCoords("left", tooltipMock, anchorMock, optionsMock)).toEqual({ x: 90, y: 215 });
668
- });
669
-
670
- it("gets coordinates (left - without correction)", () => {
671
- chartMock.container.clientWidth = 1600;
672
- expect(instance.getCoords("left", tooltipMock, anchorMock, optionsMock)).toEqual({ x: 290, y: 440 });
673
- });
674
-
675
- it("gets coordinates (left - bound to the chart - bottom)", () => {
676
- anchorBBoxMock.y = 1000;
677
- expect(instance.getCoords("left", tooltipMock, anchorMock, optionsMock)).toEqual({ x: 90, y: 572 });
678
- });
679
-
680
- it("gets coordinates (left - bound to the chart - top)", () => {
681
- anchorBBoxMock.y = 0;
682
- tooltipBBoxMock.height = 100;
683
- expect(instance.getCoords("left", tooltipMock, anchorMock, optionsMock)).toEqual({
684
- x: 90,
685
- y: 8,
686
- });
687
- });
688
-
689
- it("gets coordinates (right - without correction)", () => {
690
- expect(instance.getCoords("right", tooltipMock, anchorMock, optionsMock)).toEqual({ x: 260, y: 215 });
691
- });
692
-
693
- it("gets coordinates (right - without correction)", () => {
694
- chartMock.container.clientWidth = 1600;
695
- expect(instance.getCoords("right", tooltipMock, anchorMock, optionsMock)).toEqual({ x: 510, y: 440 });
696
- });
697
-
698
- it("gets coordinates (right - bound to the chart - bottom)", () => {
699
- anchorBBoxMock.y = 1000;
700
- expect(instance.getCoords("right", tooltipMock, anchorMock, optionsMock)).toEqual({
701
- x: 260,
702
- y: 572,
703
- });
704
- });
705
-
706
- it("gets coordinates (right - bound to the chart - top)", () => {
707
- anchorBBoxMock.y = 0;
708
- tooltipBBoxMock.height = 100;
709
- expect(instance.getCoords("right", tooltipMock, anchorMock, optionsMock)).toEqual({
710
- x: 260,
711
- y: 8,
712
- });
713
- });
714
- });
715
-
716
- describe("getAnchorBox", () => {
717
- beforeEach(() => {
718
- chartBBoxMock.x = 100;
719
- chartBBoxMock.y = 100;
720
- });
721
-
722
- it("returns the element bbox (svg element)", () => {
723
- expect(
724
- instance.getAnchorBox({
725
- getBBox: jest.fn().mockReturnValue({ x: 10, y: 10, width: 100, height: 20 }),
726
- })
727
- ).toEqual({ x: 10, y: 10, width: 100, height: 20 });
728
- });
729
-
730
- it("returns the element bbox (html element), uses chart x and y to get reletive coordinates", () => {
731
- expect(
732
- instance.getAnchorBox({
733
- getBoundingClientRect: jest.fn().mockReturnValue({ x: 150, y: 160, width: 100, height: 20 }),
734
- })
735
- ).toEqual({ x: 50, y: 60, width: 100, height: 20 });
736
- });
737
-
738
- it("returns the element bbox (point), uses chart x and y to get reletive coordinates", () => {
739
- expect(instance.getAnchorBox({ x: 150, y: 160 })).toEqual({ x: 50, y: 60, width: 0, height: 0 });
740
- });
741
- });
742
-
743
- describe("getPosition", () => {
744
- it("returns coords and direction for provided direction if it's valid", () => {
745
- optionsMock.direction = "left";
746
- instance.getCoords = jest.fn().mockReturnValue({ x: 100, y: 100 });
747
- expect(instance.getPosition(tooltipMock, anchorMock, optionsMock)).toEqual({
748
- x: 100,
749
- y: 100,
750
- direction: "left",
751
- });
752
- });
753
-
754
- it("looks for an appropriate directions unless it's valid", () => {
755
- optionsMock.direction = "top";
756
- instance.getCoords = jest.fn((direction) => {
757
- // try top -> invalid, out of y
758
- if (direction === "top") {
759
- return {
760
- x: 100,
761
- y: -20,
762
- };
763
- // try right, invalid -> out of x
764
- } else if (direction === "right") {
765
- return {
766
- x: -100,
767
- y: 20,
768
- };
769
- // try bottom, invalid -> out of y
770
- } else if (direction === "bottom") {
771
- return {
772
- x: 100,
773
- y: 2000,
774
- };
775
- } else {
776
- return {
777
- x: 50,
778
- y: 50,
779
- };
780
- }
781
- });
782
- expect(instance.getPosition(tooltipMock, anchorMock, optionsMock)).toEqual({
783
- x: 50,
784
- y: 50,
785
- direction: "left",
786
- });
787
- });
788
- });
789
- });