@internetarchive/histogram-date-range 1.0.0 → 1.0.1-alpha.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.
@@ -123,7 +123,9 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
123
123
  changedProps.has('minDate') ||
124
124
  changedProps.has('maxDate') ||
125
125
  changedProps.has('minSelectedDate') ||
126
- changedProps.has('maxSelectedDate')) {
126
+ changedProps.has('maxSelectedDate') ||
127
+ changedProps.has('width') ||
128
+ changedProps.has('height')) {
127
129
  this.handleDataUpdate();
128
130
  }
129
131
  }
@@ -260,9 +262,9 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
260
262
  const formattedNumItems = Number(dataset.numItems).toLocaleString();
261
263
  this._tooltipOffset =
262
264
  x + (this._binWidth - this.sliderWidth - this.tooltipWidth) / 2;
263
- this._tooltipContent = html `
264
- ${formattedNumItems} ${itemsText}<br />
265
- ${dataset.binStart} - ${dataset.binEnd}
265
+ this._tooltipContent = html `
266
+ ${formattedNumItems} ${itemsText}<br />
267
+ ${dataset.binStart} - ${dataset.binEnd}
266
268
  `;
267
269
  this._tooltipVisible = true;
268
270
  }
@@ -457,25 +459,25 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
457
459
  // border-radius); used as part of a SVG quadratic curve. see
458
460
  // https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#curve_commands
459
461
  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}
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}
467
469
  `;
468
470
  return this.generateSliderSVG(this.minSliderX, 'slider-min', sliderShape);
469
471
  }
470
472
  get maxSliderTemplate() {
471
473
  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}
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}
479
481
  `;
480
482
  return this.generateSliderSVG(this.maxSliderX, 'slider-max', sliderShape);
481
483
  }
@@ -483,40 +485,40 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
483
485
  // whether the curved part of the slider is facing towards the left (1), ie
484
486
  // minimum, or facing towards the right (-1), ie maximum
485
487
  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>
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>
510
512
  `;
511
513
  }
512
514
  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}"
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}"
520
522
  />`;
521
523
  }
522
524
  get histogramTemplate() {
@@ -528,23 +530,23 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
528
530
  // between adjacent bars (eg when viewing the tooltips or when trying to
529
531
  // extend the range by clicking on a bar)
530
532
  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}"
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}"
542
544
  fill="${x + barWidth >= this.minSliderX && x <= this.maxSliderX
543
545
  ? barIncludedFill
544
- : barExcludedFill}"
545
- data-num-items="${data.value}"
546
- data-bin-start="${data.binStart}"
547
- 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}"
548
550
  />`;
549
551
  x += xScale;
550
552
  return bar;
@@ -569,31 +571,31 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
569
571
  * https://lit.dev/docs/templates/directives/#live
570
572
  */
571
573
  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
- />
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
+ />
583
585
  `;
584
586
  }
585
587
  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
- />
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
+ />
597
599
  `;
598
600
  }
599
601
  get minLabelTemplate() {
@@ -603,184 +605,184 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
603
605
  return html `<label for="date-max" class="sr-only">Maximum date:</label>`;
604
606
  }
605
607
  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>
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>
620
622
  `;
621
623
  }
622
624
  get noDataTemplate() {
623
- return html `
624
- <div class="missing-data-message">${this.missingDataMessage}</div>
625
+ return html `
626
+ <div class="missing-data-message">${this.missingDataMessage}</div>
625
627
  `;
626
628
  }
627
629
  get activityIndicatorTemplate() {
628
630
  if (!this.loading) {
629
631
  return nothing;
630
632
  }
631
- return html `
632
- <ia-activity-indicator mode="processing"> </ia-activity-indicator>
633
+ return html `
634
+ <ia-activity-indicator mode="processing"> </ia-activity-indicator>
633
635
  `;
634
636
  }
635
637
  render() {
636
638
  if (!this.hasBinData) {
637
639
  return this.noDataTemplate;
638
640
  }
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>
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>
670
672
  `;
671
673
  }
672
674
  };
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
- }
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
+ }
784
786
  `;
785
787
  __decorate([
786
788
  property({ type: Number })