@internetarchive/histogram-date-range 0.1.6-alpha1 → 0.1.7

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,26 @@
1
+ name: App CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - uses: actions/setup-node@v3
16
+ with:
17
+ node-version: 16.x
18
+
19
+ - name: Install dependencies
20
+ run: yarn install
21
+
22
+ - name: Run tests
23
+ run: yarn run test
24
+
25
+ - name: Upload reports
26
+ run: npx codecov
@@ -0,0 +1,19 @@
1
+ import { LitElement, TemplateResult } from 'lit';
2
+ import '../../src/histogram-date-range';
3
+ interface DataSource {
4
+ minDate: unknown;
5
+ maxDate: unknown;
6
+ minSelectedDate: unknown;
7
+ maxSelectedDate: unknown;
8
+ bins: number[];
9
+ }
10
+ /**
11
+ * This is mainly to test the histogram-date-range within
12
+ * a lit-element.
13
+ */
14
+ export declare class AppRoot extends LitElement {
15
+ dataSource: DataSource;
16
+ render(): TemplateResult;
17
+ private randomize;
18
+ }
19
+ export {};
@@ -0,0 +1,58 @@
1
+ import { __decorate } from "tslib";
2
+ import { LitElement, html } from 'lit';
3
+ import { customElement, state } from 'lit/decorators.js';
4
+ import '../../src/histogram-date-range';
5
+ /**
6
+ * This is mainly to test the histogram-date-range within
7
+ * a lit-element.
8
+ */
9
+ let AppRoot = class AppRoot extends LitElement {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.dataSource = {
13
+ minDate: 1955,
14
+ maxDate: 2000,
15
+ minSelectedDate: 1955,
16
+ maxSelectedDate: 2000,
17
+ bins: [
18
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
19
+ ],
20
+ };
21
+ }
22
+ render() {
23
+ var _a, _b, _c, _d, _e;
24
+ return html `
25
+ <histogram-date-range
26
+ .minDate=${(_a = this.dataSource) === null || _a === void 0 ? void 0 : _a.minDate}
27
+ .maxDate=${(_b = this.dataSource) === null || _b === void 0 ? void 0 : _b.maxDate}
28
+ .minSelectedDate=${(_c = this.dataSource) === null || _c === void 0 ? void 0 : _c.minSelectedDate}
29
+ .maxSelectedDate=${(_d = this.dataSource) === null || _d === void 0 ? void 0 : _d.maxSelectedDate}
30
+ .updateDelay=${1000}
31
+ .bins=${(_e = this.dataSource) === null || _e === void 0 ? void 0 : _e.bins}
32
+ ></histogram-date-range>
33
+
34
+ <button @click=${this.randomize}>Randomize</button>
35
+ `;
36
+ }
37
+ randomize() {
38
+ const minDate = Math.round(Math.random() * 1000);
39
+ const maxDate = minDate + Math.round(Math.random() * 1000);
40
+ // generate random bins
41
+ const bins = Array.from({ length: 20 }, () => Math.floor(Math.random() * minDate));
42
+ this.dataSource = {
43
+ minDate,
44
+ maxDate,
45
+ minSelectedDate: minDate,
46
+ maxSelectedDate: maxDate,
47
+ bins: bins,
48
+ };
49
+ }
50
+ };
51
+ __decorate([
52
+ state()
53
+ ], AppRoot.prototype, "dataSource", void 0);
54
+ AppRoot = __decorate([
55
+ customElement('app-root')
56
+ ], AppRoot);
57
+ export { AppRoot };
58
+ //# sourceMappingURL=app-root.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-root.js","sourceRoot":"","sources":["../../../demo/js/app-root.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,gCAAgC,CAAC;AAUxC;;;GAGG;AAEH,IAAa,OAAO,GAApB,MAAa,OAAQ,SAAQ,UAAU;IAAvC;;QACW,eAAU,GAAe;YAChC,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;YACb,eAAe,EAAE,IAAI;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AE;2CAQN;AATS,OAAO;IADnB,aAAa,CAAC,UAAU,CAAC;GACb,OAAO,CAyCnB;SAzCY,OAAO","sourcesContent":["import { LitElement, html, TemplateResult } from 'lit';\nimport { customElement, state } from 'lit/decorators.js';\nimport '../../src/histogram-date-range';\n\ninterface DataSource {\n minDate: unknown;\n maxDate: unknown;\n minSelectedDate: unknown;\n maxSelectedDate: unknown;\n bins: number[];\n}\n\n/**\n * This is mainly to test the histogram-date-range within\n * a lit-element.\n */\n@customElement('app-root')\nexport class AppRoot extends LitElement {\n @state() dataSource: DataSource = {\n minDate: 1955,\n maxDate: 2000,\n minSelectedDate: 1955,\n maxSelectedDate: 2000,\n bins: [\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,\n ],\n };\n\n render(): TemplateResult {\n return html`\n <histogram-date-range\n .minDate=${this.dataSource?.minDate}\n .maxDate=${this.dataSource?.maxDate}\n .minSelectedDate=${this.dataSource?.minSelectedDate}\n .maxSelectedDate=${this.dataSource?.maxSelectedDate}\n .updateDelay=${1000}\n .bins=${this.dataSource?.bins}\n ></histogram-date-range>\n\n <button @click=${this.randomize}>Randomize</button>\n `;\n }\n\n private randomize() {\n const minDate = Math.round(Math.random() * 1000);\n const maxDate = minDate + Math.round(Math.random() * 1000);\n // generate random bins\n const bins = Array.from({ length: 20 }, () =>\n Math.floor(Math.random() * minDate)\n );\n this.dataSource = {\n minDate,\n maxDate,\n minSelectedDate: minDate,\n maxSelectedDate: maxDate,\n bins: bins,\n };\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export { HistogramDateRange } from './src/histogram-date-range';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { HistogramDateRange } from './src/histogram-date-range';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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';\n"]}
@@ -0,0 +1,154 @@
1
+ import { LitElement, PropertyValues, SVGTemplateResult, TemplateResult } from 'lit';
2
+ import '@internetarchive/ia-activity-indicator/ia-activity-indicator';
3
+ export declare class HistogramDateRange extends LitElement {
4
+ width: number;
5
+ height: number;
6
+ sliderWidth: number;
7
+ tooltipWidth: number;
8
+ tooltipHeight: number;
9
+ updateDelay: number;
10
+ dateFormat: string;
11
+ missingDataMessage: string;
12
+ minDate: string;
13
+ maxDate: string;
14
+ disabled: boolean;
15
+ bins: number[];
16
+ private _tooltipOffset;
17
+ private _tooltipContent?;
18
+ private _tooltipVisible;
19
+ private _isDragging;
20
+ private _isLoading;
21
+ private _minSelectedDate;
22
+ private _maxSelectedDate;
23
+ private _minDateMS;
24
+ private _maxDateMS;
25
+ private _dragOffset;
26
+ private _histWidth;
27
+ private _binWidth;
28
+ private _currentSlider?;
29
+ private _histData;
30
+ private _emitUpdatedEventTimer?;
31
+ private _previousDateRange;
32
+ disconnectedCallback(): void;
33
+ updated(changedProps: PropertyValues): void;
34
+ /**
35
+ * Set private properties that depend on the attribute bin data
36
+ *
37
+ * We're caching these values and not using getters to avoid recalculating all
38
+ * of the hist data every time the user drags a slider or hovers over a bar
39
+ * creating a tooltip.
40
+ */
41
+ private handleDataUpdate;
42
+ private calculateHistData;
43
+ private get hasBinData();
44
+ private get _numBins();
45
+ private get histogramLeftEdgeX();
46
+ private get histogramRightEdgeX();
47
+ /** component's loading (and disabled) state */
48
+ get loading(): boolean;
49
+ set loading(value: boolean);
50
+ /** formatted minimum date of selected date range */
51
+ get minSelectedDate(): string;
52
+ /** updates minSelectedDate if new date is valid */
53
+ set minSelectedDate(rawDate: string);
54
+ /** formatted maximum date of selected date range */
55
+ get maxSelectedDate(): string;
56
+ /** updates maxSelectedDate if new date is valid */
57
+ set maxSelectedDate(rawDate: string);
58
+ /** horizontal position of min date slider */
59
+ get minSliderX(): number;
60
+ /** horizontal position of max date slider */
61
+ get maxSliderX(): number;
62
+ private get dateRangeMS();
63
+ private showTooltip;
64
+ private hideTooltip;
65
+ private drag;
66
+ private drop;
67
+ /**
68
+ * Adjust the date range based on slider movement
69
+ *
70
+ * @param e PointerEvent from the slider being moved
71
+ */
72
+ private move;
73
+ /**
74
+ * Constrain a proposed value for the minimum (left) slider
75
+ *
76
+ * If the value is less than the leftmost valid position, then set it to the
77
+ * left edge of the histogram (ie the slider width). If the value is greater
78
+ * than the rightmost valid position (the position of the max slider), then
79
+ * set it to the position of the max slider
80
+ */
81
+ private validMinSliderX;
82
+ /**
83
+ * Constrain a proposed value for the maximum (right) slider
84
+ *
85
+ * If the value is greater than the rightmost valid position, then set it to
86
+ * the right edge of the histogram (ie histogram width - slider width). If the
87
+ * value is less than the leftmost valid position (the position of the min
88
+ * slider), then set it to the position of the min slider
89
+ */
90
+ private validMaxSliderX;
91
+ private addListeners;
92
+ private removeListeners;
93
+ /**
94
+ * start a timer to emit an update event. this timer can be canceled (and the
95
+ * event not emitted) if user drags a slider or focuses a date input within
96
+ * the update delay
97
+ */
98
+ private beginEmitUpdateProcess;
99
+ private cancelPendingUpdateEvent;
100
+ /**
101
+ * find position of pointer in relation to the current slider
102
+ */
103
+ private setDragOffset;
104
+ /**
105
+ * @param x horizontal position of slider
106
+ * @returns string representation of date
107
+ */
108
+ private translatePositionToDate;
109
+ /**
110
+ * Returns slider x-position corresponding to given date
111
+ *
112
+ * @param date
113
+ * @returns x-position of slider
114
+ */
115
+ private translateDateToPosition;
116
+ /** ensure that the returned value is between minValue and maxValue */
117
+ private clamp;
118
+ private handleMinDateInput;
119
+ private handleMaxDateInput;
120
+ private handleKeyUp;
121
+ private get currentDateRangeString();
122
+ private getMSFromString;
123
+ /**
124
+ * expand or narrow the selected range by moving the slider nearest the
125
+ * clicked bar to the outer edge of the clicked bar
126
+ *
127
+ * @param e Event click event from a histogram bar
128
+ */
129
+ private handleBarClick;
130
+ private get minSliderTemplate();
131
+ private get maxSliderTemplate();
132
+ private generateSliderSVG;
133
+ get selectedRangeTemplate(): SVGTemplateResult;
134
+ get histogramTemplate(): SVGTemplateResult[];
135
+ private formatDate;
136
+ /**
137
+ * NOTE: we are relying on the lit `live` directive in the template to
138
+ * ensure that the change to minSelectedDate is noticed and the input value
139
+ * gets properly re-rendered. see
140
+ * https://lit.dev/docs/templates/directives/#live
141
+ */
142
+ get minInputTemplate(): TemplateResult;
143
+ get maxInputTemplate(): TemplateResult;
144
+ get tooltipTemplate(): TemplateResult;
145
+ private get noDataTemplate();
146
+ private get activityIndicatorTemplate();
147
+ static styles: import("lit").CSSResult;
148
+ render(): TemplateResult;
149
+ }
150
+ declare global {
151
+ interface HTMLElementTagNameMap {
152
+ 'histogram-date-range': HistogramDateRange;
153
+ }
154
+ }