@internetarchive/histogram-date-range 0.1.8-alpha.3 → 0.1.8

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.
@@ -93,7 +93,6 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
93
93
  this.move = (e) => {
94
94
  const histogramClientX = this.getBoundingClientRect().x;
95
95
  const newX = e.clientX - histogramClientX - this._dragOffset;
96
- console.log('move', histogramClientX, e.clientX, this._dragOffset, newX);
97
96
  const slider = this._currentSlider;
98
97
  if (slider.id === 'slider-min') {
99
98
  this.minSelectedDate = this.translatePositionToDate(this.validMinSliderX(newX));
@@ -251,9 +250,9 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
251
250
  const formattedNumItems = Number(dataset.numItems).toLocaleString();
252
251
  this._tooltipOffset =
253
252
  x + (this._binWidth - this.sliderWidth - this.tooltipWidth) / 2;
254
- this._tooltipContent = html `
255
- ${formattedNumItems} ${itemsText}<br />
256
- ${dataset.binStart} - ${dataset.binEnd}
253
+ this._tooltipContent = html `
254
+ ${formattedNumItems} ${itemsText}<br />
255
+ ${dataset.binStart} - ${dataset.binEnd}
257
256
  `;
258
257
  this._tooltipVisible = true;
259
258
  }
@@ -344,7 +343,6 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
344
343
  : this.maxSliderX;
345
344
  const histogramClientX = this.getBoundingClientRect().x;
346
345
  this._dragOffset = e.clientX - histogramClientX - sliderX;
347
- console.log('setDragOffset', histogramClientX, e.clientX, sliderX, this._dragOffset);
348
346
  }
349
347
  /**
350
348
  * @param x horizontal position of slider
@@ -440,25 +438,25 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
440
438
  // border-radius); used as part of a SVG quadratic curve. see
441
439
  // https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#curve_commands
442
440
  const cs = SLIDER_CORNER_SIZE;
443
- const sliderShape = `
444
- M${this.minSliderX},0
445
- h-${this.sliderWidth - cs}
446
- q-${cs},0 -${cs},${cs}
447
- v${this.height - cs * 2}
448
- q0,${cs} ${cs},${cs}
449
- h${this.sliderWidth - cs}
441
+ const sliderShape = `
442
+ M${this.minSliderX},0
443
+ h-${this.sliderWidth - cs}
444
+ q-${cs},0 -${cs},${cs}
445
+ v${this.height - cs * 2}
446
+ q0,${cs} ${cs},${cs}
447
+ h${this.sliderWidth - cs}
450
448
  `;
451
449
  return this.generateSliderSVG(this.minSliderX, 'slider-min', sliderShape);
452
450
  }
453
451
  get maxSliderTemplate() {
454
452
  const cs = SLIDER_CORNER_SIZE;
455
- const sliderShape = `
456
- M${this.maxSliderX},0
457
- h${this.sliderWidth - cs}
458
- q${cs},0 ${cs},${cs}
459
- v${this.height - cs * 2}
460
- q0,${cs} -${cs},${cs}
461
- h-${this.sliderWidth - cs}
453
+ const sliderShape = `
454
+ M${this.maxSliderX},0
455
+ h${this.sliderWidth - cs}
456
+ q${cs},0 ${cs},${cs}
457
+ v${this.height - cs * 2}
458
+ q0,${cs} -${cs},${cs}
459
+ h-${this.sliderWidth - cs}
462
460
  `;
463
461
  return this.generateSliderSVG(this.maxSliderX, 'slider-max', sliderShape);
464
462
  }
@@ -466,40 +464,40 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
466
464
  // whether the curved part of the slider is facing towards the left (1), ie
467
465
  // minimum, or facing towards the right (-1), ie maximum
468
466
  const k = id === 'slider-min' ? 1 : -1;
469
- return svg `
470
- <svg
471
- id="${id}"
472
- class="
473
- ${this.disabled ? '' : 'draggable'}
474
- ${this._isDragging ? 'dragging' : ''}"
475
- @pointerdown="${this.drag}"
476
- >
477
- <path d="${sliderShape} z" fill="${sliderColor}" />
478
- <rect
479
- x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.4 * k}"
480
- y="${this.height / 3}"
481
- width="1"
482
- height="${this.height / 3}"
483
- fill="white"
484
- />
485
- <rect
486
- x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.6 * k}"
487
- y="${this.height / 3}"
488
- width="1"
489
- height="${this.height / 3}"
490
- fill="white"
491
- />
492
- </svg>
467
+ return svg `
468
+ <svg
469
+ id="${id}"
470
+ class="
471
+ ${this.disabled ? '' : 'draggable'}
472
+ ${this._isDragging ? 'dragging' : ''}"
473
+ @pointerdown="${this.drag}"
474
+ >
475
+ <path d="${sliderShape} z" fill="${sliderColor}" />
476
+ <rect
477
+ x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.4 * k}"
478
+ y="${this.height / 3}"
479
+ width="1"
480
+ height="${this.height / 3}"
481
+ fill="white"
482
+ />
483
+ <rect
484
+ x="${sliderPositionX - this.sliderWidth * k + this.sliderWidth * 0.6 * k}"
485
+ y="${this.height / 3}"
486
+ width="1"
487
+ height="${this.height / 3}"
488
+ fill="white"
489
+ />
490
+ </svg>
493
491
  `;
