@internetarchive/histogram-date-range 1.4.0-alpha-webdev7756.0 → 1.4.0-alpha-webdev7756.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.
package/demo/index.html CHANGED
@@ -9,7 +9,7 @@
9
9
  <script type="module">
10
10
  import '../dist/src/histogram-date-range.js';
11
11
  let eventCount = 0;
12
- import '../dist/demo/js/lit-histogram-wrapper.js';
12
+ import '../dist/demo/js/app-root.js';
13
13
  // listen to events from the component and display the data received from them
14
14
  document.addEventListener('histogramDateRangeUpdated', e => {
15
15
  document.querySelector('.received-events').innerHTML =
@@ -22,14 +22,7 @@
22
22
  <div class="description">
23
23
  histogram inside a lit element
24
24
  </div>
25
- <lit-histogram-wrapper></lit-histogram-wrapper>
26
-
27
- <div class="description">
28
- bars scaled linearly (not logarithmic)
29
- </div>
30
- <lit-histogram-wrapper
31
- barScaling="linear"
32
- ></lit-histogram-wrapper>
25
+ <app-root></app-root>
33
26
 
34
27
  <div class="description">
35
28
  pre-selected range with 1000ms debounce delay
@@ -79,6 +72,26 @@
79
72
  </histogram-date-range>
80
73
  </div>
81
74
 
75
+ <div class="container">
76
+ <div class="description">
77
+ as above, but with linear scaled bars
78
+ </div>
79
+ <histogram-date-range
80
+ width="175"
81
+ tooltipwidth="120"
82
+ dateFormat="YYYY"
83
+ updateDelay="1000"
84
+ missingDataMessage="..."
85
+ barScaling="linear"
86
+ minSelectedDate="1987"
87
+ maxSelectedDate="2016"
88
+ minDate="1987"
89
+ maxDate="2016"
90
+ bins="[1519,1643,1880,2046,1973,2085,2148,2152,2349,2304,2314,2484,2590,2450,2495,2475,2392,2631,2504,2619,2519,2552,2462,2217,2171,2132,2127,2041,1638,1441]"
91
+ >
92
+ </histogram-date-range>
93
+ </div>
94
+
82
95
  <div class="container">
83
96
  <div class="description">small year range and few bins</div>
84
97
  <histogram-date-range width="175" tooltipwidth="120"
@@ -1,5 +1,5 @@
1
- import { LitElement, html, css, TemplateResult, nothing } from 'lit';
2
- import { customElement, property, state } from 'lit/decorators.js';
1
+ import { LitElement, html, TemplateResult } from 'lit';
2
+ import { customElement, state } from 'lit/decorators.js';
3
3
  import '../../src/histogram-date-range';
4
4
 
5
5
  interface DataSource {
@@ -10,16 +10,12 @@ interface DataSource {
10
10
  bins: number[];
11
11
  }
12
12
 
13
- const IDENTITY_FN = (x: number) => x;
14
-
15
13
  /**
16
14
  * This is mainly to test the histogram-date-range within
17
15
  * a lit-element.
18
16
  */
19
- @customElement('lit-histogram-wrapper')
20
- export class LitHistogramWrapper extends LitElement {
21
- @property({ type: String }) barScaling?: 'linear' | 'logarithmic';
22
-
17
+ @customElement('app-root')
18
+ export class AppRoot extends LitElement {
23
19
  @state() dataSource: DataSource = {
24
20
  minDate: 1955,
25
21
  maxDate: 2000,
@@ -31,7 +27,6 @@ export class LitHistogramWrapper extends LitElement {
31
27
  };
32
28
 
33
29
  render(): TemplateResult {
34
- const scalingFn = this.barScaling === 'linear' ? IDENTITY_FN : nothing;
35
30
  return html`
36
31
  <histogram-date-range
37
32
  .minDate=${this.dataSource?.minDate}
@@ -40,7 +35,6 @@ export class LitHistogramWrapper extends LitElement {
40
35
  .maxSelectedDate=${this.dataSource?.maxSelectedDate}
41
36
  .updateDelay=${1000}
42
37
  .bins=${this.dataSource?.bins}
43
- .barScalingFunction=${scalingFn}
44
38
  ></histogram-date-range>
45
39
 
46
40
  <button @click=${this.randomize}>Randomize</button>
@@ -62,14 +56,4 @@ export class LitHistogramWrapper extends LitElement {
62
56
  bins: bins,
63
57
  };
64
58
  }
65
-
66
- static get styles() {
67
- return css`
68
- :host {
69
- display: flex;
70
- flex-direction: column;
71
- align-items: center;
72
- }
73
- `;
74
- }
75
59
  }
@@ -6,13 +6,12 @@ interface DataSource {
6
6
  minSelectedDate: unknown;
7
7
  maxSelectedDate: unknown;
8
8
  bins: number[];
9
- barScalingFunction?: (input: number) => number;
10
9
  }
11
10
  /**
12
11
  * This is mainly to test the histogram-date-range within
13
12
  * a lit-element.
14
13
  */
15
- export declare class LitHistogramWrapper extends LitElement {
14
+ export declare class AppRoot extends LitElement {
16
15
  dataSource: DataSource;
17
16
  render(): TemplateResult;
18
17
  private randomize;
@@ -1,12 +1,12 @@
1
1
  import { __decorate } from "tslib";
2
- import { LitElement, html, nothing } from 'lit';
2
+ import { LitElement, html } from 'lit';
3
3
  import { customElement, state } from 'lit/decorators.js';
4
4
  import '../../src/histogram-date-range';
5
5
  /**
6
6
  * This is mainly to test the histogram-date-range within
7
7
  * a lit-element.
8
8
  */
9
- let LitHistogramWrapper = class LitHistogramWrapper extends LitElement {
9
+ let AppRoot = class AppRoot extends LitElement {
10
10
  constructor() {
11
11
  super(...arguments);
12
12
  this.dataSource = {
@@ -20,19 +20,18 @@ let LitHistogramWrapper = class LitHistogramWrapper extends LitElement {
20
20
  };
21
21
  }
22
22
  render() {
23
- var _a, _b, _c, _d, _e, _f, _g;
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
- .barScalingFunction=${(_g = (_f = this.dataSource) === null || _f === void 0 ? void 0 : _f.barScalingFunction) !== null && _g !== void 0 ? _g : nothing}
33
- ></histogram-date-range>
34
-
35
- <button @click=${this.randomize}>Randomize</button>
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>
36
35
  `;
37
36
  }
38
37
  randomize() {
@@ -51,9 +50,9 @@ let LitHistogramWrapper = class LitHistogramWrapper extends LitElement {
51
50
  };
52
51
  __decorate([
53
52
  state()
54
- ], LitHistogramWrapper.prototype, "dataSource", void 0);
55
- LitHistogramWrapper = __decorate([
56
- customElement('lit-histogram-wrapper')
57
- ], LitHistogramWrapper);
58
- export { LitHistogramWrapper };
53
+ ], AppRoot.prototype, "dataSource", void 0);
54
+ AppRoot = __decorate([
55
+ customElement('app-root')
56
+ ], AppRoot);
57
+ export { AppRoot };
59
58
  //# sourceMappingURL=app-root.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"app-root.js","sourceRoot":"","sources":["../../../demo/js/app-root.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAkB,OAAO,EAAE,MAAM,KAAK,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,gCAAgC,CAAC;AAWxC;;;GAGG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,UAAU;IAA5C;;QACI,eAAU,GAAe;YAChC,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;YACb,eAAe,EAAE,IAAI;YACrB,eAAe,EAAE,IAAI;YACrB,IAAI,EAAE;gBACJ,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,E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, state } from 'lit/decorators.js';\r\nimport '../../src/histogram-date-range';\r\n\r\ninterface DataSource {\r\n minDate: unknown;\r\n maxDate: unknown;\r\n minSelectedDate: unknown;\r\n maxSelectedDate: unknown;\r\n bins: number[];\r\n barScalingFunction?: (input: number) => number;\r\n}\r\n\r\n/**\r\n * This is mainly to test the histogram-date-range within\r\n * a lit-element.\r\n */\r\n@customElement('lit-histogram-wrapper')\r\nexport class LitHistogramWrapper extends LitElement {\r\n @state() dataSource: DataSource = {\r\n minDate: 1955,\r\n maxDate: 2000,\r\n minSelectedDate: 1955,\r\n maxSelectedDate: 2000,\r\n bins: [\r\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,\r\n ],\r\n };\r\n\r\n render(): TemplateResult {\r\n return html`\r\n <histogram-date-range\r\n .minDate=${this.dataSource?.minDate}\r\n .maxDate=${this.dataSource?.maxDate}\r\n .minSelectedDate=${this.dataSource?.minSelectedDate}\r\n .maxSelectedDate=${this.dataSource?.maxSelectedDate}\r\n .updateDelay=${1000}\r\n .bins=${this.dataSource?.bins}\r\n .barScalingFunction=${this.dataSource?.barScalingFunction ?? nothing}\r\n ></histogram-date-range>\r\n\r\n <button @click=${this.randomize}>Randomize</button>\r\n `;\r\n }\r\n\r\n private randomize() {\r\n const minDate = Math.round(Math.random() * 1000);\r\n const maxDate = minDate + Math.round(Math.random() * 1000);\r\n // generate random bins\r\n const bins = Array.from({ length: 20 }, () =>\r\n Math.floor(Math.random() * minDate)\r\n );\r\n this.dataSource = {\r\n minDate,\r\n maxDate,\r\n minSelectedDate: minDate,\r\n maxSelectedDate: maxDate,\r\n bins: bins,\r\n };\r\n }\r\n}\r\n"]}
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,KA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AM,EAAE,GAAG,OAAO,CAAC,CACpC,CAAC;QACF,IAAI,CAAC,UAAU,GAAG;YAChB,OAAO;YACP,OAAO;YACP,eAAe,EAAE,OAAO;YACxB,eAAe,EAAE,OAAO;YACxB,IAAI,EAAE,IAAI;SACX,CAAC;IACJ,CAAC;CACF,CAAA;AAxCU;IAAR,KAAK,EAAE;2CAQN;AATS,OAAO;IADnB,aAAa,CAAC,UAAU,CAAC;GACb,OAAO,CAyCnB","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"]}
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { HistogramDateRange, BinSnappingInterval, } from './src/histogram-date-range';
1
+ export { HistogramDateRange, BinSnappingInterval, BarScalingPreset, BarScalingFunction, BarScalingOption, } from './src/histogram-date-range';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAEnB,MAAM,4BAA4B,CAAC","sourcesContent":["export {\n HistogramDateRange,\n BinSnappingInterval,\n} from './src/histogram-date-range';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAKnB,MAAM,4BAA4B,CAAC","sourcesContent":["export {\n HistogramDateRange,\n BinSnappingInterval,\n BarScalingPreset,\n BarScalingFunction,\n BarScalingOption,\n} from './src/histogram-date-range';\n"]}
@@ -1,6 +1,9 @@
1
1
  import '@internetarchive/ia-activity-indicator';
2
2
  import { LitElement, PropertyValues, SVGTemplateResult, TemplateResult } from 'lit';
3
3
  export type BinSnappingInterval = 'none' | 'month' | 'year';
4
+ export type BarScalingPreset = 'linear' | 'logarithmic';
5
+ export type BarScalingFunction = (binValue: number) => number;
6
+ export type BarScalingOption = BarScalingPreset | BarScalingFunction;
4
7
  export declare class HistogramDateRange extends LitElement {
5
8
  width: number;
6
9
  height: number;
@@ -34,18 +37,20 @@ export declare class HistogramDateRange extends LitElement {
34
37
  */
35
38
  tooltipLabel: string;
36
39
  /**
37
- * A function mapping bin values to a new value that determines how tall each bar will
38
- * be in relation to the others.
40
+ * A function or preset value indicating how the height of each bar relates to its
41
+ * corresponding bin value. Current presets available are 'logarithmic' and 'linear',
42
+ * but a custom function may be provided instead if other behavior is desired.
39
43
  *
40
- * Default sizing function is the logarithm of the bin value, yielding more prominent
41
- * bars for smaller values, at the cost of bars not being directly proportional to their
42
- * values and having relatively smooth variation among values of a similar magnitude.
43
- * This ensures that when the difference between the min and max values is large, small
44
- * values are not as liable to completely disappear visually.
44
+ * The default scaling (`'logarithmic'`) uses the logarithm of each bin value, yielding
45
+ * more prominent bars for smaller values. This ensures that even when the difference
46
+ * between the min & max values is large, small values are unlikely to completely disappear
47
+ * visually. However, the cost is that bars have less noticeable variation among values of
48
+ * a similar magnitude, and their heights are not a direct representation of the bin values.
45
49
  *
46
- * For linearly-scaled bars, set this to the identity function.
50
+ * The `'linear'` preset option instead sizes the bars in linear proportion to their bin
51
+ * values.
47
52
  */
48
- barScalingFunction: (binValue: number) => number;
53
+ barScaling: BarScalingOption;
49
54
  private _tooltipOffsetX;
50
55
  private _tooltipOffsetY;
51
56
  private _tooltipContent?;
@@ -95,6 +100,10 @@ export declare class HistogramDateRange extends LitElement {
95
100
  * Default is simply to snap to the nearest full second.
96
101
  */
97
102
  private snapTimestamp;
103
+ /**
104
+ * Function to scale bin values, whether from a preset or a provided custom function.
105
+ */
106
+ private get barScalingFunction();
98
107
  private calculateHistData;
99
108
  private get hasBinData();
100
109
  private get _numBins();
@@ -20,10 +20,15 @@ const DATE_FORMAT = 'YYYY';
20
20
  const MISSING_DATA = 'no data';
21
21
  const UPDATE_DEBOUNCE_DELAY_MS = 0;
22
22
  const TOOLTIP_LABEL = 'item';
23
- // this function may be overridden only via Lit property expression or direct assignment
24
- const LOG_BAR_SCALING_FN = (binValue) => Math.log1p(binValue);
25
23
  // this constant is not set up to be overridden
26
24
  const SLIDER_CORNER_SIZE = 4;
25
+ /**
26
+ * Map from bar scaling preset options to the corresponding function they represent
27
+ */
28
+ const BAR_SCALING_PRESET_FNS = {
29
+ linear: (binValue) => binValue,
30
+ logarithmic: (binValue) => Math.log1p(binValue),
31
+ };
27
32
  // these CSS custom props can be overridden from the HTML that is invoking this component
28
33
  const sliderColor = css `var(--histogramDateRangeSliderColor, #4B65FE)`;
29
34
  const selectedRangeColor = css `var(--histogramDateRangeSelectedRangeColor, #DBE0FF)`;
@@ -76,18 +81,20 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
76
81
  */
77
82
  this.tooltipLabel = TOOLTIP_LABEL;
78
83
  /**
79
- * A function mapping bin values to a new value that determines how tall each bar will
80
- * be in relation to the others.
84
+ * A function or preset value indicating how the height of each bar relates to its
85
+ * corresponding bin value. Current presets available are 'logarithmic' and 'linear',
86
+ * but a custom function may be provided instead if other behavior is desired.
81
87
  *
82
- * Default sizing function is the logarithm of the bin value, yielding more prominent
83
- * bars for smaller values, at the cost of bars not being directly proportional to their
84
- * values and having relatively smooth variation among values of a similar magnitude.
85
- * This ensures that when the difference between the min and max values is large, small
86
- * values are not as liable to completely disappear visually.
88
+ * The default scaling (`'logarithmic'`) uses the logarithm of each bin value, yielding
89
+ * more prominent bars for smaller values. This ensures that even when the difference
90
+ * between the min & max values is large, small values are unlikely to completely disappear
91
+ * visually. However, the cost is that bars have less noticeable variation among values of
92
+ * a similar magnitude, and their heights are not a direct representation of the bin values.
87
93
  *
88
- * For linearly-scaled bars, set this to the identity function.
94
+ * The `'linear'` preset option instead sizes the bars in linear proportion to their bin
95
+ * values.
89
96
  */
90
- this.barScalingFunction = LOG_BAR_SCALING_FN;
97
+ this.barScaling = 'logarithmic';
91
98
  // internal reactive properties not exposed as attributes
92
99
  this._tooltipOffsetX = 0;
93
100
  this._tooltipOffsetY = 0;
@@ -159,7 +166,8 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
159
166
  changedProps.has('maxSelectedDate') ||
160
167
  changedProps.has('width') ||
161
168
  changedProps.has('height') ||
162
- changedProps.has('binSnapping')) {
169
+ changedProps.has('binSnapping') ||
170
+ changedProps.has('barScaling')) {
163
171
  this.handleDataUpdate();
164
172
  }
165
173
  }
@@ -247,6 +255,15 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
247
255
  return this.snapToNextSecond(timestamp);
248
256
  }
249
257
  }
258
+ /**
259
+ * Function to scale bin values, whether from a preset or a provided custom function.
260
+ */
261
+ get barScalingFunction() {
262
+ if (typeof this.barScaling === 'string') {
263
+ return BAR_SCALING_PRESET_FNS[this.barScaling];
264
+ }
265
+ return this.barScaling;
266
+ }
250
267
  calculateHistData() {
251
268
  const { bins, height, dateRangeMS, _numBins, _minDateMS } = this;
252
269
  const minValue = Math.min(...this.bins);
@@ -270,8 +287,7 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
270
287
  : `${tooltipStart} - ${tooltipEnd}`;
271
288
  return {
272
289
  value: v,
273
- // use log scaling for the height of the bar to prevent tall bars from
274
- // making the smaller ones too small to see
290
+ // apply the configured scaling function to the bin value before determining bar height
275
291
  height: Math.floor(this.barScalingFunction(v) * valueScale),
276
292
  binStart,
277
293
  binEnd,
@@ -1023,8 +1039,8 @@ __decorate([
1023
1039
  property({ type: String })
1024
1040
  ], HistogramDateRange.prototype, "tooltipLabel", void 0);
1025
1041
  __decorate([
1026
- property({ attribute: false })
1027
- ], HistogramDateRange.prototype, "barScalingFunction", void 0);
1042
+ property({ type: String })
1043
+ ], HistogramDateRange.prototype, "barScaling", void 0);
1028
1044
  __decorate([
1029
1045
  state()
1030
1046
  ], HistogramDateRange.prototype, "_tooltipOffsetX", void 0);