@internetarchive/histogram-date-range 1.4.0 → 1.4.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.
@@ -432,9 +432,9 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
432
432
  window.scrollX;
433
433
  // Place the tooltip (with arrow) just above the top of the histogram bars
434
434
  this._tooltipOffsetY = histogramY - heightAboveHistogram + window.scrollY;
435
- this._tooltipContent = html `
436
- ${formattedNumItems} ${itemsText}<br />
437
- ${dataset.tooltip}
435
+ this._tooltipContent = html `
436
+ ${formattedNumItems} ${itemsText}<br />
437
+ ${dataset.tooltip}
438
438
  `;
439
439
  (_b = (_a = this._tooltip).showPopover) === null || _b === void 0 ? void 0 : _b.call(_a);
440
440
  }
@@ -631,25 +631,25 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
631
631
  // border-radius); used as part of a SVG quadratic curve. see
632
632
  // https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#curve_commands
633
633
  const cs = SLIDER_CORNER_SIZE;
634
- const sliderShape = `
635
- M${this.minSliderX},0
636
- h-${this.sliderWidth - cs}
637
- q-${cs},0 -${cs},${cs}
638
- v${this.height - cs * 2}
639
- q0,${cs} ${cs},${cs}
640
- h${this.sliderWidth - cs}
634
+ const sliderShape = `
635
+ M${this.minSliderX},0
636
+ h-${this.sliderWidth - cs}
637
+ q-${cs},0 -${cs},${cs}
638
+ v${this.height - cs * 2}
639
+ q0,${cs} ${cs},${cs}
640
+ h${this.sliderWidth - cs}
641
641
  `;
642
642
  return this.generateSliderSVG(this.minSliderX, 'slider-min', sliderShape);
643
643
  }
644
644
  get maxSliderTemplate() {
645
645
  const cs = SLIDER_CORNER_SIZE;
646
- const sliderShape = `
647
- M${this.maxSliderX},0
648
- h${this.sliderWidth - cs}
649
- q${cs},0 ${cs},${cs}
650
- v${this.height - cs * 2}
651
- q0,${cs} -${cs},${cs}
652
- h-${this.sliderWidth - cs}
646
+ const sliderShape = `
647
+ M${this.maxSliderX},0
648
+ h${this.sliderWidth - cs}
649
+ q${cs},0 ${cs},${cs}
650
+ v${this.height - cs * 2}
651
+ q0,${cs} -${cs},${cs}
652
+ h-${this.sliderWidth - cs}
653
653
  `;
654
654
  return this.generateSliderSVG(this.maxSliderX, 'slider-max', sliderShape);
655
655
  }
@@ -662,38 +662,38 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
662
662
  draggable: !this.disabled,
663
663
  dragging: this._isDragging,
664
664
  });
665
- return svg `
666
- <svg
667
- id=${id}
668
- class=${sliderClasses}
669
- @pointerdown=${this.drag}
670
- >
671
- <path d="${sliderShape} z" fill="${sliderColor}" />
672
- <rect
673
- x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.4 * k}"
674
- y="${this.height / 3}"
675
- width="1"
676
- height="${this.height / 3}"
677
- fill="white"
678
- />
679
- <rect
680
- x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.6 * k}"
681
- y="${this.height / 3}"
682
- width="1"
683
- height="${this.height / 3}"
684
- fill="white"
685
- />
686
- </svg>
665
+ return svg `
666
+ <svg
667
+ id=${id}
668
+ class=${sliderClasses}
669
+ @pointerdown=${this.drag}
670
+ >
671
+ <path d="${sliderShape} z" fill="${sliderColor}" />
672
+ <rect
673
+ x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.4 * k}"
674
+ y="${this.height / 3}"
675
+ width="1"
676
+ height="${this.height / 3}"
677
+ fill="white"
678
+ />
679
+ <rect
680
+ x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.6 * k}"
681
+ y="${this.height / 3}"
682
+ width="1"
683
+ height="${this.height / 3}"
684
+ fill="white"
685
+ />
686
+ </svg>
687
687
  `;
688
688
  }