494
492
  }
495
493
  get selectedRangeTemplate() {
496
- return svg `
497
- <rect
498
- x="${this.minSliderX}"
499
- y="0"
500
- width="${this.maxSliderX - this.minSliderX}"
501
- height="${this.height}"
502
- fill="${selectedRangeColor}"
494
+ return svg `
495
+ <rect
496
+ x="${this.minSliderX}"
497
+ y="0"
498
+ width="${this.maxSliderX - this.minSliderX}"
499
+ height="${this.height}"
500
+ fill="${selectedRangeColor}"
503
501
  />`;
504
502
  }
505
503
  get histogramTemplate() {
@@ -511,23 +509,23 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
511
509
  // between adjacent bars (eg when viewing the tooltips or when trying to
512
510
  // extend the range by clicking on a bar)
513
511
  return this._histData.map(data => {
514
- const bar = svg `
515
- <rect
516
- class="bar"
517
- style='stroke-dasharray: 0 ${barWidth} ${data.height} ${barWidth} 0 ${data.height};'
518
- x="${x}"
519
- y="${this.height - data.height}"
520
- width="${barWidth}"
521
- height="${data.height}"
522
- @pointerenter="${this.showTooltip}"
523
- @pointerleave="${this.hideTooltip}"
524
- @click="${this.handleBarClick}"
512
+ const bar = svg `
513
+ <rect
514
+ class="bar"
515
+ style='stroke-dasharray: 0 ${barWidth} ${data.height} ${barWidth} 0 ${data.height};'
516
+ x="${x}"
517
+ y="${this.height - data.height}"
518
+ width="${barWidth}"
519
+ height="${data.height}"
520
+ @pointerenter="${this.showTooltip}"
521
+ @pointerleave="${this.hideTooltip}"
522
+ @click="${this.handleBarClick}"
525
523
  fill="${x + barWidth >= this.minSliderX && x <= this.maxSliderX
526
524
  ? barIncludedFill
527
- : barExcludedFill}"
528
- data-num-items="${data.value}"
529
- data-bin-start="${data.binStart}"
530
- data-bin-end="${data.binEnd}"
525
+ : barExcludedFill}"
526
+ data-num-items="${data.value}"
527
+ data-bin-start="${data.binStart}"
528
+ data-bin-end="${data.binEnd}"
531
529
  />`;
532
530
  x += xScale;
533
531
  return bar;
@@ -552,196 +550,196 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
552
550
  * https://lit.dev/docs/templates/directives/#live
553
551
  */
554
552
  get minInputTemplate() {
555
- return html `
556
- <input
557
- id="date-min"
558
- placeholder="${this.dateFormat}"
559
- type="text"
560
- @focus="${this.cancelPendingUpdateEvent}"
561
- @blur="${this.handleMinDateInput}"
562
- @keyup="${this.handleKeyUp}"
563
- .value="${live(this.minSelectedDate)}"
564
- ?disabled="${this.disabled}"
565
- />
553
+ return html `
554
+ <input
555
+ id="date-min"
556
+ placeholder="${this.dateFormat}"
557
+ type="text"
558
+ @focus="${this.cancelPendingUpdateEvent}"
559
+ @blur="${this.handleMinDateInput}"
560
+ @keyup="${this.handleKeyUp}"
561
+ .value="${live(this.minSelectedDate)}"
562
+ ?disabled="${this.disabled}"
563
+ />
566
564
  `;
567
565
  }
568
566
  get maxInputTemplate() {
569
- return html `
570
- <input
571
- id="date-max"
572
- placeholder="${this.dateFormat}"
573
- type="text"
574
- @focus="${this.cancelPendingUpdateEvent}"
575
- @blur="${this.handleMaxDateInput}"
576
- @keyup="${this.handleKeyUp}"
577
- .value="${live(this.maxSelectedDate)}"
578
- ?disabled="${this.disabled}"
579
- />
567
+ return html `
568
+ <input
569
+ id="date-max"
570
+ placeholder="${this.dateFormat}"
571
+ type="text"
572
+ @focus="${this.cancelPendingUpdateEvent}"
573
+ @blur="${this.handleMaxDateInput}"
574
+ @keyup="${this.handleKeyUp}"
575
+ .value="${live(this.maxSelectedDate)}"
576
+ ?disabled="${this.disabled}"
577
+ />
580
578
  `;
581
579
  }
582
580
  get tooltipTemplate() {
583
- return html `
584
- <style>
585
- #tooltip {
586
- width: ${this.tooltipWidth}px;
587
- height: ${this.tooltipHeight}px;
588
- top: ${-9 - this.tooltipHeight}px;
589
- left: ${this._tooltipOffset}px;
590
- display: ${this._tooltipVisible ? 'block' : 'none'};
591
- }
592
- #tooltip:after {
593
- left: ${this.tooltipWidth / 2}px;
594
- }
595
- </style>
596
- <div id="tooltip">${this._tooltipContent}</div>
581
+ return html `
582
+ <style>
583
+ #tooltip {
584
+ width: ${this.tooltipWidth}px;
585
+ height: ${this.tooltipHeight}px;
586
+ top: ${-9 - this.tooltipHeight}px;
587
+ left: ${this._tooltipOffset}px;
588
+ display: ${this._tooltipVisible ? 'block' : 'none'};
589
+ }
590
+ #tooltip:after {
591
+ left: ${this.tooltipWidth / 2}px;
592
+ }
593
+ </style>
594
+ <div id="tooltip">${this._tooltipContent}</div>
597
595
  `;
598
596
  }
599
597
  get noDataTemplate() {
600
- return html `
601
- <div class="missing-data-message">${this.missingDataMessage}</div>
598
+ return html `
599
+ <div class="missing-data-message">${this.missingDataMessage}</div>
602
600
  `;
