@internetarchive/histogram-date-range 1.3.2 → 1.4.0-alpha-webdev7756.1
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.
- package/demo/index.html +20 -0
- package/dist/demo/js/list-histogram-wrapper.d.ts +20 -0
- package/dist/demo/js/list-histogram-wrapper.js +59 -0
- package/dist/demo/js/list-histogram-wrapper.js.map +1 -0
- package/dist/demo/js/lit-histogram-wrapper.d.ts +21 -0
- package/dist/demo/js/lit-histogram-wrapper.js +73 -0
- package/dist/demo/js/lit-histogram-wrapper.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/src/histogram-date-range.d.ts +27 -0
- package/dist/src/histogram-date-range.js +301 -245
- package/dist/src/histogram-date-range.js.map +1 -1
- package/dist/test/histogram-date-range.test.js +221 -179
- package/dist/test/histogram-date-range.test.js.map +1 -1
- package/docs/demo/index.html +20 -0
- package/docs/dist/src/histogram-date-range.js +44 -12
- package/index.ts +3 -0
- package/package.json +1 -1
- package/src/histogram-date-range.ts +1172 -1110
- package/test/histogram-date-range.test.ts +992 -935
- package/dist/src/dayjs/fix-first-century-years.d.ts +0 -2
- package/dist/src/dayjs/fix-first-century-years.js +0 -25
- package/dist/src/dayjs/fix-first-century-years.js.map +0 -1
- package/dist/src/dayjs/fix-two-digit-dates.d.ts +0 -2
- package/dist/src/dayjs/fix-two-digit-dates.js +0 -25
- package/dist/src/dayjs/fix-two-digit-dates.js.map +0 -1
- package/dist/src/histogram-date-range copy.d.ts +0 -214
- package/dist/src/histogram-date-range copy.js +0 -1018
- package/dist/src/histogram-date-range copy.js.map +0 -1
|
@@ -3,31 +3,31 @@ import { html, fixture, expect, oneEvent, aTimeout } from '@open-wc/testing';
|
|
|
3
3
|
import '../src/histogram-date-range';
|
|
4
4
|
const SLIDER_WIDTH = 10;
|
|
5
5
|
const WIDTH = 200;
|
|
6
|
-
const subject = html `
|
|
7
|
-
<histogram-date-range
|
|
8
|
-
width="${WIDTH}"
|
|
9
|
-
tooltipWidth="140"
|
|
10
|
-
height="50"
|
|
11
|
-
dateFormat="M/D/YYYY"
|
|
12
|
-
minDate="1900"
|
|
13
|
-
maxDate="12/4/2020"
|
|
14
|
-
bins="[33, 1, 100]"
|
|
15
|
-
>
|
|
16
|
-
</histogram-date-range>
|
|
6
|
+
const subject = html `
|
|
7
|
+
<histogram-date-range
|
|
8
|
+
width="${WIDTH}"
|
|
9
|
+
tooltipWidth="140"
|
|
10
|
+
height="50"
|
|
11
|
+
dateFormat="M/D/YYYY"
|
|
12
|
+
minDate="1900"
|
|
13
|
+
maxDate="12/4/2020"
|
|
14
|
+
bins="[33, 1, 100]"
|
|
15
|
+
>
|
|
16
|
+
</histogram-date-range>
|
|
17
17
|
`;
|
|
18
18
|
async function createCustomElementInHTMLContainer() {
|
|
19
|
-
document.head.insertAdjacentHTML('beforeend', `<style>
|
|
20
|
-
html {
|
|
21
|
-
font-size:10px;
|
|
22
|
-
}
|
|
23
|
-
.container {
|
|
24
|
-
width: 400px;
|
|
25
|
-
height: 400px;
|
|
26
|
-
display: flex;
|
|
27
|
-
background: #FFF6E1;
|
|
28
|
-
justify-content: center;
|
|
29
|
-
align-items: center;
|
|
30
|
-
}
|
|
19
|
+
document.head.insertAdjacentHTML('beforeend', `<style>
|
|
20
|
+
html {
|
|
21
|
+
font-size:10px;
|
|
22
|
+
}
|
|
23
|
+
.container {
|
|
24
|
+
width: 400px;
|
|
25
|
+
height: 400px;
|
|
26
|
+
display: flex;
|
|
27
|
+
background: #FFF6E1;
|
|
28
|
+
justify-content: center;
|
|
29
|
+
align-items: center;
|
|
30
|
+
}
|
|
31
31
|
</style>`);
|
|
32
32
|
// https://open-wc.org/docs/testing/helpers/#customize-the-fixture-container
|
|
33
33
|
const parentNode = document.createElement('div');
|
|
@@ -35,13 +35,31 @@ async function createCustomElementInHTMLContainer() {
|
|
|
35
35
|
return fixture(subject, { parentNode });
|
|
36
36
|
}
|
|
37
37
|
describe('HistogramDateRange', () => {
|
|
38
|
-
it('shows scaled histogram bars when provided with data', async () => {
|
|
38
|
+
it('shows log-scaled histogram bars when provided with data', async () => {
|
|
39
39
|
var _a;
|
|
40
40
|
const el = await createCustomElementInHTMLContainer();
|
|
41
41
|
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
42
|
-
const heights = Array.from(bars
|
|
42
|
+
const heights = Array.from(bars, b => b.height.baseVal.value);
|
|
43
43
|
expect(heights).to.eql([38, 7, 50]);
|
|
44
44
|
});
|
|
45
|
+
it('uses linear bar height scaling when specified', async () => {
|
|
46
|
+
var _a;
|
|
47
|
+
const el = await createCustomElementInHTMLContainer();
|
|
48
|
+
el.barScaling = 'linear';
|
|
49
|
+
await el.updateComplete;
|
|
50
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
51
|
+
const heights = Array.from(bars, b => b.height.baseVal.value);
|
|
52
|
+
expect(heights).to.eql([16, 0, 50]);
|
|
53
|
+
});
|
|
54
|
+
it('uses custom bar height scaling when specified', async () => {
|
|
55
|
+
var _a;
|
|
56
|
+
const el = await createCustomElementInHTMLContainer();
|
|
57
|
+
el.barScaling = (x) => Math.sqrt(x);
|
|
58
|
+
await el.updateComplete;
|
|
59
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
60
|
+
const heights = Array.from(bars, b => b.height.baseVal.value);
|
|
61
|
+
expect(heights).to.eql([28, 5, 50]);
|
|
62
|
+
});
|
|
45
63
|
it('changes the position of the sliders and standardizes date format when dates are entered', async () => {
|
|
46
64
|
var _a, _b;
|
|
47
65
|
const el = await createCustomElementInHTMLContainer();
|
|
@@ -302,7 +320,7 @@ describe('HistogramDateRange', () => {
|
|
|
302
320
|
// include a number which will require commas (1,000,000)
|
|
303
321
|
el.bins = [1000000, 1, 100];
|
|
304
322
|
await aTimeout(10);
|
|
305
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
323
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
306
324
|
const tooltip = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#tooltip');
|
|
307
325
|
expect(tooltip.innerText).to.eq('');
|
|
308
326
|
// hover
|
|
@@ -320,10 +338,34 @@ describe('HistogramDateRange', () => {
|
|
|
320
338
|
await el.updateComplete;
|
|
321
339
|
expect(tooltip.innerText).to.match(/^1 item\n4\/23\/1940 - 8\/13\/1980/);
|
|
322
340
|
});
|
|
341
|
+
it('uses provided tooltip label', async () => {
|
|
342
|
+
var _a, _b;
|
|
343
|
+
const el = await createCustomElementInHTMLContainer();
|
|
344
|
+
el.bins = [1000000, 1, 100];
|
|
345
|
+
el.tooltipLabel = 'foobar';
|
|
346
|
+
await aTimeout(10);
|
|
347
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
348
|
+
const tooltip = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#tooltip');
|
|
349
|
+
expect(tooltip.innerText).to.eq('');
|
|
350
|
+
// hover
|
|
351
|
+
bars[0].dispatchEvent(new PointerEvent('pointerenter'));
|
|
352
|
+
await el.updateComplete;
|
|
353
|
+
expect(tooltip.innerText).to.match(/^1,000,000 foobars\n1\/1\/1900 - 4\/23\/1940/);
|
|
354
|
+
expect(getComputedStyle(tooltip).display).to.eq('block');
|
|
355
|
+
// leave
|
|
356
|
+
bars[0].dispatchEvent(new PointerEvent('pointerleave'));
|
|
357
|
+
await el.updateComplete;
|
|
358
|
+
expect(getComputedStyle(tooltip).display).to.eq('none');
|
|
359
|
+
expect(tooltip.innerText).to.eq('');
|
|
360
|
+
// ensure singular item is not pluralized
|
|
361
|
+
bars[1].dispatchEvent(new PointerEvent('pointerenter'));
|
|
362
|
+
await el.updateComplete;
|
|
363
|
+
expect(tooltip.innerText).to.match(/^1 foobar\n4\/23\/1940 - 8\/13\/1980/);
|
|
364
|
+
});
|
|
323
365
|
it('does not show tooltip while dragging', async () => {
|
|
324
366
|
var _a, _b, _c;
|
|
325
367
|
const el = await createCustomElementInHTMLContainer();
|
|
326
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
368
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
327
369
|
const tooltip = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#tooltip');
|
|
328
370
|
expect(tooltip.innerText).to.eq('');
|
|
329
371
|
const minSlider = (_c = el.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('#slider-min');
|
|
@@ -342,15 +384,15 @@ describe('HistogramDateRange', () => {
|
|
|
342
384
|
});
|
|
343
385
|
it('allows range to be pre-selected', async () => {
|
|
344
386
|
var _a, _b;
|
|
345
|
-
const el = await fixture(html `
|
|
346
|
-
<histogram-date-range
|
|
347
|
-
minDate="1900"
|
|
348
|
-
maxDate="Dec 4, 2020"
|
|
349
|
-
minSelectedDate="2012"
|
|
350
|
-
maxSelectedDate="2019"
|
|
351
|
-
bins="[33, 1, 100]"
|
|
352
|
-
>
|
|
353
|
-
</histogram-date-range>
|
|
387
|
+
const el = await fixture(html `
|
|
388
|
+
<histogram-date-range
|
|
389
|
+
minDate="1900"
|
|
390
|
+
maxDate="Dec 4, 2020"
|
|
391
|
+
minSelectedDate="2012"
|
|
392
|
+
maxSelectedDate="2019"
|
|
393
|
+
bins="[33, 1, 100]"
|
|
394
|
+
>
|
|
395
|
+
</histogram-date-range>
|
|
354
396
|
`);
|
|
355
397
|
const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
|
|
356
398
|
expect(minDateInput.value).to.eq('2012');
|
|
@@ -359,57 +401,57 @@ describe('HistogramDateRange', () => {
|
|
|
359
401
|
});
|
|
360
402
|
it('extends the selected range when the histogram is clicked outside of the current range', async () => {
|
|
361
403
|
var _a, _b;
|
|
362
|
-
const el = await fixture(html `
|
|
363
|
-
<histogram-date-range
|
|
364
|
-
minDate="1900"
|
|
365
|
-
maxDate="2020"
|
|
366
|
-
minSelectedDate="1950"
|
|
367
|
-
maxSelectedDate="1955"
|
|
368
|
-
bins="[33, 1, 1, 1, 10, 10, 1, 1, 1, 50, 100]"
|
|
369
|
-
>
|
|
370
|
-
</histogram-date-range>
|
|
404
|
+
const el = await fixture(html `
|
|
405
|
+
<histogram-date-range
|
|
406
|
+
minDate="1900"
|
|
407
|
+
maxDate="2020"
|
|
408
|
+
minSelectedDate="1950"
|
|
409
|
+
maxSelectedDate="1955"
|
|
410
|
+
bins="[33, 1, 1, 1, 10, 10, 1, 1, 1, 50, 100]"
|
|
411
|
+
>
|
|
412
|
+
</histogram-date-range>
|
|
371
413
|
`);
|
|
372
|
-
const leftBarToClick = Array.from((_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar'))[1]; // click on second bar to the left
|
|
414
|
+
const leftBarToClick = Array.from((_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target'))[1]; // click on second bar to the left
|
|
373
415
|
leftBarToClick.dispatchEvent(new Event('click'));
|
|
374
416
|
await el.updateComplete;
|
|
375
417
|
expect(el.minSelectedDate).to.eq('1910'); // range was extended to left
|
|
376
|
-
const rightBarToClick = Array.from((_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelectorAll('.bar'))[8]; // click on second bar from the right
|
|
418
|
+
const rightBarToClick = Array.from((_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelectorAll('.bar-pointer-target'))[8]; // click on second bar from the right
|
|
377
419
|
rightBarToClick.dispatchEvent(new Event('click'));
|
|
378
420
|
expect(el.maxSelectedDate).to.eq('1998'); // range was extended to right
|
|
379
421
|
});
|
|
380
422
|
it('narrows the selected range when the histogram is clicked inside of the current range', async () => {
|
|
381
423
|
var _a, _b;
|
|
382
|
-
const el = await fixture(html `
|
|
383
|
-
<histogram-date-range
|
|
384
|
-
minDate="1900"
|
|
385
|
-
maxDate="2020"
|
|
386
|
-
minSelectedDate="1900"
|
|
387
|
-
maxSelectedDate="2020"
|
|
388
|
-
bins="[33, 1, 1, 1, 10, 10, 1, 1, 1, 50, 100]"
|
|
389
|
-
>
|
|
390
|
-
</histogram-date-range>
|
|
424
|
+
const el = await fixture(html `
|
|
425
|
+
<histogram-date-range
|
|
426
|
+
minDate="1900"
|
|
427
|
+
maxDate="2020"
|
|
428
|
+
minSelectedDate="1900"
|
|
429
|
+
maxSelectedDate="2020"
|
|
430
|
+
bins="[33, 1, 1, 1, 10, 10, 1, 1, 1, 50, 100]"
|
|
431
|
+
>
|
|
432
|
+
</histogram-date-range>
|
|
391
433
|
`);
|
|
392
434
|
///////////////////////////////////////////////
|
|
393
435
|
// NB: the slider nearest the clicked bar moves
|
|
394
436
|
///////////////////////////////////////////////
|
|
395
|
-
const leftBarToClick = Array.from((_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar'))[3]; // click on fourth bar to the left
|
|
437
|
+
const leftBarToClick = Array.from((_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target'))[3]; // click on fourth bar to the left
|
|
396
438
|
leftBarToClick.dispatchEvent(new Event('click'));
|
|
397
439
|
expect(el.minSelectedDate).to.eq('1932'); // range was extended to the right
|
|
398
|
-
const rightBarToClick = Array.from((_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelectorAll('.bar'))[8]; // click on second bar from the right
|
|
440
|
+
const rightBarToClick = Array.from((_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelectorAll('.bar-pointer-target'))[8]; // click on second bar from the right
|
|
399
441
|
rightBarToClick.dispatchEvent(new Event('click'));
|
|
400
442
|
expect(el.maxSelectedDate).to.eq('1998'); // range was extended to the left
|
|
401
443
|
});
|
|
402
444
|
it('handles invalid pre-selected range by defaulting to overall max and min', async () => {
|
|
403
445
|
var _a, _b;
|
|
404
|
-
const el = await fixture(html `
|
|
405
|
-
<histogram-date-range
|
|
406
|
-
minDate="1900"
|
|
407
|
-
maxDate="2020"
|
|
408
|
-
minSelectedDate="2000xyz"
|
|
409
|
-
maxSelectedDate="5000"
|
|
410
|
-
bins="[33, 1, 100]"
|
|
411
|
-
>
|
|
412
|
-
</histogram-date-range>
|
|
446
|
+
const el = await fixture(html `
|
|
447
|
+
<histogram-date-range
|
|
448
|
+
minDate="1900"
|
|
449
|
+
maxDate="2020"
|
|
450
|
+
minSelectedDate="2000xyz"
|
|
451
|
+
maxSelectedDate="5000"
|
|
452
|
+
bins="[33, 1, 100]"
|
|
453
|
+
>
|
|
454
|
+
</histogram-date-range>
|
|
413
455
|
`);
|
|
414
456
|
const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
|
|
415
457
|
// malformed min date defaults to overall min
|
|
@@ -420,16 +462,16 @@ describe('HistogramDateRange', () => {
|
|
|
420
462
|
});
|
|
421
463
|
it('handles year values less than 1000 correctly', async () => {
|
|
422
464
|
var _a, _b;
|
|
423
|
-
const el = await fixture(html `
|
|
424
|
-
<histogram-date-range
|
|
425
|
-
dateFormat="M/D/YYYY"
|
|
426
|
-
minDate="-2000"
|
|
427
|
-
maxDate="2000"
|
|
428
|
-
minSelectedDate="-500"
|
|
429
|
-
maxSelectedDate="500"
|
|
430
|
-
bins="[33, 1, 100]"
|
|
431
|
-
>
|
|
432
|
-
</histogram-date-range>
|
|
465
|
+
const el = await fixture(html `
|
|
466
|
+
<histogram-date-range
|
|
467
|
+
dateFormat="M/D/YYYY"
|
|
468
|
+
minDate="-2000"
|
|
469
|
+
maxDate="2000"
|
|
470
|
+
minSelectedDate="-500"
|
|
471
|
+
maxSelectedDate="500"
|
|
472
|
+
bins="[33, 1, 100]"
|
|
473
|
+
>
|
|
474
|
+
</histogram-date-range>
|
|
433
475
|
`);
|
|
434
476
|
const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
|
|
435
477
|
expect(minDateInput.value).to.eq('1/1/-500');
|
|
@@ -438,52 +480,52 @@ describe('HistogramDateRange', () => {
|
|
|
438
480
|
});
|
|
439
481
|
it('handles missing data', async () => {
|
|
440
482
|
var _a, _b;
|
|
441
|
-
let el = await fixture(html `<histogram-date-range>
|
|
442
|
-
minDate="1900" maxDate="2020" bins=""
|
|
483
|
+
let el = await fixture(html `<histogram-date-range>
|
|
484
|
+
minDate="1900" maxDate="2020" bins=""
|
|
443
485
|
</histogram-date-range>`);
|
|
444
486
|
expect((_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.innerHTML).to.contain('no data');
|
|
445
|
-
el = await fixture(html `<histogram-date-range
|
|
446
|
-
minDate="1900"
|
|
447
|
-
maxDate="2020"
|
|
448
|
-
bins="[]"
|
|
449
|
-
missingDataMessage="no data available"
|
|
487
|
+
el = await fixture(html `<histogram-date-range
|
|
488
|
+
minDate="1900"
|
|
489
|
+
maxDate="2020"
|
|
490
|
+
bins="[]"
|
|
491
|
+
missingDataMessage="no data available"
|
|
450
492
|
></histogram-date-range>`);
|
|
451
493
|
expect((_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.innerHTML).to.contain('no data available');
|
|
452
494
|
});
|
|
453
495
|
it('correctly displays data consisting of a single bin', async () => {
|
|
454
496
|
var _a;
|
|
455
|
-
const el = await fixture(html `
|
|
456
|
-
<histogram-date-range minDate="2020" maxDate="2020" bins="[50]">
|
|
457
|
-
</histogram-date-range>
|
|
497
|
+
const el = await fixture(html `
|
|
498
|
+
<histogram-date-range minDate="2020" maxDate="2020" bins="[50]">
|
|
499
|
+
</histogram-date-range>
|
|
458
500
|
`);
|
|
459
501
|
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
460
|
-
const heights = Array.from(bars
|
|
502
|
+
const heights = Array.from(bars, b => b.height.baseVal.value);
|
|
461
503
|
expect(heights).to.eql([157]);
|
|
462
504
|
});
|
|
463
505
|
it('correctly displays small diff between max and min values', async () => {
|
|
464
506
|
var _a;
|
|
465
|
-
const el = await fixture(html `
|
|
466
|
-
<histogram-date-range bins="[1519,2643,1880,2041,1638,1441]">
|
|
467
|
-
</histogram-date-range>
|
|
507
|
+
const el = await fixture(html `
|
|
508
|
+
<histogram-date-range bins="[1519,2643,1880,2041,1638,1441]">
|
|
509
|
+
</histogram-date-range>
|
|
468
510
|
`);
|
|
469
511
|
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
470
|
-
const heights = Array.from(bars
|
|
512
|
+
const heights = Array.from(bars, b => b.height.baseVal.value);
|
|
471
513
|
expect(heights).to.eql([37, 40, 38, 38, 37, 36]);
|
|
472
514
|
});
|
|
473
515
|
it('correctly aligns bins to exact month boundaries when binSnapping=month', async () => {
|
|
474
516
|
var _a;
|
|
475
|
-
const el = await fixture(html `
|
|
476
|
-
<histogram-date-range
|
|
477
|
-
binSnapping="month"
|
|
478
|
-
dateFormat="YYYY-MM"
|
|
479
|
-
tooltipDateFormat="MMM YYYY"
|
|
480
|
-
minDate="2020-01"
|
|
481
|
-
maxDate="2021-12"
|
|
482
|
-
bins="[10,20,30,40,50,60,70,80]"
|
|
483
|
-
></histogram-date-range>
|
|
517
|
+
const el = await fixture(html `
|
|
518
|
+
<histogram-date-range
|
|
519
|
+
binSnapping="month"
|
|
520
|
+
dateFormat="YYYY-MM"
|
|
521
|
+
tooltipDateFormat="MMM YYYY"
|
|
522
|
+
minDate="2020-01"
|
|
523
|
+
maxDate="2021-12"
|
|
524
|
+
bins="[10,20,30,40,50,60,70,80]"
|
|
525
|
+
></histogram-date-range>
|
|
484
526
|
`);
|
|
485
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
486
|
-
const tooltips = Array.from(bars
|
|
527
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
528
|
+
const tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
487
529
|
expect(tooltips).to.eql([
|
|
488
530
|
'Jan 2020 - Mar 2020',
|
|
489
531
|
'Apr 2020 - Jun 2020',
|
|
@@ -497,18 +539,18 @@ describe('HistogramDateRange', () => {
|
|
|
497
539
|
});
|
|
498
540
|
it('correctly handles month snapping for years 0-99', async () => {
|
|
499
541
|
var _a;
|
|
500
|
-
const el = await fixture(html `
|
|
501
|
-
<histogram-date-range
|
|
502
|
-
binSnapping="month"
|
|
503
|
-
dateFormat="YYYY-MM"
|
|
504
|
-
tooltipDateFormat="MMM YYYY"
|
|
505
|
-
minDate="0050-01"
|
|
506
|
-
maxDate="0065-12"
|
|
507
|
-
bins="[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]"
|
|
508
|
-
></histogram-date-range>
|
|
542
|
+
const el = await fixture(html `
|
|
543
|
+
<histogram-date-range
|
|
544
|
+
binSnapping="month"
|
|
545
|
+
dateFormat="YYYY-MM"
|
|
546
|
+
tooltipDateFormat="MMM YYYY"
|
|
547
|
+
minDate="0050-01"
|
|
548
|
+
maxDate="0065-12"
|
|
549
|
+
bins="[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]"
|
|
550
|
+
></histogram-date-range>
|
|
509
551
|
`);
|
|
510
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
511
|
-
const tooltips = Array.from(bars
|
|
552
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
553
|
+
const tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
512
554
|
expect(tooltips).to.eql([
|
|
513
555
|
'Jan 50 - Jun 50',
|
|
514
556
|
'Jul 50 - Dec 50',
|
|
@@ -546,16 +588,16 @@ describe('HistogramDateRange', () => {
|
|
|
546
588
|
});
|
|
547
589
|
it('correctly aligns bins to exact year boundaries when binSnapping=year', async () => {
|
|
548
590
|
var _a;
|
|
549
|
-
const el = await fixture(html `
|
|
550
|
-
<histogram-date-range
|
|
551
|
-
binSnapping="year"
|
|
552
|
-
minDate="2000"
|
|
553
|
-
maxDate="2019"
|
|
554
|
-
bins="[10,20,30,40,50,60,70,80,90,100]"
|
|
555
|
-
></histogram-date-range>
|
|
591
|
+
const el = await fixture(html `
|
|
592
|
+
<histogram-date-range
|
|
593
|
+
binSnapping="year"
|
|
594
|
+
minDate="2000"
|
|
595
|
+
maxDate="2019"
|
|
596
|
+
bins="[10,20,30,40,50,60,70,80,90,100]"
|
|
597
|
+
></histogram-date-range>
|
|
556
598
|
`);
|
|
557
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
558
|
-
const tooltips = Array.from(bars
|
|
599
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
600
|
+
const tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
559
601
|
expect(tooltips).to.eql([
|
|
560
602
|
'2000 - 2001',
|
|
561
603
|
'2002 - 2003',
|
|
@@ -571,53 +613,53 @@ describe('HistogramDateRange', () => {
|
|
|
571
613
|
});
|
|
572
614
|
it('correctly handles year snapping for years 0-99', async () => {
|
|
573
615
|
var _a;
|
|
574
|
-
const el = await fixture(html `
|
|
575
|
-
<histogram-date-range
|
|
576
|
-
binSnapping="year"
|
|
577
|
-
dateFormat="YYYY"
|
|
578
|
-
minDate="0020"
|
|
579
|
-
maxDate="0025"
|
|
580
|
-
bins="[1,2,3,4,5,6]"
|
|
581
|
-
></histogram-date-range>
|
|
616
|
+
const el = await fixture(html `
|
|
617
|
+
<histogram-date-range
|
|
618
|
+
binSnapping="year"
|
|
619
|
+
dateFormat="YYYY"
|
|
620
|
+
minDate="0020"
|
|
621
|
+
maxDate="0025"
|
|
622
|
+
bins="[1,2,3,4,5,6]"
|
|
623
|
+
></histogram-date-range>
|
|
582
624
|
`);
|
|
583
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
584
|
-
const tooltips = Array.from(bars
|
|
625
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
626
|
+
const tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
585
627
|
expect(tooltips).to.eql(['20', '21', '22', '23', '24', '25']);
|
|
586
628
|
});
|
|
587
629
|
it('does not duplicate start/end date in tooltips when representing a single year', async () => {
|
|
588
630
|
var _a;
|
|
589
|
-
const el = await fixture(html `
|
|
590
|
-
<histogram-date-range
|
|
591
|
-
binSnapping="year"
|
|
592
|
-
dateFormat="YYYY"
|
|
593
|
-
minDate="2001"
|
|
594
|
-
maxDate="2005"
|
|
595
|
-
bins="[10,20,30,40,50]"
|
|
596
|
-
></histogram-date-range>
|
|
631
|
+
const el = await fixture(html `
|
|
632
|
+
<histogram-date-range
|
|
633
|
+
binSnapping="year"
|
|
634
|
+
dateFormat="YYYY"
|
|
635
|
+
minDate="2001"
|
|
636
|
+
maxDate="2005"
|
|
637
|
+
bins="[10,20,30,40,50]"
|
|
638
|
+
></histogram-date-range>
|
|
597
639
|
`);
|
|
598
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
599
|
-
const tooltips = Array.from(bars
|
|
640
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
641
|
+
const tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
600
642
|
expect(tooltips).to.eql(['2001', '2002', '2003', '2004', '2005']);
|
|
601
643
|
});
|
|
602
644
|
it('falls back to default date format for tooltips if no tooltip date format provided', async () => {
|
|
603
645
|
var _a;
|
|
604
|
-
const el = await fixture(html `
|
|
605
|
-
<histogram-date-range
|
|
606
|
-
binSnapping="year"
|
|
607
|
-
minDate="2001"
|
|
608
|
-
maxDate="2005"
|
|
609
|
-
bins="[10,20,30,40,50]"
|
|
610
|
-
></histogram-date-range>
|
|
646
|
+
const el = await fixture(html `
|
|
647
|
+
<histogram-date-range
|
|
648
|
+
binSnapping="year"
|
|
649
|
+
minDate="2001"
|
|
650
|
+
maxDate="2005"
|
|
651
|
+
bins="[10,20,30,40,50]"
|
|
652
|
+
></histogram-date-range>
|
|
611
653
|
`);
|
|
612
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
613
|
-
let tooltips = Array.from(bars
|
|
654
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
655
|
+
let tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
614
656
|
expect(tooltips).to.eql(['2001', '2002', '2003', '2004', '2005']); // default YYYY date format
|
|
615
657
|
el.dateFormat = 'YYYY/MM';
|
|
616
658
|
el.minDate = '2001/01';
|
|
617
659
|
el.maxDate = '2005/01';
|
|
618
660
|
await el.updateComplete;
|
|
619
661
|
// Should use dateFormat fallback for tooltips
|
|
620
|
-
tooltips = Array.from(bars
|
|
662
|
+
tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
621
663
|
expect(tooltips).to.eql([
|
|
622
664
|
'2001/01 - 2001/12',
|
|
623
665
|
'2002/01 - 2002/12',
|
|
@@ -631,7 +673,7 @@ describe('HistogramDateRange', () => {
|
|
|
631
673
|
el.maxDate = '2005';
|
|
632
674
|
await el.updateComplete;
|
|
633
675
|
// Should use defined tooltipDateFormat for tooltips
|
|
634
|
-
tooltips = Array.from(bars
|
|
676
|
+
tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
635
677
|
expect(tooltips).to.eql([
|
|
636
678
|
'January 2001 - December 2001',
|
|
637
679
|
'January 2002 - December 2002',
|
|
@@ -642,14 +684,14 @@ describe('HistogramDateRange', () => {
|
|
|
642
684
|
});
|
|
643
685
|
it('has a disabled state', async () => {
|
|
644
686
|
var _a, _b, _c;
|
|
645
|
-
const el = await fixture(html `
|
|
646
|
-
<histogram-date-range
|
|
647
|
-
minDate="1900"
|
|
648
|
-
maxDate="2020"
|
|
649
|
-
disabled
|
|
650
|
-
bins="[33, 1, 100]"
|
|
651
|
-
>
|
|
652
|
-
</histogram-date-range>
|
|
687
|
+
const el = await fixture(html `
|
|
688
|
+
<histogram-date-range
|
|
689
|
+
minDate="1900"
|
|
690
|
+
maxDate="2020"
|
|
691
|
+
disabled
|
|
692
|
+
bins="[33, 1, 100]"
|
|
693
|
+
>
|
|
694
|
+
</histogram-date-range>
|
|
653
695
|
`);
|
|
654
696
|
expect((_b = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.inner-container')) === null || _b === void 0 ? void 0 : _b.classList.contains('disabled')).to.eq(true);
|
|
655
697
|
const minSlider = (_c = el.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('#slider-min');
|
|
@@ -667,28 +709,28 @@ describe('HistogramDateRange', () => {
|
|
|
667
709
|
});
|
|
668
710
|
it('has a loading state with an activity indicator', async () => {
|
|
669
711
|
var _a, _b, _c, _d;
|
|
670
|
-
const el = await fixture(html `
|
|
671
|
-
<histogram-date-range
|
|
672
|
-
minDate="1900"
|
|
673
|
-
maxDate="2020"
|
|
674
|
-
loading
|
|
675
|
-
bins="[33, 1, 100]"
|
|
676
|
-
>
|
|
677
|
-
</histogram-date-range>
|
|
712
|
+
const el = await fixture(html `
|
|
713
|
+
<histogram-date-range
|
|
714
|
+
minDate="1900"
|
|
715
|
+
maxDate="2020"
|
|
716
|
+
loading
|
|
717
|
+
bins="[33, 1, 100]"
|
|
718
|
+
>
|
|
719
|
+
</histogram-date-range>
|
|
678
720
|
`);
|
|
679
721
|
expect((_d = (_c = (_b = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('ia-activity-indicator')) === null || _b === void 0 ? void 0 : _b.attributes) === null || _c === void 0 ? void 0 : _c.getNamedItem('mode')) === null || _d === void 0 ? void 0 : _d.value).to.eq('processing');
|
|
680
722
|
});
|
|
681
723
|
it('can use LitElement bound properties', async () => {
|
|
682
724
|
var _a, _b;
|
|
683
|
-
const el = await fixture(html `
|
|
684
|
-
<histogram-date-range
|
|
685
|
-
.minDate=${1900}
|
|
686
|
-
.maxDate=${'Dec 4, 2020'}
|
|
687
|
-
.minSelectedDate=${2012}
|
|
688
|
-
.maxSelectedDate=${2019}
|
|
689
|
-
.bins=${[33, 1, 100]}
|
|
690
|
-
>
|
|
691
|
-
</histogram-date-range>
|
|
725
|
+
const el = await fixture(html `
|
|
726
|
+
<histogram-date-range
|
|
727
|
+
.minDate=${1900}
|
|
728
|
+
.maxDate=${'Dec 4, 2020'}
|
|
729
|
+
.minSelectedDate=${2012}
|
|
730
|
+
.maxSelectedDate=${2019}
|
|
731
|
+
.bins=${[33, 1, 100]}
|
|
732
|
+
>
|
|
733
|
+
</histogram-date-range>
|
|
692
734
|
`);
|
|
693
735
|
const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
|
|
694
736
|
expect(minDateInput.value).to.eq('2012');
|