markdown-up 2.4.0 → 3.0.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/lib/dataTable.js +2 -2
- package/lib/dataUtil.js +16 -13
- package/lib/lineChart.js +2 -2
- package/lib/scriptLibrary.js +999 -630
- package/package.json +5 -5
package/lib/dataTable.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
/** @module lib/dataTable */
|
|
5
5
|
|
|
6
|
-
import {compareValues} from 'bare-script/lib/data.js';
|
|
7
6
|
import {formatValue} from './dataUtil.js';
|
|
8
7
|
import {markdownElements} from 'markdown-model/lib/elements.js';
|
|
9
8
|
import {parseMarkdown} from 'markdown-model/lib/parser.js';
|
|
10
9
|
import {parseSchemaMarkdown} from 'schema-markdown/lib/parser.js';
|
|
11
10
|
import {validateType} from 'schema-markdown/lib/schema.js';
|
|
11
|
+
import {valueCompare} from 'bare-script/lib/value.js';
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
// The data table model's Schema Markdown
|
|
@@ -164,7 +164,7 @@ export function dataTableElements(data, dataTable = null, options = null) {
|
|
|
164
164
|
|
|
165
165
|
// Skip this value?
|
|
166
166
|
if (skip) {
|
|
167
|
-
skip = (
|
|
167
|
+
skip = (valueCompare(value, rowPrev[field] ?? null) === 0);
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
const fieldFormat = (fieldFormats !== null ? (fieldFormats[field] ?? null) : null);
|
package/lib/dataUtil.js
CHANGED
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
// Licensed under the MIT License
|
|
2
2
|
// https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
|
|
3
3
|
|
|
4
|
+
import {valueString, valueType} from 'bare-script/lib/value.js';
|
|
5
|
+
|
|
4
6
|
|
|
5
7
|
// Helper function to format labels
|
|
6
8
|
export function formatValue(value, precision = null, datetime = null, trim = null) {
|
|
7
|
-
|
|
9
|
+
const type = valueType(value);
|
|
10
|
+
if (type === 'datetime') {
|
|
8
11
|
if (datetime === 'year') {
|
|
9
12
|
// Round to nearest year
|
|
10
13
|
let valueRounded = value;
|
|
11
|
-
if (value.
|
|
14
|
+
if (value.getMonth() > 5) {
|
|
12
15
|
valueRounded = new Date(value);
|
|
13
|
-
valueRounded.
|
|
16
|
+
valueRounded.setFullYear(value.getFullYear() + 1);
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
const isoFormat = valueRounded
|
|
19
|
+
const isoFormat = valueString(valueRounded);
|
|
17
20
|
return isoFormat.slice(0, isoFormat.indexOf('T') - 6);
|
|
18
21
|
} else if (datetime === 'month') {
|
|
19
22
|
// Round to the nearest month
|
|
20
23
|
let valueRounded = value;
|
|
21
|
-
if (value.
|
|
24
|
+
if (value.getDate() > 15) {
|
|
22
25
|
valueRounded = new Date(value);
|
|
23
|
-
valueRounded.setMonth(value.
|
|
26
|
+
valueRounded.setMonth(value.getMonth() + 1);
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
const isoFormat = valueRounded
|
|
29
|
+
const isoFormat = valueString(valueRounded);
|
|
27
30
|
return isoFormat.slice(0, isoFormat.indexOf('T') - 3);
|
|
28
31
|
} else if (datetime === 'day') {
|
|
29
|
-
const isoFormat = value
|
|
32
|
+
const isoFormat = valueString(value);
|
|
30
33
|
return isoFormat.slice(0, isoFormat.indexOf('T'));
|
|
31
34
|
}
|
|
32
|
-
return value
|
|
33
|
-
} else if (
|
|
35
|
+
return valueString(value).replace(rDateCleanup, '');
|
|
36
|
+
} else if (type === 'number') {
|
|
34
37
|
const numberFormat = value.toFixed(precision ?? defaultPrecision);
|
|
35
38
|
return (trim ?? defaultTrim) ? numberFormat.replace(rNumberCleanup, '') : numberFormat;
|
|
36
39
|
}
|
|
@@ -40,7 +43,7 @@ export function formatValue(value, precision = null, datetime = null, trim = nul
|
|
|
40
43
|
const defaultPrecision = 2;
|
|
41
44
|
const defaultTrim = true;
|
|
42
45
|
const rNumberCleanup = /\.0*$/;
|
|
43
|
-
const rDateCleanup = /(?:(?:(?:-01)?T00:00)?:00)
|
|
46
|
+
const rDateCleanup = /(?:(?:(?:-01)?T00:00)?:00)?(?:\.\d{1,6})?(?:Z|[+-]\d\d:\d\d)$/;
|
|
44
47
|
|
|
45
48
|
|
|
46
49
|
// Helper function to compute a value's parameter
|
|
@@ -49,7 +52,7 @@ export function valueParameter(value, minValue, maxValue) {
|
|
|
49
52
|
return 0;
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
if (minValue
|
|
55
|
+
if (valueType(minValue) === 'datetime') {
|
|
53
56
|
const minDateValue = minValue.valueOf();
|
|
54
57
|
return (value.valueOf() - minDateValue) / (maxValue.valueOf() - minDateValue);
|
|
55
58
|
}
|
|
@@ -60,7 +63,7 @@ export function valueParameter(value, minValue, maxValue) {
|
|
|
60
63
|
|
|
61
64
|
// Helper function to compute a value from a parameter
|
|
62
65
|
export function parameterValue(param, minValue, maxValue) {
|
|
63
|
-
if (minValue
|
|
66
|
+
if (valueType(minValue) === 'datetime') {
|
|
64
67
|
const minDateValue = minValue.valueOf();
|
|
65
68
|
return new Date(minDateValue + param * (maxValue.valueOf() - minDateValue));
|
|
66
69
|
}
|
package/lib/lineChart.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
/** @module lib/lineChart */
|
|
5
5
|
|
|
6
6
|
import {formatValue, parameterValue, valueParameter} from './dataUtil.js';
|
|
7
|
-
import {compareValues} from 'bare-script/lib/data.js';
|
|
8
7
|
import {parseSchemaMarkdown} from 'schema-markdown/lib/parser.js';
|
|
9
8
|
import {validateType} from 'schema-markdown/lib/schema.js';
|
|
9
|
+
import {valueCompare} from 'bare-script/lib/value.js';
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
// The line chart model's Schema Markdown
|
|
@@ -185,7 +185,7 @@ export function lineChartElements(data, lineChart, options = null) {
|
|
|
185
185
|
data.sort((row1, row2) => {
|
|
186
186
|
const x1 = row1[xField] ?? null;
|
|
187
187
|
const x2 = row2[xField] ?? null;
|
|
188
|
-
return
|
|
188
|
+
return valueCompare(x1, x2);
|
|
189
189
|
});
|
|
190
190
|
|
|
191
191
|
// Generate the line points - [(label, color, points), ...]
|