@hpcc-js/chart 3.5.1 → 3.5.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hpcc-js/chart",
3
- "version": "3.5.1",
3
+ "version": "3.5.3",
4
4
  "description": "hpcc-js - Viz Chart",
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.cjs",
@@ -37,12 +37,12 @@
37
37
  "update-major": "npx --yes npm-check-updates -u"
38
38
  },
39
39
  "dependencies": {
40
- "@hpcc-js/api": "^3.4.1",
41
- "@hpcc-js/common": "^3.5.1",
42
- "@hpcc-js/util": "^3.4.1"
40
+ "@hpcc-js/api": "^3.4.3",
41
+ "@hpcc-js/common": "^3.5.3",
42
+ "@hpcc-js/util": "^3.4.3"
43
43
  },
44
44
  "devDependencies": {
45
- "@hpcc-js/esbuild-plugins": "^1.6.1",
45
+ "@hpcc-js/esbuild-plugins": "^1.7.0",
46
46
  "@types/d3-shape": "1.3.12",
47
47
  "@types/d3-transition": "1.3.6",
48
48
  "d3-array": "^1",
@@ -76,5 +76,5 @@
76
76
  "url": "https://github.com/hpcc-systems/Visualization/issues"
77
77
  },
78
78
  "homepage": "https://github.com/hpcc-systems/Visualization",
79
- "gitHead": "d93d09e45945a39ab056bae20a3dcca3c918cd82"
79
+ "gitHead": "0289b8552e19395a8da9b70a154821cf70ce42e7"
80
80
  }