689
689
  get selectedRangeTemplate() {
690
- return svg `
691
- <rect
692
- x="${this.minSliderX}"
693
- y="0"
694
- width="${this.maxSliderX - this.minSliderX}"
695
- height="${this.height}"
696
- fill="${selectedRangeColor}"
690
+ return svg `
691
+ <rect
692
+ x="${this.minSliderX}"
693
+ y="0"
694
+ width="${this.maxSliderX - this.minSliderX}"
695
+ height="${this.height}"
696
+ fill="${selectedRangeColor}"
697
697
  />`;
698
698
  }
699
699
  get histogramTemplate() {
@@ -711,30 +711,30 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
711
711
  // between adjacent bars (eg when viewing the tooltips or when trying to
712
712
  // extend the range by clicking on a bar)
713
713
  const barStyle = `stroke-dasharray: 0 ${barWidth} ${barHeight} ${barWidth} 0 ${barHeight}`;
714
- const bar = svg `
715
- <rect
716
- class="bar-pointer-target"
717
- x=${x}
718
- y="0"
719
- width=${barWidth}
720
- height=${this.height}
721
- @pointerenter=${this.showTooltip}
722
- @pointerleave=${this.hideTooltip}
723
- @click=${this.handleBarClick}
724
- fill="transparent"
725
- data-num-items=${data.value}
726
- data-bin-start=${data.binStart}
727
- data-bin-end=${data.binEnd}
728
- data-tooltip=${data.tooltip}
729
- />
730
- <rect
731
- class="bar"
732
- style=${barStyle}
733
- x=${x}
734
- y=${this.height - barHeight}
735
- width=${barWidth}
736
- height=${barHeight}
737
- fill=${barFill}
714
+ const bar = svg `
715
+ <rect
716
+ class="bar-pointer-target"
717
+ x=${x}
718
+ y="0"
719
+ width=${barWidth}
720
+ height=${this.height}
721
+ @pointerenter=${this.showTooltip}
722
+ @pointerleave=${this.hideTooltip}
723
+ @click=${this.handleBarClick}
724
+ fill="transparent"
725
+ data-num-items=${data.value}
726
+ data-bin-start=${data.binStart}
727
+ data-bin-end=${data.binEnd}
728
+ data-tooltip=${data.tooltip}
729
+ />
730
+ <rect
731
+ class="bar"
732
+ style=${barStyle}
733
+ x=${x}
734
+ y=${this.height - barHeight}
735
+ width=${barWidth}
736
+ height=${barHeight}
737
+ fill=${barFill}
738
738
  />`;
739
739
  x += xScale;
740
740
  return bar;
@@ -774,31 +774,31 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
774
774
  * https://lit.dev/docs/templates/directives/#live
775
775
  */
776
776
  get minInputTemplate() {
777
- return html `
778
- <input
779
- id="date-min"
780
- placeholder=${this.dateFormat}
781
- type="text"
782
- @focus=${this.handleInputFocus}
783
- @blur=${this.handleMinDateInput}
784
- @keyup=${this.handleKeyUp}
785
- .value=${live(this.minSelectedDate)}
786
- ?disabled=${this.disabled}
787
- />
777
+ return html `
778
+ <input
779
+ id="date-min"
780
+ placeholder=${this.dateFormat}
781
+ type="text"
782
+ @focus=${this.handleInputFocus}
783
+ @blur=${this.handleMinDateInput}
784
+ @keyup=${this.handleKeyUp}
785
+ .value=${live(this.minSelectedDate)}
786
+ ?disabled=${this.disabled}
787
+ />
788
788
  `;
789
789
  }
790
790
  get maxInputTemplate() {
791
- return html `
792
- <input
793
- id="date-max"
794
- placeholder=${this.dateFormat}
795
- type="text"
796
- @focus=${this.handleInputFocus}
797
- @blur=${this.handleMaxDateInput}
798
- @keyup=${this.handleKeyUp}
799
- .value=${live(this.maxSelectedDate)}
800
- ?disabled=${this.disabled}
801
- />
791
+ return html `
792
+ <input
793
+ id="date-max"
794
+ placeholder=${this.dateFormat}
795
+ type="text"
796
+ @focus=${this.handleInputFocus}
797
+ @blur=${this.handleMaxDateInput}
798
+ @keyup=${this.handleKeyUp}
799
+ .value=${live(this.maxSelectedDate)}
800
+ ?disabled=${this.disabled}
801
+ />
802
802
  `;
803
803
  }
804
804
  get minLabelTemplate() {
@@ -814,184 +814,201 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
814
814
  top: `${this._tooltipOffsetY}px`,
815
815
  left: `${this._tooltipOffsetX}px`,
816
816
  });
