@internetarchive/histogram-date-range 1.1.1-alpha.4 → 1.2.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.
@@ -262,9 +262,9 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
262
262
  const formattedNumItems = Number(dataset.numItems).toLocaleString();
263
263
  this._tooltipOffset =
264
264
  x + (this._binWidth - this.sliderWidth - this.tooltipWidth) / 2;
265
- this._tooltipContent = html `
266
- ${formattedNumItems} ${itemsText}<br />
267
- ${dataset.binStart} - ${dataset.binEnd}
265
+ this._tooltipContent = html `
266
+ ${formattedNumItems} ${itemsText}<br />
267
+ ${dataset.binStart} - ${dataset.binEnd}
268
268
  `;
269
269
  this._tooltipVisible = true;
270
270
  }
@@ -459,25 +459,25 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
459
459
  // border-radius); used as part of a SVG quadratic curve. see
460
460
  // https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#curve_commands
461
461
  const cs = SLIDER_CORNER_SIZE;
462
- const sliderShape = `
463
- M${this.minSliderX},0
464
- h-${this.sliderWidth - cs}
465
- q-${cs},0 -${cs},${cs}
466
- v${this.height - cs * 2}
467
- q0,${cs} ${cs},${cs}
468
- h${this.sliderWidth - cs}
462
+ const sliderShape = `
463
+ M${this.minSliderX},0
464
+ h-${this.sliderWidth - cs}
465
+ q-${cs},0 -${cs},${cs}
466
+ v${this.height - cs * 2}
467
+ q0,${cs} ${cs},${cs}
468
+ h${this.sliderWidth - cs}
469
469
  `;
470
470
  return this.generateSliderSVG(this.minSliderX, 'slider-min', sliderShape);
471
471
  }
472
472
  get maxSliderTemplate() {
473
473
  const cs = SLIDER_CORNER_SIZE;
474
- const sliderShape = `
475
- M${this.maxSliderX},0
476
- h${this.sliderWidth - cs}
477
- q${cs},0 ${cs},${cs}
478
- v${this.height - cs * 2}
479
- q0,${cs} -${cs},${cs}
480
- h-${this.sliderWidth - cs}
474
+ const sliderShape = `
475
+ M${this.maxSliderX},0
476
+ h${this.sliderWidth - cs}
477
+ q${cs},0 ${cs},${cs}
478
+ v${this.height - cs * 2}
479
+ q0,${cs} -${cs},${cs}
480
+ h-${this.sliderWidth - cs}
481
481
  `;
482
482
  return this.generateSliderSVG(this.maxSliderX, 'slider-max', sliderShape);
483
483
  }
@@ -485,40 +485,40 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
485
485
  // whether the curved part of the slider is facing towards the left (1), ie
486
486
  // minimum, or facing towards the right (-1), ie maximum
487
487
  const k = id === 'slider-min' ? 1 : -1;
488
- return svg `
489
- <svg
490
- id="${id}"
491
- class="
492
- ${this.disabled ? '' : 'draggable'}
493
- ${this._isDragging ? 'dragging' : ''}"
494
- @pointerdown="${this.drag}"
495
- >
496
- <path d="${sliderShape} z" fill="${sliderColor}" />
497
- <rect
498
- x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.4 * k}"
499
- y="${this.height / 3}"
500
- width="1"
501
- height="${this.height / 3}"
502
- fill="white"
503
- />
504
- <rect
505
- x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.6 * k}"
506
- y="${this.height / 3}"
507
- width="1"
508
- height="${this.height / 3}"
509
- fill="white"
510
- />
511
- </svg>
488
+ return svg `
489
+ <svg
490
+ id="${id}"
491
+ class="
492
+ ${this.disabled ? '' : 'draggable'}
493
+ ${this._isDragging ? 'dragging' : ''}"
494
+ @pointerdown="${this.drag}"
495
+ >
496
+ <path d="${sliderShape} z" fill="${sliderColor}" />
497
+ <rect
498
+ x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.4 * k}"
499
+ y="${this.height / 3}"
500
+ width="1"
501
+ height="${this.height / 3}"
502
+ fill="white"
503
+ />
504
+ <rect
505
+ x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.6 * k}"
506
+ y="${this.height / 3}"
507
+ width="1"
508
+ height="${this.height / 3}"
509
+ fill="white"
510
+ />
511
+ </svg>
512
512
  `;
