@internetarchive/histogram-date-range 1.3.0 → 1.3.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.
@@ -580,7 +580,7 @@ describe('HistogramDateRange', () => {
580
580
  expect(maxDateInput.value).to.eq('5000');
581
581
  });
582
582
 
583
- it('handles year values less than 1000 by overriding date format to just display year', async () => {
583
+ it('handles year values less than 1000 correctly', async () => {
584
584
  const el = await fixture<HistogramDateRange>(
585
585
  html`
586
586
  <histogram-date-range
@@ -597,12 +597,12 @@ describe('HistogramDateRange', () => {
597
597
  const minDateInput = el.shadowRoot?.querySelector(
598
598
  '#date-min'
599
599
  ) as HTMLInputElement;
600
- expect(minDateInput.value).to.eq('-500');
600
+ expect(minDateInput.value).to.eq('1/1/-500');
601
601
 
602
602
  const maxDateInput = el.shadowRoot?.querySelector(
603
603
  '#date-max'
604
604
  ) as HTMLInputElement;
605
- expect(maxDateInput.value).to.eq('500');
605
+ expect(maxDateInput.value).to.eq('1/1/500');
606
606
  });
607
607
 
608
608
  it('handles missing data', async () => {
@@ -680,6 +680,60 @@ describe('HistogramDateRange', () => {
680
680
  ]);
681
681
  });
682
682
 
683
+ it('correctly handles month snapping for years 0-99', async () => {
684
+ const el = await fixture<HistogramDateRange>(
685
+ html`
686
+ <histogram-date-range
687
+ binSnapping="month"
688
+ dateFormat="YYYY-MM"
689
+ tooltipDateFormat="MMM YYYY"
690
+ minDate="0050-01"
691
+ maxDate="0065-12"
692
+ 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]"
693
+ ></histogram-date-range>
694
+ `
695
+ );
696
+
697
+ const bars = el.shadowRoot?.querySelectorAll(
698
+ '.bar'
699
+ ) as unknown as SVGRectElement[];
700
+ const tooltips = Array.from(bars).map(b => b.dataset.tooltip);
701
+ expect(tooltips).to.eql([
702
+ 'Jan 50 - Jun 50',
703
+ 'Jul 50 - Dec 50',
704
+ 'Jan 51 - Jun 51',
705
+ 'Jul 51 - Dec 51',
706
+ 'Jan 52 - Jun 52',
707
+ 'Jul 52 - Dec 52',
708
+ 'Jan 53 - Jun 53',
709
+ 'Jul 53 - Dec 53',
710
+ 'Jan 54 - Jun 54',
711
+ 'Jul 54 - Dec 54',
712
+ 'Jan 55 - Jun 55',
713
+ 'Jul 55 - Dec 55',
714
+ 'Jan 56 - Jun 56',
715
+ 'Jul 56 - Dec 56',
716
+ 'Jan 57 - Jun 57',
717
+ 'Jul 57 - Dec 57',
718
+ 'Jan 58 - Jun 58',
719
+ 'Jul 58 - Dec 58',
720
+ 'Jan 59 - Jun 59',
721
+ 'Jul 59 - Dec 59',
722
+ 'Jan 60 - Jun 60',
723
+ 'Jul 60 - Dec 60',
724
+ 'Jan 61 - Jun 61',
725
+ 'Jul 61 - Dec 61',
726
+ 'Jan 62 - Jun 62',
727
+ 'Jul 62 - Dec 62',
728
+ 'Jan 63 - Jun 63',
729
+ 'Jul 63 - Dec 63',
730
+ 'Jan 64 - Jun 64',
731
+ 'Jul 64 - Dec 64',
732
+ 'Jan 65 - Jun 65',
733
+ 'Jul 65 - Dec 65',
734
+ ]);
735
+ });
736
+
683
737
  it('correctly aligns bins to exact year boundaries when binSnapping=year', async () => {
684
738
  const el = await fixture<HistogramDateRange>(
685
739
  html`
@@ -709,6 +763,26 @@ describe('HistogramDateRange', () => {
709
763
  ]);
710
764
  });
711
765
 
766
+ it('correctly handles year snapping for years 0-99', async () => {
767
+ const el = await fixture<HistogramDateRange>(
768
+ html`
769
+ <histogram-date-range
770
+ binSnapping="year"
771
+ dateFormat="YYYY"
772
+ minDate="0020"
773
+ maxDate="0025"
774
+ bins="[1,2,3,4,5,6]"
775
+ ></histogram-date-range>
776
+ `
777
+ );
778
+
779
+ const bars = el.shadowRoot?.querySelectorAll(
780
+ '.bar'
781
+ ) as unknown as SVGRectElement[];
782
+ const tooltips = Array.from(bars).map(b => b.dataset.tooltip);
783
+ expect(tooltips).to.eql(['20', '21', '22', '23', '24', '25']);
784
+ });
785
+
712
786
  it('does not duplicate start/end date in tooltips when representing a single year', async () => {
713
787
  const el = await fixture<HistogramDateRange>(
714
788
  html`
@@ -0,0 +1,10 @@
1
+ export { default } from 'dayjs/esm';
2
+
3
+ declare module 'dayjs/esm' {
4
+ // Widening the Dayjs interface so that we can properly extend it via plugin
5
+ interface Dayjs {
6
+ $d: Date;
7
+ parse(cfg: { date: unknown; args: unknown[] }): void;
8
+ init(): void;
9
+ }
10
+ }