@internetarchive/elements 1.0.0 → 1.0.1-webdev-9121.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.
@@ -0,0 +1,243 @@
1
+ import '../../elements/ia-status-indicator/ia-status-indicator.js';
2
+ import { LitElement, PropertyValues, SVGTemplateResult, TemplateResult } from 'lit';
3
+ import type { BarScalingOption, BinSnappingInterval } from './models.js';
4
+ export declare class IAHistogramDateRange extends LitElement {
5
+ width: number;
6
+ height: number;
7
+ sliderWidth: number;
8
+ tooltipWidth: number;
9
+ tooltipHeight: number;
10
+ updateDelay: number;
11
+ dateFormat: string;
12
+ missingDataMessage: string;
13
+ minDate: string;
14
+ maxDate: string;
15
+ disabled: boolean;
16
+ bins: number[];
17
+ /** If true, update events will not be canceled by the date inputs receiving focus */
18
+ updateWhileFocused: boolean;
19
+ /**
20
+ * What interval bins should be snapped to for determining their time ranges.
21
+ * - `none` (default): Bins should each represent an identical duration of time,
22
+ * without regard for the actual dates represented.
23
+ * - `month`: Bins should each represent one or more full, non-overlapping months.
24
+ * The bin ranges will be "snapped" to the nearest month boundaries, which can
25
+ * result in bins that represent different amounts of time, particularly if the
26
+ * provided bins do not evenly divide the provided date range, or if the months
27
+ * represented are of different lengths.
28
+ * - `year`: Same as `month`, but snapping to year boundaries instead of months.
29
+ */
30
+ binSnapping: BinSnappingInterval;
31
+ /**
32
+ * What label to use on tooltips to identify the type of data being represented.
33
+ * Defaults to `'item(s)'`.
34
+ */
35
+ tooltipLabel: string;
36
+ /**
37
+ * A function or preset value indicating how the height of each bar relates to its
38
+ * corresponding bin value. Current presets available are 'logarithmic' and 'linear',
39
+ * but a custom function may be provided instead if other behavior is desired.
40
+ *
41
+ * The default scaling (`'logarithmic'`) uses the logarithm of each bin value, yielding
42
+ * more prominent bars for smaller values. This ensures that even when the difference
43
+ * between the min & max values is large, small values are unlikely to completely disappear
44
+ * visually. However, the cost is that bars have less noticeable variation among values of
45
+ * a similar magnitude, and their heights are not a direct representation of the bin values.
46
+ *
47
+ * The `'linear'` preset option instead sizes the bars in linear proportion to their bin
48
+ * values.
49
+ */
50
+ barScaling: BarScalingOption;
51
+ private _tooltipOffsetX;
52
+ private _tooltipOffsetY;
53
+ private _tooltipContent?;
54
+ private _tooltipDateFormat?;
55
+ private _isDragging;
56
+ private _isLoading;
57
+ private _tooltip;
58
+ private _minSelectedDate;
59
+ private _maxSelectedDate;
60
+ private _minDateMS;
61
+ private _maxDateMS;
62
+ private _dragOffset;
63
+ private _histWidth;
64
+ private _binWidth;
65
+ private _currentSlider?;
66
+ private _histData;
67
+ private _emitUpdatedEventTimer?;
68
+ private _previousDateRange;
69
+ private _updateDeferredWhileFocused;
70
+ updated(): void;
71
+ disconnectedCallback(): void;
72
+ willUpdate(changedProps: PropertyValues): void;
73
+ /**
74
+ * Set private properties that depend on the attribute bin data
75
+ *
76
+ * We're caching these values and not using getters to avoid recalculating all
77
+ * of the hist data every time the user drags a slider or hovers over a bar
78
+ * creating a tooltip.
79
+ */
80
+ private handleDataUpdate;
81
+ /**
82
+ * Rounds the given timestamp to the next full second.
83
+ */
84
+ private snapToNextSecond;
85
+ /**
86
+ * Rounds the given timestamp to the (approximate) nearest start of a month,
87
+ * such that dates up to and including the 15th of the month are rounded down,
88
+ * while dates past the 15th are rounded up.
89
+ */
90
+ private snapToMonth;
91
+ /**
92
+ * Rounds the given timestamp to the (approximate) nearest start of a year,
93
+ * such that dates up to the end of June are rounded down, while dates in
94
+ * July or later are rounded up.
95
+ */
96
+ private snapToYear;
97
+ /**
98
+ * Rounds the given timestamp according to the `binSnapping` property.
99
+ * Default is simply to snap to the nearest full second.
100
+ */
101
+ private snapTimestamp;
102
+ /**
103
+ * Function to scale bin values, whether from a preset or a provided custom function.
104
+ */
105
+ private get barScalingFunction();
106
+ private calculateHistData;
107
+ private get hasBinData();
108
+ private get _numBins();
109
+ private get histogramLeftEdgeX();
110
+ private get histogramRightEdgeX();
111
+ /**
112
+ * Approximate size in ms of the interval to which bins are snapped.
113
+ */
114
+ private get snapInterval();
115
+ /**
116
+ * Offset added to the end of each bin to ensure disjoint intervals,
117
+ * depending on whether snapping is enabled and there are multiple bins.
118
+ */
119
+ private get snapEndOffset();
120
+ /**
121
+ * Optional date format to use for tooltips only.
122
+ * Falls back to `dateFormat` if not provided.
123
+ */
124
+ get tooltipDateFormat(): string;
125
+ set tooltipDateFormat(value: string);
126
+ /** component's loading (and disabled) state */
127
+ get loading(): boolean;
128
+ set loading(value: boolean);
129
+ /** formatted minimum date of selected date range */
130
+ get minSelectedDate(): string;
131
+ /** updates minSelectedDate if new date is valid */
132
+ set minSelectedDate(rawDate: string);
133
+ /** formatted maximum date of selected date range */
134
+ get maxSelectedDate(): string;
135
+ /** updates maxSelectedDate if new date is valid */
136
+ set maxSelectedDate(rawDate: string);
137
+ /** horizontal position of min date slider */
138
+ get minSliderX(): number;
139
+ /** horizontal position of max date slider */
140
+ get maxSliderX(): number;
141
+ private get dateRangeMS();
142
+ private showTooltip;
143
+ private hideTooltip;
144
+ private drag;
145
+ private drop;
146
+ /**
147
+ * Adjust the date range based on slider movement
148
+ *
149
+ * @param e PointerEvent from the slider being moved
150
+ */
151
+ private move;
152
+ /**
153
+ * Constrain a proposed value for the minimum (left) slider
154
+ *
155
+ * If the value is less than the leftmost valid position, then set it to the
156
+ * left edge of the histogram (ie the slider width). If the value is greater
157
+ * than the rightmost valid position (the position of the max slider), then
158
+ * set it to the position of the max slider
159
+ */
160
+ private validMinSliderX;
161
+ /**
162
+ * Constrain a proposed value for the maximum (right) slider
163
+ *
164
+ * If the value is greater than the rightmost valid position, then set it to
165
+ * the right edge of the histogram (ie histogram width - slider width). If the
166
+ * value is less than the leftmost valid position (the position of the min
167
+ * slider), then set it to the position of the min slider
168
+ */
169
+ private validMaxSliderX;
170
+ private addListeners;
171
+ private removeListeners;
172
+ /**
173
+ * start a timer to emit an update event. this timer can be canceled (and the
174
+ * event not emitted) if user drags a slider or focuses a date input within
175
+ * the update delay
176
+ */
177
+ private beginEmitUpdateProcess;
178
+ /** @returns whether there was a pending update event to cancel */
179
+ private cancelPendingUpdateEvent;
180
+ /**
181
+ * find position of pointer in relation to the current slider
182
+ */
183
+ private setDragOffset;
184
+ /**
185
+ * @param x horizontal position of slider
186
+ * @returns string representation of date
187
+ */
188
+ private translatePositionToDate;
189
+ /**
190
+ * Returns slider x-position corresponding to given date
191
+ *
192
+ * @param date
193
+ * @returns x-position of slider
194
+ */
195
+ private translateDateToPosition;
196
+ /** ensure that the returned value is between minValue and maxValue */
197
+ private clamp;
198
+ private handleInputFocus;
199
+ private handleMinDateInput;
200
+ private handleMaxDateInput;
201
+ private handleKeyUp;
202
+ private get currentDateRangeString();
203
+ private getMSFromString;
204
+ /**
205
+ * expand or narrow the selected range by moving the slider nearest the
206
+ * clicked bar to the outer edge of the clicked bar
207
+ *
208
+ * @param e Event click event from a histogram bar
209
+ */
210
+ private handleBarClick;
211
+ private get minSliderTemplate();
212
+ private get maxSliderTemplate();
213
+ private generateSliderSVG;
214
+ get selectedRangeTemplate(): SVGTemplateResult;
215
+ get histogramTemplate(): SVGTemplateResult[];
216
+ /** Whether the first arg represents a date strictly before the second arg */
217
+ private isBefore;
218
+ /** Whether the first arg represents a date strictly after the second arg */
219
+ private isAfter;
220
+ private formatDate;
221
+ /**
222
+ * NOTE: we are relying on the lit `live` directive in the template to
223
+ * ensure that the change to minSelectedDate is noticed and the input value
224
+ * gets properly re-rendered. see
225
+ * https://lit.dev/docs/templates/directives/#live
226
+ */
227
+ get minInputTemplate(): TemplateResult;
228
+ get maxInputTemplate(): TemplateResult;
229
+ get minLabelTemplate(): TemplateResult;
230
+ get maxLabelTemplate(): TemplateResult;
231
+ get tooltipTemplate(): TemplateResult;
232
+ private get histogramAccessibilityTemplate();
233
+ private get noDataTemplate();
234
+ private get activityIndicatorTemplate();
235
+ static styles: import("lit").CSSResult;
236
+ render(): TemplateResult;
237
+ }
238
+ declare global {
239
+ interface HTMLElementTagNameMap {
240
+ 'ia-histogram-date-range': IAHistogramDateRange;
241
+ }
242
+ }
243
+ //# sourceMappingURL=ia-histogram-date-range.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ia-histogram-date-range.d.ts","sourceRoot":"","sources":["../../../../src/elements/ia-histogram-date-range/ia-histogram-date-range.ts"],"names":[],"mappings":"AAAA,OAAO,uDAAuD,CAAC;AAI/D,OAAO,EAGL,UAAU,EAEV,cAAc,EAEd,iBAAiB,EACjB,cAAc,EACf,MAAM,KAAK,CAAC;AAMb,OAAO,KAAK,EAEV,gBAAgB,EAEhB,mBAAmB,EACpB,MAAM,UAAU,CAAC;AA2DlB,qBACa,oBAAqB,SAAQ,UAAU;IAEtB,KAAK,SAAS;IACd,MAAM,SAAU;IAChB,WAAW,SAAgB;IAC3B,YAAY,SAAiB;IAC7B,aAAa,SAAkB;IAC/B,WAAW,SAA4B;IACvC,UAAU,SAAe;IACzB,kBAAkB,SAAgB;IAClC,OAAO,SAAM;IACb,OAAO,SAAM;IACZ,QAAQ,UAAS;IACnB,IAAI,EAAE,MAAM,EAAE,CAAM;IAC/C,qFAAqF;IACxD,kBAAkB,UAAS;IAExD;;;;;;;;;;OAUG;IACyB,WAAW,EAAE,mBAAmB,CAAU;IAEtE;;;OAGG;IACyB,YAAY,SAAiB;IAEzD;;;;;;;;;;;;;OAaG;IACyB,UAAU,EAAE,gBAAgB,CAAiB;IAGhE,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,eAAe,CAAC,CAAiB;IACzC,OAAO,CAAC,kBAAkB,CAAC,CAAS;IACpC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAS;IAEjB,OAAO,CAAC,QAAQ,CAAkB;IAGrD,OAAO,CAAC,gBAAgB,CAAM;IAC9B,OAAO,CAAC,gBAAgB,CAAM;IAC9B,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,UAAU,CAAK;IACv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