@internetarchive/histogram-date-range 1.3.2-alpha-webdev7713.0 → 1.4.0-alpha-webdev7756.0

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.
Files changed (31) hide show
  1. package/demo/index.html +9 -2
  2. package/demo/js/{app-root.ts → lit-histogram-wrapper.ts} +20 -4
  3. package/dist/demo/js/app-root.d.ts +2 -1
  4. package/dist/demo/js/app-root.js +20 -19
  5. package/dist/demo/js/app-root.js.map +1 -1
  6. package/dist/demo/js/list-histogram-wrapper.d.ts +20 -0
  7. package/dist/demo/js/list-histogram-wrapper.js +59 -0
  8. package/dist/demo/js/list-histogram-wrapper.js.map +1 -0
  9. package/dist/demo/js/lit-histogram-wrapper.d.ts +21 -0
  10. package/dist/demo/js/lit-histogram-wrapper.js +73 -0
  11. package/dist/demo/js/lit-histogram-wrapper.js.map +1 -0
  12. package/dist/src/histogram-date-range.d.ts +18 -0
  13. package/dist/src/histogram-date-range.js +51 -11
  14. package/dist/src/histogram-date-range.js.map +1 -1
  15. package/dist/test/histogram-date-range.test.js +47 -23
  16. package/dist/test/histogram-date-range.test.js.map +1 -1
  17. package/docs/demo/index.html +9 -2
  18. package/docs/dist/demo/js/{app-root.js → lit-histogram-wrapper.js} +22 -7
  19. package/docs/dist/src/histogram-date-range.js +34 -11
  20. package/package.json +1 -1
  21. package/src/histogram-date-range.ts +53 -11
  22. package/test/histogram-date-range.test.ts +54 -23
  23. package/dist/src/dayjs/fix-first-century-years.d.ts +0 -2
  24. package/dist/src/dayjs/fix-first-century-years.js +0 -25
  25. package/dist/src/dayjs/fix-first-century-years.js.map +0 -1
  26. package/dist/src/dayjs/fix-two-digit-dates.d.ts +0 -2
  27. package/dist/src/dayjs/fix-two-digit-dates.js +0 -25
  28. package/dist/src/dayjs/fix-two-digit-dates.js.map +0 -1
  29. package/dist/src/histogram-date-range copy.d.ts +0 -214
  30. package/dist/src/histogram-date-range copy.js +0 -1018
  31. package/dist/src/histogram-date-range copy.js.map +0 -1
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/app-root.js';
12
+ import '../dist/demo/js/lit-histogram-wrapper.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,7 +22,14 @@
22
22
  <div class="description">
23
23
  histogram inside a lit element
24
24
  </div>
25
- <app-root></app-root>
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>
26
33
 
27
34
  <div class="description">
28
35
  pre-selected range with 1000ms debounce delay
@@ -1,5 +1,5 @@
1
- import { LitElement, html, TemplateResult } from 'lit';
2
- import { customElement, state } from 'lit/decorators.js';
1
+ import { LitElement, html, css, TemplateResult, nothing } from 'lit';
2
+ import { customElement, property, state } from 'lit/decorators.js';
3
3
  import '../../src/histogram-date-range';
4
4
 