package/src/Axis.ts CHANGED
@@ -22,7 +22,7 @@ export class Axis extends SVGWidget {
22
22
 
23
23
  protected parser;
24
24
  protected parserInvert;
25
- protected formatter: (date: Date) => string;
25
+ protected formatter: ((d: Date | any) => string) | null;
26
26
  protected d3Scale;
27
27
  protected d3Axis;
28
28
  protected d3Guides;
@@ -30,6 +30,7 @@ export class Axis extends SVGWidget {
30
30
  protected svg;
31
31
  protected svgAxis;
32
32
  protected svgGuides;
33
+ protected _tickFormatFunc?: (d: any) => string;
33
34
 
34
35
  constructor(drawStartPosition: "origin" | "center" = "origin") {
35
36
  super();
@@ -91,6 +92,15 @@ export class Axis extends SVGWidget {
91
92
  return this.format(this.parse(d));
92
93
  }
93
94
 
95
+ tickFormatFunc(fn: (d: any) => string): this;
96
+ tickFormatFunc(): ((d: any) => string) | undefined;
97
+ tickFormatFunc(fn?: (d: any) => string): this | ((d: any) => string) | undefined {
98
+ if (!arguments.length) return this._tickFormatFunc;
99
+ this._tickFormatFunc = fn;
100
+ this.updateScale();
101
+ return this;
102
+ }
103
+
94
104
  scalePos(d) {
95
105
  let retVal = this.d3Scale(this.parse(d));
96
106
  if (this.type() === "ordinal") {
@@ -211,7 +221,11 @@ export class Axis extends SVGWidget {
211
221
  }
212
222
  this.parser = this.timePattern_exists() ? d3TimeParse(this.timePattern()) : null;
213
223
  this.parserInvert = this.timePattern_exists() ? d3TimeFormat(this.timePattern()) : null;
214
- this.formatter = this.tickFormat_exists() ? d3TimeFormat(this.tickFormat()) : null;
224
+ if (this._tickFormatFunc) {
225
+ this.formatter = this._tickFormatFunc;
226
+ } else {
227
+ this.formatter = this.tickFormat_exists() ? d3TimeFormat(this.tickFormat()) : null;
228
+ }
215
229
  break;
216
230
  default:
217
231
  }
@@ -677,6 +691,8 @@ export interface Axis {
677
691
  tickFormat(_: string): this;
678
692
  tickFormat_exists(): boolean;
679
693
  tickFormat_reset(): void;
694
+ tickFormatFunc(fn: (d: any) => string): this;
695
+ tickFormatFunc(): ((d: any) => string) | undefined;
680
696
  tickLength(): number;
681
697
  tickLength(_: number): this;
682
698
  tickLength_exists(): boolean;
package/src/index.ts CHANGED
@@ -25,3 +25,4 @@ export * from "./Summary.ts";
25
25
  export * from "./SummaryC.ts";
26
26
  export * from "./WordCloud.ts";
27
27
  export * from "./XYAxis.ts";
28
+ export * from "./timeFormats.ts";
@@ -0,0 +1,26 @@
1
+ import { timeFormat } from "d3-time-format";
2
+
3
+ /**
4
+ * Adaptive 24-hour multi-scale tick formatter.
5
+ * Order of precedence (first predicate that matches):
6
+ * milliseconds -> seconds -> minutes -> hours -> day -> month -> year.
7
+ */
8
+ export function multiScale24Hours(): (d: Date) => string {
9
+ const fmtMs = timeFormat(".%L");
10
+ const fmtSec = timeFormat(":%S");
11
+ const fmtMin = timeFormat("%H:%M");
12
+ const fmtHour = timeFormat("%H:00");
13
+ const fmtDay = timeFormat("%b %d");
14
+ const fmtMonth = timeFormat("%b");
15
+ const fmtYear = timeFormat("%Y");
16
+
17
+ return (d: Date): string => {
18
+ if (d.getMilliseconds() !== 0) return fmtMs(d);
19
+ if (d.getSeconds() !== 0) return fmtSec(d);
20
+ if (d.getMinutes() !== 0) return fmtMin(d);
21
+ if (d.getHours() !== 0) return fmtHour(d);
22
+ if (d.getDate() !== 1) return fmtDay(d);
23
+ if (d.getMonth() !== 0) return fmtMonth(d);
24
+ return fmtYear(d);
25
+ };
26
+ }
package/types/Axis.d.ts CHANGED
@@ -13,7 +13,7 @@ export declare class Axis extends SVGWidget {
13
13
  _origTimePattern: any;
14
14
  protected parser: any;
15
15
  protected parserInvert: any;
16
- protected formatter: (date: Date) => string;
16
+ protected formatter: ((d: Date | any) => string) | null;
17
17
  protected d3Scale: any;
18
18
  protected d3Axis: any;
19
19
  protected d3Guides: any;
@@ -21,6 +21,7 @@ export declare class Axis extends SVGWidget {
21
21
  protected svg: any;
22
22
  protected svgAxis: any;
23
23
  protected svgGuides: any;
24
+ protected _tickFormatFunc?: (d: any) => string;
24
25
  constructor(drawStartPosition?: "origin" | "center");
25
26
  lowValue(): any;
26
27
  highValue(): any;
@@ -28,6 +29,8 @@ export declare class Axis extends SVGWidget {
28
29
  parseInvert(d: any): any;
29
30
  format(d: any): any;
30
31
  parseFormat(d: any): any;
32
+ tickFormatFunc(fn: (d: any) => string): this;
33
+ tickFormatFunc(): ((d: any) => string) | undefined;
31
34
  scalePos(d: any): any;
32
35
  bandwidth(): any;
33
36
  isHorizontal(): boolean;
@@ -81,6 +84,8 @@ export interface Axis {
81
84
  tickFormat(_: string): this;
82
85
  tickFormat_exists(): boolean;
83
86
  tickFormat_reset(): void;
87
+ tickFormatFunc(fn: (d: any) => string): this;
88
+ tickFormatFunc(): ((d: any) => string) | undefined;
84
89
  tickLength(): number;
85
90
  tickLength(_: number): this;
86
91
  tickLength_exists(): boolean;
package/types/index.d.ts CHANGED
@@ -25,3 +25,4 @@ export * from "./Summary.ts";
25
25
  export * from "./SummaryC.ts";
26
26
  export * from "./WordCloud.ts";
27
27
  export * from "./XYAxis.ts";
28
+ export * from "./timeFormats.ts";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Adaptive 24-hour multi-scale tick formatter.
3
+ * Order of precedence (first predicate that matches):
4
+ * milliseconds -> seconds -> minutes -> hours -> day -> month -> year.
5
+ */
6
+ export declare function multiScale24Hours(): (d: Date) => string;