817
- return html `
818
- <div id="tooltip" style=${styles} popover>${this._tooltipContent}</div>
817
+ return html `
818
+ <div id="tooltip" style=${styles} popover>${this._tooltipContent}</div>
819
819
  `;
820
820
  }
821
+ get histogramAccessibilityTemplate() {
822
+ let rangeText = '';
823
+ if (this.minSelectedDate && this.maxSelectedDate) {
824
+ rangeText = ` from ${this.minSelectedDate} to ${this.maxSelectedDate}`;
825
+ }
826
+ else if (this.minSelectedDate) {
827
+ rangeText = ` from ${this.minSelectedDate}`;
828
+ }
829
+ else if (this.maxSelectedDate) {
830
+ rangeText = ` up to ${this.maxSelectedDate}`;
831
+ }
832
+ const titleText = `Filter results for dates${rangeText}`;
833
+ const descText = `This histogram shows the distribution of dates${rangeText}`;
834
+ return html `<title id="histogram-title">${titleText}</title
835
+ ><desc id="histogram-desc">${descText}</desc>`;
836
+ }
821
837
  get noDataTemplate() {
822
- return html `
823
- <div class="missing-data-message">${this.missingDataMessage}</div>
838
+ return html `
839
+ <div class="missing-data-message">${this.missingDataMessage}</div>
824
840
  `;
825
841
  }
826
842
  get activityIndicatorTemplate() {
827
843
  if (!this.loading) {
828
844
  return nothing;
829
845
  }
830
- return html `
831
- <ia-activity-indicator mode="processing"> </ia-activity-indicator>
846
+ return html `
847
+ <ia-activity-indicator mode="processing"> </ia-activity-indicator>
832
848
  `;
833
849
  }
834
850
  render() {
835
851
  if (!this.hasBinData) {
836
852
  return this.noDataTemplate;
837
853
  }
838
- return html `
839
- <div
840
- id="container"
841
- class="
842
- noselect
843
- ${this._isDragging ? 'dragging' : ''}
844
- "
845
- style="width: ${this.width}px"
846
- >
847
- ${this.activityIndicatorTemplate} ${this.tooltipTemplate}
848
- <div
849
- class="inner-container
850
- ${this.disabled ? 'disabled' : ''}"
851
- >
852
- <svg
853
- width="${this.width}"
854
- height="${this.height}"
855
- @pointerleave="${this.drop}"
856
- >
857
- ${this.selectedRangeTemplate}
858
- <svg id="histogram">${this.histogramTemplate}</svg>
859
- ${this.minSliderTemplate} ${this.maxSliderTemplate}
860
- </svg>
861
- <div id="inputs">
862
- ${this.minLabelTemplate} ${this.minInputTemplate}
863
- <div class="dash">-</div>
864
- ${this.maxLabelTemplate} ${this.maxInputTemplate}
865
- <slot name="inputs-right-side"></slot>
866
- </div>
867
- </div>
868
- </div>
854
+ return html `
855
+ <div
856
+ id="container"
857
+ class="
858
+ noselect
859
+ ${this._isDragging ? 'dragging' : ''}
860
+ "
861
+ style="width: ${this.width}px"
862
+ >
863
+ ${this.activityIndicatorTemplate} ${this.tooltipTemplate}
864
+ <div
865
+ class="inner-container
866
+ ${this.disabled ? 'disabled' : ''}"
867
+ >
868
+ <svg
869
+ width="${this.width}"
870
+ height="${this.height}"
871
+ aria-labelledby="histogram-title histogram-desc"
872
+ @pointerleave="${this.drop}"
873
+ >
874
+ ${this.histogramAccessibilityTemplate} ${this.selectedRangeTemplate}
875
+ <svg id="histogram">${this.histogramTemplate}</svg>
876
+ ${this.minSliderTemplate} ${this.maxSliderTemplate}
877
+ </svg>
878
+ <div id="inputs">
879
+ ${this.minLabelTemplate} ${this.minInputTemplate}
880
+ <div class="dash">-</div>
881
+ ${this.maxLabelTemplate} ${this.maxInputTemplate}
882
+ <slot name="inputs-right-side"></slot>
883
+ </div>
884
+ </div>
885
+ </div>
869
886
  `;
870
887
  }
871
888
  };