5
5
  interface DataSource {
@@ -10,12 +10,16 @@ interface DataSource {
10
10
  bins: number[];
11
11
  }
12
12
 
13
+ const IDENTITY_FN = (x: number) => x;
14
+
13
15
  /**
14
16
  * This is mainly to test the histogram-date-range within
15
17
  * a lit-element.
16
18
  */
17
- @customElement('app-root')
18
- export class AppRoot extends LitElement {
19
+ @customElement('lit-histogram-wrapper')
20
+ export class LitHistogramWrapper extends LitElement {
21
+ @property({ type: String }) barScaling?: 'linear' | 'logarithmic';
22
+
19
23
  @state() dataSource: DataSource = {
20
24
  minDate: 1955,
21
25
  maxDate: 2000,
@@ -27,6 +31,7 @@ export class AppRoot extends LitElement {
27
31
  };
28
32
 
29
33
  render(): TemplateResult {
34
+ const scalingFn = this.barScaling === 'linear' ? IDENTITY_FN : nothing;
30
35
  return html`
31
36
  <histogram-date-range
32
37
  .minDate=${this.dataSource?.minDate}
@@ -35,6 +40,7 @@ export class AppRoot extends LitElement {
35
40
  .maxSelectedDate=${this.dataSource?.maxSelectedDate}
36
41
  .updateDelay=${1000}
37
42
  .bins=${this.dataSource?.bins}
43
+ .barScalingFunction=${scalingFn}
38
44
  ></histogram-date-range>
39
45
 
40
46
  <button @click=${this.randomize}>Randomize</button>
@@ -56,4 +62,14 @@ export class AppRoot extends LitElement {
56
62
  bins: bins,
57
63
  };
58
64
  }
65
+
66
+ static get styles() {
67
+ return css`
68
+ :host {
69
+ display: flex;
70
+ flex-direction: column;
71
+ align-items: center;
72
+ }
73
+ `;
74
+ }
59
75
  }
@@ -6,12 +6,13 @@ interface DataSource {
6
6
  minSelectedDate: unknown;
7
7
  maxSelectedDate: unknown;
8
8
  bins: number[];
9
+ barScalingFunction?: (input: number) => number;
9
10
  }
10
11
  /**
11
12
  * This is mainly to test the histogram-date-range within
12
13
  * a lit-element.
13
14
  */
14
- export declare class AppRoot extends LitElement {
15
+ export declare class LitHistogramWrapper extends LitElement {
15
16
  dataSource: DataSource;
16
17
  render(): TemplateResult;
17
18
  private randomize;
@@ -1,12 +1,12 @@
1
1
  import { __decorate } from "tslib";
2
- import { LitElement, html } from 'lit';
2
+ import { LitElement, html, nothing } 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 AppRoot = class AppRoot extends LitElement {
9
+ let LitHistogramWrapper = class LitHistogramWrapper extends LitElement {
10
10
  constructor() {
11
11
  super(...arguments);
12
12
  this.dataSource = {
@@ -20,18 +20,19 @@ let AppRoot = class AppRoot extends LitElement {
20
20
  };
21
21
  }
22
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>
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>
35
36
  `;
36
37
  }
37
38
  randomize() {
@@ -50,9 +51,9 @@ let AppRoot = class AppRoot extends LitElement {
50
51
  };
51
52
  __decorate([
52
53
  state()
53
- ], AppRoot.prototype, "dataSource", void 0);
54
- AppRoot = __decorate([
55
- customElement('app-root')
56
- ], AppRoot);
57
- export { AppRoot };
54
+ ], LitHistogramWrapper.prototype, "dataSource", void 0);
55
+ LitHistogramWrapper = __decorate([
56
+ customElement('lit-histogram-wrapper')
57
+ ], LitHistogramWrapper);
58
+ export { LitHistogramWrapper };
58
59
  //# sourceMappingURL=app-root.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"app-root.js","sourceRoot":"","sources":["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I,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,CAC3C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,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"]}
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,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;aACtE;SACF,CAAC;IAiCJ,CAAC;IA/BC,MAAM;;QACJ,OAAO,IAAI,CAAA;;mBAEI,MAAA,IAAI,CAAC,UAAU,0CAAE,OAAO;mBACxB,MAAA,IAAI,CAAC,UAAU,0CAAE,OAAO;2BAChB,MAAA,IAAI,CAAC,UAAU,0CAAE,eAAe;2BAChC,MAAA,IAAI,CAAC,UAAU,0CAAE,eAAe;uBACpC,IAAI;gBACX,MAAA,IAAI,CAAC,UAAU,0CAAE,IAAI;8BACP,MAAA,MAAA,IAAI,CAAC,UAAU,0CAAE,kBAAkB,mCAAI,OAAO;;;uBAGrD,IAAI,CAAC,SAAS;KAChC,CAAC;IACJ,CAAC;IAEO,SAAS;QACf,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;QACjD,MAAM,OAAO,GAAG,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;QAC3D,uBAAuB;QACvB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,CAC3C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,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;AAzCU;IAAR,KAAK,EAAE;uDAQN;AATS,mBAAmB;IAD/B,aAAa,CAAC,uBAAuB,CAAC;GAC1B,mBAAmB,CA0C/B","sourcesContent":["import { LitElement, html, TemplateResult, nothing } from 'lit';\r\nimport { customElement, 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"]}
@@ -0,0 +1,20 @@
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
+ barScalingFunction?: (input: number) => number;
10
+ }
11
+ /**
12
+ * This is mainly to test the histogram-date-range within
13
+ * a lit-element.
14
+ */
15
+ export declare class LitHistogramWrapper extends LitElement {
16
+ dataSource: DataSource;
17
+ render(): TemplateResult;
18
+ private randomize;
19
+ }
20
+ export {};
@@ -0,0 +1,59 @@
1
+ import { __decorate } from "tslib";
2
+ import { LitElement, html, nothing } 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 LitHistogramWrapper = class LitHistogramWrapper 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, _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>
36
+ `;
37
+ }
38
+ randomize() {
39
+ const minDate = Math.round(Math.random() * 1000);
40
+ const maxDate = minDate + Math.round(Math.random() * 1000);
41
+ // generate random bins
42
+ const bins = Array.from({ length: 20 }, () => Math.floor(Math.random() * minDate));
43
+ this.dataSource = {
44
+ minDate,
45
+ maxDate,
46
+ minSelectedDate: minDate,
47
+ maxSelectedDate: maxDate,
48
+ bins: bins,
49
+ };
50
+ }
51
+ };
52
+ __decorate([
53
+ state()
54
+ ], LitHistogramWrapper.prototype, "dataSource", void 0);
55
+ LitHistogramWrapper = __decorate([
56
+ customElement('lit-histogram-wrapper')
57
+ ], LitHistogramWrapper);
58
+ export { LitHistogramWrapper };
59
+ //# sourceMappingURL=list-histogram-wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-histogram-wrapper.js","sourceRoot":"","sources":["../../../demo/js/list-histogram-wrapper.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAkB,OAA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IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,CAC3C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,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;AAzCU;IAAR,KAAK,EAAE;uDAQN;AATS,mBAAmB;IAD/B,aAAa,CAAC,uBAAuB,CAAC;GAC1B,mBAAmB,CA0C/B","sourcesContent":["import { LitElement, html, TemplateResult, nothing } from 'lit';\r\nimport { customElement, 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"]}
@@ -0,0 +1,21 @@
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 LitHistogramWrapper extends LitElement {
15
+ barScaling?: 'linear' | 'logarithmic';
16
+ dataSource: DataSource;
17
+ render(): TemplateResult;
18
+ private randomize;
19
+ static get styles(): import("lit").CSSResult;
20
+ }
21
+ export {};
@@ -0,0 +1,73 @@
1
+ import { __decorate } from "tslib";
2
+ import { LitElement, html, css, nothing } from 'lit';
3
+ import { customElement, property, state } from 'lit/decorators.js';
4
+ import '../../src/histogram-date-range';
5
+ const IDENTITY_FN = (x) => x;
6
+ /**
7
+ * This is mainly to test the histogram-date-range within
8
+ * a lit-element.
9
+ */
10
+ let LitHistogramWrapper = class LitHistogramWrapper extends LitElement {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.dataSource = {
14
+ minDate: 1955,
15
+ maxDate: 2000,
16
+ minSelectedDate: 1955,
17
+ maxSelectedDate: 2000,
18
+ bins: [
19
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
20
+ ],
21
+ };
22
+ }
23
+ render() {
24
+ var _a, _b, _c, _d, _e;
25
+ const scalingFn = this.barScaling === 'linear' ? IDENTITY_FN : nothing;
26
+ return html `
27
+ <histogram-date-range
28
+ .minDate=${(_a = this.dataSource) === null || _a === void 0 ? void 0 : _a.minDate}
29
+ .maxDate=${(_b = this.dataSource) === null || _b === void 0 ? void 0 : _b.maxDate}
30
+ .minSelectedDate=${(_c = this.dataSource) === null || _c === void 0 ? void 0 : _c.minSelectedDate}
31
+ .maxSelectedDate=${(_d = this.dataSource) === null || _d === void 0 ? void 0 : _d.maxSelectedDate}
32
+ .updateDelay=${1000}
33
+ .bins=${(_e = this.dataSource) === null || _e === void 0 ? void 0 : _e.bins}
34
+ .barScalingFunction=${scalingFn}
35
+ ></histogram-date-range>
36
+
37
+ <button @click=${this.randomize}>Randomize</button>
38
+ `;
39
+ }
40
+ randomize() {
41
+ const minDate = Math.round(Math.random() * 1000);
42
+ const maxDate = minDate + Math.round(Math.random() * 1000);
43
+ // generate random bins
44
+ const bins = Array.from({ length: 20 }, () => Math.floor(Math.random() * minDate));
45
+ this.dataSource = {
46
+ minDate,
47
+ maxDate,
48
+ minSelectedDate: minDate,
49
+ maxSelectedDate: maxDate,
50
+ bins: bins,
51
+ };
52
+ }
53
+ static get styles() {
54
+ return css `
55
+ :host {
56
+ display: flex;
57
+ flex-direction: column;
58
+ align-items: center;
59
+ }
60
+ `;
61
+ }
62
+ };
63
+ __decorate([
64
+ property({ type: String })
65
+ ], LitHistogramWrapper.prototype, "barScaling", void 0);
66
+ __decorate([
67
+ state()
68
+ ], LitHistogramWrapper.prototype, "dataSource", void 0);
69
+ LitHistogramWrapper = __decorate([
70
+ customElement('lit-histogram-wrapper')
71
+ ], LitHistogramWrapper);
72
+ export { LitHistogramWrapper };
73
+ //# sourceMappingURL=lit-histogram-wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lit-histogram-wrapper.js","sourceRoot":"","sources":["../../../demo/js/lit-histogram-wrapper.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAA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G,IAAI,CAAC,CAAC;QACjD,MAAM,OAAO,GAAG,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;QAC3D,uBAAuB;QACvB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,CAC3C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,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;IAED,MAAM,KAAK,MAAM;QACf,OAAO,GAAG,CAAA;;;;;;KAMT,CAAC;IACJ,CAAC;CACF,CAAA;AAtD6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uDAAuC;AAEzD;IAAR,KAAK,EAAE;uDAQN;AAXS,mBAAmB;IAD/B,aAAa,CAAC,uBAAuB,CAAC;GAC1B,mBAAmB,CAuD/B","sourcesContent":["import { LitElement, html, css, TemplateResult, nothing } from 'lit';\nimport { customElement, property, 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\nconst IDENTITY_FN = (x: number) => x;\n\n/**\n * This is mainly to test the histogram-date-range within\n * a lit-element.\n */\n@customElement('lit-histogram-wrapper')\nexport class LitHistogramWrapper extends LitElement {\n @property({ type: String }) barScaling?: 'linear' | 'logarithmic';\n\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 const scalingFn = this.barScaling === 'linear' ? IDENTITY_FN : nothing;\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 .barScalingFunction=${scalingFn}\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 static get styles() {\n return css`\n :host {\n display: flex;\n flex-direction: column;\n align-items: center;\n }\n `;\n }\n}\n"]}
@@ -28,6 +28,24 @@ export declare class HistogramDateRange extends LitElement {
28
28
  * - `year`: Same as `month`, but snapping to year boundaries instead of months.
29
29
  */
30
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 mapping bin values to a new value that determines how tall each bar will
38
+ * be in relation to the others.
39
+ *
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.
45
+ *
46
+ * For linearly-scaled bars, set this to the identity function.
47
+ */
48
+ barScalingFunction: (binValue: number) => number;
31
49
  private _tooltipOffsetX;
32
50
  private _tooltipOffsetY;
33
51
  private _tooltipContent?;
@@ -19,6 +19,9 @@ const TOOLTIP_HEIGHT = 30;
19
19
  const DATE_FORMAT = 'YYYY';
20
20
  const MISSING_DATA = 'no data';
21
21
  const UPDATE_DEBOUNCE_DELAY_MS = 0;
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);
22
25
  // this constant is not set up to be overridden
23
26
  const SLIDER_CORNER_SIZE = 4;
24
27
  // these CSS custom props can be overridden from the HTML that is invoking this component
@@ -67,6 +70,24 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
67
70
  * - `year`: Same as `month`, but snapping to year boundaries instead of months.
68
71
  */
69
72
  this.binSnapping = 'none';
73
+ /**
74
+ * What label to use on tooltips to identify the type of data being represented.
75
+ * Defaults to `'item(s)'`.
76
+ */
77
+ this.tooltipLabel = TOOLTIP_LABEL;
78
+ /**
79
+ * A function mapping bin values to a new value that determines how tall each bar will
80
+ * be in relation to the others.
81
+ *
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.
87
+ *
88
+ * For linearly-scaled bars, set this to the identity function.
89
+ */
90
+ this.barScalingFunction = LOG_BAR_SCALING_FN;
70
91
  // internal reactive properties not exposed as attributes
71
92
  this._tooltipOffsetX = 0;
72
93
  this._tooltipOffsetY = 0;
@@ -232,7 +253,7 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
232
253
  const maxValue = Math.max(...this.bins);
233
254
  // if there is no difference between the min and max values, use a range of
234
255
  // 1 because log scaling will fail if the range is 0
235
- const valueRange = minValue === maxValue ? 1 : Math.log1p(maxValue);
256
+ const valueRange = minValue === maxValue ? 1 : this.barScalingFunction(maxValue);
236
257
  const valueScale = height / valueRange;
237
258
  const dateScale = dateRangeMS / _numBins;
238
259
  return bins.map((v, i) => {
@@ -251,7 +272,7 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
251
272
  value: v,
252
273
  // use log scaling for the height of the bar to prevent tall bars from
253
274
  // making the smaller ones too small to see
254
- height: Math.floor(Math.log1p(v) * valueScale),
275
+ height: Math.floor(this.barScalingFunction(v) * valueScale),
255
276
  binStart,
256
277
  binEnd,
257
278
  tooltip,
@@ -379,7 +400,7 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
379
400
  const target = e.currentTarget;
380
401
  const x = target.x.baseVal.value + this.sliderWidth / 2;
381
402
  const dataset = target.dataset;
382
- const itemsText = `item${dataset.numItems !== '1' ? 's' : ''}`;
403
+ const itemsText = `${this.tooltipLabel}${dataset.numItems !== '1' ? 's' : ''}`;
383
404
  const formattedNumItems = Number(dataset.numItems).toLocaleString();
384
405
  const tooltipPadding = 2;
385
406
  const bufferHeight = 9;
@@ -676,20 +697,28 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
676
697
  const barStyle = `stroke-dasharray: 0 ${barWidth} ${barHeight} ${barWidth} 0 ${barHeight}`;
677
698
  const bar = svg `
678
699
  <rect
679
- class="bar"
680
- style=${barStyle}
700
+ class="bar-pointer-target"
681
701
  x=${x}
682
- y=${this.height - barHeight}
702
+ y="0"
683
703
  width=${barWidth}
684
- height=${barHeight}
704
+ height=${this.height}
685
705
  @pointerenter=${this.showTooltip}
686
706
  @pointerleave=${this.hideTooltip}
687
707
  @click=${this.handleBarClick}
688
- fill=${barFill}
708
+ fill="transparent"
689
709
  data-num-items=${data.value}
690
710
  data-bin-start=${data.binStart}
691
711
  data-bin-end=${data.binEnd}
692
712
  data-tooltip=${data.tooltip}
713
+ />
714
+ <rect
715
+ class="bar"
716
+ style=${barStyle}
717
+ x=${x}
718
+ y=${this.height - barHeight}
719
+ width=${barWidth}
720
+ height=${barHeight}
721
+ fill=${barFill}
693
722
  />`;
694
723
  x += xScale;
695
724
  return bar;
@@ -855,7 +884,8 @@ HistogramDateRange.styles = css `
855
884
  -ms-user-select: none; /* Internet Explorer/Edge */
856
885
  user-select: none; /* current Chrome, Edge, Opera and Firefox */
857
886
  }
858
- .bar {
887
+ .bar,
888
+ .bar-pointer-target {
859
889
  /* create a transparent border around the hist bars to prevent "gaps" and
860
890
  flickering when moving around between bars. this also helps with handling
861
891
  clicks on the bars, preventing users from being able to click in between
@@ -864,11 +894,15 @@ HistogramDateRange.styles = css `
864
894
  /* ensure transparent stroke wide enough to cover gap between bars */
865
895
  stroke-width: 2px;
866
896
  }
867
- .bar:hover {
897
+ .bar {
898
+ /* ensure the bar's pointer target receives events, not the bar itself */
899
+ pointer-events: none;
900
+ }
901
+ .bar-pointer-target:hover + .bar {
868
902
  /* highlight currently hovered bar */
869
903
  fill-opacity: 0.7;
870
904
  }
871
- .disabled .bar:hover {
905
+ .disabled .bar-pointer-target:hover + .bar {
872
906
  /* ensure no visual hover interaction when disabled */
873
907
  fill-opacity: 1;
874
908
  }
@@ -985,6 +1019,12 @@ __decorate([
985
1019
  __decorate([
986
1020
  property({ type: String })
987
1021
  ], HistogramDateRange.prototype, "binSnapping", void 0);
1022
+ __decorate([
1023
+ property({ type: String })
1024
+ ], HistogramDateRange.prototype, "tooltipLabel", void 0);
1025
+ __decorate([
1026
+ property({ attribute: false })
1027
+ ], HistogramDateRange.prototype, "barScalingFunction", void 0);
988
1028
  __decorate([
989
1029
  state()
990
1030
  ], HistogramDateRange.prototype, "_tooltipOffsetX", void 0);