@malloydata/render 0.0.33 → 0.0.34-dev230523182411
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/dist/data_styles.d.ts +9 -3
- package/dist/html/area_sparkline.d.ts +6 -0
- package/dist/html/area_sparkline.js +104 -0
- package/dist/html/bar_sparkline.d.ts +10 -0
- package/dist/html/bar_sparkline.js +105 -0
- package/dist/html/cartesian_chart.js +2 -0
- package/dist/html/column_sparkline.d.ts +10 -0
- package/dist/html/column_sparkline.js +106 -0
- package/dist/html/html_view.js +20 -0
- package/dist/html/sparkline.d.ts +10 -0
- package/dist/html/sparkline.js +109 -0
- package/package.json +2 -2
package/dist/data_styles.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ export declare type RenderDef = ({
|
|
|
46
46
|
} & PercentRenderOptions) | ({
|
|
47
47
|
renderer: 'boolean';
|
|
48
48
|
} & BooleanRenderOptions) | ({
|
|
49
|
-
renderer: '
|
|
49
|
+
renderer: 'sparkline';
|
|
50
50
|
} & SparkLineRenderOptions) | ({
|
|
51
51
|
renderer: 'bytes';
|
|
52
52
|
} & BytesRenderOptions) | ({
|
|
@@ -145,14 +145,20 @@ export interface CartesianChartRenderOptions extends ChartRenderOptions {
|
|
|
145
145
|
export interface BarChartRenderOptions extends DataRenderOptions {
|
|
146
146
|
size?: ChartSize;
|
|
147
147
|
}
|
|
148
|
+
export interface BarSparkLineRenderOptions extends BarChartRenderOptions {
|
|
149
|
+
size?: ChartSize;
|
|
150
|
+
}
|
|
151
|
+
export interface ColumnSparkLineRenderOptions extends BarChartRenderOptions {
|
|
152
|
+
size?: ChartSize;
|
|
153
|
+
}
|
|
148
154
|
export interface ScatterChartRenderOptions extends CartesianChartRenderOptions {
|
|
149
155
|
scatter_chart?: Record<string, unknown>;
|
|
150
156
|
}
|
|
151
157
|
export interface LineChartRenderOptions extends CartesianChartRenderOptions {
|
|
152
158
|
line_chart?: Record<string, unknown>;
|
|
153
159
|
}
|
|
154
|
-
export interface SparkLineRenderOptions extends
|
|
155
|
-
|
|
160
|
+
export interface SparkLineRenderOptions extends DataRenderOptions {
|
|
161
|
+
size?: ChartSize;
|
|
156
162
|
}
|
|
157
163
|
export interface PointMapRenderOptions extends ChartRenderOptions {
|
|
158
164
|
chart?: {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { HTMLSparkLineRenderer } from './sparkline';
|
|
2
|
+
import { DataArray } from '@malloydata/malloy';
|
|
3
|
+
import * as lite from 'vega-lite';
|
|
4
|
+
export declare class HTMLAreaSparkLineRenderer extends HTMLSparkLineRenderer {
|
|
5
|
+
getVegaLiteSpec(data: DataArray): lite.TopLevelSpec;
|
|
6
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.HTMLAreaSparkLineRenderer = void 0;
|
|
26
|
+
const sparkline_1 = require("./sparkline");
|
|
27
|
+
const utils_1 = require("./utils");
|
|
28
|
+
const vega_spec_1 = require("./vega_spec");
|
|
29
|
+
class HTMLAreaSparkLineRenderer extends sparkline_1.HTMLSparkLineRenderer {
|
|
30
|
+
getVegaLiteSpec(data) {
|
|
31
|
+
const fields = data.field.intrinsicFields;
|
|
32
|
+
const xField = fields[0];
|
|
33
|
+
const yField = fields[1];
|
|
34
|
+
const colorField = fields[2];
|
|
35
|
+
const xType = this.getDataType(xField);
|
|
36
|
+
const yType = this.getDataType(yField);
|
|
37
|
+
const colorType = colorField ? this.getDataType(colorField) : undefined;
|
|
38
|
+
const colorDef = colorField !== undefined
|
|
39
|
+
? {
|
|
40
|
+
field: colorField.name,
|
|
41
|
+
type: colorType,
|
|
42
|
+
axis: { title: null },
|
|
43
|
+
scale: (0, utils_1.getColorScale)(colorType, false),
|
|
44
|
+
}
|
|
45
|
+
: { value: '#4285F4' };
|
|
46
|
+
const xSort = xType === 'nominal' ? null : undefined;
|
|
47
|
+
const ySort = yType === 'nominal' ? null : undefined;
|
|
48
|
+
const xDef = {
|
|
49
|
+
field: xField.name,
|
|
50
|
+
type: xType,
|
|
51
|
+
sort: xSort,
|
|
52
|
+
axis: {
|
|
53
|
+
title: null,
|
|
54
|
+
domain: false,
|
|
55
|
+
grid: false,
|
|
56
|
+
lables: false,
|
|
57
|
+
ticks: false,
|
|
58
|
+
values: [],
|
|
59
|
+
},
|
|
60
|
+
scale: { zero: false },
|
|
61
|
+
};
|
|
62
|
+
const yDef = {
|
|
63
|
+
field: yField.name,
|
|
64
|
+
type: yType,
|
|
65
|
+
sort: ySort,
|
|
66
|
+
axis: {
|
|
67
|
+
title: null,
|
|
68
|
+
domain: false,
|
|
69
|
+
ticks: false,
|
|
70
|
+
grid: false,
|
|
71
|
+
lables: false,
|
|
72
|
+
values: [],
|
|
73
|
+
},
|
|
74
|
+
scale: { zero: false },
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
...vega_spec_1.DEFAULT_SPEC,
|
|
78
|
+
...this.getSize(),
|
|
79
|
+
data: {
|
|
80
|
+
values: this.mapData(data),
|
|
81
|
+
},
|
|
82
|
+
config: {
|
|
83
|
+
view: {
|
|
84
|
+
stroke: 'transparent',
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
mark: {
|
|
88
|
+
type: 'area',
|
|
89
|
+
line: {
|
|
90
|
+
color: '#4285F4',
|
|
91
|
+
},
|
|
92
|
+
point: false,
|
|
93
|
+
},
|
|
94
|
+
encoding: {
|
|
95
|
+
x: xDef,
|
|
96
|
+
y: yDef,
|
|
97
|
+
color: colorDef,
|
|
98
|
+
},
|
|
99
|
+
background: 'transparent',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.HTMLAreaSparkLineRenderer = HTMLAreaSparkLineRenderer;
|
|
104
|
+
//# sourceMappingURL=area_sparkline.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DataArray } from '@malloydata/malloy';
|
|
2
|
+
import * as lite from 'vega-lite';
|
|
3
|
+
import { HTMLBarChartRenderer } from './bar_chart';
|
|
4
|
+
export declare class HTMLBarSparkLineRenderer extends HTMLBarChartRenderer {
|
|
5
|
+
getSize(): {
|
|
6
|
+
height: number;
|
|
7
|
+
width: number;
|
|
8
|
+
};
|
|
9
|
+
getVegaLiteSpec(data: DataArray): lite.TopLevelSpec;
|
|
10
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.HTMLBarSparkLineRenderer = void 0;
|
|
26
|
+
const utils_1 = require("./utils");
|
|
27
|
+
const vega_spec_1 = require("./vega_spec");
|
|
28
|
+
const bar_chart_1 = require("./bar_chart");
|
|
29
|
+
class HTMLBarSparkLineRenderer extends bar_chart_1.HTMLBarChartRenderer {
|
|
30
|
+
getSize() {
|
|
31
|
+
if (this.size === 'large') {
|
|
32
|
+
return { height: 250, width: 100 };
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return { height: 125, width: 50 };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
getVegaLiteSpec(data) {
|
|
39
|
+
const fields = data.field.intrinsicFields;
|
|
40
|
+
const xField = fields[0];
|
|
41
|
+
const yField = fields[1];
|
|
42
|
+
const colorField = fields[2];
|
|
43
|
+
const xType = this.getDataType(xField);
|
|
44
|
+
const yType = this.getDataType(yField);
|
|
45
|
+
const colorType = colorField ? this.getDataType(colorField) : undefined;
|
|
46
|
+
const mark = { type: this.getMark(), tooltip: true };
|
|
47
|
+
const colorDef = colorField !== undefined
|
|
48
|
+
? {
|
|
49
|
+
field: colorField.name,
|
|
50
|
+
type: colorType,
|
|
51
|
+
axis: { title: null },
|
|
52
|
+
scale: (0, utils_1.getColorScale)(colorType, true),
|
|
53
|
+
}
|
|
54
|
+
: { value: '#4285F4' };
|
|
55
|
+
const xSort = xType === 'nominal' ? null : undefined;
|
|
56
|
+
const ySort = yType === 'nominal' ? null : undefined;
|
|
57
|
+
const xDef = {
|
|
58
|
+
field: xField.name,
|
|
59
|
+
type: xType,
|
|
60
|
+
sort: xSort,
|
|
61
|
+
axis: {
|
|
62
|
+
title: null,
|
|
63
|
+
domain: false,
|
|
64
|
+
grid: false,
|
|
65
|
+
ticks: false,
|
|
66
|
+
values: [],
|
|
67
|
+
},
|
|
68
|
+
scale: { zero: false },
|
|
69
|
+
};
|
|
70
|
+
const yDef = {
|
|
71
|
+
field: yField.name,
|
|
72
|
+
type: yType,
|
|
73
|
+
sort: ySort,
|
|
74
|
+
axis: {
|
|
75
|
+
title: null,
|
|
76
|
+
domain: false,
|
|
77
|
+
ticks: false,
|
|
78
|
+
grid: false,
|
|
79
|
+
values: [],
|
|
80
|
+
},
|
|
81
|
+
scale: { zero: false },
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
...vega_spec_1.DEFAULT_SPEC,
|
|
85
|
+
...this.getSize(),
|
|
86
|
+
data: {
|
|
87
|
+
values: this.mapData(data),
|
|
88
|
+
},
|
|
89
|
+
config: {
|
|
90
|
+
view: {
|
|
91
|
+
stroke: 'transparent',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
mark,
|
|
95
|
+
encoding: {
|
|
96
|
+
y: xDef,
|
|
97
|
+
x: yDef,
|
|
98
|
+
color: colorDef,
|
|
99
|
+
},
|
|
100
|
+
background: 'transparent',
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.HTMLBarSparkLineRenderer = HTMLBarSparkLineRenderer;
|
|
105
|
+
//# sourceMappingURL=bar_sparkline.js.map
|
|
@@ -69,12 +69,14 @@ class HTMLCartesianChartRenderer extends chart_1.HTMLChartRenderer {
|
|
|
69
69
|
type: xType,
|
|
70
70
|
sort: xSort,
|
|
71
71
|
axis: { title: (0, utils_1.formatTitle)(this.options, xField.name) },
|
|
72
|
+
scale: { zero: false },
|
|
72
73
|
};
|
|
73
74
|
const yDef = {
|
|
74
75
|
field: yField.name,
|
|
75
76
|
type: yType,
|
|
76
77
|
sort: ySort,
|
|
77
78
|
axis: { title: (0, utils_1.formatTitle)(this.options, yField.name) },
|
|
79
|
+
scale: { zero: false },
|
|
78
80
|
};
|
|
79
81
|
return {
|
|
80
82
|
...vega_spec_1.DEFAULT_SPEC,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DataArray } from '@malloydata/malloy';
|
|
2
|
+
import * as lite from 'vega-lite';
|
|
3
|
+
import { HTMLBarChartRenderer } from './bar_chart';
|
|
4
|
+
export declare class HTMLColumnSparkLineRenderer extends HTMLBarChartRenderer {
|
|
5
|
+
getSize(): {
|
|
6
|
+
height: number;
|
|
7
|
+
width: number;
|
|
8
|
+
};
|
|
9
|
+
getVegaLiteSpec(data: DataArray): lite.TopLevelSpec;
|
|
10
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.HTMLColumnSparkLineRenderer = void 0;
|
|
26
|
+
const utils_1 = require("./utils");
|
|
27
|
+
const vega_spec_1 = require("./vega_spec");
|
|
28
|
+
const bar_chart_1 = require("./bar_chart");
|
|
29
|
+
class HTMLColumnSparkLineRenderer extends bar_chart_1.HTMLBarChartRenderer {
|
|
30
|
+
getSize() {
|
|
31
|
+
if (this.size === 'large') {
|
|
32
|
+
return { height: 100, width: 250 };
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return { height: 50, width: 125 };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
getVegaLiteSpec(data) {
|
|
39
|
+
const fields = data.field.intrinsicFields;
|
|
40
|
+
const xField = fields[0];
|
|
41
|
+
const yField = fields[1];
|
|
42
|
+
const colorField = fields[2];
|
|
43
|
+
const xType = this.getDataType(xField);
|
|
44
|
+
const yType = this.getDataType(yField);
|
|
45
|
+
const colorType = colorField ? this.getDataType(colorField) : undefined;
|
|
46
|
+
// const mark = this.getMark();
|
|
47
|
+
const mark = { type: this.getMark(), tooltip: true };
|
|
48
|
+
const colorDef = colorField !== undefined
|
|
49
|
+
? {
|
|
50
|
+
field: colorField.name,
|
|
51
|
+
type: colorType,
|
|
52
|
+
axis: { title: null },
|
|
53
|
+
scale: (0, utils_1.getColorScale)(colorType, true),
|
|
54
|
+
}
|
|
55
|
+
: { value: '#4285F4' };
|
|
56
|
+
const xSort = xType === 'nominal' ? null : undefined;
|
|
57
|
+
const ySort = yType === 'nominal' ? null : undefined;
|
|
58
|
+
const xDef = {
|
|
59
|
+
field: xField.name,
|
|
60
|
+
type: xType,
|
|
61
|
+
sort: xSort,
|
|
62
|
+
axis: {
|
|
63
|
+
title: null,
|
|
64
|
+
domain: false,
|
|
65
|
+
grid: false,
|
|
66
|
+
ticks: false,
|
|
67
|
+
values: [],
|
|
68
|
+
},
|
|
69
|
+
scale: { zero: false },
|
|
70
|
+
};
|
|
71
|
+
const yDef = {
|
|
72
|
+
field: yField.name,
|
|
73
|
+
type: yType,
|
|
74
|
+
sort: ySort,
|
|
75
|
+
axis: {
|
|
76
|
+
title: null,
|
|
77
|
+
domain: false,
|
|
78
|
+
ticks: false,
|
|
79
|
+
grid: false,
|
|
80
|
+
values: [],
|
|
81
|
+
},
|
|
82
|
+
scale: { zero: false },
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
...vega_spec_1.DEFAULT_SPEC,
|
|
86
|
+
...this.getSize(),
|
|
87
|
+
data: {
|
|
88
|
+
values: this.mapData(data),
|
|
89
|
+
},
|
|
90
|
+
config: {
|
|
91
|
+
view: {
|
|
92
|
+
stroke: 'transparent',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
mark,
|
|
96
|
+
encoding: {
|
|
97
|
+
x: xDef,
|
|
98
|
+
y: yDef,
|
|
99
|
+
color: colorDef,
|
|
100
|
+
},
|
|
101
|
+
background: 'transparent',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.HTMLColumnSparkLineRenderer = HTMLColumnSparkLineRenderer;
|
|
106
|
+
//# sourceMappingURL=column_sparkline.js.map
|
package/dist/html/html_view.js
CHANGED
|
@@ -42,12 +42,16 @@ const point_map_1 = require("./point_map");
|
|
|
42
42
|
const scatter_chart_1 = require("./scatter_chart");
|
|
43
43
|
const segment_map_1 = require("./segment_map");
|
|
44
44
|
const shape_map_1 = require("./shape_map");
|
|
45
|
+
const sparkline_1 = require("./sparkline");
|
|
45
46
|
const table_1 = require("./table");
|
|
46
47
|
const text_1 = require("./text");
|
|
47
48
|
const vega_spec_1 = require("./vega_spec");
|
|
48
49
|
const container_1 = require("./container");
|
|
49
50
|
const utils_1 = require("./utils");
|
|
50
51
|
const unsupported_1 = require("./unsupported");
|
|
52
|
+
const column_sparkline_1 = require("./column_sparkline");
|
|
53
|
+
const bar_sparkline_1 = require("./bar_sparkline");
|
|
54
|
+
const area_sparkline_1 = require("./area_sparkline");
|
|
51
55
|
class HTMLView {
|
|
52
56
|
constructor(document) {
|
|
53
57
|
this.document = document;
|
|
@@ -109,6 +113,10 @@ const suffixMap = {
|
|
|
109
113
|
_url: 'link',
|
|
110
114
|
_list: 'list',
|
|
111
115
|
_list_detail: 'list_detail',
|
|
116
|
+
_sparkline: 'sparkline',
|
|
117
|
+
_sparkline_area: 'sparkline',
|
|
118
|
+
_sparkline_column: 'sparkline',
|
|
119
|
+
_sparkline_bar: 'sparkline',
|
|
112
120
|
};
|
|
113
121
|
function getRendererOptions(field, dataStyles) {
|
|
114
122
|
var _a, _b, _c;
|
|
@@ -175,6 +183,18 @@ function makeRenderer(field, document, options, styleDefaults) {
|
|
|
175
183
|
else if (renderDef.renderer === 'line_chart') {
|
|
176
184
|
return new line_chart_1.HTMLLineChartRenderer(document, styleDefaults, options, renderDef);
|
|
177
185
|
}
|
|
186
|
+
else if (renderDef.renderer === 'sparkline') {
|
|
187
|
+
if (field.name.endsWith('_column')) {
|
|
188
|
+
return new column_sparkline_1.HTMLColumnSparkLineRenderer(document, styleDefaults, options, renderDef);
|
|
189
|
+
}
|
|
190
|
+
else if (field.name.endsWith('_bar')) {
|
|
191
|
+
return new bar_sparkline_1.HTMLBarSparkLineRenderer(document, styleDefaults, options, renderDef);
|
|
192
|
+
}
|
|
193
|
+
else if (field.name.endsWith('area')) {
|
|
194
|
+
return new area_sparkline_1.HTMLAreaSparkLineRenderer(document, styleDefaults, options, renderDef);
|
|
195
|
+
}
|
|
196
|
+
return new sparkline_1.HTMLSparkLineRenderer(document, styleDefaults, options, renderDef);
|
|
197
|
+
}
|
|
178
198
|
else if (renderDef.renderer === 'scatter_chart') {
|
|
179
199
|
return new scatter_chart_1.HTMLScatterChartRenderer(document, styleDefaults, options, renderDef);
|
|
180
200
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DataArray } from '@malloydata/malloy';
|
|
2
|
+
import * as lite from 'vega-lite';
|
|
3
|
+
import { HTMLLineChartRenderer } from './line_chart';
|
|
4
|
+
export declare class HTMLSparkLineRenderer extends HTMLLineChartRenderer {
|
|
5
|
+
getSize(): {
|
|
6
|
+
height: number;
|
|
7
|
+
width: number;
|
|
8
|
+
};
|
|
9
|
+
getVegaLiteSpec(data: DataArray): lite.TopLevelSpec;
|
|
10
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.HTMLSparkLineRenderer = void 0;
|
|
26
|
+
const line_chart_1 = require("./line_chart");
|
|
27
|
+
const utils_1 = require("./utils");
|
|
28
|
+
const vega_spec_1 = require("./vega_spec");
|
|
29
|
+
class HTMLSparkLineRenderer extends line_chart_1.HTMLLineChartRenderer {
|
|
30
|
+
getSize() {
|
|
31
|
+
if (this.size === 'large') {
|
|
32
|
+
return { height: 100, width: 250 };
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return { height: 50, width: 125 };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
getVegaLiteSpec(data) {
|
|
39
|
+
const fields = data.field.intrinsicFields;
|
|
40
|
+
const xField = fields[0];
|
|
41
|
+
const yField = fields[1];
|
|
42
|
+
const colorField = fields[2];
|
|
43
|
+
const xType = this.getDataType(xField);
|
|
44
|
+
const yType = this.getDataType(yField);
|
|
45
|
+
const colorType = colorField ? this.getDataType(colorField) : undefined;
|
|
46
|
+
const colorDef = colorField !== undefined
|
|
47
|
+
? {
|
|
48
|
+
field: colorField.name,
|
|
49
|
+
type: colorType,
|
|
50
|
+
axis: { title: null },
|
|
51
|
+
scale: (0, utils_1.getColorScale)(colorType, false),
|
|
52
|
+
}
|
|
53
|
+
: { value: '#4285F4' };
|
|
54
|
+
const xSort = xType === 'nominal' ? null : undefined;
|
|
55
|
+
const ySort = yType === 'nominal' ? null : undefined;
|
|
56
|
+
const xDef = {
|
|
57
|
+
field: xField.name,
|
|
58
|
+
type: xType,
|
|
59
|
+
sort: xSort,
|
|
60
|
+
axis: {
|
|
61
|
+
title: null,
|
|
62
|
+
domain: false,
|
|
63
|
+
grid: false,
|
|
64
|
+
lables: false,
|
|
65
|
+
ticks: false,
|
|
66
|
+
values: [],
|
|
67
|
+
},
|
|
68
|
+
scale: { zero: false },
|
|
69
|
+
};
|
|
70
|
+
const yDef = {
|
|
71
|
+
field: yField.name,
|
|
72
|
+
type: yType,
|
|
73
|
+
sort: ySort,
|
|
74
|
+
axis: {
|
|
75
|
+
title: null,
|
|
76
|
+
domain: false,
|
|
77
|
+
ticks: false,
|
|
78
|
+
grid: false,
|
|
79
|
+
lables: false,
|
|
80
|
+
values: [],
|
|
81
|
+
},
|
|
82
|
+
scale: { zero: false },
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
...vega_spec_1.DEFAULT_SPEC,
|
|
86
|
+
...this.getSize(),
|
|
87
|
+
data: {
|
|
88
|
+
values: this.mapData(data),
|
|
89
|
+
},
|
|
90
|
+
config: {
|
|
91
|
+
view: {
|
|
92
|
+
stroke: 'transparent',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
mark: {
|
|
96
|
+
type: 'line',
|
|
97
|
+
tooltip: true,
|
|
98
|
+
},
|
|
99
|
+
encoding: {
|
|
100
|
+
x: xDef,
|
|
101
|
+
y: yDef,
|
|
102
|
+
color: colorDef,
|
|
103
|
+
},
|
|
104
|
+
background: 'transparent',
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.HTMLSparkLineRenderer = HTMLSparkLineRenderer;
|
|
109
|
+
//# sourceMappingURL=sparkline.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/render",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34-dev230523182411",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"prepublishOnly": "npm run build"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@malloydata/malloy": "^0.0.
|
|
21
|
+
"@malloydata/malloy": "^0.0.34-dev230523182411",
|
|
22
22
|
"lodash": "^4.17.20",
|
|
23
23
|
"us-atlas": "^3.0.0",
|
|
24
24
|
"vega": "^5.21.0",
|