@internetarchive/histogram-date-range 0.1.10-alpha.2 → 0.1.10

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