Skip to content

Commit 39349b1

Browse files
authored
WEBDEV-7756 Linear scaling & updated labels for TV date histograms (#490)
* Upgrade to alpha date picker * Add props to expanded-date-picker * Select correct scaling fn and tooltip label based on context * Upgrade alpha version * Rename some props of the expanded date picker * Simplify & clean up histogram prop logic * Upgrade off alpha date picker * Fix template typo
1 parent a93fe62 commit 39349b1

File tree

5 files changed

+71
-31
lines changed

5 files changed

+71
-31
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@internetarchive/analytics-manager": "^0.1.4",
2727
"@internetarchive/feature-feedback": "^1.0.0",
2828
"@internetarchive/field-parsers": "^1.0.0",
29-
"@internetarchive/histogram-date-range": "^1.3.2",
29+
"@internetarchive/histogram-date-range": "^1.4.0",
3030
"@internetarchive/ia-activity-indicator": "^0.0.6",
3131
"@internetarchive/ia-dropdown": "^1.3.10",
3232
"@internetarchive/iaux-item-metadata": "^1.0.5",

src/collection-browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ export class CollectionBrowser
12521252
<h2>${msg('Filters')}</h2>
12531253
</summary>
12541254
${facets}
1255-
</button>
1255+
</details>
12561256
`;
12571257
}
12581258
// Otherwise, just render the facets component bare

src/collection-facets.ts

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ import type { FeatureFeedbackServiceInterface } from '@internetarchive/feature-f
2929
import type { RecaptchaManagerInterface } from '@internetarchive/recaptcha-manager';
3030
import type { AnalyticsManagerInterface } from '@internetarchive/analytics-manager';
3131
import type { SharedResizeObserverInterface } from '@internetarchive/shared-resize-observer';
32-
import type { BinSnappingInterval } from '@internetarchive/histogram-date-range';
32+
import type {
33+
BarScalingOption,
34+
BinSnappingInterval,
35+
} from '@internetarchive/histogram-date-range';
3336
import chevronIcon from './assets/img/icons/chevron';
3437
import expandIcon from './assets/img/icons/expand';
3538
import {
@@ -258,23 +261,36 @@ export class CollectionFacets extends LitElement {
258261

259262
const zeroPadMonth = (month: number) => month.toString().padStart(2, '0');
260263

261-
// Format the min/max dates appropriately
262-
const minDate = this.isTvSearch
263-
? `${firstYear}-${zeroPadMonth(firstMonth)}`
264-
: `${firstYear}`;
265-
266-
const maxDate = this.isTvSearch
267-
? `${lastYear}-${zeroPadMonth(lastMonth + monthInterval - 1)}`
268-
: `${lastYear + yearInterval - 1}`;
264+
// The date picker is configured differently for TV search, allowing month-level resolution
265+
if (this.isTvSearch) {
266+
// Whether the bucket interval is less than a year
267+
// (i.e., requires individual months to be handled & labeled)
268+
const mustHandleMonths = monthInterval < 12;
269+
270+
return {
271+
buckets: aggregation.buckets as number[],
272+
dateFormat: 'YYYY-MM',
273+
tooltipDateFormat: mustHandleMonths ? 'MMM YYYY' : 'YYYY',
274+
tooltipLabel: 'broadcast',
275+
binSnapping: (mustHandleMonths
276+
? 'month'
277+
: 'year') as BinSnappingInterval,
278+
barScaling: 'linear' as BarScalingOption,
279+
minDate: `${firstYear}-${zeroPadMonth(firstMonth)}`,
280+
maxDate: `${lastYear}-${zeroPadMonth(lastMonth + monthInterval - 1)}`,
281+
};
282+
}
269283

270-
const hasMonths = this.isTvSearch && monthInterval < 12;
284+
// All other search types use the same configuration
271285
return {
272286
buckets: aggregation.buckets as number[],
273-
dateFormat: this.isTvSearch ? 'YYYY-MM' : 'YYYY',
274-
tooltipDateFormat: hasMonths ? 'MMM YYYY' : 'YYYY',
275-
binSnapping: (hasMonths ? 'month' : 'year') as BinSnappingInterval,
276-
minDate,
277-
maxDate,
287+
dateFormat: 'YYYY',
288+
tooltipDateFormat: 'YYYY',
289+
tooltipLabel: 'item',
290+
binSnapping: 'year' as BinSnappingInterval,
291+
barScaling: 'logarithmic' as BarScalingOption,
292+
minDate: `${firstYear}`,
293+
maxDate: `${lastYear + yearInterval - 1}`,
278294
};
279295
}
280296

@@ -289,7 +305,9 @@ export class CollectionFacets extends LitElement {
289305
buckets,
290306
dateFormat,
291307
tooltipDateFormat,
308+
tooltipLabel,
292309
binSnapping,
310+
barScaling,
293311
minDate,
294312
maxDate,
295313
} = histogramProps;
@@ -317,9 +335,11 @@ export class CollectionFacets extends LitElement {
317335
.maxDate=${maxDate}
318336
.minSelectedDate=${this.minSelectedDate}
319337
.maxSelectedDate=${this.maxSelectedDate}
320-
.dateFormat=${dateFormat}
321-
.tooltipDateFormat=${tooltipDateFormat}
338+
.customDateFormat=${dateFormat}
339+
.customTooltipDateFormat=${tooltipDateFormat}
340+
.customTooltipLabel=${tooltipLabel}
322341
.binSnapping=${binSnapping}
342+
.barScaling=${barScaling}
323343
.buckets=${buckets}
324344
.modalManager=${this.modalManager}
325345
.analyticsHandler=${this.analyticsHandler}
@@ -396,7 +416,9 @@ export class CollectionFacets extends LitElement {
396416
buckets,
397417
dateFormat,
398418
tooltipDateFormat,
419+
tooltipLabel,
399420
binSnapping,
421+
barScaling,
400422
minDate,
401423
maxDate,
402424
} = histogramProps;
@@ -411,7 +433,9 @@ export class CollectionFacets extends LitElement {
411433
.updateDelay=${100}
412434
.dateFormat=${dateFormat}
413435
.tooltipDateFormat=${tooltipDateFormat}
436+
.tooltipLabel=${tooltipLabel}
414437
.binSnapping=${binSnapping}
438+
.barScaling=${barScaling}
415439
.bins=${buckets}
416440
missingDataMessage="..."
417441
.width=${this.collapsableFacets && this.contentWidth

src/expanded-date-picker.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
import { css, html, LitElement, CSSResultGroup, TemplateResult } from 'lit';
1+
import {
2+
css,
3+
html,
4+
LitElement,
5+
CSSResultGroup,
6+
TemplateResult,
7+
nothing,
8+
} from 'lit';
29
import { customElement, property } from 'lit/decorators.js';
310
import { ifDefined } from 'lit/directives/if-defined.js';
411
import { msg } from '@lit/localize';
512
import type { ModalManagerInterface } from '@internetarchive/modal-manager';
613
import type { AnalyticsManagerInterface } from '@internetarchive/analytics-manager';
7-
import { BinSnappingInterval } from '@internetarchive/histogram-date-range';
14+
import {
15+
BarScalingOption,
16+
BinSnappingInterval,
17+
} from '@internetarchive/histogram-date-range';
818
import {
919
analyticsActions,
1020
analyticsCategories,
@@ -24,11 +34,15 @@ export class ExpandedDatePicker extends LitElement {
2434

2535
@property({ type: Array }) buckets?: number[];
2636

27-
@property({ type: String }) dateFormat: string = 'YYYY';
37+
@property({ type: String }) customDateFormat?: string;
38+
39+
@property({ type: String }) customTooltipDateFormat?: string;
40+
41+
@property({ type: String }) customTooltipLabel?: string;
2842

29-
@property({ type: String }) tooltipDateFormat?: string;
43+
@property({ type: String }) binSnapping: BinSnappingInterval = 'none';
3044

31-
@property({ type: String }) binSnapping?: BinSnappingInterval;
45+
@property({ type: String }) barScaling: BarScalingOption = 'logarithmic';
3246

3347
@property({ type: Object, attribute: false })
3448
modalManager?: ModalManagerInterface;
@@ -45,9 +59,11 @@ export class ExpandedDatePicker extends LitElement {
4559
.maxDate=${this.maxDate}
4660
.minSelectedDate=${this.minSelectedDate ?? this.minDate}
4761
.maxSelectedDate=${this.maxSelectedDate ?? this.maxDate}
48-
.dateFormat=${this.dateFormat}
49-
tooltipDateFormat=${ifDefined(this.tooltipDateFormat)}
50-
binSnapping=${ifDefined(this.binSnapping)}
62+
dateFormat=${ifDefined(this.customDateFormat)}
63+
tooltipDateFormat=${ifDefined(this.customTooltipDateFormat)}
64+
tooltipLabel=${ifDefined(this.customTooltipLabel)}
65+
.binSnapping=${this.binSnapping}
66+
.barScaling=${this.barScaling ?? nothing}
5167
.updateDelay=${0}
5268
updateWhileFocused
5369
missingDataMessage="..."

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,10 @@
318318
resolved "https://registry.npmjs.org/@internetarchive/field-parsers/-/field-parsers-1.0.0.tgz"
319319
integrity sha512-cbD0FtJOjzBm7exxFrzrkHnqbmalKbEXA4i7KrwhUGBojF/QTTLAvaIRXH/bfoiTyCh6YT1/E/mULAQPdB6yvQ==
320320

321-
"@internetarchive/histogram-date-range@^1.3.2":
322-
version "1.3.2"
323-
resolved "https://registry.npmjs.org/@internetarchive/histogram-date-range/-/histogram-date-range-1.3.2.tgz"
324-
integrity sha512-bsKBB+A1ldTtE3cdgQBoMLKBOP4gqyfWPfw6M0ezXY9r+camFdwXoTmOvABSug68USTE4fB9TFNF8KRm5JosmQ==
321+
"@internetarchive/histogram-date-range@^1.4.0":
322+
version "1.4.0"
323+
resolved "https://registry.yarnpkg.com/@internetarchive/histogram-date-range/-/histogram-date-range-1.4.0.tgz#3e1a97094a988acdedad3999632a919833d935fd"
324+
integrity sha512-pE7QuMHaueKjy9FXicFdBq8sjhyWgWNPfsPb5wM1qyyoeqgDRnZnlld3/yXTd8VaKM5IoZG9X8nhiPPbN6YBUA==
325325
dependencies:
326326
"@internetarchive/ia-activity-indicator" "^0.0.6"
327327
dayjs "^1.11.13"

0 commit comments

Comments
 (0)