markdown-up 1.7.2 → 1.7.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/README.md +43 -26
- package/lib/app.js +304 -204
- package/lib/barChart.js +5 -6
- package/lib/data.js +27 -31
- package/lib/dataTable.js +5 -6
- package/lib/lineChart.js +5 -6
- package/lib/model.js +5 -11
- package/lib/script.js +577 -179
- package/lib/util.js +19 -23
- package/package.json +5 -5
package/lib/barChart.js
CHANGED
|
@@ -11,13 +11,12 @@ import {validateBarChart} from './model.js';
|
|
|
11
11
|
/**
|
|
12
12
|
* Bar chart code block function
|
|
13
13
|
*
|
|
14
|
-
* @param {
|
|
15
|
-
* @param {
|
|
16
|
-
* @param {module:lib/util~MarkdownScriptOptions} [options=null] - Markdown script options
|
|
14
|
+
* @param {object} codeBlock - The code block model
|
|
15
|
+
* @param {Object} [options=null] - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
|
|
17
16
|
* @returns {Object} The bar chart element model
|
|
18
17
|
*/
|
|
19
|
-
export function barChartCodeBlock(
|
|
20
|
-
return chartCodeBlock(
|
|
18
|
+
export function barChartCodeBlock(codeBlock, options = null) {
|
|
19
|
+
return chartCodeBlock(codeBlock, options, validateBarChart, barChartElements);
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
|
|
@@ -25,7 +24,7 @@ export function barChartCodeBlock(language, lines, options = null) {
|
|
|
25
24
|
* Render a bar chart
|
|
26
25
|
*
|
|
27
26
|
* @param {Object} barChart - The bar chart model
|
|
28
|
-
* @param {
|
|
27
|
+
* @param {Object} [options=null] - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
|
|
29
28
|
* @returns {Object} The bar chart element model
|
|
30
29
|
*/
|
|
31
30
|
export async function barChartElements(barChart, options = null) {
|
package/lib/data.js
CHANGED
|
@@ -17,13 +17,13 @@ const dataExprFunctions = {
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
// Helper function to create the data expression's variables argument
|
|
20
|
-
function createDataVariables(
|
|
20
|
+
function createDataVariables(chart, variables = null) {
|
|
21
21
|
const dataVariables = {...dataExprFunctions};
|
|
22
22
|
|
|
23
23
|
// Add the chart model variable expressions
|
|
24
|
-
if ('var' in
|
|
25
|
-
for (const varName of Object.keys(
|
|
26
|
-
const varExpr = parseExpression(
|
|
24
|
+
if (chart !== null && 'var' in chart) {
|
|
25
|
+
for (const varName of Object.keys(chart.var)) {
|
|
26
|
+
const varExpr = parseExpression(chart.var[varName]);
|
|
27
27
|
dataVariables[varName] = evaluateExpression(varExpr, dataVariables);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -51,52 +51,49 @@ function createDataVariables(chartModel, variables = null) {
|
|
|
51
51
|
* Load the chart's data
|
|
52
52
|
*
|
|
53
53
|
* @async
|
|
54
|
-
* @param {Object}
|
|
55
|
-
* @param {
|
|
54
|
+
* @param {Object} chart - The chart model
|
|
55
|
+
* @param {Object} [options=null] - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
|
|
56
56
|
* @returns {module:lib/data~LoadChartDataResult}
|
|
57
57
|
*/
|
|
58
|
-
export async function loadChartData(
|
|
59
|
-
// Compute the data variable values
|
|
60
|
-
const variables = createDataVariables(chartModel, options !== null ? options.variables : null);
|
|
61
|
-
|
|
58
|
+
export async function loadChartData(chart, options = null) {
|
|
62
59
|
// Load the data resources
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
let {data, types} = await loadData(chart.data, options);
|
|
61
|
+
|
|
62
|
+
// Compute the data variable values
|
|
63
|
+
const variables = createDataVariables(chart, options !== null ? options.variables : null);
|
|
67
64
|
|
|
68
65
|
// Add calculated fields
|
|
69
|
-
if ('calc' in
|
|
70
|
-
for (const calculatedField of
|
|
66
|
+
if ('calc' in chart) {
|
|
67
|
+
for (const calculatedField of chart.calc) {
|
|
71
68
|
types[calculatedField.name] = addCalculatedField(data, calculatedField.name, calculatedField.expr, variables);
|
|
72
69
|
}
|
|
73
70
|
}
|
|
74
71
|
|
|
75
72
|
// Filter the data
|
|
76
|
-
if ('filter' in
|
|
77
|
-
data = filterData(data,
|
|
73
|
+
if ('filter' in chart) {
|
|
74
|
+
data = filterData(data, chart.filter, variables);
|
|
78
75
|
}
|
|
79
76
|
|
|
80
77
|
// Aggregate the data
|
|
81
|
-
if ('agg' in
|
|
82
|
-
({data, types} = aggregateData(
|
|
78
|
+
if ('agg' in chart) {
|
|
79
|
+
({data, types} = aggregateData(chart.agg, data, types));
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
// Add the post-aggregation calculated fields
|
|
86
|
-
if ('aggcalc' in
|
|
87
|
-
for (const calculatedField of
|
|
83
|
+
if ('aggcalc' in chart) {
|
|
84
|
+
for (const calculatedField of chart.aggcalc) {
|
|
88
85
|
types[calculatedField.name] = addCalculatedField(data, calculatedField.name, calculatedField.expr, variables);
|
|
89
86
|
}
|
|
90
87
|
}
|
|
91
88
|
|
|
92
89
|
// Sort the data
|
|
93
|
-
if ('sort' in
|
|
94
|
-
sortData(
|
|
90
|
+
if ('sort' in chart) {
|
|
91
|
+
sortData(chart.sort, data);
|
|
95
92
|
}
|
|
96
93
|
|
|
97
94
|
// Top the data
|
|
98
|
-
if ('top' in
|
|
99
|
-
data = topData(
|
|
95
|
+
if ('top' in chart) {
|
|
96
|
+
data = topData(chart.top, data);
|
|
100
97
|
}
|
|
101
98
|
|
|
102
99
|
return {data, types, variables};
|
|
@@ -117,18 +114,17 @@ export async function loadChartData(chartModel, options = null) {
|
|
|
117
114
|
*
|
|
118
115
|
* @async
|
|
119
116
|
* @param {Object} dataModel - The data model
|
|
120
|
-
* @param {
|
|
121
|
-
* @param {Object} [variables = null] - Map of variables to variable value
|
|
117
|
+
* @param {Object} options - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
|
|
122
118
|
* @returns {module:lib/data~LoadDataResult}
|
|
123
119
|
*/
|
|
124
|
-
export async function loadData(dataModel,
|
|
120
|
+
export async function loadData(dataModel, options) {
|
|
125
121
|
const dataBases = [dataModel, ...('join' in dataModel ? dataModel.join : [])];
|
|
126
122
|
const dataURLs = dataBases.map((base) => base.url);
|
|
127
|
-
const dataResponses = await Promise.all(dataURLs.map((joinURL) => fetchFn(joinURL)));
|
|
123
|
+
const dataResponses = await Promise.all(dataURLs.map((joinURL) => options.fetchFn(options.urlFn(joinURL))));
|
|
128
124
|
const dataTypes = await Promise.all(dataResponses.map((response, ixResponse) => dataResponseHandler(dataURLs[ixResponse], response)));
|
|
129
125
|
|
|
130
126
|
// Compute the data variable values
|
|
131
|
-
const dataVariables = variables ?? createDataVariables(null);
|
|
127
|
+
const dataVariables = options.variables ?? createDataVariables(null);
|
|
132
128
|
|
|
133
129
|
// Join the data
|
|
134
130
|
let [{data}] = dataTypes;
|
package/lib/dataTable.js
CHANGED
|
@@ -13,13 +13,12 @@ import {validateDataTable} from './model.js';
|
|
|
13
13
|
/**
|
|
14
14
|
* Data table code block function
|
|
15
15
|
*
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {module:lib/util~MarkdownScriptOptions} [options=null] - Markdown script options
|
|
16
|
+
* @param {object} codeBlock - The code block model
|
|
17
|
+
* @param {Object} [options=null] - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
|
|
19
18
|
* @returns {Object} The data table element model
|
|
20
19
|
*/
|
|
21
|
-
export function dataTableCodeBlock(
|
|
22
|
-
return chartCodeBlock(
|
|
20
|
+
export function dataTableCodeBlock(codeBlock, options = null) {
|
|
21
|
+
return chartCodeBlock(codeBlock, options, validateDataTable, dataTableElements);
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
|
|
@@ -27,7 +26,7 @@ export function dataTableCodeBlock(language, lines, options = null) {
|
|
|
27
26
|
* Render a data table
|
|
28
27
|
*
|
|
29
28
|
* @param {Object} dataTable - The data table model
|
|
30
|
-
* @param {
|
|
29
|
+
* @param {Object} [options=null] - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
|
|
31
30
|
* @returns {Object} The data table element model
|
|
32
31
|
*/
|
|
33
32
|
export async function dataTableElements(dataTable, options = null) {
|
package/lib/lineChart.js
CHANGED
|
@@ -41,13 +41,12 @@ const chartLineWidth = 3;
|
|
|
41
41
|
/**
|
|
42
42
|
* Line chart code block function
|
|
43
43
|
*
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {
|
|
46
|
-
* @param {module:lib/util~MarkdownScriptOptions} [options=null] - Markdown script options
|
|
44
|
+
* @param {object} codeBlock - The code block model
|
|
45
|
+
* @param {Object} [options=null] - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
|
|
47
46
|
* @returns {Object} The line chart element model
|
|
48
47
|
*/
|
|
49
|
-
export function lineChartCodeBlock(
|
|
50
|
-
return chartCodeBlock(
|
|
48
|
+
export function lineChartCodeBlock(codeBlock, options = null) {
|
|
49
|
+
return chartCodeBlock(codeBlock, options, validateLineChart, lineChartElements);
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
|
|
@@ -55,7 +54,7 @@ export function lineChartCodeBlock(language, lines, options = null) {
|
|
|
55
54
|
* Render a line chart
|
|
56
55
|
*
|
|
57
56
|
* @param {Object} lineChart - The line chart model
|
|
58
|
-
* @param {
|
|
57
|
+
* @param {Object} [options=null] - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
|
|
59
58
|
* @returns {Object} The line chart element model
|
|
60
59
|
*/
|
|
61
60
|
export async function lineChartElements(lineChart, options = null) {
|
package/lib/model.js
CHANGED
|
@@ -14,7 +14,7 @@ import {validateType} from 'schema-markdown/lib/schema.js';
|
|
|
14
14
|
* @returns {Object}
|
|
15
15
|
*/
|
|
16
16
|
export function validateBarChart(barChart) {
|
|
17
|
-
return validateType(
|
|
17
|
+
return validateType(chartTypes, 'BarChart', barChart);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
|
|
@@ -25,7 +25,7 @@ export function validateBarChart(barChart) {
|
|
|
25
25
|
* @returns {Object}
|
|
26
26
|
*/
|
|
27
27
|
export function validateDataTable(dataTable) {
|
|
28
|
-
return validateType(
|
|
28
|
+
return validateType(chartTypes, 'DataTable', dataTable);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
|
|
@@ -36,14 +36,14 @@ export function validateDataTable(dataTable) {
|
|
|
36
36
|
* @returns {Object}
|
|
37
37
|
*/
|
|
38
38
|
export function validateLineChart(lineChart) {
|
|
39
|
-
return validateType(
|
|
39
|
+
return validateType(chartTypes, 'LineChart', lineChart);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* The chart model defined using Schema Markdown
|
|
45
45
|
*/
|
|
46
|
-
|
|
46
|
+
const chartSmd = `\
|
|
47
47
|
# Base struct for all chart types
|
|
48
48
|
struct ChartBase
|
|
49
49
|
|
|
@@ -288,11 +288,5 @@ struct AxisTicks
|
|
|
288
288
|
|
|
289
289
|
/**
|
|
290
290
|
* The chart model
|
|
291
|
-
*
|
|
292
|
-
* @property {string} title - The model's title
|
|
293
|
-
* @property {Object} types - The model's referenced types dictionary
|
|
294
291
|
*/
|
|
295
|
-
export const
|
|
296
|
-
'title': 'The Chart Model',
|
|
297
|
-
'types': (new SchemaMarkdownParser(chartModelSmd)).types
|
|
298
|
-
};
|
|
292
|
+
export const chartTypes = (new SchemaMarkdownParser(chartSmd)).types;
|