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