@internetarchive/histogram-date-range 1.2.2-alpha-webdev7377.1 → 1.2.2-alpha-webdev7377.2

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.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC","sourcesContent":["export { HistogramDateRange } from './src/histogram-date-range';\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC","sourcesContent":["export { HistogramDateRange } from './src/histogram-date-range';\n"]}
@@ -152,21 +152,22 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
152
152
  roundToMonth(timestamp) {
153
153
  const date = new Date(timestamp);
154
154
  const [y, m, d] = [date.getFullYear(), date.getMonth(), date.getDate()];
155
- if (d < 15)
156
- return new Date(y, m, 1).getTime();
157
- return new Date(y, m + 1, 1).getTime();
155
+ return d < 15
156
+ ? new Date(y, m, 1).getTime()
157
+ : new Date(y, m + 1, 1).getTime();
158
158
  }
159
159
  calculateHistData() {
160
+ const { bins, height, dateRangeMS, _numBins, _minDateMS } = this;
160
161
  const minValue = Math.min(...this.bins);
161
162
  const maxValue = Math.max(...this.bins);
162
163
  // if there is no difference between the min and max values, use a range of
163
164
  // 1 because log scaling will fail if the range is 0
164
165
  const valueRange = minValue === maxValue ? 1 : Math.log1p(maxValue);
165
- const valueScale = this.height / valueRange;
166
- const dateScale = this.dateRangeMS / this._numBins;
167
- return this.bins.map((v, i) => {
168
- const binStartMS = this.roundToMonth(i * dateScale + this._minDateMS);
169
- const binEndMS = this.roundToMonth((i + 1) * dateScale + this._minDateMS);
166
+ const valueScale = height / valueRange;
167
+ const dateScale = dateRangeMS / _numBins;
168
+ return bins.map((v, i) => {
169
+ const binStartMS = this.roundToMonth(i * dateScale + _minDateMS);
170
+ const binEndMS = this.roundToMonth((i + 1) * dateScale + _minDateMS) - 1;
170
171
  return {
171
172
  value: v,
172
173
  // use log scaling for the height of the bar to prevent tall bars from
@@ -274,9 +275,9 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
274
275
  const formattedNumItems = Number(dataset.numItems).toLocaleString();
275
276
  this._tooltipOffset =
276
277
  x + (this._binWidth - this.sliderWidth - this.tooltipWidth) / 2;
277
- this._tooltipContent = html `
278
- ${formattedNumItems} ${itemsText}<br />
279
- ${dataset.binStart} - ${dataset.binEnd}
278
+ this._tooltipContent = html `
279
+ ${formattedNumItems} ${itemsText}<br />
280
+ ${dataset.binStart} - ${dataset.binEnd}
280
281
  `;
281
282
  this._tooltipVisible = true;
282
283
  }
@@ -471,25 +472,25 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
471
472
  // border-radius); used as part of a SVG quadratic curve. see
472
473
  // https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#curve_commands
473
474
  const cs = SLIDER_CORNER_SIZE;
474
- const sliderShape = `
475
- M${this.minSliderX},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}
475
+ const sliderShape = `
476
+ M${this.minSliderX},0
477
+ h-${this.sliderWidth - cs}
478
+ q-${cs},0 -${cs},${cs}
479
+ v${this.height - cs * 2}
480
+ q0,${cs} ${cs},${cs}
481
+ h${this.sliderWidth - cs}
481
482
  `;
482
483
  return this.generateSliderSVG(this.minSliderX, 'slider-min', sliderShape);
483
484
  }
484
485
  get maxSliderTemplate() {
485
486
  const cs = SLIDER_CORNER_SIZE;
486
- const sliderShape = `
487
- M${this.maxSliderX},0
488
- h${this.sliderWidth - cs}
489
- q${cs},0 ${cs},${cs}
490
- v${this.height - cs * 2}
491
- q0,${cs} -${cs},${cs}
492
- h-${this.sliderWidth - cs}
487
+ const sliderShape = `
488
+ M${this.maxSliderX},0
489
+ h${this.sliderWidth - cs}
490
+ q${cs},0 ${cs},${cs}
491
+ v${this.height - cs * 2}
492
+ q0,${cs} -${cs},${cs}
493
+ h-${this.sliderWidth - cs}
493
494
  `;
494
495
  return this.generateSliderSVG(this.maxSliderX, 'slider-max', sliderShape);
495
496
  }
@@ -497,40 +498,40 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
497
498
  // whether the curved part of the slider is facing towards the left (1), ie
498
499
  // minimum, or facing towards the right (-1), ie maximum
499
500
  const k = id === 'slider-min' ? 1 : -1;
500
- return svg `
501
- <svg
502
- id="${id}"
503
- class="
504
- ${this.disabled ? '' : 'draggable'}
505
- ${this._isDragging ? 'dragging' : ''}"
506
- @pointerdown="${this.drag}"
507
- >
508
- <path d="${sliderShape} z" fill="${sliderColor}" />
509
- <rect
510
- x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.4 * k}"
511
- y="${this.height / 3}"
512
- width="1"
513
- height="${this.height / 3}"
514
- fill="white"
515
- />
516
- <rect
517
- x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.6 * k}"
518
- y="${this.height / 3}"
519
- width="1"
520
- height="${this.height / 3}"
521
- fill="white"
522
- />
523
- </svg>
501
+ return svg `
502
+ <svg
503
+ id="${id}"
504
+ class="
505
+ ${this.disabled ? '' : 'draggable'}
506
+ ${this._isDragging ? 'dragging' : ''}"
507
+ @pointerdown="${this.drag}"
508
+ >
509
+ <path d="${sliderShape} z" fill="${sliderColor}" />
510
+ <rect
511
+ x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.4 * k}"
512
+ y="${this.height / 3}"
513
+ width="1"
514
+ height="${this.height / 3}"
515
+ fill="white"
516
+ />
517
+ <rect
518
+ x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.6 * k}"
519
+ y="${this.height / 3}"
520
+ width="1"
521
+ height="${this.height / 3}"
522
+ fill="white"
523
+ />
524
+ </svg>
524
525
  `;
525
526
  }
526
527
  get selectedRangeTemplate() {
527
- return svg `
528
- <rect
529
- x="${this.minSliderX}"
530
- y="0"
531
- width="${this.maxSliderX - this.minSliderX}"
532
- height="${this.height}"
533
- fill="${selectedRangeColor}"
528
+ return svg `
529
+ <rect
530
+ x="${this.minSliderX}"
531
+ y="0"
532
+ width="${this.maxSliderX - this.minSliderX}"
533
+ height="${this.height}"
534
+ fill="${selectedRangeColor}"
534
535
  />`;
535
536
  }
536
537
  get histogramTemplate() {
@@ -542,23 +543,23 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
542
543
  // between adjacent bars (eg when viewing the tooltips or when trying to
543
544
  // extend the range by clicking on a bar)
544
545
  return this._histData.map(data => {
545
- const bar = svg `
546
- <rect
547
- class="bar"
548
- style='stroke-dasharray: 0 ${barWidth} ${data.height} ${barWidth} 0 ${data.height};'
549
- x="${x}"
550
- y="${this.height - data.height}"
551
- width="${barWidth}"
552
- height="${data.height}"
553
- @pointerenter="${this.showTooltip}"
554
- @pointerleave="${this.hideTooltip}"
555
- @click="${this.handleBarClick}"
546
+ const bar = svg `
547
+ <rect
548
+ class="bar"
549
+ style='stroke-dasharray: 0 ${barWidth} ${data.height} ${barWidth} 0 ${data.height};'
550
+ x="${x}"
551
+ y="${this.height - data.height}"
552
+ width="${barWidth}"
553
+ height="${data.height}"
554
+ @pointerenter="${this.showTooltip}"
555
+ @pointerleave="${this.hideTooltip}"
556
+ @click="${this.handleBarClick}"
556
557
  fill="${x + barWidth >= this.minSliderX && x <= this.maxSliderX
557
558
  ? barIncludedFill
558
- : barExcludedFill}"
559
- data-num-items="${data.value}"
560
- data-bin-start="${data.binStart}"
561
- data-bin-end="${data.binEnd}"
559
+ : barExcludedFill}"
560
+ data-num-items="${data.value}"
561
+ data-bin-start="${data.binStart}"
562
+ data-bin-end="${data.binEnd}"
562
563
  />`;
563
564
  x += xScale;
564
565
  return bar;
@@ -583,31 +584,31 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
583
584
  * https://lit.dev/docs/templates/directives/#live
584
585
  */
585
586
  get minInputTemplate() {
586
- return html `
587
- <input
588
- id="date-min"
589
- placeholder="${this.dateFormat}"
590
- type="text"
591
- @focus="${this.handleInputFocus}"
592
- @blur="${this.handleMinDateInput}"
593
- @keyup="${this.handleKeyUp}"
594
- .value="${live(this.minSelectedDate)}"
595
- ?disabled="${this.disabled}"
596
- />
587
+ return html `
588
+ <input
589
+ id="date-min"
590
+ placeholder="${this.dateFormat}"
591
+ type="text"
592
+ @focus="${this.handleInputFocus}"
593
+ @blur="${this.handleMinDateInput}"
594
+ @keyup="${this.handleKeyUp}"
595
+ .value="${live(this.minSelectedDate)}"
596
+ ?disabled="${this.disabled}"
597
+ />
597
598
  `;
598
599
  }
599
600
  get maxInputTemplate() {
600
- return html `
601
- <input
602
- id="date-max"
603
- placeholder="${this.dateFormat}"
604
- type="text"
605
- @focus="${this.handleInputFocus}"
606
- @blur="${this.handleMaxDateInput}"
607
- @keyup="${this.handleKeyUp}"
608
- .value="${live(this.maxSelectedDate)}"
609
- ?disabled="${this.disabled}"
610
- />
601
+ return html `
602
+ <input
603
+ id="date-max"
604
+ placeholder="${this.dateFormat}"
605
+ type="text"
606
+ @focus="${this.handleInputFocus}"
607
+ @blur="${this.handleMaxDateInput}"
608
+ @keyup="${this.handleKeyUp}"
609
+ .value="${live(this.maxSelectedDate)}"
610
+ ?disabled="${this.disabled}"
611
+ />
611
612
  `;
612
613
  }
613
614
  get minLabelTemplate() {
@@ -617,184 +618,184 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
617
618
  return html `<label for="date-max" class="sr-only">Maximum date:</label>`;
618
619
  }
619
620
  get tooltipTemplate() {
620
- return html `
621
- <style>
622
- #tooltip {
623
- width: ${this.tooltipWidth}px;
624
- height: ${this.tooltipHeight}px;
625
- top: ${-9 - this.tooltipHeight}px;
626
- left: ${this._tooltipOffset}px;
627
- display: ${this._tooltipVisible ? 'block' : 'none'};
628
- }
629
- #tooltip:after {
630
- left: ${this.tooltipWidth / 2}px;
631
- }
632
- </style>
633
- <div id="tooltip">${this._tooltipContent}</div>
621
+ return html `
622
+ <style>
623
+ #tooltip {
624
+ width: ${this.tooltipWidth}px;
625
+ height: ${this.tooltipHeight}px;
626
+ top: ${-9 - this.tooltipHeight}px;
627
+ left: ${this._tooltipOffset}px;
628
+ display: ${this._tooltipVisible ? 'block' : 'none'};
629
+ }
630
+ #tooltip:after {
631
+ left: ${this.tooltipWidth / 2}px;
632
+ }
633
+ </style>
634
+ <div id="tooltip">${this._tooltipContent}</div>
634
635
  `;
635
636
  }
636
637
  get noDataTemplate() {
637
- return html `
638
- <div class="missing-data-message">${this.missingDataMessage}</div>
638
+ return html `
639
+ <div class="missing-data-message">${this.missingDataMessage}</div>
639
640
  `;
640
641
  }
641
642
  get activityIndicatorTemplate() {
642
643
  if (!this.loading) {
643
644
  return nothing;
644
645
  }
645
- return html `
646
- <ia-activity-indicator mode="processing"> </ia-activity-indicator>
646
+ return html `
647
+ <ia-activity-indicator mode="processing"> </ia-activity-indicator>
647
648
  `;
648
649
  }
649
650
  render() {
650
651
  if (!this.hasBinData) {
651
652
  return this.noDataTemplate;
652
653
  }
653
- return html `
654
- <div
655
- id="container"
656
- class="
657
- noselect
658
- ${this._isDragging ? 'dragging' : ''}
659
- "
660
- style="width: ${this.width}px"
661
- >
662
- ${this.activityIndicatorTemplate} ${this.tooltipTemplate}
663
- <div
664
- class="inner-container
665
- ${this.disabled ? 'disabled' : ''}"
666
- >
667
- <svg
668
- width="${this.width}"
669
- height="${this.height}"
670
- @pointerleave="${this.drop}"
671
- >
672
- ${this.selectedRangeTemplate}
673
- <svg id="histogram">${this.histogramTemplate}</svg>
674
- ${this.minSliderTemplate} ${this.maxSliderTemplate}
675
- </svg>
676
- <div id="inputs">
677
- ${this.minLabelTemplate} ${this.minInputTemplate}
678
- <div class="dash">-</div>
679
- ${this.maxLabelTemplate} ${this.maxInputTemplate}
680
- <slot name="inputs-right-side"></slot>
681
- </div>
682
- </div>
683
- </div>
654
+ return html `
655
+ <div
656
+ id="container"
657
+ class="
658
+ noselect
659
+ ${this._isDragging ? 'dragging' : ''}
660
+ "
661
+ style="width: ${this.width}px"
662
+ >
663
+ ${this.activityIndicatorTemplate} ${this.tooltipTemplate}
664
+ <div
665
+ class="inner-container
666
+ ${this.disabled ? 'disabled' : ''}"
667
+ >
668
+ <svg
669
+ width="${this.width}"
670
+ height="${this.height}"
671
+ @pointerleave="${this.drop}"
672
+ >
673
+ ${this.selectedRangeTemplate}
674
+ <svg id="histogram">${this.histogramTemplate}</svg>
675
+ ${this.minSliderTemplate} ${this.maxSliderTemplate}
676
+ </svg>
677
+ <div id="inputs">
678
+ ${this.minLabelTemplate} ${this.minInputTemplate}
679
+ <div class="dash">-</div>
680
+ ${this.maxLabelTemplate} ${this.maxInputTemplate}
681
+ <slot name="inputs-right-side"></slot>
682
+ </div>
683
+ </div>
684
+ </div>
684
685
  `;
685
686
  }
686
687
  };