513
513
  }
514
514
  get selectedRangeTemplate() {
515
- return svg `
516
- <rect
517
- x="${this.minSliderX}"
518
- y="0"
519
- width="${this.maxSliderX - this.minSliderX}"
520
- height="${this.height}"
521
- fill="${selectedRangeColor}"
515
+ return svg `
516
+ <rect
517
+ x="${this.minSliderX}"
518
+ y="0"
519
+ width="${this.maxSliderX - this.minSliderX}"
520
+ height="${this.height}"
521
+ fill="${selectedRangeColor}"
522
522
  />`;
523
523
  }
524
524
  get histogramTemplate() {
@@ -530,23 +530,23 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
530
530
  // between adjacent bars (eg when viewing the tooltips or when trying to
531
531
  // extend the range by clicking on a bar)
532
532
  return this._histData.map(data => {
533
- const bar = svg `
534
- <rect
535
- class="bar"
536
- style='stroke-dasharray: 0 ${barWidth} ${data.height} ${barWidth} 0 ${data.height};'
537
- x="${x}"
538
- y="${this.height - data.height}"
539
- width="${barWidth}"
540
- height="${data.height}"
541
- @pointerenter="${this.showTooltip}"
542
- @pointerleave="${this.hideTooltip}"
543
- @click="${this.handleBarClick}"
533
+ const bar = svg `
534
+ <rect
535
+ class="bar"
536
+ style='stroke-dasharray: 0 ${barWidth} ${data.height} ${barWidth} 0 ${data.height};'
537
+ x="${x}"
538
+ y="${this.height - data.height}"
539
+ width="${barWidth}"
540
+ height="${data.height}"
541
+ @pointerenter="${this.showTooltip}"
542
+ @pointerleave="${this.hideTooltip}"
543
+ @click="${this.handleBarClick}"
544
544
  fill="${x + barWidth >= this.minSliderX && x <= this.maxSliderX
545
545
  ? barIncludedFill
546
- : barExcludedFill}"
547
- data-num-items="${data.value}"
548
- data-bin-start="${data.binStart}"
549
- data-bin-end="${data.binEnd}"
546
+ : barExcludedFill}"
547
+ data-num-items="${data.value}"
548
+ data-bin-start="${data.binStart}"
549
+ data-bin-end="${data.binEnd}"
550
550
  />`;
551
551
  x += xScale;
552
552
  return bar;
@@ -571,31 +571,31 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
571
571
  * https://lit.dev/docs/templates/directives/#live
572
572
  */
573
573
  get minInputTemplate() {
574
- return html `
575
- <input
576
- id="date-min"
577
- placeholder="${this.dateFormat}"
578
- type="text"
579
- @focus="${this.handleInputFocus}"
580
- @blur="${this.handleMinDateInput}"
581
- @keyup="${this.handleKeyUp}"
582
- .value="${live(this.minSelectedDate)}"
583
- ?disabled="${this.disabled}"
584
- />
574
+ return html `
575
+ <input
576
+ id="date-min"
577
+ placeholder="${this.dateFormat}"
578
+ type="text"
579
+ @focus="${this.handleInputFocus}"
580
+ @blur="${this.handleMinDateInput}"
581
+ @keyup="${this.handleKeyUp}"
582
+ .value="${live(this.minSelectedDate)}"
583
+ ?disabled="${this.disabled}"
584
+ />
585
585
  `;
586
586
  }
587
587
  get maxInputTemplate() {
588
- return html `
589
- <input
590
- id="date-max"
591
- placeholder="${this.dateFormat}"
592
- type="text"
593
- @focus="${this.handleInputFocus}"
594
- @blur="${this.handleMaxDateInput}"
595
- @keyup="${this.handleKeyUp}"
596
- .value="${live(this.maxSelectedDate)}"
597
- ?disabled="${this.disabled}"
598
- />
588
+ return html `
589
+ <input
590
+ id="date-max"
591
+ placeholder="${this.dateFormat}"
592
+ type="text"
593
+ @focus="${this.handleInputFocus}"
594
+ @blur="${this.handleMaxDateInput}"
595
+ @keyup="${this.handleKeyUp}"
596
+ .value="${live(this.maxSelectedDate)}"
597
+ ?disabled="${this.disabled}"
598
+ />
599
599
  `;
600
600
  }
601
601
  get minLabelTemplate() {
@@ -605,184 +605,184 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
605
605
  return html `<label for="date-max" class="sr-only">Maximum date:</label>`;
606
606
  }
607
607
  get tooltipTemplate() {
608
- return html `
609
- <style>
610
- #tooltip {
611
- width: ${this.tooltipWidth}px;
612
- height: ${this.tooltipHeight}px;
613
- top: ${-9 - this.tooltipHeight}px;
614
- left: ${this._tooltipOffset}px;
615
- display: ${this._tooltipVisible ? 'block' : 'none'};
616
- }
617
- #tooltip:after {
618
- left: ${this.tooltipWidth / 2}px;
619
- }
620
- </style>
621
- <div id="tooltip">${this._tooltipContent}</div>
608
+ return html `
609
+ <style>
610
+ #tooltip {
611
+ width: ${this.tooltipWidth}px;
612
+ height: ${this.tooltipHeight}px;
613
+ top: ${-9 - this.tooltipHeight}px;
614
+ left: ${this._tooltipOffset}px;
615
+ display: ${this._tooltipVisible ? 'block' : 'none'};
616
+ }
617
+ #tooltip:after {
618
+ left: ${this.tooltipWidth / 2}px;
619
+ }
620
+ </style>
621
+ <div id="tooltip">${this._tooltipContent}</div>
622
622
  `;
623
623
  }
624
624
  get noDataTemplate() {
625
- return html `
626
- <div class="missing-data-message">${this.missingDataMessage}</div>
625
+ return html `
626
+ <div class="missing-data-message">${this.missingDataMessage}</div>
627
627
  `;
