@malloydata/render 0.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/README.md +7 -0
- package/dist/data_styles.d.ts +181 -0
- package/dist/data_styles.js +15 -0
- package/dist/drill.d.ts +10 -0
- package/dist/drill.js +103 -0
- package/dist/html/bar_chart.d.ts +7 -0
- package/dist/html/bar_chart.js +48 -0
- package/dist/html/boolean.d.ts +5 -0
- package/dist/html/boolean.js +26 -0
- package/dist/html/bytes.d.ts +5 -0
- package/dist/html/bytes.js +26 -0
- package/dist/html/cartesian_chart.d.ts +7 -0
- package/dist/html/cartesian_chart.js +88 -0
- package/dist/html/chart.d.ts +21 -0
- package/dist/html/chart.js +105 -0
- package/dist/html/container.d.ts +21 -0
- package/dist/html/container.js +43 -0
- package/dist/html/currency.d.ts +5 -0
- package/dist/html/currency.js +32 -0
- package/dist/html/dashboard.d.ts +7 -0
- package/dist/html/dashboard.js +224 -0
- package/dist/html/date.d.ts +7 -0
- package/dist/html/date.js +38 -0
- package/dist/html/html_view.d.ts +23 -0
- package/dist/html/html_view.js +217 -0
- package/dist/html/image.d.ts +7 -0
- package/dist/html/image.js +34 -0
- package/dist/html/index.d.ts +1 -0
- package/dist/html/index.js +18 -0
- package/dist/html/json.d.ts +7 -0
- package/dist/html/json.js +31 -0
- package/dist/html/line_chart.d.ts +7 -0
- package/dist/html/line_chart.js +51 -0
- package/dist/html/link.d.ts +7 -0
- package/dist/html/link.js +35 -0
- package/dist/html/list.d.ts +9 -0
- package/dist/html/list.js +63 -0
- package/dist/html/list_detail.d.ts +5 -0
- package/dist/html/list_detail.js +23 -0
- package/dist/html/number.d.ts +6 -0
- package/dist/html/number.js +30 -0
- package/dist/html/percent.d.ts +5 -0
- package/dist/html/percent.js +26 -0
- package/dist/html/point_map.d.ts +8 -0
- package/dist/html/point_map.js +147 -0
- package/dist/html/scatter_chart.d.ts +7 -0
- package/dist/html/scatter_chart.js +51 -0
- package/dist/html/segment_map.d.ts +8 -0
- package/dist/html/segment_map.js +128 -0
- package/dist/html/shape_map.d.ts +10 -0
- package/dist/html/shape_map.js +171 -0
- package/dist/html/state_codes.d.ts +3 -0
- package/dist/html/state_codes.js +127 -0
- package/dist/html/table.d.ts +7 -0
- package/dist/html/table.js +111 -0
- package/dist/html/text.d.ts +8 -0
- package/dist/html/text.js +35 -0
- package/dist/html/utils.d.ts +18 -0
- package/dist/html/utils.js +175 -0
- package/dist/html/vega_spec.d.ts +18 -0
- package/dist/html/vega_spec.js +499 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +19 -0
- package/dist/renderer.d.ts +21 -0
- package/dist/renderer.js +23 -0
- package/package.json +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Malloy
|
|
2
|
+
|
|
3
|
+
Malloy is an experimental language for describing data relationships and transformations. It is both a semantic modeling language and a querying language that runs queries against a relational database. Malloy currently connects to BigQuery and Postgres, and natively supports DuckDB. We've built a Visual Studio Code extension to facilitate building Malloy data models, querying and transforming data, and creating simple visualizations and dashboards.
|
|
4
|
+
|
|
5
|
+
## This package
|
|
6
|
+
|
|
7
|
+
This package provides a simple mechanism to render charts based on results from using the `malloydata/malloy` library. See [here](https://github.com/looker-open-source/malloy/blob/main/packages/malloy/README.md) for additional information.
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import * as lite from "vega-lite";
|
|
2
|
+
export declare type DataStyles = {
|
|
3
|
+
[fieldName: string]: RenderDef;
|
|
4
|
+
};
|
|
5
|
+
export declare type ChartSize = "small" | "medium" | "large";
|
|
6
|
+
export declare type RenderDef = ({
|
|
7
|
+
renderer?: undefined;
|
|
8
|
+
} & DataRenderOptions) | ({
|
|
9
|
+
renderer: "table";
|
|
10
|
+
} & TableRenderOptions) | ({
|
|
11
|
+
renderer: "dashboard";
|
|
12
|
+
} & DashboardRenderOptions) | ({
|
|
13
|
+
renderer: "text";
|
|
14
|
+
} & TextRenderOptions) | ({
|
|
15
|
+
renderer: "currency";
|
|
16
|
+
} & CurrencyRenderOptions) | ({
|
|
17
|
+
renderer: "image";
|
|
18
|
+
} & ImageRenderOptions) | ({
|
|
19
|
+
renderer: "time";
|
|
20
|
+
} & TimeRenderOptions) | ({
|
|
21
|
+
renderer: "json";
|
|
22
|
+
} & JSONRenderOptions) | ({
|
|
23
|
+
renderer: "single_value";
|
|
24
|
+
} & SingleValueRenderOptions) | ({
|
|
25
|
+
renderer: "list";
|
|
26
|
+
} & ListRenderOptions) | ({
|
|
27
|
+
renderer: "list_detail";
|
|
28
|
+
} & ListDetailRenderOptions) | ({
|
|
29
|
+
renderer: "cartesian_chart";
|
|
30
|
+
} & CartesianChartRenderOptions) | ({
|
|
31
|
+
renderer: "bar_chart";
|
|
32
|
+
} & BarChartRenderOptions) | ({
|
|
33
|
+
renderer: "scatter_chart";
|
|
34
|
+
} & ScatterChartRenderOptions) | ({
|
|
35
|
+
renderer: "line_chart";
|
|
36
|
+
} & LineChartRenderOptions) | ({
|
|
37
|
+
renderer: "point_map";
|
|
38
|
+
} & PointMapRenderOptions) | ({
|
|
39
|
+
renderer: "segment_map";
|
|
40
|
+
} & SegmentMapRenderOptions) | ({
|
|
41
|
+
renderer: "shape_map";
|
|
42
|
+
} & ShapeMapRenderOptions) | ({
|
|
43
|
+
renderer: "number";
|
|
44
|
+
} & NumberRenderOptions) | ({
|
|
45
|
+
renderer: "percent";
|
|
46
|
+
} & PercentRenderOptions) | ({
|
|
47
|
+
renderer: "boolean";
|
|
48
|
+
} & BooleanRenderOptions) | ({
|
|
49
|
+
renderer: "spark_line";
|
|
50
|
+
} & SparkLineRenderOptions) | ({
|
|
51
|
+
renderer: "bytes";
|
|
52
|
+
} & BytesRenderOptions) | ({
|
|
53
|
+
renderer: "link";
|
|
54
|
+
} & LinkRenderOptions) | ({
|
|
55
|
+
renderer: "vega";
|
|
56
|
+
} & VegaRenderOptions);
|
|
57
|
+
export interface DataRenderOptions {
|
|
58
|
+
data?: {
|
|
59
|
+
color?: string;
|
|
60
|
+
label?: string;
|
|
61
|
+
};
|
|
62
|
+
sheet?: DataStyles;
|
|
63
|
+
}
|
|
64
|
+
export declare type StyleDefaults = {
|
|
65
|
+
size?: ChartSize;
|
|
66
|
+
};
|
|
67
|
+
export interface TableRenderOptions extends DataRenderOptions {
|
|
68
|
+
table?: {
|
|
69
|
+
pivot?: string | string[];
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export interface DashboardRenderOptions extends DataRenderOptions {
|
|
73
|
+
dashboard?: Record<string, unknown>;
|
|
74
|
+
}
|
|
75
|
+
export interface TextRenderOptions extends DataRenderOptions {
|
|
76
|
+
text?: {
|
|
77
|
+
italic?: boolean;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export interface BytesRenderOptions extends TextRenderOptions {
|
|
81
|
+
bytes?: Record<string, unknown>;
|
|
82
|
+
}
|
|
83
|
+
export interface CurrencyRenderOptions extends TextRenderOptions {
|
|
84
|
+
currency?: {
|
|
85
|
+
unit?: "dollars" | "pounds";
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export interface TimeRenderOptions extends TextRenderOptions {
|
|
89
|
+
time?: Record<string, unknown>;
|
|
90
|
+
}
|
|
91
|
+
export interface NumberRenderOptions extends TextRenderOptions {
|
|
92
|
+
number?: Record<string, unknown>;
|
|
93
|
+
}
|
|
94
|
+
export interface ImageRenderOptions extends TextRenderOptions {
|
|
95
|
+
border?: boolean;
|
|
96
|
+
}
|
|
97
|
+
export interface PercentRenderOptions extends TextRenderOptions {
|
|
98
|
+
percent?: Record<string, unknown>;
|
|
99
|
+
}
|
|
100
|
+
export interface BooleanRenderOptions extends TextRenderOptions {
|
|
101
|
+
boolean?: Record<string, unknown>;
|
|
102
|
+
}
|
|
103
|
+
export interface JSONRenderOptions extends DataRenderOptions {
|
|
104
|
+
json?: Record<string, unknown>;
|
|
105
|
+
}
|
|
106
|
+
export interface LinkRenderOptions extends DataRenderOptions {
|
|
107
|
+
link?: Record<string, unknown>;
|
|
108
|
+
}
|
|
109
|
+
export interface VegaRenderOptions extends DataRenderOptions {
|
|
110
|
+
spec?: lite.TopLevelSpec;
|
|
111
|
+
spec_name?: string;
|
|
112
|
+
}
|
|
113
|
+
export interface SingleValueRenderOptions extends DataRenderOptions {
|
|
114
|
+
single_value?: Record<string, unknown>;
|
|
115
|
+
}
|
|
116
|
+
export interface ListRenderOptions extends DataRenderOptions {
|
|
117
|
+
list?: {
|
|
118
|
+
separator?: string;
|
|
119
|
+
value?: string;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export interface ListDetailRenderOptions extends DataRenderOptions {
|
|
123
|
+
list?: {
|
|
124
|
+
separator?: string;
|
|
125
|
+
value?: string;
|
|
126
|
+
detail?: string;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export interface ChartRenderOptions extends DataRenderOptions {
|
|
130
|
+
size?: ChartSize;
|
|
131
|
+
chart?: {
|
|
132
|
+
color?: string;
|
|
133
|
+
shape?: string;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export interface CartesianChartRenderOptions extends ChartRenderOptions {
|
|
137
|
+
chart?: {
|
|
138
|
+
x_axis?: string;
|
|
139
|
+
y_axis?: string;
|
|
140
|
+
color?: string;
|
|
141
|
+
shape?: string;
|
|
142
|
+
spark_line?: boolean;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
export interface BarChartRenderOptions {
|
|
146
|
+
size?: ChartSize;
|
|
147
|
+
}
|
|
148
|
+
export interface ScatterChartRenderOptions extends CartesianChartRenderOptions {
|
|
149
|
+
scatter_chart?: Record<string, unknown>;
|
|
150
|
+
}
|
|
151
|
+
export interface LineChartRenderOptions extends CartesianChartRenderOptions {
|
|
152
|
+
line_chart?: Record<string, unknown>;
|
|
153
|
+
}
|
|
154
|
+
export interface SparkLineRenderOptions extends LineChartRenderOptions {
|
|
155
|
+
spark_line?: Record<string, unknown>;
|
|
156
|
+
}
|
|
157
|
+
export interface PointMapRenderOptions extends ChartRenderOptions {
|
|
158
|
+
chart?: {
|
|
159
|
+
latitude?: string;
|
|
160
|
+
longitude?: string;
|
|
161
|
+
color?: string;
|
|
162
|
+
shape?: string;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
export interface SegmentMapRenderOptions extends ChartRenderOptions {
|
|
166
|
+
chart?: {
|
|
167
|
+
latitude1?: string;
|
|
168
|
+
longitude1?: string;
|
|
169
|
+
latitude2?: string;
|
|
170
|
+
longitude2?: string;
|
|
171
|
+
color?: string;
|
|
172
|
+
shape?: string;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
export interface ShapeMapRenderOptions extends ChartRenderOptions {
|
|
176
|
+
chart?: {
|
|
177
|
+
region?: string;
|
|
178
|
+
color?: string;
|
|
179
|
+
shape?: string;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU General Public License
|
|
7
|
+
* version 2 as published by the Free Software Foundation.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
//# sourceMappingURL=data_styles.js.map
|
package/dist/drill.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DataArrayOrRecord, Explore } from "@malloydata/malloy";
|
|
2
|
+
export declare function getDrillFilters(data: DataArrayOrRecord): {
|
|
3
|
+
formattedFilters: string[];
|
|
4
|
+
source: Explore | undefined;
|
|
5
|
+
};
|
|
6
|
+
export declare function getDrillQuery(data: DataArrayOrRecord): {
|
|
7
|
+
drillQuery: string;
|
|
8
|
+
drillFilters: string[];
|
|
9
|
+
};
|
|
10
|
+
export declare type DrillFunction = (drillQuery: string, target: HTMLElement, drillFilters: string[]) => void;
|
package/dist/drill.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU General Public License
|
|
7
|
+
* version 2 as published by the Free Software Foundation.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getDrillQuery = exports.getDrillFilters = void 0;
|
|
16
|
+
const malloy_1 = require("@malloydata/malloy");
|
|
17
|
+
const utils_1 = require("./html/utils");
|
|
18
|
+
function filterQuote(s) {
|
|
19
|
+
return `'${s.replace("'", "\\'")}'`;
|
|
20
|
+
}
|
|
21
|
+
function timestampToDateFilter(key, value, timeframe) {
|
|
22
|
+
const adjustedTimeframe = timeframe === malloy_1.TimestampTimeframe.Minute
|
|
23
|
+
? malloy_1.TimestampTimeframe.Second
|
|
24
|
+
: timeframe || malloy_1.TimestampTimeframe.Second;
|
|
25
|
+
const filterValue = "@" + (0, utils_1.timeToString)(value, adjustedTimeframe);
|
|
26
|
+
return { key, value: filterValue };
|
|
27
|
+
}
|
|
28
|
+
function getTableFilters(table) {
|
|
29
|
+
const filters = [];
|
|
30
|
+
for (const f of table.field.filters || []) {
|
|
31
|
+
if (!f.aggregate) {
|
|
32
|
+
filters.push({ key: f.code, value: undefined });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return filters;
|
|
36
|
+
}
|
|
37
|
+
function getRowFilters(row) {
|
|
38
|
+
const filters = [];
|
|
39
|
+
const dimensions = row.field.intrinsicFields.filter((field) => field.isAtomicField() && field.sourceWasDimension());
|
|
40
|
+
for (const dim of dimensions) {
|
|
41
|
+
const cell = row.cell(dim);
|
|
42
|
+
// if we have an expression, use it instead of the name of the field.
|
|
43
|
+
const key = dim.isAtomicField() || dim.isQueryField() ? dim.expression : undefined;
|
|
44
|
+
if (key && !cell.isArray()) {
|
|
45
|
+
if (cell.isNull()) {
|
|
46
|
+
filters.push({ key, value: "null" });
|
|
47
|
+
}
|
|
48
|
+
else if (cell.isString()) {
|
|
49
|
+
filters.push({ key, value: filterQuote(cell.value) });
|
|
50
|
+
}
|
|
51
|
+
else if (cell.isNumber() || cell.isBoolean()) {
|
|
52
|
+
filters.push({ key, value: cell.value.toString() });
|
|
53
|
+
}
|
|
54
|
+
else if (cell.isTimestamp() || cell.isDate()) {
|
|
55
|
+
filters.push(timestampToDateFilter(key, cell.value, cell.field.timeframe));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return filters;
|
|
60
|
+
}
|
|
61
|
+
function getFilters(data) {
|
|
62
|
+
if (data.isRecord()) {
|
|
63
|
+
return getRowFilters(data);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return getTableFilters(data);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function getDrillFilters(data) {
|
|
70
|
+
const filters = [];
|
|
71
|
+
let current = data;
|
|
72
|
+
while (current.parent) {
|
|
73
|
+
filters.push(...getFilters(current));
|
|
74
|
+
current = current.parent;
|
|
75
|
+
}
|
|
76
|
+
filters.push(...getFilters(current));
|
|
77
|
+
const source = current.field.parentExplore;
|
|
78
|
+
const formattedFilters = [];
|
|
79
|
+
for (const { key, value } of filters) {
|
|
80
|
+
if (value !== undefined) {
|
|
81
|
+
formattedFilters.push(`${key}: ${value}`);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
formattedFilters.push(key);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// TODO HACK: some filters get duplicated by the language, and this
|
|
88
|
+
// is a workaround until that is fixed
|
|
89
|
+
const dedupedFilters = formattedFilters.filter((filter, index) => formattedFilters.find((otherFilter, otherIndex) => otherFilter === filter && index < otherIndex) === undefined);
|
|
90
|
+
return { formattedFilters: dedupedFilters, source };
|
|
91
|
+
}
|
|
92
|
+
exports.getDrillFilters = getDrillFilters;
|
|
93
|
+
function getDrillQuery(data) {
|
|
94
|
+
const { formattedFilters, source } = getDrillFilters(data);
|
|
95
|
+
let ret = `query: ${(source === null || source === void 0 ? void 0 : source.name) || '"unable to compute source"'} `;
|
|
96
|
+
if (formattedFilters.length) {
|
|
97
|
+
ret += `{ \n where: \n ${formattedFilters.join(",\n ")}\n \n}\n`;
|
|
98
|
+
}
|
|
99
|
+
const drillQuery = ret + "-> ";
|
|
100
|
+
return { drillQuery, drillFilters: formattedFilters };
|
|
101
|
+
}
|
|
102
|
+
exports.getDrillQuery = getDrillQuery;
|
|
103
|
+
//# sourceMappingURL=drill.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DataColumn, Field } from "@malloydata/malloy";
|
|
2
|
+
import { HTMLCartesianChartRenderer } from "./cartesian_chart";
|
|
3
|
+
export declare class HTMLBarChartRenderer extends HTMLCartesianChartRenderer {
|
|
4
|
+
getMark(): "bar";
|
|
5
|
+
getDataType(field: Field): "temporal" | "ordinal" | "quantitative" | "nominal";
|
|
6
|
+
getDataValue(data: DataColumn): Date | string | number | null;
|
|
7
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU General Public License
|
|
7
|
+
* version 2 as published by the Free Software Foundation.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.HTMLBarChartRenderer = void 0;
|
|
16
|
+
const cartesian_chart_1 = require("./cartesian_chart");
|
|
17
|
+
class HTMLBarChartRenderer extends cartesian_chart_1.HTMLCartesianChartRenderer {
|
|
18
|
+
getMark() {
|
|
19
|
+
return "bar";
|
|
20
|
+
}
|
|
21
|
+
getDataType(field) {
|
|
22
|
+
if (field.isAtomicField()) {
|
|
23
|
+
if (field.isDate() || field.isTimestamp() || field.isString()) {
|
|
24
|
+
return "nominal";
|
|
25
|
+
}
|
|
26
|
+
else if (field.isNumber()) {
|
|
27
|
+
return "quantitative";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
throw new Error("Invalid field type for bar chart.");
|
|
31
|
+
}
|
|
32
|
+
getDataValue(data) {
|
|
33
|
+
if (data.isNull()) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
else if (data.isTimestamp() ||
|
|
37
|
+
data.isDate() ||
|
|
38
|
+
data.isNumber() ||
|
|
39
|
+
data.isString()) {
|
|
40
|
+
return data.value;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error("Invalid field type for bar chart.");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.HTMLBarChartRenderer = HTMLBarChartRenderer;
|
|
48
|
+
//# sourceMappingURL=bar_chart.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU General Public License
|
|
7
|
+
* version 2 as published by the Free Software Foundation.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.HTMLBooleanRenderer = void 0;
|
|
16
|
+
const text_1 = require("./text");
|
|
17
|
+
class HTMLBooleanRenderer extends text_1.HTMLTextRenderer {
|
|
18
|
+
getText(data) {
|
|
19
|
+
if (data.isNull()) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return `${data.boolean.value}`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.HTMLBooleanRenderer = HTMLBooleanRenderer;
|
|
26
|
+
//# sourceMappingURL=boolean.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU General Public License
|
|
7
|
+
* version 2 as published by the Free Software Foundation.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.HTMLBytesRenderer = void 0;
|
|
16
|
+
const text_1 = require("./text");
|
|
17
|
+
class HTMLBytesRenderer extends text_1.HTMLTextRenderer {
|
|
18
|
+
getText(data) {
|
|
19
|
+
if (data.isNull()) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return data.bytes.value.toString("base64");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.HTMLBytesRenderer = HTMLBytesRenderer;
|
|
26
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DataArray } from "@malloydata/malloy";
|
|
2
|
+
import * as lite from "vega-lite";
|
|
3
|
+
import { HTMLChartRenderer } from "./chart";
|
|
4
|
+
export declare abstract class HTMLCartesianChartRenderer extends HTMLChartRenderer {
|
|
5
|
+
abstract getMark(): "bar" | "line" | "point";
|
|
6
|
+
getVegaLiteSpec(data: DataArray): lite.TopLevelSpec;
|
|
7
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU General Public License
|
|
7
|
+
* version 2 as published by the Free Software Foundation.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.HTMLCartesianChartRenderer = void 0;
|
|
16
|
+
const chart_1 = require("./chart");
|
|
17
|
+
const utils_1 = require("./utils");
|
|
18
|
+
const vega_spec_1 = require("./vega_spec");
|
|
19
|
+
class HTMLCartesianChartRenderer extends chart_1.HTMLChartRenderer {
|
|
20
|
+
getVegaLiteSpec(data) {
|
|
21
|
+
const fields = data.field.intrinsicFields;
|
|
22
|
+
const xField = fields[0];
|
|
23
|
+
const yField = fields[1];
|
|
24
|
+
const colorField = fields[2];
|
|
25
|
+
const sizeField = fields[3];
|
|
26
|
+
const shapeField = fields[4];
|
|
27
|
+
const xType = this.getDataType(xField);
|
|
28
|
+
const yType = this.getDataType(yField);
|
|
29
|
+
const colorType = colorField ? this.getDataType(colorField) : undefined;
|
|
30
|
+
const sizeType = sizeField ? this.getDataType(sizeField) : undefined;
|
|
31
|
+
const shapeType = shapeField ? this.getDataType(shapeField) : undefined;
|
|
32
|
+
const mark = this.getMark();
|
|
33
|
+
const colorDef = colorField !== undefined
|
|
34
|
+
? {
|
|
35
|
+
field: colorField.name,
|
|
36
|
+
type: colorType,
|
|
37
|
+
axis: { title: colorField.name },
|
|
38
|
+
scale: (0, utils_1.getColorScale)(colorType, mark === "bar"),
|
|
39
|
+
}
|
|
40
|
+
: { value: "#4285F4" };
|
|
41
|
+
const sizeDef = sizeField
|
|
42
|
+
? {
|
|
43
|
+
field: sizeField.name,
|
|
44
|
+
type: sizeType,
|
|
45
|
+
axis: { title: sizeField.name },
|
|
46
|
+
}
|
|
47
|
+
: undefined;
|
|
48
|
+
const shapeDef = shapeField
|
|
49
|
+
? {
|
|
50
|
+
field: shapeField.name,
|
|
51
|
+
type: shapeType,
|
|
52
|
+
axis: { title: shapeField.name },
|
|
53
|
+
}
|
|
54
|
+
: undefined;
|
|
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: { title: xField.name },
|
|
62
|
+
};
|
|
63
|
+
const yDef = {
|
|
64
|
+
field: yField.name,
|
|
65
|
+
type: yType,
|
|
66
|
+
sort: ySort,
|
|
67
|
+
axis: { title: yField.name },
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
...vega_spec_1.DEFAULT_SPEC,
|
|
71
|
+
...this.getSize(),
|
|
72
|
+
data: {
|
|
73
|
+
values: this.mapData(data),
|
|
74
|
+
},
|
|
75
|
+
mark,
|
|
76
|
+
encoding: {
|
|
77
|
+
x: xDef,
|
|
78
|
+
y: yDef,
|
|
79
|
+
size: sizeDef,
|
|
80
|
+
color: colorDef,
|
|
81
|
+
shape: shapeDef,
|
|
82
|
+
},
|
|
83
|
+
background: "transparent",
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.HTMLCartesianChartRenderer = HTMLCartesianChartRenderer;
|
|
88
|
+
//# sourceMappingURL=cartesian_chart.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as lite from "vega-lite";
|
|
2
|
+
import { DataArray, DataColumn, Field } from "@malloydata/malloy";
|
|
3
|
+
import { Renderer } from "../renderer";
|
|
4
|
+
import { ChartRenderOptions, StyleDefaults } from "../data_styles";
|
|
5
|
+
export declare abstract class HTMLChartRenderer implements Renderer {
|
|
6
|
+
protected readonly document: Document;
|
|
7
|
+
protected styleDefaults: StyleDefaults;
|
|
8
|
+
size: string;
|
|
9
|
+
abstract getDataType(field: Field): "temporal" | "ordinal" | "quantitative" | "nominal";
|
|
10
|
+
abstract getDataValue(value: DataColumn): Date | string | number | null | undefined;
|
|
11
|
+
mapData(data: DataArray): {
|
|
12
|
+
[p: string]: string | number | Date | undefined | null;
|
|
13
|
+
}[];
|
|
14
|
+
getSize(): {
|
|
15
|
+
height: number;
|
|
16
|
+
width: number;
|
|
17
|
+
};
|
|
18
|
+
constructor(document: Document, styleDefaults: StyleDefaults, options?: ChartRenderOptions);
|
|
19
|
+
abstract getVegaLiteSpec(data: DataArray): lite.TopLevelSpec;
|
|
20
|
+
render(table: DataColumn): Promise<HTMLElement>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU General Public License
|
|
7
|
+
* version 2 as published by the Free Software Foundation.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*/
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
+
}) : function(o, v) {
|
|
28
|
+
o["default"] = v;
|
|
29
|
+
});
|
|
30
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.HTMLChartRenderer = void 0;
|
|
39
|
+
const lite = __importStar(require("vega-lite"));
|
|
40
|
+
const vega = __importStar(require("vega"));
|
|
41
|
+
class HTMLChartRenderer {
|
|
42
|
+
constructor(document, styleDefaults, options = {}) {
|
|
43
|
+
this.document = document;
|
|
44
|
+
this.styleDefaults = styleDefaults;
|
|
45
|
+
this.size = options.size || this.styleDefaults.size || "medium";
|
|
46
|
+
}
|
|
47
|
+
mapData(data) {
|
|
48
|
+
const mappedRows = [];
|
|
49
|
+
for (const row of data) {
|
|
50
|
+
const mappedRow = {};
|
|
51
|
+
for (const field of data.field.intrinsicFields) {
|
|
52
|
+
mappedRow[field.name] = this.getDataValue(row.cell(field));
|
|
53
|
+
}
|
|
54
|
+
mappedRows.push(mappedRow);
|
|
55
|
+
}
|
|
56
|
+
return mappedRows;
|
|
57
|
+
}
|
|
58
|
+
getSize() {
|
|
59
|
+
if (this.size === "large") {
|
|
60
|
+
return { height: 350, width: 500 };
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return { height: 175, width: 250 };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async render(table) {
|
|
67
|
+
if (!table.isArray()) {
|
|
68
|
+
throw new Error("Invalid type for chart renderer");
|
|
69
|
+
}
|
|
70
|
+
const spec = this.getVegaLiteSpec(table);
|
|
71
|
+
const vegaspec = lite.compile(spec, {
|
|
72
|
+
logger: {
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
level(newLevel) {
|
|
76
|
+
if (newLevel !== undefined) {
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
return 0;
|
|
80
|
+
},
|
|
81
|
+
info() {
|
|
82
|
+
return this;
|
|
83
|
+
},
|
|
84
|
+
error() {
|
|
85
|
+
return this;
|
|
86
|
+
},
|
|
87
|
+
warn() {
|
|
88
|
+
return this;
|
|
89
|
+
},
|
|
90
|
+
debug() {
|
|
91
|
+
return this;
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
}).spec;
|
|
95
|
+
const view = new vega.View(vega.parse(vegaspec), {
|
|
96
|
+
renderer: "none",
|
|
97
|
+
});
|
|
98
|
+
view.logger().level(-1);
|
|
99
|
+
const element = this.document.createElement("div");
|
|
100
|
+
element.innerHTML = await view.toSVG();
|
|
101
|
+
return element;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.HTMLChartRenderer = HTMLChartRenderer;
|
|
105
|
+
//# sourceMappingURL=chart.js.map
|