@internetarchive/histogram-date-range 1.3.2 → 1.4.0-alpha-webdev7756.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.
- package/demo/index.html +9 -2
- package/demo/js/{app-root.ts → lit-histogram-wrapper.ts} +20 -4
- package/dist/demo/js/app-root.d.ts +2 -1
- package/dist/demo/js/app-root.js +20 -19
- package/dist/demo/js/app-root.js.map +1 -1
- 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/src/histogram-date-range.d.ts +18 -0
- package/dist/src/histogram-date-range.js +282 -242
- package/dist/src/histogram-date-range.js.map +1 -1
- package/dist/test/histogram-date-range.test.js +202 -178
- package/dist/test/histogram-date-range.test.js.map +1 -1
- package/docs/demo/index.html +9 -2
- package/docs/dist/demo/js/{app-root.js → lit-histogram-wrapper.js} +22 -7
- package/docs/dist/src/histogram-date-range.js +34 -11
- package/package.json +1 -1
- package/src/histogram-date-range.ts +1152 -1110
- package/test/histogram-date-range.test.ts +966 -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');
|
|
@@ -39,7 +39,7 @@ describe('HistogramDateRange', () => {
|
|
|
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
45
|
it('changes the position of the sliders and standardizes date format when dates are entered', async () => {
|
|
@@ -302,7 +302,7 @@ describe('HistogramDateRange', () => {
|
|
|
302
302
|
// include a number which will require commas (1,000,000)
|
|
303
303
|
el.bins = [1000000, 1, 100];
|
|
304
304
|
await aTimeout(10);
|
|
305
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
305
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
306
306
|
const tooltip = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#tooltip');
|
|
307
307
|
expect(tooltip.innerText).to.eq('');
|
|
308
308
|
// hover
|
|
@@ -320,10 +320,34 @@ describe('HistogramDateRange', () => {
|
|
|
320
320
|
await el.updateComplete;
|
|
321
321
|
expect(tooltip.innerText).to.match(/^1 item\n4\/23\/1940 - 8\/13\/1980/);
|
|
322
322
|
});
|
|
323
|
+
it('uses provided tooltip label', async () => {
|
|
324
|
+
var _a, _b;
|
|
325
|
+
const el = await createCustomElementInHTMLContainer();
|
|
326
|
+
el.bins = [1000000, 1, 100];
|
|
327
|
+
el.tooltipLabel = 'foobar';
|
|
328
|
+
await aTimeout(10);
|
|
329
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
330
|
+
const tooltip = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#tooltip');
|
|
331
|
+
expect(tooltip.innerText).to.eq('');
|
|
332
|
+
// hover
|
|
333
|
+
bars[0].dispatchEvent(new PointerEvent('pointerenter'));
|
|
334
|
+
await el.updateComplete;
|
|
335
|
+
expect(tooltip.innerText).to.match(/^1,000,000 foobars\n1\/1\/1900 - 4\/23\/1940/);
|
|
336
|
+
expect(getComputedStyle(tooltip).display).to.eq('block');
|
|
337
|
+
// leave
|
|
338
|
+
bars[0].dispatchEvent(new PointerEvent('pointerleave'));
|
|
339
|
+
await el.updateComplete;
|
|
340
|
+
expect(getComputedStyle(tooltip).display).to.eq('none');
|
|
341
|
+
expect(tooltip.innerText).to.eq('');
|
|
342
|
+
// ensure singular item is not pluralized
|
|
343
|
+
bars[1].dispatchEvent(new PointerEvent('pointerenter'));
|
|
344
|
+
await el.updateComplete;
|
|
345
|
+
expect(tooltip.innerText).to.match(/^1 foobar\n4\/23\/1940 - 8\/13\/1980/);
|
|
346
|
+
});
|
|
323
347
|
it('does not show tooltip while dragging', async () => {
|
|
324
348
|
var _a, _b, _c;
|
|
325
349
|
const el = await createCustomElementInHTMLContainer();
|
|
326
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
350
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
327
351
|
const tooltip = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#tooltip');
|
|
328
352
|
expect(tooltip.innerText).to.eq('');
|
|
329
353
|
const minSlider = (_c = el.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('#slider-min');
|
|
@@ -342,15 +366,15 @@ describe('HistogramDateRange', () => {
|
|
|
342
366
|
});
|
|
343
367
|
it('allows range to be pre-selected', async () => {
|
|
344
368
|
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>
|
|
369
|
+
const el = await fixture(html `
|
|
370
|
+
<histogram-date-range
|
|
371
|
+
minDate="1900"
|
|
372
|
+
maxDate="Dec 4, 2020"
|
|
373
|
+
minSelectedDate="2012"
|
|
374
|
+
maxSelectedDate="2019"
|
|
375
|
+
bins="[33, 1, 100]"
|
|
376
|
+
>
|
|
377
|
+
</histogram-date-range>
|
|
354
378
|
`);
|
|
355
379
|
const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
|
|
356
380
|
expect(minDateInput.value).to.eq('2012');
|
|
@@ -359,57 +383,57 @@ describe('HistogramDateRange', () => {
|
|
|
359
383
|
});
|
|
360
384
|
it('extends the selected range when the histogram is clicked outside of the current range', async () => {
|
|
361
385
|
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>
|
|
386
|
+
const el = await fixture(html `
|
|
387
|
+
<histogram-date-range
|
|
388
|
+
minDate="1900"
|
|
389
|
+
maxDate="2020"
|
|
390
|
+
minSelectedDate="1950"
|
|
391
|
+
maxSelectedDate="1955"
|
|
392
|
+
bins="[33, 1, 1, 1, 10, 10, 1, 1, 1, 50, 100]"
|
|
393
|
+
>
|
|
394
|
+
</histogram-date-range>
|
|
371
395
|
`);
|
|
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
|
|
396
|
+
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
397
|
leftBarToClick.dispatchEvent(new Event('click'));
|
|
374
398
|
await el.updateComplete;
|
|
375
399
|
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
|
|
400
|
+
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
401
|
rightBarToClick.dispatchEvent(new Event('click'));
|
|
378
402
|
expect(el.maxSelectedDate).to.eq('1998'); // range was extended to right
|
|
379
403
|
});
|
|
380
404
|
it('narrows the selected range when the histogram is clicked inside of the current range', async () => {
|
|
381
405
|
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>
|
|
406
|
+
const el = await fixture(html `
|
|
407
|
+
<histogram-date-range
|
|
408
|
+
minDate="1900"
|
|
409
|
+
maxDate="2020"
|
|
410
|
+
minSelectedDate="1900"
|
|
411
|
+
maxSelectedDate="2020"
|
|
412
|
+
bins="[33, 1, 1, 1, 10, 10, 1, 1, 1, 50, 100]"
|
|
413
|
+
>
|
|
414
|
+
</histogram-date-range>
|
|
391
415
|
`);
|
|
392
416
|
///////////////////////////////////////////////
|
|
393
417
|
// NB: the slider nearest the clicked bar moves
|
|
394
418
|
///////////////////////////////////////////////
|
|
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
|
|
419
|
+
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
420
|
leftBarToClick.dispatchEvent(new Event('click'));
|
|
397
421
|
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
|
|
422
|
+
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
423
|
rightBarToClick.dispatchEvent(new Event('click'));
|
|
400
424
|
expect(el.maxSelectedDate).to.eq('1998'); // range was extended to the left
|
|
401
425
|
});
|
|
402
426
|
it('handles invalid pre-selected range by defaulting to overall max and min', async () => {
|
|
403
427
|
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>
|
|
428
|
+
const el = await fixture(html `
|
|
429
|
+
<histogram-date-range
|
|
430
|
+
minDate="1900"
|
|
431
|
+
maxDate="2020"
|
|
432
|
+
minSelectedDate="2000xyz"
|
|
433
|
+
maxSelectedDate="5000"
|
|
434
|
+
bins="[33, 1, 100]"
|
|
435
|
+
>
|
|
436
|
+
</histogram-date-range>
|
|
413
437
|
`);
|
|
414
438
|
const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
|
|
415
439
|
// malformed min date defaults to overall min
|
|
@@ -420,16 +444,16 @@ describe('HistogramDateRange', () => {
|
|
|
420
444
|
});
|
|
421
445
|
it('handles year values less than 1000 correctly', async () => {
|
|
422
446
|
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>
|
|
447
|
+
const el = await fixture(html `
|
|
448
|
+
<histogram-date-range
|
|
449
|
+
dateFormat="M/D/YYYY"
|
|
450
|
+
minDate="-2000"
|
|
451
|
+
maxDate="2000"
|
|
452
|
+
minSelectedDate="-500"
|
|
453
|
+
maxSelectedDate="500"
|
|
454
|
+
bins="[33, 1, 100]"
|
|
455
|
+
>
|
|
456
|
+
</histogram-date-range>
|
|
433
457
|
`);
|
|
434
458
|
const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
|
|
435
459
|
expect(minDateInput.value).to.eq('1/1/-500');
|
|
@@ -438,52 +462,52 @@ describe('HistogramDateRange', () => {
|
|
|
438
462
|
});
|
|
439
463
|
it('handles missing data', async () => {
|
|
440
464
|
var _a, _b;
|
|
441
|
-
let el = await fixture(html `<histogram-date-range>
|
|
442
|
-
minDate="1900" maxDate="2020" bins=""
|
|
465
|
+
let el = await fixture(html `<histogram-date-range>
|
|
466
|
+
minDate="1900" maxDate="2020" bins=""
|
|
443
467
|
</histogram-date-range>`);
|
|
444
468
|
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"
|
|
469
|
+
el = await fixture(html `<histogram-date-range
|
|
470
|
+
minDate="1900"
|
|
471
|
+
maxDate="2020"
|
|
472
|
+
bins="[]"
|
|
473
|
+
missingDataMessage="no data available"
|
|
450
474
|
></histogram-date-range>`);
|
|
451
475
|
expect((_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.innerHTML).to.contain('no data available');
|
|
452
476
|
});
|
|
453
477
|
it('correctly displays data consisting of a single bin', async () => {
|
|
454
478
|
var _a;
|
|
455
|
-
const el = await fixture(html `
|
|
456
|
-
<histogram-date-range minDate="2020" maxDate="2020" bins="[50]">
|
|
457
|
-
</histogram-date-range>
|
|
479
|
+
const el = await fixture(html `
|
|
480
|
+
<histogram-date-range minDate="2020" maxDate="2020" bins="[50]">
|
|
481
|
+
</histogram-date-range>
|
|
458
482
|
`);
|
|
459
483
|
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
460
|
-
const heights = Array.from(bars
|
|
484
|
+
const heights = Array.from(bars, b => b.height.baseVal.value);
|
|
461
485
|
expect(heights).to.eql([157]);
|
|
462
486
|
});
|
|
463
487
|
it('correctly displays small diff between max and min values', async () => {
|
|
464
488
|
var _a;
|
|
465
|
-
const el = await fixture(html `
|
|
466
|
-
<histogram-date-range bins="[1519,2643,1880,2041,1638,1441]">
|
|
467
|
-
</histogram-date-range>
|
|
489
|
+
const el = await fixture(html `
|
|
490
|
+
<histogram-date-range bins="[1519,2643,1880,2041,1638,1441]">
|
|
491
|
+
</histogram-date-range>
|
|
468
492
|
`);
|
|
469
493
|
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
470
|
-
const heights = Array.from(bars
|
|
494
|
+
const heights = Array.from(bars, b => b.height.baseVal.value);
|
|
471
495
|
expect(heights).to.eql([37, 40, 38, 38, 37, 36]);
|
|
472
496
|
});
|
|
473
497
|
it('correctly aligns bins to exact month boundaries when binSnapping=month', async () => {
|
|
474
498
|
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>
|
|
499
|
+
const el = await fixture(html `
|
|
500
|
+
<histogram-date-range
|
|
501
|
+
binSnapping="month"
|
|
502
|
+
dateFormat="YYYY-MM"
|
|
503
|
+
tooltipDateFormat="MMM YYYY"
|
|
504
|
+
minDate="2020-01"
|
|
505
|
+
maxDate="2021-12"
|
|
506
|
+
bins="[10,20,30,40,50,60,70,80]"
|
|
507
|
+
></histogram-date-range>
|
|
484
508
|
`);
|
|
485
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
486
|
-
const tooltips = Array.from(bars
|
|
509
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
510
|
+
const tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
487
511
|
expect(tooltips).to.eql([
|
|
488
512
|
'Jan 2020 - Mar 2020',
|
|
489
513
|
'Apr 2020 - Jun 2020',
|
|
@@ -497,18 +521,18 @@ describe('HistogramDateRange', () => {
|
|
|
497
521
|
});
|
|
498
522
|
it('correctly handles month snapping for years 0-99', async () => {
|
|
499
523
|
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>
|
|
524
|
+
const el = await fixture(html `
|
|
525
|
+
<histogram-date-range
|
|
526
|
+
binSnapping="month"
|
|
527
|
+
dateFormat="YYYY-MM"
|
|
528
|
+
tooltipDateFormat="MMM YYYY"
|
|
529
|
+
minDate="0050-01"
|
|
530
|
+
maxDate="0065-12"
|
|
531
|
+
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]"
|
|
532
|
+
></histogram-date-range>
|
|
509
533
|
`);
|
|
510
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
511
|
-
const tooltips = Array.from(bars
|
|
534
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
535
|
+
const tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
512
536
|
expect(tooltips).to.eql([
|
|
513
537
|
'Jan 50 - Jun 50',
|
|
514
538
|
'Jul 50 - Dec 50',
|
|
@@ -546,16 +570,16 @@ describe('HistogramDateRange', () => {
|
|
|
546
570
|
});
|
|
547
571
|
it('correctly aligns bins to exact year boundaries when binSnapping=year', async () => {
|
|
548
572
|
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>
|
|
573
|
+
const el = await fixture(html `
|
|
574
|
+
<histogram-date-range
|
|
575
|
+
binSnapping="year"
|
|
576
|
+
minDate="2000"
|
|
577
|
+
maxDate="2019"
|
|
578
|
+
bins="[10,20,30,40,50,60,70,80,90,100]"
|
|
579
|
+
></histogram-date-range>
|
|
556
580
|
`);
|
|
557
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
558
|
-
const tooltips = Array.from(bars
|
|
581
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
582
|
+
const tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
559
583
|
expect(tooltips).to.eql([
|
|
560
584
|
'2000 - 2001',
|
|
561
585
|
'2002 - 2003',
|
|
@@ -571,53 +595,53 @@ describe('HistogramDateRange', () => {
|
|
|
571
595
|
});
|
|
572
596
|
it('correctly handles year snapping for years 0-99', async () => {
|
|
573
597
|
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>
|
|
598
|
+
const el = await fixture(html `
|
|
599
|
+
<histogram-date-range
|
|
600
|
+
binSnapping="year"
|
|
601
|
+
dateFormat="YYYY"
|
|
602
|
+
minDate="0020"
|
|
603
|
+
maxDate="0025"
|
|
604
|
+
bins="[1,2,3,4,5,6]"
|
|
605
|
+
></histogram-date-range>
|
|
582
606
|
`);
|
|
583
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
584
|
-
const tooltips = Array.from(bars
|
|
607
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
608
|
+
const tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
585
609
|
expect(tooltips).to.eql(['20', '21', '22', '23', '24', '25']);
|
|
586
610
|
});
|
|
587
611
|
it('does not duplicate start/end date in tooltips when representing a single year', async () => {
|
|
588
612
|
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>
|
|
613
|
+
const el = await fixture(html `
|
|
614
|
+
<histogram-date-range
|
|
615
|
+
binSnapping="year"
|
|
616
|
+
dateFormat="YYYY"
|
|
617
|
+
minDate="2001"
|
|
618
|
+
maxDate="2005"
|
|
619
|
+
bins="[10,20,30,40,50]"
|
|
620
|
+
></histogram-date-range>
|
|
597
621
|
`);
|
|
598
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
599
|
-
const tooltips = Array.from(bars
|
|
622
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
623
|
+
const tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
600
624
|
expect(tooltips).to.eql(['2001', '2002', '2003', '2004', '2005']);
|
|
601
625
|
});
|
|
602
626
|
it('falls back to default date format for tooltips if no tooltip date format provided', async () => {
|
|
603
627
|
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>
|
|
628
|
+
const el = await fixture(html `
|
|
629
|
+
<histogram-date-range
|
|
630
|
+
binSnapping="year"
|
|
631
|
+
minDate="2001"
|
|
632
|
+
maxDate="2005"
|
|
633
|
+
bins="[10,20,30,40,50]"
|
|
634
|
+
></histogram-date-range>
|
|
611
635
|
`);
|
|
612
|
-
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
|
|
613
|
-
let tooltips = Array.from(bars
|
|
636
|
+
const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
|
|
637
|
+
let tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
614
638
|
expect(tooltips).to.eql(['2001', '2002', '2003', '2004', '2005']); // default YYYY date format
|
|
615
639
|
el.dateFormat = 'YYYY/MM';
|
|
616
640
|
el.minDate = '2001/01';
|
|
617
641
|
el.maxDate = '2005/01';
|
|
618
642
|
await el.updateComplete;
|
|
619
643
|
// Should use dateFormat fallback for tooltips
|
|
620
|
-
tooltips = Array.from(bars
|
|
644
|
+
tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
621
645
|
expect(tooltips).to.eql([
|
|
622
646
|
'2001/01 - 2001/12',
|
|
623
647
|
'2002/01 - 2002/12',
|
|
@@ -631,7 +655,7 @@ describe('HistogramDateRange', () => {
|
|
|
631
655
|
el.maxDate = '2005';
|
|
632
656
|
await el.updateComplete;
|
|
633
657
|
// Should use defined tooltipDateFormat for tooltips
|
|
634
|
-
tooltips = Array.from(bars
|
|
658
|
+
tooltips = Array.from(bars, b => b.dataset.tooltip);
|
|
635
659
|
expect(tooltips).to.eql([
|
|
636
660
|
'January 2001 - December 2001',
|
|
637
661
|
'January 2002 - December 2002',
|
|
@@ -642,14 +666,14 @@ describe('HistogramDateRange', () => {
|
|
|
642
666
|
});
|
|
643
667
|
it('has a disabled state', async () => {
|
|
644
668
|
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>
|
|
669
|
+
const el = await fixture(html `
|
|
670
|
+
<histogram-date-range
|
|
671
|
+
minDate="1900"
|
|
672
|
+
maxDate="2020"
|
|
673
|
+
disabled
|
|
674
|
+
bins="[33, 1, 100]"
|
|
675
|
+
>
|
|
676
|
+
</histogram-date-range>
|
|
653
677
|
`);
|
|
654
678
|
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
679
|
const minSlider = (_c = el.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('#slider-min');
|
|
@@ -667,28 +691,28 @@ describe('HistogramDateRange', () => {
|
|
|
667
691
|
});
|
|
668
692
|
it('has a loading state with an activity indicator', async () => {
|
|
669
693
|
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>
|
|
694
|
+
const el = await fixture(html `
|
|
695
|
+
<histogram-date-range
|
|
696
|
+
minDate="1900"
|
|
697
|
+
maxDate="2020"
|
|
698
|
+
loading
|
|
699
|
+
bins="[33, 1, 100]"
|
|
700
|
+
>
|
|
701
|
+
</histogram-date-range>
|
|
678
702
|
`);
|
|
679
703
|
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
704
|
});
|
|
681
705
|
it('can use LitElement bound properties', async () => {
|
|
682
706
|
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>
|
|
707
|
+
const el = await fixture(html `
|
|
708
|
+
<histogram-date-range
|
|
709
|
+
.minDate=${1900}
|
|
710
|
+
.maxDate=${'Dec 4, 2020'}
|
|
711
|
+
.minSelectedDate=${2012}
|
|
712
|
+
.maxSelectedDate=${2019}
|
|
713
|
+
.bins=${[33, 1, 100]}
|
|
714
|
+
>
|
|
715
|
+
</histogram-date-range>
|
|
692
716
|
`);
|
|
693
717
|
const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
|
|
694
718
|
expect(minDateInput.value).to.eq('2012');
|