628
628
  }
629
629
  get activityIndicatorTemplate() {
630
630
  if (!this.loading) {
631
631
  return nothing;
632
632
  }
633
- return html `
634
- <ia-activity-indicator mode="processing"> </ia-activity-indicator>
633
+ return html `
634
+ <ia-activity-indicator mode="processing"> </ia-activity-indicator>
635
635
  `;
636
636
  }
637
637
  render() {
638
638
  if (!this.hasBinData) {
639
639
  return this.noDataTemplate;
640
640
  }
641
- return html `
642
- <div
643
- id="container"
644
- class="
645
- noselect
646
- ${this._isDragging ? 'dragging' : ''}
647
- "
648
- style="width: ${this.width}px"
649
- >
650
- ${this.activityIndicatorTemplate} ${this.tooltipTemplate}
651
- <div
652
- class="inner-container
653
- ${this.disabled ? 'disabled' : ''}"
654
- >
655
- <svg
656
- width="${this.width}"
657
- height="${this.height}"
658
- @pointerleave="${this.drop}"
659
- >
660
- ${this.selectedRangeTemplate}
661
- <svg id="histogram">${this.histogramTemplate}</svg>
662
- ${this.minSliderTemplate} ${this.maxSliderTemplate}
663
- </svg>
664
- <div id="inputs">
665
- ${this.minLabelTemplate} ${this.minInputTemplate}
666
- <div class="dash">-</div>
667
- ${this.maxLabelTemplate} ${this.maxInputTemplate}
668
- <slot name="inputs-right-side"></slot>
669
- </div>
670
- </div>
671
- </div>
641
+ return html `
642
+ <div
643
+ id="container"
644
+ class="
645
+ noselect
646
+ ${this._isDragging ? 'dragging' : ''}
647
+ "
648
+ style="width: ${this.width}px"
649
+ >
650
+ ${this.activityIndicatorTemplate} ${this.tooltipTemplate}
651
+ <div
652
+ class="inner-container
653
+ ${this.disabled ? 'disabled' : ''}"
654
+ >
655
+ <svg
656
+ width="${this.width}"
657
+ height="${this.height}"
658
+ @pointerleave="${this.drop}"
659
+ >
660
+ ${this.selectedRangeTemplate}
661
+ <svg id="histogram">${this.histogramTemplate}</svg>
662
+ ${this.minSliderTemplate} ${this.maxSliderTemplate}
663
+ </svg>
664
+ <div id="inputs">
665
+ ${this.minLabelTemplate} ${this.minInputTemplate}
666
+ <div class="dash">-</div>
667
+ ${this.maxLabelTemplate} ${this.maxInputTemplate}
668
+ <slot name="inputs-right-side"></slot>
669
+ </div>
670
+ </div>
671
+ </div>
672
672
  `;
673
673
  }