603
601
  }
604
602
  get activityIndicatorTemplate() {
605
603
  if (!this.loading) {
606
604
  return nothing;
607
605
  }
608
- return html `
609
- <ia-activity-indicator mode="processing"> </ia-activity-indicator>
606
+ return html `
607
+ <ia-activity-indicator mode="processing"> </ia-activity-indicator>
610
608
  `;
611
609
  }
612
610
  render() {
613
611
  if (!this.hasBinData) {
614
612
  return this.noDataTemplate;
615
613
  }
616
- return html `
617
- <div
618
- id="container"
619
- class="
620
- noselect
621
- ${this._isDragging ? 'dragging' : ''}
622
- "
623
- style="width: ${this.width}px"
624
- >
625
- ${this.activityIndicatorTemplate} ${this.tooltipTemplate}
626
- <div
627
- class="inner-container
628
- ${this.disabled ? 'disabled' : ''}"
629
- >
630
- <svg
631
- width="${this.width}"
632
- height="${this.height}"
633
- @pointerleave="${this.drop}"
634
- >
635
- ${this.selectedRangeTemplate}
636
- <svg id="histogram">${this.histogramTemplate}</svg>
637
- ${this.minSliderTemplate} ${this.maxSliderTemplate}
638
- </svg>
639
- <div id="inputs">
640
- ${this.minInputTemplate}
641
- <div class="dash">-</div>
642
- ${this.maxInputTemplate}
643
- </div>
644
- </div>
645
- </div>
614
+ return html `
615
+ <div
616
+ id="container"
617
+ class="
618
+ noselect
619
+ ${this._isDragging ? 'dragging' : ''}
620
+ "
621
+ style="width: ${this.width}px"
622
+ >
623
+ ${this.activityIndicatorTemplate} ${this.tooltipTemplate}
624
+ <div
625
+ class="inner-container
626
+ ${this.disabled ? 'disabled' : ''}"
627
+ >
628
+ <svg
629
+ width="${this.width}"
630
+ height="${this.height}"
631
+ @pointerleave="${this.drop}"
632
+ >
633
+ ${this.selectedRangeTemplate}
634
+ <svg id="histogram">${this.histogramTemplate}</svg>
635
+ ${this.minSliderTemplate} ${this.maxSliderTemplate}
636
+ </svg>
637
+ <div id="inputs">
638
+ ${this.minInputTemplate}
639
+ <div class="dash">-</div>
640
+ ${this.maxInputTemplate}
641
+ </div>
642
+ </div>
643
+ </div>
646
644
  `;
647
645
  }