872
- HistogramDateRange.styles = css `
873
- .missing-data-message {
874
- text-align: center;
875
- }
876
- #container {
877
- margin: 0;
878
- touch-action: none;
879
- position: relative;
880
- }
881
- .disabled {
882
- opacity: 0.3;
883
- }
884
- ia-activity-indicator {
885
- position: absolute;
886
- left: calc(50% - 10px);
887
- top: 10px;
888
- width: 20px;
889
- height: 20px;
890
- --activityIndicatorLoadingDotColor: rgba(0, 0, 0, 0);
891
- --activityIndicatorLoadingRingColor: ${activityIndicatorColor};
892
- }
893
-
894
- /* prevent selection from interfering with tooltip, especially on mobile */
895
- /* https://stackoverflow.com/a/4407335/1163042 */
896
- .noselect {
897
- -webkit-touch-callout: none; /* iOS Safari */
898
- -webkit-user-select: none; /* Safari */
899
- -moz-user-select: none; /* Old versions of Firefox */
900
- -ms-user-select: none; /* Internet Explorer/Edge */
901
- user-select: none; /* current Chrome, Edge, Opera and Firefox */
902
- }
903
- .bar,
904
- .bar-pointer-target {
905
- /* create a transparent border around the hist bars to prevent "gaps" and
906
- flickering when moving around between bars. this also helps with handling
907
- clicks on the bars, preventing users from being able to click in between
908
- bars */
909
- stroke: rgba(0, 0, 0, 0);
910
- /* ensure transparent stroke wide enough to cover gap between bars */
911
- stroke-width: 2px;
912
- }
913
- .bar {
914
- /* ensure the bar's pointer target receives events, not the bar itself */
915
- pointer-events: none;
916
- }
917
- .bar-pointer-target:hover + .bar {
918
- /* highlight currently hovered bar */
919
- fill-opacity: 0.7;
920
- }
921
- .disabled .bar-pointer-target:hover + .bar {
922
- /* ensure no visual hover interaction when disabled */
923
- fill-opacity: 1;
924
- }
925
- /****** histogram ********/
926
- #tooltip {
927
- position: absolute;
928
- background: ${tooltipBackgroundColor};
929
- margin: 0;
930
- border: 0;
931
- color: ${tooltipTextColor};
932
- text-align: center;
933
- border-radius: 3px;
934
- padding: 2px;
935
- font-size: ${tooltipFontSize};
936
- font-family: ${tooltipFontFamily};
937
- touch-action: none;
938
- pointer-events: none;
939
- overflow: visible;
940
- }
941
- #tooltip:after {
942
- content: '';
943
- position: absolute;
944
- margin-left: -5px;
945
- top: 100%;
946
- left: 50%;
947
- /* arrow */
948
- border: 5px solid ${tooltipTextColor};
949
- border-color: ${tooltipBackgroundColor} transparent transparent
950
- transparent;
951
- }
952
- /****** slider ********/
953
- .slider {
954
- shape-rendering: crispEdges; /* So the slider doesn't get blurry if dragged between pixels */
955
- }
956
- .draggable:hover {
957
- cursor: grab;
958
- }
959
- .dragging {
960
- cursor: grabbing !important;
961
- }
962
- /****** inputs ********/
963
- #inputs {
964
- display: flex;
965
- justify-content: center;
966
- margin: ${inputRowMargin};
967
- }
968
- #inputs .dash {
969
- position: relative;
970
- bottom: -1px;
971
- align-self: center; /* Otherwise the dash sticks to the top while the inputs grow */
972
- }
973
- input {
974
- width: ${inputWidth};
975
- margin: 0 3px;
976
- border: ${inputBorder};
977
- border-radius: 2px !important;
978
- text-align: center;
979
- font-size: ${inputFontSize};
980
- font-family: ${inputFontFamily};
981
- }
982
- .sr-only {
983
- position: absolute !important;
984
- width: 1px !important;
985
- height: 1px !important;
986
- margin: 0 !important;
987
- padding: 0 !important;
988
- border: 0 !important;
989
- overflow: hidden !important;
990
- white-space: nowrap !important;
991
- clip: rect(1px, 1px, 1px, 1px) !important;
992
- -webkit-clip-path: inset(50%) !important;
993
- clip-path: inset(50%) !important;
994
- }
889
+ HistogramDateRange.styles = css `
890
+ .missing-data-message {
891
+ text-align: center;
892
+ }
893
+ #container {
894
+ margin: 0;
895
+ touch-action: none;
896
+ position: relative;
897
+ }
898
+ .disabled {
899
+ opacity: 0.3;
900
+ }
901
+ ia-activity-indicator {
902
+ position: absolute;
903
+ left: calc(50% - 10px);
904
+ top: 10px;
905
+ width: 20px;
906
+ height: 20px;
907
+ --activityIndicatorLoadingDotColor: rgba(0, 0, 0, 0);
908
+ --activityIndicatorLoadingRingColor: ${activityIndicatorColor};
909
+ }
910
+
911
+ /* prevent selection from interfering with tooltip, especially on mobile */
912
+ /* https://stackoverflow.com/a/4407335/1163042 */
913
+ .noselect {
914
+ -webkit-touch-callout: none; /* iOS Safari */
915
+ -webkit-user-select: none; /* Safari */
916
+ -moz-user-select: none; /* Old versions of Firefox */
917
+ -ms-user-select: none; /* Internet Explorer/Edge */
918
+ user-select: none; /* current Chrome, Edge, Opera and Firefox */
919
+ }
920
+ .bar,
921
+ .bar-pointer-target {
922
+ /* create a transparent border around the hist bars to prevent "gaps" and
923
+ flickering when moving around between bars. this also helps with handling
924
+ clicks on the bars, preventing users from being able to click in between
925
+ bars */
926
+ stroke: rgba(0, 0, 0, 0);
927
+ /* ensure transparent stroke wide enough to cover gap between bars */
928
+ stroke-width: 2px;
929
+ }
930
+ .bar {
931
+ /* ensure the bar's pointer target receives events, not the bar itself */
932
+ pointer-events: none;
933
+ }
934
+ .bar-pointer-target:hover + .bar {
935
+ /* highlight currently hovered bar */
936
+ fill-opacity: 0.7;
937
+ }
938
+ .disabled .bar-pointer-target:hover + .bar {
939
+ /* ensure no visual hover interaction when disabled */
940
+ fill-opacity: 1;
941
+ }
942
+ /****** histogram ********/
943
+ #tooltip {
944
+ position: absolute;
945
+ background: ${tooltipBackgroundColor};
946
+ margin: 0;
947
+ border: 0;
948
+ color: ${tooltipTextColor};
949
+ text-align: center;
950
+ border-radius: 3px;
951
+ padding: 2px;
952
+ font-size: ${tooltipFontSize};
953
+ font-family: ${tooltipFontFamily};
954
+ touch-action: none;
955
+ pointer-events: none;
956
+ overflow: visible;
957
+ }
958
+ #tooltip:after {
959
+ content: '';
960
+ position: absolute;
961
+ margin-left: -5px;
962
+ top: 100%;
963
+ left: 50%;
964
+ /* arrow */
965
+ border: 5px solid ${tooltipTextColor};
966
+ border-color: ${tooltipBackgroundColor} transparent transparent
967
+ transparent;
968
+ }
969
+ /****** slider ********/
970
+ .slider {
971
+ shape-rendering: crispEdges; /* So the slider doesn't get blurry if dragged between pixels */
972
+ }
973
+ .draggable:hover {
974
+ cursor: grab;
975
+ }
976
+ .dragging {
977
+ cursor: grabbing !important;
978
+ }
979
+ /****** inputs ********/
980
+ #inputs {
981
+ display: flex;
982
+ justify-content: center;
983
+ margin: ${inputRowMargin};
984
+ }
985
+ #inputs .dash {
986
+ position: relative;
987
+ bottom: -1px;
988
+ align-self: center; /* Otherwise the dash sticks to the top while the inputs grow */
989
+ }
990
+ input {
991
+ width: ${inputWidth};
992
+ margin: 0 3px;
993
+ border: ${inputBorder};
994
+ border-radius: 2px !important;
995
+ text-align: center;
996
+ font-size: ${inputFontSize};
997
+ font-family: ${inputFontFamily};
998
+ }
999
+ .sr-only {
1000
+ position: absolute !important;
1001
+ width: 1px !important;
1002
+ height: 1px !important;
1003
+ margin: 0 !important;
1004
+ padding: 0 !important;
1005
+ border: 0 !important;
1006
+ overflow: hidden !important;
1007
+ white-space: nowrap !important;
1008
+ clip: rect(1px, 1px, 1px, 1px) !important;
1009
+ -webkit-clip-path: inset(50%) !important;
1010
+ clip-path: inset(50%) !important;
1011
+ }
995
1012
  `;
996
1013
  __decorate([
997
1014
  property({ type: Number })