@internetarchive/histogram-date-range 1.4.1 → 1.4.2

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.
@@ -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');
@@ -314,6 +314,21 @@ describe('HistogramDateRange', () => {
314
314
  expect(event2.detail.minDate).to.equal('1/1/1985');
315
315
  expect(eventCount).to.equal(1); // only one event was fired
316
316
  });
317
+ it('emits a custom event when sliders are dragged to a new range', async () => {
318
+ var _a;
319
+ const el = await createCustomElementInHTMLContainer();
320
+ el.updateDelay = 0;
321
+ await el.updateComplete;
322
+ const minSlider = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#slider-min');
323
+ const updateEventPromise = oneEvent(el, 'histogramDateRangeUpdated');
324
+ // simulate dragging the min slider to the right and releasing
325
+ minSlider.dispatchEvent(new PointerEvent('pointerdown'));
326
+ window.dispatchEvent(new PointerEvent('pointermove', { clientX: 75 }));
327
+ window.dispatchEvent(new PointerEvent('pointerup'));
328
+ const { detail } = await updateEventPromise;
329
+ expect(detail.minDate).to.equal('5/21/1950');
330
+ expect(detail.maxDate).to.equal('12/4/2020');
331
+ });
317
332
  it('shows/hides tooltip when hovering over (or pointing at) a bar', async () => {
318
333
  var _a, _b;
319
334
  const el = await createCustomElementInHTMLContainer();
@@ -384,15 +399,15 @@ describe('HistogramDateRange', () => {
384
399
  });
385
400
  it('allows range to be pre-selected', async () => {
386
401
  var _a, _b;
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>
402
+ const el = await fixture(html `
403
+ <histogram-date-range
404
+ minDate="1900"
405
+ maxDate="Dec 4, 2020"
406
+ minSelectedDate="2012"
407
+ maxSelectedDate="2019"
408
+ bins="[33, 1, 100]"
409
+ >
410
+ </histogram-date-range>
396
411
  `);
397
412
  const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
398
413
  expect(minDateInput.value).to.eq('2012');
@@ -401,15 +416,15 @@ describe('HistogramDateRange', () => {
401
416
  });
402
417
  it('extends the selected range when the histogram is clicked outside of the current range', async () => {
403
418
  var _a, _b;
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>
419
+ const el = await fixture(html `
420
+ <histogram-date-range
421
+ minDate="1900"
422
+ maxDate="2020"
423
+ minSelectedDate="1950"
424
+ maxSelectedDate="1955"
425
+ bins="[33, 1, 1, 1, 10, 10, 1, 1, 1, 50, 100]"
426
+ >
427
+ </histogram-date-range>
413
428
  `);
414
429
  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
415
430
  leftBarToClick.dispatchEvent(new Event('click'));
@@ -421,15 +436,15 @@ describe('HistogramDateRange', () => {
421
436
  });
422
437
  it('narrows the selected range when the histogram is clicked inside of the current range', async () => {
423
438
  var _a, _b;
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>
439
+ const el = await fixture(html `
440
+ <histogram-date-range
441
+ minDate="1900"
442
+ maxDate="2020"
443
+ minSelectedDate="1900"
444
+ maxSelectedDate="2020"
445
+ bins="[33, 1, 1, 1, 10, 10, 1, 1, 1, 50, 100]"
446
+ >
447
+ </histogram-date-range>
433
448
  `);
434
449
  ///////////////////////////////////////////////
435
450
  // NB: the slider nearest the clicked bar moves
@@ -443,15 +458,15 @@ describe('HistogramDateRange', () => {
443
458
  });
444
459
  it('handles invalid pre-selected range by defaulting to overall max and min', async () => {
445
460
  var _a, _b;
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>
461
+ const el = await fixture(html `
462
+ <histogram-date-range
463
+ minDate="1900"
464
+ maxDate="2020"
465
+ minSelectedDate="2000xyz"
466
+ maxSelectedDate="5000"
467
+ bins="[33, 1, 100]"
468
+ >
469
+ </histogram-date-range>
455
470
  `);
456
471
  const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
457
472
  // malformed min date defaults to overall min
@@ -462,16 +477,16 @@ describe('HistogramDateRange', () => {
462
477
  });
463
478
  it('handles year values less than 1000 correctly', async () => {
464
479
  var _a, _b;
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>
480
+ const el = await fixture(html `
481
+ <histogram-date-range
482
+ dateFormat="M/D/YYYY"
483
+ minDate="-2000"
484
+ maxDate="2000"
485
+ minSelectedDate="-500"
486
+ maxSelectedDate="500"
487
+ bins="[33, 1, 100]"
488
+ >
489
+ </histogram-date-range>
475
490
  `);
476
491
  const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
477
492
  expect(minDateInput.value).to.eq('1/1/-500');
@@ -480,23 +495,23 @@ describe('HistogramDateRange', () => {
480
495
  });
481
496
  it('handles missing data', async () => {
482
497
  var _a, _b;
483
- let el = await fixture(html `<histogram-date-range>
484
- minDate="1900" maxDate="2020" bins=""
498
+ let el = await fixture(html `<histogram-date-range>
499
+ minDate="1900" maxDate="2020" bins=""
485
500
  </histogram-date-range>`);
486
501
  expect((_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.innerHTML).to.contain('no data');
487
- el = await fixture(html `<histogram-date-range
488
- minDate="1900"
489
- maxDate="2020"
490
- bins="[]"
491
- missingDataMessage="no data available"
502
+ el = await fixture(html `<histogram-date-range
503
+ minDate="1900"
504
+ maxDate="2020"
505
+ bins="[]"
506
+ missingDataMessage="no data available"
492
507
  ></histogram-date-range>`);
493
508
  expect((_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.innerHTML).to.contain('no data available');
494
509
  });
495
510
  it('correctly displays data consisting of a single bin', async () => {
496
511
  var _a;
497
- const el = await fixture(html `
498
- <histogram-date-range minDate="2020" maxDate="2020" bins="[50]">
499
- </histogram-date-range>
512
+ const el = await fixture(html `
513
+ <histogram-date-range minDate="2020" maxDate="2020" bins="[50]">
514
+ </histogram-date-range>
500
515
  `);
501
516
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
502
517
  const heights = Array.from(bars, b => b.height.baseVal.value);
@@ -504,9 +519,9 @@ describe('HistogramDateRange', () => {
504
519
  });
505
520
  it('correctly displays small diff between max and min values', async () => {
506
521
  var _a;
507
- const el = await fixture(html `
508
- <histogram-date-range bins="[1519,2643,1880,2041,1638,1441]">
509
- </histogram-date-range>
522
+ const el = await fixture(html `
523
+ <histogram-date-range bins="[1519,2643,1880,2041,1638,1441]">
524
+ </histogram-date-range>
510
525
  `);
511
526
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
512
527
  const heights = Array.from(bars, b => b.height.baseVal.value);
@@ -514,15 +529,15 @@ describe('HistogramDateRange', () => {
514
529
  });
515
530
  it('correctly aligns bins to exact month boundaries when binSnapping=month', async () => {
516
531
  var _a;
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>
532
+ const el = await fixture(html `
533
+ <histogram-date-range
534
+ binSnapping="month"
535
+ dateFormat="YYYY-MM"
536
+ tooltipDateFormat="MMM YYYY"
537
+ minDate="2020-01"
538
+ maxDate="2021-12"
539
+ bins="[10,20,30,40,50,60,70,80]"
540
+ ></histogram-date-range>
526
541
  `);
527
542
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
528
543
  const tooltips = Array.from(bars, b => b.dataset.tooltip);
@@ -539,15 +554,15 @@ describe('HistogramDateRange', () => {
539
554
  });
540
555
  it('correctly handles month snapping for years 0-99', async () => {
541
556
  var _a;
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>
557
+ const el = await fixture(html `
558
+ <histogram-date-range
559
+ binSnapping="month"
560
+ dateFormat="YYYY-MM"
561
+ tooltipDateFormat="MMM YYYY"
562
+ minDate="0050-01"
563
+ maxDate="0065-12"
564
+ 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]"
565
+ ></histogram-date-range>
551
566
  `);
552
567
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
553
568
  const tooltips = Array.from(bars, b => b.dataset.tooltip);
@@ -588,13 +603,13 @@ describe('HistogramDateRange', () => {
588
603
  });
589
604
  it('correctly aligns bins to exact year boundaries when binSnapping=year', async () => {
590
605
  var _a;
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>
606
+ const el = await fixture(html `
607
+ <histogram-date-range
608
+ binSnapping="year"
609
+ minDate="2000"
610
+ maxDate="2019"
611
+ bins="[10,20,30,40,50,60,70,80,90,100]"
612
+ ></histogram-date-range>
598
613
  `);
599
614
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
600
615
  const tooltips = Array.from(bars, b => b.dataset.tooltip);
@@ -613,14 +628,14 @@ describe('HistogramDateRange', () => {
613
628
  });
614
629
  it('correctly handles year snapping for years 0-99', async () => {
615
630
  var _a;
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>
631
+ const el = await fixture(html `
632
+ <histogram-date-range
633
+ binSnapping="year"
634
+ dateFormat="YYYY"
635
+ minDate="0020"
636
+ maxDate="0025"
637
+ bins="[1,2,3,4,5,6]"
638
+ ></histogram-date-range>
624
639
  `);
625
640
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
626
641
  const tooltips = Array.from(bars, b => b.dataset.tooltip);
@@ -628,14 +643,14 @@ describe('HistogramDateRange', () => {
628
643
  });
629
644
  it('does not duplicate start/end date in tooltips when representing a single year', async () => {
630
645
  var _a;
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>
646
+ const el = await fixture(html `
647
+ <histogram-date-range
648
+ binSnapping="year"
649
+ dateFormat="YYYY"
650
+ minDate="2001"
651
+ maxDate="2005"
652
+ bins="[10,20,30,40,50]"
653
+ ></histogram-date-range>
639
654
  `);
640
655
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
641
656
  const tooltips = Array.from(bars, b => b.dataset.tooltip);
@@ -643,13 +658,13 @@ describe('HistogramDateRange', () => {
643
658
  });
644
659
  it('falls back to default date format for tooltips if no tooltip date format provided', async () => {
645
660
  var _a;
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>
661
+ const el = await fixture(html `
662
+ <histogram-date-range
663
+ binSnapping="year"
664
+ minDate="2001"
665
+ maxDate="2005"
666
+ bins="[10,20,30,40,50]"
667
+ ></histogram-date-range>
653
668
  `);
654
669
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
655
670
  let tooltips = Array.from(bars, b => b.dataset.tooltip);
@@ -684,14 +699,14 @@ describe('HistogramDateRange', () => {
684
699
  });
685
700
  it('has a disabled state', async () => {
686
701
  var _a, _b, _c;
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>
702
+ const el = await fixture(html `
703
+ <histogram-date-range
704
+ minDate="1900"
705
+ maxDate="2020"
706
+ disabled
707
+ bins="[33, 1, 100]"
708
+ >
709
+ </histogram-date-range>
695
710
  `);
696
711
  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);
697
712
  const minSlider = (_c = el.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('#slider-min');
@@ -709,28 +724,28 @@ describe('HistogramDateRange', () => {
709
724
  });
710
725
  it('has a loading state with an activity indicator', async () => {
711
726
  var _a, _b, _c, _d;
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>
727
+ const el = await fixture(html `
728
+ <histogram-date-range
729
+ minDate="1900"
730
+ maxDate="2020"
731
+ loading
732
+ bins="[33, 1, 100]"
733
+ >
734
+ </histogram-date-range>
720
735
  `);
721
736
  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');
722
737
  });
723
738
  it('can use LitElement bound properties', async () => {
724
739
  var _a, _b;
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>
740
+ const el = await fixture(html `
741
+ <histogram-date-range
742
+ .minDate=${1900}
743
+ .maxDate=${'Dec 4, 2020'}
744
+ .minSelectedDate=${2012}
745
+ .maxSelectedDate=${2019}
746
+ .bins=${[33, 1, 100]}
747
+ >
748
+ </histogram-date-range>
734
749
  `);
735
750
  const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
736
751
  expect(minDateInput.value).to.eq('2012');
@@ -739,48 +754,48 @@ describe('HistogramDateRange', () => {
739
754
  });
740
755
  it('SVG accessbility - dynamic title for MIN and MAX date', async () => {
741
756
  var _a, _b;
742
- const el = await fixture(html `
743
- <histogram-date-range
744
- minDate="1900"
745
- maxDate="2020"
746
- .bins=${[33, 1, 100]}
747
- >
748
- </histogram-date-range>
757
+ const el = await fixture(html `
758
+ <histogram-date-range
759
+ minDate="1900"
760
+ maxDate="2020"
761
+ .bins=${[33, 1, 100]}
762
+ >
763
+ </histogram-date-range>
749
764
  `);
750
765
  const svg = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('svg');
751
766
  expect((_b = svg.querySelector('title')) === null || _b === void 0 ? void 0 : _b.textContent).to.equal('Filter results for dates from 1900 to 2020');
752
767
  });
753
768
  it('SVG accessbility - dynamic title for MIN date', async () => {
754
769
  var _a, _b;
755
- const el = await fixture(html `
756
- <histogram-date-range minDate="1900" .bins=${[33, 1, 100]}>
757
- </histogram-date-range>
770
+ const el = await fixture(html `
771
+ <histogram-date-range minDate="1900" .bins=${[33, 1, 100]}>
772
+ </histogram-date-range>
758
773
  `);
759
774
  const svg = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('svg');
760
775
  expect((_b = svg.querySelector('title')) === null || _b === void 0 ? void 0 : _b.textContent).to.equal('Filter results for dates from 1900');
761
776
  });
762
777
  it('SVG accessbility - dynamic title for MAX date', async () => {
763
778
  var _a, _b;
764
- const el = await fixture(html `
765
- <histogram-date-range maxDate="2020" .bins=${[33, 1, 100]}>
766
- </histogram-date-range>
779
+ const el = await fixture(html `
780
+ <histogram-date-range maxDate="2020" .bins=${[33, 1, 100]}>
781
+ </histogram-date-range>
767
782
  `);
768
783
  const svg = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('svg');
769
784
  expect((_b = svg.querySelector('title')) === null || _b === void 0 ? void 0 : _b.textContent).to.equal('Filter results for dates up to 2020');
770
785
  });
771
786
  it('SVG accessbility - dynamic title for all dates', async () => {
772
787
  var _a, _b;
773
- const el = await fixture(html `
774
- <histogram-date-range .bins=${[33, 1, 100]}> </histogram-date-range>
788
+ const el = await fixture(html `
789
+ <histogram-date-range .bins=${[33, 1, 100]}> </histogram-date-range>
775
790
  `);
776
791
  const svg = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('svg');
777
792
  expect((_b = svg.querySelector('title')) === null || _b === void 0 ? void 0 : _b.textContent).to.equal('Filter results for dates');
778
793
  });
779
794
  it('SVG accessibility - dynamic desc', async () => {
780
795
  var _a, _b;
781
- const el = await fixture(html `
782
- <histogram-date-range maxDate="2020" .bins=${[33, 1, 100]}>
783
- </histogram-date-range>
796
+ const el = await fixture(html `
797
+ <histogram-date-range maxDate="2020" .bins=${[33, 1, 100]}>
798
+ </histogram-date-range>
784
799
  `);
785
800
  const svg = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('svg');
786
801
  expect((_b = svg.querySelector('desc')) === null || _b === void 0 ? void 0 : _b.textContent).to.equal('This histogram shows the distribution of dates up to 2020');