648
646
  };
649
- HistogramDateRange.styles = css `
650
- .missing-data-message {
651
- text-align: center;
652
- }
653
- #container {
654
- margin: 0;
655
- touch-action: none;
656
- position: relative;
657
- }
658
- .disabled {
659
- opacity: 0.3;
660
- }
661
- ia-activity-indicator {
662
- position: absolute;
663
- left: calc(50% - 10px);
664
- top: 10px;
665
- width: 20px;
666
- height: 20px;
667
- --activityIndicatorLoadingDotColor: rgba(0, 0, 0, 0);
668
- --activityIndicatorLoadingRingColor: ${activityIndicatorColor};
669
- }
670
-
671
- /* prevent selection from interfering with tooltip, especially on mobile */
672
- /* https://stackoverflow.com/a/4407335/1163042 */
673
- .noselect {
674
- -webkit-touch-callout: none; /* iOS Safari */
675
- -webkit-user-select: none; /* Safari */
676
- -moz-user-select: none; /* Old versions of Firefox */
677
- -ms-user-select: none; /* Internet Explorer/Edge */
678
- user-select: none; /* current Chrome, Edge, Opera and Firefox */
679
- }
680
- .bar {
681
- /* create a transparent border around the hist bars to prevent "gaps" and
682
- flickering when moving around between bars. this also helps with handling
683
- clicks on the bars, preventing users from being able to click in between
684
- bars */
685
- stroke: rgba(0, 0, 0, 0);
686
- /* ensure transparent stroke wide enough to cover gap between bars */
687
- stroke-width: 2px;
688
- }
689
- .bar:hover {
690
- /* highlight currently hovered bar */
691
- fill-opacity: 0.7;
692
- }
693
- .disabled .bar:hover {
694
- /* ensure no visual hover interaction when disabled */
695
- fill-opacity: 1;
696
- }
697
- /****** histogram ********/
698
- #tooltip {
699
- position: absolute;
700
- background: ${tooltipBackgroundColor};
701
- color: ${tooltipTextColor};
702
- text-align: center;
703
- border-radius: 3px;
704
- padding: 2px;
705
- font-size: ${tooltipFontSize};
706
- font-family: ${tooltipFontFamily};
707
- touch-action: none;
708
- pointer-events: none;
709
- }
710
- #tooltip:after {
711
- content: '';
712
- position: absolute;
713
- margin-left: -5px;
714
- top: 100%;
715
- /* arrow */
716
- border: 5px solid ${tooltipTextColor};
717
- border-color: ${tooltipBackgroundColor} transparent transparent
718
- transparent;
719
- }
720
- /****** slider ********/
721
- .draggable:hover {
722
- cursor: grab;
723
- }
724
- .dragging {
725
- cursor: grabbing !important;
726
- }
727
- /****** inputs ********/
728
- #inputs {
729
- display: flex;
730
- justify-content: center;
731
- }
732
- #inputs .dash {
733
- position: relative;
734
- bottom: -1px;
735
- }
736
- input {
737
- width: ${inputWidth};
738
- margin: 0 3px;
739
- border: ${inputBorder};
740
- border-radius: 2px !important;
741
- text-align: center;
742
- font-size: ${inputFontSize};
743
- font-family: ${inputFontFamily};
744
- }
647
+ HistogramDateRange.styles = css `
648
+ .missing-data-message {
649
+ text-align: center;
650
+ }
651
+ #container {
652
+ margin: 0;
653
+ touch-action: none;
654
+ position: relative;
655
+ }
656
+ .disabled {
657
+ opacity: 0.3;
658
+ }
659
+ ia-activity-indicator {
660
+ position: absolute;
661
+ left: calc(50% - 10px);
662
+ top: 10px;
663
+ width: 20px;
664
+ height: 20px;
665
+ --activityIndicatorLoadingDotColor: rgba(0, 0, 0, 0);
666
+ --activityIndicatorLoadingRingColor: ${activityIndicatorColor};
667
+ }
668
+
669
+ /* prevent selection from interfering with tooltip, especially on mobile */
670
+ /* https://stackoverflow.com/a/4407335/1163042 */
671
+ .noselect {
672
+ -webkit-touch-callout: none; /* iOS Safari */
673
+ -webkit-user-select: none; /* Safari */
674
+ -moz-user-select: none; /* Old versions of Firefox */
675
+ -ms-user-select: none; /* Internet Explorer/Edge */
676
+ user-select: none; /* current Chrome, Edge, Opera and Firefox */
677
+ }
678
+ .bar {
679
+ /* create a transparent border around the hist bars to prevent "gaps" and
680
+ flickering when moving around between bars. this also helps with handling
681
+ clicks on the bars, preventing users from being able to click in between
682
+ bars */
683
+ stroke: rgba(0, 0, 0, 0);
684
+ /* ensure transparent stroke wide enough to cover gap between bars */
685
+ stroke-width: 2px;
686
+ }
687
+ .bar:hover {
688
+ /* highlight currently hovered bar */
689
+ fill-opacity: 0.7;
690
+ }
691
+ .disabled .bar:hover {
692
+ /* ensure no visual hover interaction when disabled */
693
+ fill-opacity: 1;
694
+ }
695
+ /****** histogram ********/
696
+ #tooltip {
697
+ position: absolute;
698
+ background: ${tooltipBackgroundColor};
699
+ color: ${tooltipTextColor};
700
+ text-align: center;
701
+ border-radius: 3px;
702
+ padding: 2px;
703
+ font-size: ${tooltipFontSize};
704
+ font-family: ${tooltipFontFamily};
705
+ touch-action: none;
706
+ pointer-events: none;
707
+ }
708
+ #tooltip:after {
709
+ content: '';
710
+ position: absolute;
711
+ margin-left: -5px;
712
+ top: 100%;
713
+ /* arrow */
714
+ border: 5px solid ${tooltipTextColor};
715
+ border-color: ${tooltipBackgroundColor} transparent transparent
716
+ transparent;
717
+ }
718
+ /****** slider ********/
719
+ .draggable:hover {
720
+ cursor: grab;
721
+ }
722
+ .dragging {
723
+ cursor: grabbing !important;
724
+ }
725
+ /****** inputs ********/
726
+ #inputs {
727
+ display: flex;
728
+ justify-content: center;
729
+ }
730
+ #inputs .dash {
731
+ position: relative;
732
+ bottom: -1px;
733
+ }
734
+ input {
735
+ width: ${inputWidth};
736
+ margin: 0 3px;
737
+ border: ${inputBorder};
738
+ border-radius: 2px !important;
739
+ text-align: center;
740
+ font-size: ${inputFontSize};
741
+ font-family: ${inputFontFamily};
742
+ }
745
743
  `;
746
744
  __decorate([
747
745
  property({ type: Number })