687
- HistogramDateRange.styles = css `
688
- .missing-data-message {
689
- text-align: center;
690
- }
691
- #container {
692
- margin: 0;
693
- touch-action: none;
694
- position: relative;
695
- }
696
- .disabled {
697
- opacity: 0.3;
698
- }
699
- ia-activity-indicator {
700
- position: absolute;
701
- left: calc(50% - 10px);
702
- top: 10px;
703
- width: 20px;
704
- height: 20px;
705
- --activityIndicatorLoadingDotColor: rgba(0, 0, 0, 0);
706
- --activityIndicatorLoadingRingColor: ${activityIndicatorColor};
707
- }
708
-
709
- /* prevent selection from interfering with tooltip, especially on mobile */
710
- /* https://stackoverflow.com/a/4407335/1163042 */
711
- .noselect {
712
- -webkit-touch-callout: none; /* iOS Safari */
713
- -webkit-user-select: none; /* Safari */
714
- -moz-user-select: none; /* Old versions of Firefox */
715
- -ms-user-select: none; /* Internet Explorer/Edge */
716
- user-select: none; /* current Chrome, Edge, Opera and Firefox */
717
- }
718
- .bar {
719
- /* create a transparent border around the hist bars to prevent "gaps" and
720
- flickering when moving around between bars. this also helps with handling
721
- clicks on the bars, preventing users from being able to click in between
722
- bars */
723
- stroke: rgba(0, 0, 0, 0);
724
- /* ensure transparent stroke wide enough to cover gap between bars */
725
- stroke-width: 2px;
726
- }
727
- .bar:hover {
728
- /* highlight currently hovered bar */
729
- fill-opacity: 0.7;
730
- }
731
- .disabled .bar:hover {
732
- /* ensure no visual hover interaction when disabled */
733
- fill-opacity: 1;
734
- }
735
- /****** histogram ********/
736
- #tooltip {
737
- position: absolute;
738
- background: ${tooltipBackgroundColor};
739
- color: ${tooltipTextColor};
740
- text-align: center;
741
- border-radius: 3px;
742
- padding: 2px;
743
- font-size: ${tooltipFontSize};
744
- font-family: ${tooltipFontFamily};
745
- touch-action: none;
746
- pointer-events: none;
747
- }
748
- #tooltip:after {
749
- content: '';
750
- position: absolute;
751
- margin-left: -5px;
752
- top: 100%;
753
- /* arrow */
754
- border: 5px solid ${tooltipTextColor};
755
- border-color: ${tooltipBackgroundColor} transparent transparent
756
- transparent;
757
- }
758
- /****** slider ********/
759
- .draggable:hover {
760
- cursor: grab;
761
- }
762
- .dragging {
763
- cursor: grabbing !important;
764
- }
765
- /****** inputs ********/
766
- #inputs {
767
- display: flex;
768
- justify-content: center;
769
- margin: ${inputRowMargin};
770
- }
771
- #inputs .dash {
772
- position: relative;
773
- bottom: -1px;
774
- align-self: center; /* Otherwise the dash sticks to the top while the inputs grow */
775
- }
776
- input {
777
- width: ${inputWidth};
778
- margin: 0 3px;
779
- border: ${inputBorder};
780
- border-radius: 2px !important;
781
- text-align: center;
782
- font-size: ${inputFontSize};
783
- font-family: ${inputFontFamily};
784
- }
785
- .sr-only {
786
- position: absolute !important;
787
- width: 1px !important;
788
- height: 1px !important;
789
- margin: 0 !important;
790
- padding: 0 !important;
791
- border: 0 !important;
792
- overflow: hidden !important;
793
- white-space: nowrap !important;
794
- clip: rect(1px, 1px, 1px, 1px) !important;
795
- -webkit-clip-path: inset(50%) !important;
796
- clip-path: inset(50%) !important;
797
- }
688
+ HistogramDateRange.styles = css `
689
+ .missing-data-message {
690
+ text-align: center;
691
+ }
692
+ #container {
693
+ margin: 0;
694
+ touch-action: none;
695
+ position: relative;
696
+ }
697
+ .disabled {
698
+ opacity: 0.3;
699
+ }
700
+ ia-activity-indicator {
701
+ position: absolute;
702
+ left: calc(50% - 10px);
703
+ top: 10px;
704
+ width: 20px;
705
+ height: 20px;
706
+ --activityIndicatorLoadingDotColor: rgba(0, 0, 0, 0);
707
+ --activityIndicatorLoadingRingColor: ${activityIndicatorColor};
708
+ }
709
+
710
+ /* prevent selection from interfering with tooltip, especially on mobile */
711
+ /* https://stackoverflow.com/a/4407335/1163042 */
712
+ .noselect {
713
+ -webkit-touch-callout: none; /* iOS Safari */
714
+ -webkit-user-select: none; /* Safari */
715
+ -moz-user-select: none; /* Old versions of Firefox */
716
+ -ms-user-select: none; /* Internet Explorer/Edge */
717
+ user-select: none; /* current Chrome, Edge, Opera and Firefox */
718
+ }
719
+ .bar {
720
+ /* create a transparent border around the hist bars to prevent "gaps" and
721
+ flickering when moving around between bars. this also helps with handling
722
+ clicks on the bars, preventing users from being able to click in between
723
+ bars */
724
+ stroke: rgba(0, 0, 0, 0);
725
+ /* ensure transparent stroke wide enough to cover gap between bars */
726
+ stroke-width: 2px;
727
+ }
728
+ .bar:hover {
729
+ /* highlight currently hovered bar */
730
+ fill-opacity: 0.7;
731
+ }
732
+ .disabled .bar:hover {
733
+ /* ensure no visual hover interaction when disabled */
734
+ fill-opacity: 1;
735
+ }
736
+ /****** histogram ********/
737
+ #tooltip {
738
+ position: absolute;
739
+ background: ${tooltipBackgroundColor};
740
+ color: ${tooltipTextColor};
741
+ text-align: center;
742
+ border-radius: 3px;
743
+ padding: 2px;
744
+ font-size: ${tooltipFontSize};
745
+ font-family: ${tooltipFontFamily};
746
+ touch-action: none;
747
+ pointer-events: none;
748
+ }
749
+ #tooltip:after {
750
+ content: '';
751
+ position: absolute;
752
+ margin-left: -5px;
753
+ top: 100%;
754
+ /* arrow */
755
+ border: 5px solid ${tooltipTextColor};
756
+ border-color: ${tooltipBackgroundColor} transparent transparent
757
+ transparent;
758
+ }
759
+ /****** slider ********/
760
+ .draggable:hover {
761
+ cursor: grab;
762
+ }
763
+ .dragging {
764
+ cursor: grabbing !important;
765
+ }
766
+ /****** inputs ********/
767
+ #inputs {
768
+ display: flex;
769
+ justify-content: center;
770
+ margin: ${inputRowMargin};
771
+ }
772
+ #inputs .dash {
773
+ position: relative;
774
+ bottom: -1px;
775
+ align-self: center; /* Otherwise the dash sticks to the top while the inputs grow */
776
+ }
777
+ input {
778
+ width: ${inputWidth};
779
+ margin: 0 3px;
780
+ border: ${inputBorder};
781
+ border-radius: 2px !important;
782
+ text-align: center;
783
+ font-size: ${inputFontSize};
784
+ font-family: ${inputFontFamily};
785
+ }
786
+ .sr-only {
787
+ position: absolute !important;
788
+ width: 1px !important;
789
+ height: 1px !important;
790
+ margin: 0 !important;
791
+ padding: 0 !important;
792
+ border: 0 !important;
793
+ overflow: hidden !important;
794
+ white-space: nowrap !important;
795
+ clip: rect(1px, 1px, 1px, 1px) !important;
796
+ -webkit-clip-path: inset(50%) !important;
797
+ clip-path: inset(50%) !important;
798
+ }
798
799
  `;
799
800
  __decorate([
800
801
  property({ type: Number })