674
674
  };
675
- HistogramDateRange.styles = css `
676
- .missing-data-message {
677
- text-align: center;
678
- }
679
- #container {
680
- margin: 0;
681
- touch-action: none;
682
- position: relative;
683
- }
684
- .disabled {
685
- opacity: 0.3;
686
- }
687
- ia-activity-indicator {
688
- position: absolute;
689
- left: calc(50% - 10px);
690
- top: 10px;
691
- width: 20px;
692
- height: 20px;
693
- --activityIndicatorLoadingDotColor: rgba(0, 0, 0, 0);
694
- --activityIndicatorLoadingRingColor: ${activityIndicatorColor};
695
- }
696
-
697
- /* prevent selection from interfering with tooltip, especially on mobile */
698
- /* https://stackoverflow.com/a/4407335/1163042 */
699
- .noselect {
700
- -webkit-touch-callout: none; /* iOS Safari */
701
- -webkit-user-select: none; /* Safari */
702
- -moz-user-select: none; /* Old versions of Firefox */
703
- -ms-user-select: none; /* Internet Explorer/Edge */
704
- user-select: none; /* current Chrome, Edge, Opera and Firefox */
705
- }
706
- .bar {
707
- /* create a transparent border around the hist bars to prevent "gaps" and
708
- flickering when moving around between bars. this also helps with handling
709
- clicks on the bars, preventing users from being able to click in between
710
- bars */
711
- stroke: rgba(0, 0, 0, 0);
712
- /* ensure transparent stroke wide enough to cover gap between bars */
713
- stroke-width: 2px;
714
- }
715
- .bar:hover {
716
- /* highlight currently hovered bar */
717
- fill-opacity: 0.7;
718
- }
719
- .disabled .bar:hover {
720
- /* ensure no visual hover interaction when disabled */
721
- fill-opacity: 1;
722
- }
723
- /****** histogram ********/
724
- #tooltip {
725
- position: absolute;
726
- background: ${tooltipBackgroundColor};
727
- color: ${tooltipTextColor};
728
- text-align: center;
729
- border-radius: 3px;
730
- padding: 2px;
731
- font-size: ${tooltipFontSize};
732
- font-family: ${tooltipFontFamily};
733
- touch-action: none;
734
- pointer-events: none;
735
- }
736
- #tooltip:after {
737
- content: '';
738
- position: absolute;
739
- margin-left: -5px;
740
- top: 100%;
741
- /* arrow */
742
- border: 5px solid ${tooltipTextColor};
743
- border-color: ${tooltipBackgroundColor} transparent transparent
744
- transparent;
745
- }
746
- /****** slider ********/
747
- .draggable:hover {
748
- cursor: grab;
749
- }
750
- .dragging {
751
- cursor: grabbing !important;
752
- }
753
- /****** inputs ********/
754
- #inputs {
755
- display: flex;
756
- justify-content: center;
757
- margin: ${inputRowMargin};
758
- }
759
- #inputs .dash {
760
- position: relative;
761
- bottom: -1px;
762
- align-self: center; /* Otherwise the dash sticks to the top while the inputs grow */
763
- }
764
- input {
765
- width: ${inputWidth};
766
- margin: 0 3px;
767
- border: ${inputBorder};
768
- border-radius: 2px !important;
769
- text-align: center;
770
- font-size: ${inputFontSize};
771
- font-family: ${inputFontFamily};
772
- }
773
- .sr-only {
774
- position: absolute !important;
775
- width: 1px !important;
776
- height: 1px !important;
777
- margin: 0 !important;
778
- padding: 0 !important;
779
- border: 0 !important;
780
- overflow: hidden !important;
781
- white-space: nowrap !important;
782
- clip: rect(1px, 1px, 1px, 1px) !important;
783
- -webkit-clip-path: inset(50%) !important;
784
- clip-path: inset(50%) !important;
785
- }
675
+ HistogramDateRange.styles = css `
676
+ .missing-data-message {
677
+ text-align: center;
678
+ }
679
+ #container {
680
+ margin: 0;
681
+ touch-action: none;
682
+ position: relative;
683
+ }
684
+ .disabled {
685
+ opacity: 0.3;
686
+ }
687
+ ia-activity-indicator {
688
+ position: absolute;
689
+ left: calc(50% - 10px);
690
+ top: 10px;
691
+ width: 20px;
692
+ height: 20px;
693
+ --activityIndicatorLoadingDotColor: rgba(0, 0, 0, 0);
694
+ --activityIndicatorLoadingRingColor: ${activityIndicatorColor};
695
+ }
696
+
697
+ /* prevent selection from interfering with tooltip, especially on mobile */
698
+ /* https://stackoverflow.com/a/4407335/1163042 */
699
+ .noselect {
700
+ -webkit-touch-callout: none; /* iOS Safari */
701
+ -webkit-user-select: none; /* Safari */
702
+ -moz-user-select: none; /* Old versions of Firefox */
703
+ -ms-user-select: none; /* Internet Explorer/Edge */
704
+ user-select: none; /* current Chrome, Edge, Opera and Firefox */
705
+ }
706
+ .bar {
707
+ /* create a transparent border around the hist bars to prevent "gaps" and
708
+ flickering when moving around between bars. this also helps with handling
709
+ clicks on the bars, preventing users from being able to click in between
710
+ bars */
711
+ stroke: rgba(0, 0, 0, 0);
712
+ /* ensure transparent stroke wide enough to cover gap between bars */
713
+ stroke-width: 2px;
714
+ }
715
+ .bar:hover {
716
+ /* highlight currently hovered bar */
717
+ fill-opacity: 0.7;
718
+ }
719
+ .disabled .bar:hover {
720
+ /* ensure no visual hover interaction when disabled */
721
+ fill-opacity: 1;
722
+ }
723
+ /****** histogram ********/
724
+ #tooltip {
725
+ position: absolute;
726
+ background: ${tooltipBackgroundColor};
727
+ color: ${tooltipTextColor};
728
+ text-align: center;
729
+ border-radius: 3px;
730
+ padding: 2px;
731
+ font-size: ${tooltipFontSize};
732
+ font-family: ${tooltipFontFamily};
733
+ touch-action: none;
734
+ pointer-events: none;
735
+ }
736
+ #tooltip:after {
737
+ content: '';
738
+ position: absolute;
739
+ margin-left: -5px;
740
+ top: 100%;
741
+ /* arrow */
742
+ border: 5px solid ${tooltipTextColor};
743
+ border-color: ${tooltipBackgroundColor} transparent transparent
744
+ transparent;
745
+ }
746
+ /****** slider ********/
747
+ .draggable:hover {
748
+ cursor: grab;
749
+ }
750
+ .dragging {
751
+ cursor: grabbing !important;
752
+ }
753
+ /****** inputs ********/
754
+ #inputs {
755
+ display: flex;
756
+ justify-content: center;
757
+ margin: ${inputRowMargin};
758
+ }
759
+ #inputs .dash {
760
+ position: relative;
761
+ bottom: -1px;
762
+ align-self: center; /* Otherwise the dash sticks to the top while the inputs grow */
763
+ }
764
+ input {
765
+ width: ${inputWidth};
766
+ margin: 0 3px;
767
+ border: ${inputBorder};
768
+ border-radius: 2px !important;
769
+ text-align: center;
770
+ font-size: ${inputFontSize};
771
+ font-family: ${inputFontFamily};
772
+ }
773
+ .sr-only {
774
+ position: absolute !important;
775
+ width: 1px !important;
776
+ height: 1px !important;
777
+ margin: 0 !important;
778
+ padding: 0 !important;
779
+ border: 0 !important;
780
+ overflow: hidden !important;
781
+ white-space: nowrap !important;
782
+ clip: rect(1px, 1px, 1px, 1px) !important;
783
+ -webkit-clip-path: inset(50%) !important;
784
+ clip-path: inset(50%) !important;
785
+ }
786
786
  `;
787
787
  __decorate([
788
788
  property({ type: Number })