@jackens/nnn 2024.2.9 → 2024.2.10

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/chartable.d.ts CHANGED
@@ -6,38 +6,32 @@
6
6
  * - `gapX`: X axis spacing
7
7
  * - `gapY`: Y axis spacing
8
8
  * - `headerColumn`: flag indicating that `table` has a header column (with X axis labels)
9
- * - `headerRow`: flag indicating that `table` has a header row (with data series labels)
10
9
  * - `id`: chart id
11
10
  * - `left`: left padding (for data series labels)
12
11
  * - `maxY`: number of Y axis lines
13
12
  * - `reverse`: flag to reverse all data series
14
13
  * - `right`: right padding (for data series labels)
14
+ * - `rotate`: flag to rotate X axis labels
15
15
  * - `singleScale`: flag to force single scale
16
16
  * - `table`: `HTMLTableElement` to extract data, data series labels and X axis labels
17
17
  * - `title`: chart title
18
18
  * - `top`: top padding (for the title)
19
- * - `xLabels`: X axis labels
20
- * - `zLabels`: data series labels
21
- * - `zxY`: chart data
22
19
  */
23
- export function chartable({ bottom, gapX, gapY, headerColumn, headerRow, id, left, maxY, reverse, right, singleScale, table, title, top, xLabels, zLabels, zxY }?: {
20
+ export function chartable({ bottom, gapX, gapY, headerColumn, id, left, maxY, reverse, right, rotate, singleScale, table, title, top }: {
24
21
  bottom?: number;
25
22
  gapX?: number;
26
23
  gapY?: number;
27
24
  headerColumn?: boolean;
28
- headerRow?: boolean;
29
25
  id?: string;
30
26
  left?: number;
31
27
  maxY?: number;
32
28
  reverse?: boolean;
33
29
  right?: number;
30
+ rotate?: boolean;
34
31
  singleScale?: boolean;
35
- table?: HTMLTableElement;
32
+ table: HTMLTableElement;
36
33
  title?: string;
37
34
  top?: number;
38
- xLabels?: string[];
39
- zLabels?: string[];
40
- zxY?: number[][];
41
35
  }): SVGSVGElement;
42
36
 
43
37
  export const tests: {};
package/chartable.js CHANGED
@@ -10,38 +10,32 @@ const COLORS = ['#e22', '#e73', '#fc3', '#ad4', '#4d9', '#3be', '#45d', '#c3e']
10
10
  * - `gapX`: X axis spacing
11
11
  * - `gapY`: Y axis spacing
12
12
  * - `headerColumn`: flag indicating that `table` has a header column (with X axis labels)
13
- * - `headerRow`: flag indicating that `table` has a header row (with data series labels)
14
13
  * - `id`: chart id
15
14
  * - `left`: left padding (for data series labels)
16
15
  * - `maxY`: number of Y axis lines
17
16
  * - `reverse`: flag to reverse all data series
18
17
  * - `right`: right padding (for data series labels)
18
+ * - `rotate`: flag to rotate X axis labels
19
19
  * - `singleScale`: flag to force single scale
20
20
  * - `table`: `HTMLTableElement` to extract data, data series labels and X axis labels
21
21
  * - `title`: chart title
22
22
  * - `top`: top padding (for the title)
23
- * - `xLabels`: X axis labels
24
- * - `zLabels`: data series labels
25
- * - `zxY`: chart data
26
23
  *
27
24
  * @param {{
28
25
  * bottom?: number;
29
26
  * gapX?: number;
30
27
  * gapY?: number;
31
28
  * headerColumn?: boolean;
32
- * headerRow?: boolean;
33
29
  * id?: string;
34
30
  * left?: number;
35
31
  * maxY?: number;
36
32
  * reverse?: boolean;
37
33
  * right?: number;
34
+ * rotate?: boolean;
38
35
  * singleScale?: boolean;
39
- * table?: HTMLTableElement;
36
+ * table: HTMLTableElement;
40
37
  * title?: string;
41
38
  * top?: number;
42
- * xLabels?: string[];
43
- * zLabels?: string[];
44
- * zxY?: number[][];
45
39
  * }} options
46
40
  */
47
41
  export const chartable = ({
@@ -49,42 +43,37 @@ export const chartable = ({
49
43
  gapX = 70,
50
44
  gapY = 30,
51
45
  headerColumn = false,
52
- headerRow = true,
53
46
  id,
54
47
  left = 200,
55
48
  maxY = 10,
56
49
  reverse = false,
57
50
  right = 200,
51
+ rotate = false,
58
52
  singleScale = false,
59
53
  table,
60
54
  title,
61
- top = 70,
62
- xLabels = [],
63
- zLabels = [],
64
- zxY = []
65
- } = {}) => {
66
- if (table != null) {
67
- const zxYNotPassed = !zxY.length
68
- const xLabelsNotPassed = !xLabels.length
69
- const zLabelsNotPassed = !zLabels.length
70
-
71
- table.querySelectorAll('tr').forEach((row, r) =>
72
- // @ts-ignore
73
- row.querySelectorAll('td,th').forEach((/** @type {HTMLTableCellElement} */ col, c) => {
74
- const x = r - +headerRow
75
- const z = c - +headerColumn
76
- const value = col.innerText
77
-
78
- if (x >= 0 && z >= 0 && zxYNotPassed) {
79
- zxY[z] = zxY[z] ?? []
80
- zxY[z][x] = parseFloat(value)
81
- } else if (x >= 0 && z < 0 && xLabelsNotPassed) {
82
- xLabels[x] = value
83
- } else if (x < 0 && z >= 0 && zLabelsNotPassed) {
84
- zLabels[z] = value
85
- }
86
- }))
87
- }
55
+ top = 70
56
+ }) => {
57
+ const /** @type {number[][]} */ zxY = []
58
+ const /** @type {string[]} */ xLabels = []
59
+ const /** @type {string[]} */ zLabels = []
60
+
61
+ table.querySelectorAll('tr').forEach((row, r) =>
62
+ // @ts-ignore
63
+ row.querySelectorAll('td,th').forEach((/** @type {HTMLTableCellElement} */ col, c) => {
64
+ const x = r - 1
65
+ const z = c - +headerColumn
66
+ const value = col.innerText
67
+
68
+ if (x >= 0 && z >= 0) {
69
+ zxY[z] = zxY[z] ?? []
70
+ zxY[z][x] = parseFloat(value)
71
+ } else if (x >= 0 && z < 0) {
72
+ xLabels[x] = value
73
+ } else if (x < 0 && z >= 0) {
74
+ zLabels[z] = value
75
+ }
76
+ }))
88
77
 
89
78
  if (reverse) {
90
79
  xLabels.reverse()
@@ -217,9 +206,10 @@ export const chartable = ({
217
206
  xLabels.length > 0
218
207
  ? ['g', { transform: `translate(${left} ${top + h})` },
219
208
  ['g', { class: 'chartable-x-labels', transform: 'translate(0 15)' },
220
- ...xi.map((x, i) => ['text',
221
- { x, y: 0, 'text-anchor': 'middle', 'alignment-baseline': 'hanging' },
222
- xLabels[i]])]]
209
+ ...xi.slice(0).map((x, i) => ['text', rotate
210
+ ? { x: 0, y: -x, 'text-anchor': 'start', 'alignment-baseline': 'hanging', transform: 'rotate(90)' }
211
+ : { x, y: 0, 'text-anchor': 'middle', 'alignment-baseline': 'hanging' },
212
+ xLabels[i]])]]
223
213
  : null
224
214
  )
225
215
  }
package/package.json CHANGED
@@ -40,5 +40,5 @@
40
40
  "types": "nnn.d.ts",
41
41
  "name": "@jackens/nnn",
42
42
  "type": "module",
43
- "version": "2024.2.9"
43
+ "version": "2024.2.10"
44
44
  }
package/readme.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Jackens’ JavaScript helpers.
4
4
 
5
- <sub>Version: <code class="version">2024.2.9</code></sub>
5
+ <sub>Version: <code class="version">2024.2.10</code></sub>
6
6
 
7
7
  ## Installation
8
8
 
@@ -101,24 +101,21 @@ The type of arguments of the `jcss` helper.
101
101
  ### chartable
102
102
 
103
103
  ```ts
104
- export function chartable({ bottom, gapX, gapY, headerColumn, headerRow, id, left, maxY, reverse, right, singleScale, table, title, top, xLabels, zLabels, zxY }?: {
104
+ export function chartable({ bottom, gapX, gapY, headerColumn, id, left, maxY, reverse, right, rotate, singleScale, table, title, top }: {
105
105
  bottom?: number;
106
106
  gapX?: number;
107
107
  gapY?: number;
108
108
  headerColumn?: boolean;
109
- headerRow?: boolean;
110
109
  id?: string;
111
110
  left?: number;
112
111
  maxY?: number;
113
112
  reverse?: boolean;
114
113
  right?: number;
114
+ rotate?: boolean;
115
115
  singleScale?: boolean;
116
- table?: HTMLTableElement;
116
+ table: HTMLTableElement;
117
117
  title?: string;
118
118
  top?: number;
119
- xLabels?: string[];
120
- zLabels?: string[];
121
- zxY?: number[][];
122
119
  }): SVGSVGElement;
123
120
  ```
124
121
 
@@ -129,19 +126,16 @@ Options:
129
126
  - `gapX`: X axis spacing
130
127
  - `gapY`: Y axis spacing
131
128
  - `headerColumn`: flag indicating that `table` has a header column (with X axis labels)
132
- - `headerRow`: flag indicating that `table` has a header row (with data series labels)
133
129
  - `id`: chart id
134
130
  - `left`: left padding (for data series labels)
135
131
  - `maxY`: number of Y axis lines
136
132
  - `reverse`: flag to reverse all data series
137
133
  - `right`: right padding (for data series labels)
134
+ - `rotate`: flag to rotate X axis labels
138
135
  - `singleScale`: flag to force single scale
139
136
  - `table`: `HTMLTableElement` to extract data, data series labels and X axis labels
140
137
  - `title`: chart title
141
138
  - `top`: top padding (for the title)
142
- - `xLabels`: X axis labels
143
- - `zLabels`: data series labels
144
- - `zxY`: chart data
145
139
 
146
140
  ### eq
147
141