@malloydata/render 0.0.116-dev240104000530 → 0.0.116-dev240104225124
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/component/bar-chart.d.ts +9 -0
- package/dist/component/bar-chart.js +130 -0
- package/dist/component/chart-settings.d.ts +30 -0
- package/dist/component/chart-settings.js +152 -0
- package/dist/component/render-result-metadata.d.ts +2 -0
- package/dist/component/render-result-metadata.js +21 -17
- package/dist/component/render.d.ts +1 -0
- package/dist/component/render.js +1 -0
- package/dist/component/table-layout.d.ts +11 -0
- package/dist/component/table-layout.js +83 -0
- package/dist/component/table.d.ts +5 -5
- package/dist/component/table.js +47 -58
- package/dist/component/util.d.ts +2 -0
- package/dist/component/util.js +15 -1
- package/dist/component/vega-chart.d.ts +15 -0
- package/dist/component/vega-chart.js +105 -0
- package/dist/component/vega-lite-base-spec.d.ts +2 -0
- package/dist/component/vega-lite-base-spec.js +61 -0
- package/dist/component/vega-types.d.ts +10 -0
- package/dist/component/vega-types.js +34 -0
- package/dist/stories/bars.stories.d.ts +23 -0
- package/dist/stories/bars.stories.js +46 -0
- package/package.json +2 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import './vega-chart';
|
|
3
|
+
import { DataArray } from '@malloydata/malloy';
|
|
4
|
+
import { RenderResultMetadata } from './render-result-metadata';
|
|
5
|
+
export declare class BarChart extends LitElement {
|
|
6
|
+
data: DataArray;
|
|
7
|
+
metadata: RenderResultMetadata;
|
|
8
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.BarChart = void 0;
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2023 Google LLC
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files
|
|
15
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
16
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
17
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
18
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
19
|
+
* subject to the following conditions:
|
|
20
|
+
*
|
|
21
|
+
* The above copyright notice and this permission notice shall be
|
|
22
|
+
* included in all copies or substantial portions of the Software.
|
|
23
|
+
*
|
|
24
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
25
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
26
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
27
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
28
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
29
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
30
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
31
|
+
*/
|
|
32
|
+
const lit_1 = require("lit");
|
|
33
|
+
const decorators_js_1 = require("lit/decorators.js");
|
|
34
|
+
require("./vega-chart");
|
|
35
|
+
const context_1 = require("@lit/context");
|
|
36
|
+
const result_context_1 = require("./result-context");
|
|
37
|
+
const chart_settings_1 = require("./chart-settings");
|
|
38
|
+
const vega_lite_base_spec_1 = require("./vega-lite-base-spec");
|
|
39
|
+
const util_1 = require("./util");
|
|
40
|
+
let BarChart = class BarChart extends lit_1.LitElement {
|
|
41
|
+
render() {
|
|
42
|
+
const field = this.data.field;
|
|
43
|
+
const keys = field.allFields;
|
|
44
|
+
const { tag } = field.tagParse();
|
|
45
|
+
const isSpark = tag.text('size') === 'spark';
|
|
46
|
+
const chartSettings = (0, chart_settings_1.getChartSettings)(field, this.metadata);
|
|
47
|
+
const records = [];
|
|
48
|
+
for (const rec of this.data) {
|
|
49
|
+
const record = {};
|
|
50
|
+
const xValue = rec.cell(chartSettings.xField.name).value;
|
|
51
|
+
const yValue = rec.cell(chartSettings.yField.name).value;
|
|
52
|
+
if ((0, util_1.valueIsString)(chartSettings.xField, xValue)) {
|
|
53
|
+
record.barDim = xValue;
|
|
54
|
+
}
|
|
55
|
+
if ((0, util_1.valueIsNumber)(chartSettings.yField, yValue)) {
|
|
56
|
+
record.sizeMeasure = yValue;
|
|
57
|
+
}
|
|
58
|
+
records.push(record);
|
|
59
|
+
}
|
|
60
|
+
const spec = (0, vega_lite_base_spec_1.baseSpec)();
|
|
61
|
+
spec.data = {
|
|
62
|
+
values: records,
|
|
63
|
+
};
|
|
64
|
+
spec.layer = [
|
|
65
|
+
{
|
|
66
|
+
mark: {
|
|
67
|
+
type: 'bar',
|
|
68
|
+
width: { 'band': 0.8 },
|
|
69
|
+
cornerRadiusEnd: 0,
|
|
70
|
+
},
|
|
71
|
+
encoding: {
|
|
72
|
+
x: {
|
|
73
|
+
field: 'barDim',
|
|
74
|
+
type: 'nominal',
|
|
75
|
+
sort: null, // Uses the sort order of underlying data
|
|
76
|
+
axis: {
|
|
77
|
+
labelAngle: chartSettings.xAxis.labelAngle,
|
|
78
|
+
maxExtent: chartSettings.xAxis.height,
|
|
79
|
+
labelLimit: chartSettings.xAxis.labelSize,
|
|
80
|
+
title: keys[0].name,
|
|
81
|
+
},
|
|
82
|
+
scale: {},
|
|
83
|
+
},
|
|
84
|
+
y: {
|
|
85
|
+
field: 'sizeMeasure',
|
|
86
|
+
type: 'quantitative',
|
|
87
|
+
scale: {
|
|
88
|
+
domain: chartSettings.yScale.domain,
|
|
89
|
+
},
|
|
90
|
+
axis: {
|
|
91
|
+
maxExtent: chartSettings.yAxis.width,
|
|
92
|
+
labelLimit: chartSettings.yAxis.width + 10,
|
|
93
|
+
tickCount: chartSettings.yAxis.tickCount,
|
|
94
|
+
title: keys[1].name,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
// TODO: fill color from theme
|
|
98
|
+
fill: { value: '#53B2C8' },
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
if (isSpark) {
|
|
103
|
+
spec.padding = 0;
|
|
104
|
+
spec.layer[0].encoding.y.axis = null;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
spec.padding = chartSettings.padding;
|
|
108
|
+
}
|
|
109
|
+
return (0, lit_1.html) `<div style="">
|
|
110
|
+
<malloy-vega-chart
|
|
111
|
+
.spec="${spec}"
|
|
112
|
+
type="vega-lite"
|
|
113
|
+
width="${chartSettings.plotWidth}"
|
|
114
|
+
height="${chartSettings.plotHeight}"
|
|
115
|
+
></malloy-vega-chart>
|
|
116
|
+
</div>`;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
exports.BarChart = BarChart;
|
|
120
|
+
__decorate([
|
|
121
|
+
(0, decorators_js_1.property)({ attribute: false })
|
|
122
|
+
], BarChart.prototype, "data", void 0);
|
|
123
|
+
__decorate([
|
|
124
|
+
(0, context_1.consume)({ context: result_context_1.resultContext }),
|
|
125
|
+
(0, decorators_js_1.property)({ attribute: false })
|
|
126
|
+
], BarChart.prototype, "metadata", void 0);
|
|
127
|
+
exports.BarChart = BarChart = __decorate([
|
|
128
|
+
(0, decorators_js_1.customElement)('malloy-bar-chart')
|
|
129
|
+
], BarChart);
|
|
130
|
+
//# sourceMappingURL=bar-chart.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ExploreField, Field } from '@malloydata/malloy';
|
|
2
|
+
import { RenderResultMetadata } from './render-result-metadata';
|
|
3
|
+
export type ChartSettings = {
|
|
4
|
+
plotWidth: number;
|
|
5
|
+
plotHeight: number;
|
|
6
|
+
xAxis: {
|
|
7
|
+
labelAngle: number;
|
|
8
|
+
labelSize: number;
|
|
9
|
+
height: number;
|
|
10
|
+
titleSize: number;
|
|
11
|
+
};
|
|
12
|
+
yAxis: {
|
|
13
|
+
width: number;
|
|
14
|
+
tickCount?: number;
|
|
15
|
+
};
|
|
16
|
+
yScale: {
|
|
17
|
+
domain: number[];
|
|
18
|
+
};
|
|
19
|
+
xField: Field;
|
|
20
|
+
yField: Field;
|
|
21
|
+
padding: {
|
|
22
|
+
top: number;
|
|
23
|
+
left: number;
|
|
24
|
+
right: number;
|
|
25
|
+
bottom: number;
|
|
26
|
+
};
|
|
27
|
+
totalWidth: number;
|
|
28
|
+
totalHeight: number;
|
|
29
|
+
};
|
|
30
|
+
export declare function getChartSettings(field: ExploreField, metadata: RenderResultMetadata): ChartSettings;
|
|
@@ -0,0 +1,152 @@
|
|
|
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.getChartSettings = void 0;
|
|
26
|
+
const vega_1 = require("vega");
|
|
27
|
+
const util_1 = require("./util");
|
|
28
|
+
// Later should depend on chart type?
|
|
29
|
+
const CHART_SIZES = {
|
|
30
|
+
'spark': [180, 1], // row height
|
|
31
|
+
'xs': [170, 2], // 2x row height
|
|
32
|
+
'sm': [216, 3], // 3x row height
|
|
33
|
+
'md': [256, 4], // 4x row height
|
|
34
|
+
'lg': [472, 7], // 7x row height
|
|
35
|
+
'xl': [508, 10], // 10x row height
|
|
36
|
+
'2xl': [730, 14], // 14x row height
|
|
37
|
+
};
|
|
38
|
+
// TODO: read from theme CSS
|
|
39
|
+
const ROW_HEIGHT = 28;
|
|
40
|
+
function getChartSettings(field, metadata) {
|
|
41
|
+
// TODO: improve logic for field extraction
|
|
42
|
+
const xField = field.allFields.at(0);
|
|
43
|
+
const yField = field.allFields.at(1);
|
|
44
|
+
const { tag } = field.tagParse();
|
|
45
|
+
let chartWidth = 0, chartHeight = 0;
|
|
46
|
+
const customWidth = tag.numeric('size', 'width');
|
|
47
|
+
const customHeight = tag.numeric('size', 'height');
|
|
48
|
+
let presetSize = tag.text('size');
|
|
49
|
+
if (customWidth && customHeight) {
|
|
50
|
+
chartWidth = customWidth;
|
|
51
|
+
chartHeight = customHeight;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
presetSize = presetSize || 'md';
|
|
55
|
+
[chartWidth, chartHeight] = CHART_SIZES[presetSize];
|
|
56
|
+
chartHeight = chartHeight * ROW_HEIGHT;
|
|
57
|
+
}
|
|
58
|
+
let xAxisHeight = 0;
|
|
59
|
+
let yAxisWidth = 0;
|
|
60
|
+
let labelAngle = -90;
|
|
61
|
+
let labelSize = 0;
|
|
62
|
+
let xTitleSize = 0;
|
|
63
|
+
const hasXAxis = presetSize !== 'spark';
|
|
64
|
+
const hasYAxis = presetSize !== 'spark';
|
|
65
|
+
const exploreMetadata = metadata.fields[(0, util_1.getFieldKey)(field)];
|
|
66
|
+
let topPadding = presetSize !== 'spark' ? ROW_HEIGHT - 1 : 0; // Subtract 1 to account for top border
|
|
67
|
+
let yTickCount;
|
|
68
|
+
const yKey = (0, util_1.getFieldKey)(yField);
|
|
69
|
+
const maxVal = metadata.fields[yKey].max;
|
|
70
|
+
const yScale = (0, vega_1.scale)('linear')()
|
|
71
|
+
.domain([0, maxVal])
|
|
72
|
+
.nice()
|
|
73
|
+
.range([chartHeight, 0]);
|
|
74
|
+
const yDomain = yScale.domain();
|
|
75
|
+
if (hasYAxis) {
|
|
76
|
+
const maxAxisVal = yScale.domain().at(1);
|
|
77
|
+
const l = (0, vega_1.locale)();
|
|
78
|
+
const formatted = l.format(',')(maxAxisVal);
|
|
79
|
+
const yTitleSize = 31; // Estimate for now, can be dynamic later
|
|
80
|
+
const yLabelOffset = 5;
|
|
81
|
+
yAxisWidth =
|
|
82
|
+
(0, util_1.getTextWidth)(formatted, 'Inter, sans-serif 12px') +
|
|
83
|
+
yLabelOffset +
|
|
84
|
+
yTitleSize;
|
|
85
|
+
// Check whether we need to adjust axis values manually
|
|
86
|
+
const noOfTicks = Math.ceil(chartHeight / 40);
|
|
87
|
+
const ticks = yScale.ticks(noOfTicks);
|
|
88
|
+
if (ticks.at(-1) < maxAxisVal) {
|
|
89
|
+
const offRatio = (maxAxisVal - ticks.at(-1)) / maxAxisVal;
|
|
90
|
+
// adjust chart height
|
|
91
|
+
const newChartHeight = chartHeight / (1 - offRatio);
|
|
92
|
+
// adjust chart padding
|
|
93
|
+
topPadding = topPadding - (newChartHeight - chartHeight);
|
|
94
|
+
chartHeight = newChartHeight;
|
|
95
|
+
// Hardcode # of ticks, or the resize could make room for more ticks and then screw things up
|
|
96
|
+
yTickCount = noOfTicks;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (hasXAxis) {
|
|
100
|
+
// TODO: add type checking here for axis. for now assume number, string
|
|
101
|
+
const xKey = (0, util_1.getFieldKey)(xField);
|
|
102
|
+
const maxString = metadata.fields[xKey].maxString;
|
|
103
|
+
const maxStringSize = (0, util_1.getTextWidth)(maxString, 'Inter, sans-serif 12px');
|
|
104
|
+
const X_AXIS_THRESHOLD = 0.3;
|
|
105
|
+
const minBottomPadding = 15;
|
|
106
|
+
xTitleSize = 22 + minBottomPadding;
|
|
107
|
+
xAxisHeight = Math.min(maxStringSize, X_AXIS_THRESHOLD * chartHeight);
|
|
108
|
+
labelSize = xAxisHeight;
|
|
109
|
+
const xSpacePerLabel = (chartWidth - yAxisWidth) / exploreMetadata.maxRecordCt;
|
|
110
|
+
if (xSpacePerLabel > xAxisHeight) {
|
|
111
|
+
labelAngle = 0;
|
|
112
|
+
labelSize = xSpacePerLabel;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Additional xTitle padding to snap to row height grid
|
|
116
|
+
const totalSize = chartHeight + xAxisHeight + xTitleSize;
|
|
117
|
+
const roundedUpRowHeight = Math.ceil(totalSize / ROW_HEIGHT) * ROW_HEIGHT;
|
|
118
|
+
xTitleSize += roundedUpRowHeight - totalSize;
|
|
119
|
+
return {
|
|
120
|
+
plotWidth: chartWidth,
|
|
121
|
+
plotHeight: chartHeight,
|
|
122
|
+
xAxis: {
|
|
123
|
+
labelAngle,
|
|
124
|
+
labelSize,
|
|
125
|
+
height: xAxisHeight,
|
|
126
|
+
titleSize: xTitleSize,
|
|
127
|
+
},
|
|
128
|
+
yAxis: {
|
|
129
|
+
width: yAxisWidth,
|
|
130
|
+
tickCount: yTickCount,
|
|
131
|
+
},
|
|
132
|
+
yScale: {
|
|
133
|
+
domain: yDomain,
|
|
134
|
+
},
|
|
135
|
+
padding: {
|
|
136
|
+
top: topPadding,
|
|
137
|
+
left: yAxisWidth,
|
|
138
|
+
bottom: xAxisHeight + xTitleSize,
|
|
139
|
+
right: 0,
|
|
140
|
+
},
|
|
141
|
+
xField,
|
|
142
|
+
yField,
|
|
143
|
+
get totalWidth() {
|
|
144
|
+
return this.plotWidth + this.padding.left + this.padding.right;
|
|
145
|
+
},
|
|
146
|
+
get totalHeight() {
|
|
147
|
+
return this.plotHeight + this.padding.top + this.padding.bottom;
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
exports.getChartSettings = getChartSettings;
|
|
152
|
+
//# sourceMappingURL=chart-settings.js.map
|
|
@@ -26,10 +26,10 @@ exports.getResultMetadata = void 0;
|
|
|
26
26
|
const util_1 = require("./util");
|
|
27
27
|
function getResultMetadata(result) {
|
|
28
28
|
const fieldKeyMap = new WeakMap();
|
|
29
|
-
const
|
|
29
|
+
const getCachedFieldKey = (f) => {
|
|
30
30
|
if (fieldKeyMap.has(f))
|
|
31
31
|
return fieldKeyMap.get(f);
|
|
32
|
-
const fieldKey =
|
|
32
|
+
const fieldKey = (0, util_1.getFieldKey)(f);
|
|
33
33
|
fieldKeyMap.set(f, fieldKey);
|
|
34
34
|
return fieldKey;
|
|
35
35
|
};
|
|
@@ -38,27 +38,28 @@ function getResultMetadata(result) {
|
|
|
38
38
|
};
|
|
39
39
|
function initFieldMeta(e) {
|
|
40
40
|
for (const f of e.allFields) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
41
|
+
const fieldKey = getCachedFieldKey(f);
|
|
42
|
+
metadata.fields[fieldKey] = {
|
|
43
|
+
field: f,
|
|
44
|
+
min: null,
|
|
45
|
+
max: null,
|
|
46
|
+
minString: null,
|
|
47
|
+
maxString: null,
|
|
48
|
+
values: new Set(),
|
|
49
|
+
maxRecordCt: null,
|
|
50
|
+
};
|
|
51
|
+
if (f.isExploreField()) {
|
|
52
52
|
initFieldMeta(f);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
const populateFieldMeta = (data, metadata) => {
|
|
57
|
-
var _a, _b;
|
|
56
|
+
const populateFieldMeta = (data, metadata, cb) => {
|
|
57
|
+
var _a, _b, _c;
|
|
58
58
|
for (const row of data) {
|
|
59
|
+
cb === null || cb === void 0 ? void 0 : cb(row);
|
|
59
60
|
for (const f of data.field.allFields) {
|
|
60
61
|
const value = f.isAtomicField() ? row.cell(f).value : undefined;
|
|
61
|
-
const fieldKey = getFieldKey(f);
|
|
62
|
+
const fieldKey = (0, util_1.getFieldKey)(f);
|
|
62
63
|
const fieldMeta = metadata.fields[fieldKey];
|
|
63
64
|
if ((0, util_1.valueIsNumber)(f, value)) {
|
|
64
65
|
const n = value;
|
|
@@ -67,6 +68,7 @@ function getResultMetadata(result) {
|
|
|
67
68
|
}
|
|
68
69
|
else if ((0, util_1.valueIsString)(f, value)) {
|
|
69
70
|
const s = value;
|
|
71
|
+
fieldMeta.values.add(s);
|
|
70
72
|
if (!fieldMeta.minString || fieldMeta.minString.length > s.length)
|
|
71
73
|
fieldMeta.minString = s;
|
|
72
74
|
if (!fieldMeta.maxString || fieldMeta.maxString.length < s.length)
|
|
@@ -74,7 +76,9 @@ function getResultMetadata(result) {
|
|
|
74
76
|
}
|
|
75
77
|
else if (f.isExploreField()) {
|
|
76
78
|
const data = row.cell(f);
|
|
77
|
-
|
|
79
|
+
let recordCt = 0;
|
|
80
|
+
populateFieldMeta(data, metadata, () => recordCt++);
|
|
81
|
+
fieldMeta.maxRecordCt = Math.max((_c = fieldMeta.maxRecordCt) !== null && _c !== void 0 ? _c : recordCt, recordCt);
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Result } from '@malloydata/malloy';
|
|
2
2
|
import { LitElement, PropertyValues } from 'lit';
|
|
3
3
|
import './table';
|
|
4
|
+
import './bar-chart';
|
|
4
5
|
import { RenderResultMetadata } from './render-result-metadata';
|
|
5
6
|
export declare class MalloyRender extends LitElement {
|
|
6
7
|
static styles: import("lit").CSSResult;
|
package/dist/component/render.js
CHANGED
|
@@ -32,6 +32,7 @@ exports.MalloyRender = void 0;
|
|
|
32
32
|
const lit_1 = require("lit");
|
|
33
33
|
const decorators_js_1 = require("lit/decorators.js");
|
|
34
34
|
require("./table");
|
|
35
|
+
require("./bar-chart");
|
|
35
36
|
const context_1 = require("@lit/context");
|
|
36
37
|
const result_context_1 = require("./result-context");
|
|
37
38
|
const render_result_metadata_1 = require("./render-result-metadata");
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FieldRenderMetadata, RenderResultMetadata } from './render-result-metadata';
|
|
2
|
+
import { ChartSettings } from './chart-settings';
|
|
3
|
+
type LayoutEntry = {
|
|
4
|
+
metadata: FieldRenderMetadata;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number | null;
|
|
7
|
+
chartSettings: ChartSettings | null;
|
|
8
|
+
};
|
|
9
|
+
export type TableLayout = Record<string, LayoutEntry>;
|
|
10
|
+
export declare function getTableLayout(metadata: RenderResultMetadata): TableLayout;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
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.getTableLayout = void 0;
|
|
26
|
+
const util_1 = require("./util");
|
|
27
|
+
const render_numeric_field_1 = require("./render-numeric-field");
|
|
28
|
+
const chart_settings_1 = require("./chart-settings");
|
|
29
|
+
const MIN_COLUMN_WIDTH = 32;
|
|
30
|
+
const MAX_COLUMN_WIDTH = 384;
|
|
31
|
+
const COLUMN_BUFFER = 12;
|
|
32
|
+
// TODO: get from theme
|
|
33
|
+
const ROW_HEIGHT = 28;
|
|
34
|
+
function getTableLayout(metadata) {
|
|
35
|
+
const layout = {};
|
|
36
|
+
for (const [key, fieldMeta] of Object.entries(metadata.fields)) {
|
|
37
|
+
const field = fieldMeta.field;
|
|
38
|
+
const layoutEntry = {
|
|
39
|
+
metadata: fieldMeta,
|
|
40
|
+
width: getColumnWidth(field, metadata),
|
|
41
|
+
height: null,
|
|
42
|
+
chartSettings: null,
|
|
43
|
+
};
|
|
44
|
+
const { tag } = field.tagParse();
|
|
45
|
+
if (tag.has('bar') && field.isExploreField()) {
|
|
46
|
+
layoutEntry.chartSettings = (0, chart_settings_1.getChartSettings)(field, metadata);
|
|
47
|
+
layoutEntry.width = layoutEntry.chartSettings.totalWidth;
|
|
48
|
+
layoutEntry.height = layoutEntry.chartSettings.totalHeight;
|
|
49
|
+
}
|
|
50
|
+
else if (field.isAtomicField()) {
|
|
51
|
+
layoutEntry.height = ROW_HEIGHT;
|
|
52
|
+
}
|
|
53
|
+
layout[key] = layoutEntry;
|
|
54
|
+
}
|
|
55
|
+
return layout;
|
|
56
|
+
}
|
|
57
|
+
exports.getTableLayout = getTableLayout;
|
|
58
|
+
function getColumnWidth(f, metadata) {
|
|
59
|
+
const fieldKey = (0, util_1.getFieldKey)(f);
|
|
60
|
+
const fieldMeta = metadata.fields[fieldKey];
|
|
61
|
+
let width = 0;
|
|
62
|
+
if (f.isAtomicField()) {
|
|
63
|
+
// TODO: get font styles from theme
|
|
64
|
+
const font = `12px Inter, sans-serif`;
|
|
65
|
+
const titleWidth = (0, util_1.getTextWidth)(f.name, font);
|
|
66
|
+
if (f.isAtomicField() && f.isString()) {
|
|
67
|
+
width =
|
|
68
|
+
Math.max((0, util_1.getTextWidth)(fieldMeta.maxString, font), titleWidth) +
|
|
69
|
+
COLUMN_BUFFER;
|
|
70
|
+
}
|
|
71
|
+
else if (f.isAtomicField() && f.isNumber()) {
|
|
72
|
+
const formattedValue = (0, render_numeric_field_1.renderNumericField)(f, fieldMeta.max);
|
|
73
|
+
width =
|
|
74
|
+
Math.max((0, util_1.getTextWidth)(formattedValue, font), titleWidth) +
|
|
75
|
+
COLUMN_BUFFER;
|
|
76
|
+
}
|
|
77
|
+
else
|
|
78
|
+
width = 130;
|
|
79
|
+
width = (0, util_1.clamp)(MIN_COLUMN_WIDTH, MAX_COLUMN_WIDTH, width);
|
|
80
|
+
}
|
|
81
|
+
return width;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=table-layout.js.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { DataArray
|
|
2
|
-
import { LitElement, TemplateResult } from 'lit';
|
|
1
|
+
import { DataArray } from '@malloydata/malloy';
|
|
2
|
+
import { LitElement, PropertyValues, TemplateResult } from 'lit';
|
|
3
3
|
import { RenderResultMetadata } from './render-result-metadata';
|
|
4
|
+
import { TableLayout } from './table-layout';
|
|
4
5
|
type TableContext = {
|
|
5
6
|
root: boolean;
|
|
6
|
-
|
|
7
|
+
layout: TableLayout;
|
|
7
8
|
};
|
|
8
9
|
export declare class Table extends LitElement {
|
|
9
10
|
static styles: import("lit").CSSResult;
|
|
@@ -19,12 +20,11 @@ export declare class Table extends LitElement {
|
|
|
19
20
|
protected createRenderRoot(): HTMLElement | DocumentFragment;
|
|
20
21
|
private renderHeader;
|
|
21
22
|
private renderField;
|
|
22
|
-
private getCellFontStyling;
|
|
23
|
-
private measuringCanvas;
|
|
24
23
|
private getColumnWidth;
|
|
25
24
|
private getContentStyle;
|
|
26
25
|
private renderCell;
|
|
27
26
|
private renderFieldContent;
|
|
27
|
+
willUpdate(changedProperties: PropertyValues<this>): void;
|
|
28
28
|
render(): TemplateResult<1>;
|
|
29
29
|
}
|
|
30
30
|
declare global {
|
package/dist/component/table.js
CHANGED
|
@@ -36,9 +36,7 @@ const context_1 = require("@lit/context");
|
|
|
36
36
|
const util_1 = require("./util");
|
|
37
37
|
const render_numeric_field_1 = require("./render-numeric-field");
|
|
38
38
|
const result_context_1 = require("./result-context");
|
|
39
|
-
const
|
|
40
|
-
const MAX_COLUMN_WIDTH = 384;
|
|
41
|
-
const COLUMN_BUFFER = 12;
|
|
39
|
+
const table_layout_1 = require("./table-layout");
|
|
42
40
|
const tableContext = (0, context_1.createContext)('table');
|
|
43
41
|
let Table = class Table extends lit_1.LitElement {
|
|
44
42
|
constructor() {
|
|
@@ -46,20 +44,19 @@ let Table = class Table extends lit_1.LitElement {
|
|
|
46
44
|
this.rowLimit = Infinity;
|
|
47
45
|
this.pinnedHeader = false;
|
|
48
46
|
this._scrolling = false;
|
|
49
|
-
this.measuringCanvas = document.createElement('canvas');
|
|
50
47
|
}
|
|
51
48
|
connectedCallback() {
|
|
52
49
|
super.connectedCallback();
|
|
53
50
|
if (typeof this.parentCtx === 'undefined') {
|
|
54
51
|
this.ctx = {
|
|
55
52
|
root: true,
|
|
56
|
-
|
|
53
|
+
layout: {},
|
|
57
54
|
};
|
|
58
55
|
}
|
|
59
56
|
else {
|
|
60
57
|
this.ctx = {
|
|
61
58
|
root: false,
|
|
62
|
-
|
|
59
|
+
layout: this.parentCtx.layout,
|
|
63
60
|
};
|
|
64
61
|
}
|
|
65
62
|
}
|
|
@@ -89,6 +86,7 @@ let Table = class Table extends lit_1.LitElement {
|
|
|
89
86
|
${this.renderCell(f, f.name, {
|
|
90
87
|
hideStartGutter,
|
|
91
88
|
hideEndGutter,
|
|
89
|
+
isHeader: true,
|
|
92
90
|
})}
|
|
93
91
|
</th>`;
|
|
94
92
|
}
|
|
@@ -101,49 +99,23 @@ let Table = class Table extends lit_1.LitElement {
|
|
|
101
99
|
${this.renderFieldContent(row, f)}
|
|
102
100
|
</td>`;
|
|
103
101
|
}
|
|
104
|
-
getCellFontStyling() {
|
|
105
|
-
const rootStyle = getComputedStyle(this);
|
|
106
|
-
const fontFamily = rootStyle
|
|
107
|
-
.getPropertyValue('--malloy-render--font-family')
|
|
108
|
-
.trim();
|
|
109
|
-
const fontSize = rootStyle
|
|
110
|
-
.getPropertyValue('--malloy-render--table-font-size')
|
|
111
|
-
.trim();
|
|
112
|
-
return {
|
|
113
|
-
fontFamily,
|
|
114
|
-
fontSize,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
102
|
getColumnWidth(f) {
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
let width = this.ctx.widthCache.get(f);
|
|
121
|
-
if (typeof width === 'undefined') {
|
|
122
|
-
const fontStyles = this.getCellFontStyling();
|
|
123
|
-
const font = `${fontStyles.fontSize} ${fontStyles.fontFamily}`;
|
|
124
|
-
const titleWidth = (0, util_1.getTextWidth)(f.name, font, this.measuringCanvas);
|
|
125
|
-
if (f.isAtomicField() && f.isString()) {
|
|
126
|
-
width =
|
|
127
|
-
Math.max((0, util_1.getTextWidth)(fieldMeta.maxString, font, this.measuringCanvas), titleWidth) + COLUMN_BUFFER;
|
|
128
|
-
}
|
|
129
|
-
else if (f.isAtomicField() && f.isNumber()) {
|
|
130
|
-
const formattedValue = (0, render_numeric_field_1.renderNumericField)(f, fieldMeta.max);
|
|
131
|
-
width =
|
|
132
|
-
Math.max((0, util_1.getTextWidth)(formattedValue, font, this.measuringCanvas), titleWidth) + COLUMN_BUFFER;
|
|
133
|
-
}
|
|
134
|
-
else
|
|
135
|
-
width = 130;
|
|
136
|
-
width = (0, util_1.clamp)(MIN_COLUMN_WIDTH, MAX_COLUMN_WIDTH, width);
|
|
137
|
-
this.ctx.widthCache.set(f, width);
|
|
138
|
-
}
|
|
139
|
-
return width;
|
|
103
|
+
const key = (0, util_1.getFieldKey)(f);
|
|
104
|
+
return this.ctx.layout[key].width;
|
|
140
105
|
}
|
|
141
|
-
getContentStyle(f) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
106
|
+
getContentStyle(f, isHeader = false) {
|
|
107
|
+
const width = this.getColumnWidth(f);
|
|
108
|
+
let style = '';
|
|
109
|
+
if (isHeader)
|
|
110
|
+
return style;
|
|
111
|
+
if (typeof width !== 'undefined') {
|
|
112
|
+
style += `width: ${width}px; min-width: ${width}px; max-width: ${width}px;`;
|
|
113
|
+
}
|
|
114
|
+
const height = this.ctx.layout[(0, util_1.getFieldKey)(f)].height;
|
|
115
|
+
if (typeof height === 'number') {
|
|
116
|
+
style += `height: ${height}px;`;
|
|
145
117
|
}
|
|
146
|
-
return
|
|
118
|
+
return style;
|
|
147
119
|
}
|
|
148
120
|
renderCell(f, value, options) {
|
|
149
121
|
return (0, lit_1.html) `<div class="cell-wrapper">
|
|
@@ -155,7 +127,7 @@ let Table = class Table extends lit_1.LitElement {
|
|
|
155
127
|
></div>
|
|
156
128
|
<div
|
|
157
129
|
class="cell-content"
|
|
158
|
-
style="${this.getContentStyle(f)}"
|
|
130
|
+
style="${this.getContentStyle(f, options.isHeader)}"
|
|
159
131
|
title="${value}"
|
|
160
132
|
>
|
|
161
133
|
${value}
|
|
@@ -170,28 +142,45 @@ let Table = class Table extends lit_1.LitElement {
|
|
|
170
142
|
}
|
|
171
143
|
renderFieldContent(row, f) {
|
|
172
144
|
var _a;
|
|
173
|
-
|
|
145
|
+
const renderAs = (0, util_1.shouldRenderAs)(f);
|
|
146
|
+
// Render nested tables without gutters
|
|
147
|
+
if (renderAs === 'table') {
|
|
174
148
|
return (0, lit_1.html) `<malloy-table
|
|
175
149
|
.data=${row.cell(f)}
|
|
176
150
|
.pinnedHeader=${(_a = this.pinnedHeader) !== null && _a !== void 0 ? _a : false}
|
|
177
151
|
.rowLimit=${this.pinnedHeader ? 1 : Infinity}
|
|
178
152
|
></malloy-table>`;
|
|
179
153
|
}
|
|
180
|
-
|
|
154
|
+
const resultCellValue = row.cell(f).value;
|
|
155
|
+
let renderValue = '';
|
|
181
156
|
if (this.pinnedHeader)
|
|
182
|
-
|
|
183
|
-
else if (
|
|
157
|
+
renderValue = '';
|
|
158
|
+
else if (renderAs === 'bar-chart') {
|
|
159
|
+
renderValue = (0, lit_1.html) `<malloy-bar-chart
|
|
160
|
+
.data=${row.cell(f)}
|
|
161
|
+
></malloy-bar-chart>`;
|
|
162
|
+
}
|
|
163
|
+
else if ((0, util_1.valueIsNumber)(f, resultCellValue)) {
|
|
184
164
|
// TS doesn't support typeguards for multiple parameters, so unfortunately have to assert AtomicField here. https://github.com/microsoft/TypeScript/issues/26916
|
|
185
|
-
|
|
165
|
+
renderValue = (0, render_numeric_field_1.renderNumericField)(f, resultCellValue);
|
|
166
|
+
}
|
|
167
|
+
else if (resultCellValue === null) {
|
|
168
|
+
renderValue = '∅';
|
|
186
169
|
}
|
|
187
|
-
else if (
|
|
188
|
-
|
|
170
|
+
else if ((0, util_1.valueIsString)(f, resultCellValue)) {
|
|
171
|
+
renderValue = resultCellValue;
|
|
189
172
|
}
|
|
190
|
-
return this.renderCell(f,
|
|
173
|
+
return this.renderCell(f, renderValue, {
|
|
191
174
|
hideStartGutter: (0, util_1.isFirstChild)(f),
|
|
192
175
|
hideEndGutter: (0, util_1.isLastChild)(f),
|
|
176
|
+
isHeader: false,
|
|
193
177
|
});
|
|
194
178
|
}
|
|
179
|
+
willUpdate(changedProperties) {
|
|
180
|
+
if (this.ctx.root && changedProperties.has('data')) {
|
|
181
|
+
this.ctx.layout = (0, table_layout_1.getTableLayout)(this.metadata);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
195
184
|
render() {
|
|
196
185
|
const fields = this.data.field.allFields;
|
|
197
186
|
const headers = fields.map(f => this.renderHeader(f));
|
|
@@ -307,15 +296,15 @@ Table.styles = (0, lit_1.css) `
|
|
|
307
296
|
}
|
|
308
297
|
|
|
309
298
|
.cell-wrapper {
|
|
310
|
-
height: var(--malloy-render--table-row-height);
|
|
299
|
+
// height: var(--malloy-render--table-row-height);
|
|
311
300
|
display: flex;
|
|
312
|
-
align-items:
|
|
301
|
+
align-items: start;
|
|
313
302
|
overflow: hidden;
|
|
314
303
|
}
|
|
315
304
|
|
|
316
305
|
.cell-content {
|
|
317
306
|
border-top: var(--malloy-render--table-border);
|
|
318
|
-
height:
|
|
307
|
+
height: 100%;
|
|
319
308
|
line-height: var(--malloy-render--table-row-height);
|
|
320
309
|
flex: 1;
|
|
321
310
|
overflow: hidden;
|
package/dist/component/util.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ export declare function valueIsNumber(f: Field, v: unknown): v is number;
|
|
|
5
5
|
export declare function valueIsString(f: Field, s: unknown): s is string;
|
|
6
6
|
export declare function getTextWidth(text: string, font: string, canvasToUse?: HTMLCanvasElement): number;
|
|
7
7
|
export declare function clamp(s: number, e: number, v: number): number;
|
|
8
|
+
export declare function shouldRenderAs(f: Field): "table" | "cell" | "bar-chart";
|
|
9
|
+
export declare function getFieldKey(f: Field): string;
|
package/dist/component/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.clamp = exports.getTextWidth = exports.valueIsString = exports.valueIsNumber = exports.isFirstChild = exports.isLastChild = void 0;
|
|
3
|
+
exports.getFieldKey = exports.shouldRenderAs = exports.clamp = exports.getTextWidth = exports.valueIsString = exports.valueIsNumber = exports.isFirstChild = exports.isLastChild = void 0;
|
|
4
4
|
function getLocationInParent(f) {
|
|
5
5
|
var _a;
|
|
6
6
|
const parent = f.parentExplore;
|
|
@@ -36,4 +36,18 @@ function clamp(s, e, v) {
|
|
|
36
36
|
return Math.max(s, Math.min(e, v));
|
|
37
37
|
}
|
|
38
38
|
exports.clamp = clamp;
|
|
39
|
+
function shouldRenderAs(f) {
|
|
40
|
+
if (f.isAtomicField())
|
|
41
|
+
return 'cell';
|
|
42
|
+
const { tag } = f.tagParse();
|
|
43
|
+
if (tag.has('bar'))
|
|
44
|
+
return 'bar-chart';
|
|
45
|
+
else
|
|
46
|
+
return 'table';
|
|
47
|
+
}
|
|
48
|
+
exports.shouldRenderAs = shouldRenderAs;
|
|
49
|
+
function getFieldKey(f) {
|
|
50
|
+
return JSON.stringify(f.fieldPath);
|
|
51
|
+
}
|
|
52
|
+
exports.getFieldKey = getFieldKey;
|
|
39
53
|
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LitElement, TemplateResult, PropertyValues } from 'lit';
|
|
2
|
+
import { VegaJSON } from './vega-types';
|
|
3
|
+
export declare class VegaChart extends LitElement {
|
|
4
|
+
static styles: import("lit").CSSResult;
|
|
5
|
+
spec: VegaJSON;
|
|
6
|
+
type: 'vega' | 'vega-lite';
|
|
7
|
+
width?: number;
|
|
8
|
+
height?: number;
|
|
9
|
+
private el;
|
|
10
|
+
private view;
|
|
11
|
+
setupView(): void;
|
|
12
|
+
firstUpdated(): void;
|
|
13
|
+
protected willUpdate(changedProperties: PropertyValues<this>): void;
|
|
14
|
+
render(): TemplateResult;
|
|
15
|
+
}
|
|
@@ -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
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
25
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
26
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
27
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
28
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.VegaChart = void 0;
|
|
32
|
+
const lit_1 = require("lit");
|
|
33
|
+
const decorators_js_1 = require("lit/decorators.js");
|
|
34
|
+
const vega_1 = require("vega");
|
|
35
|
+
const vega_lite_1 = require("vega-lite");
|
|
36
|
+
const vega_types_1 = require("./vega-types");
|
|
37
|
+
let VegaChart = class VegaChart extends lit_1.LitElement {
|
|
38
|
+
constructor() {
|
|
39
|
+
super(...arguments);
|
|
40
|
+
this.type = 'vega';
|
|
41
|
+
this.el = null;
|
|
42
|
+
this.view = null;
|
|
43
|
+
}
|
|
44
|
+
setupView() {
|
|
45
|
+
if (this.view)
|
|
46
|
+
this.view.finalize();
|
|
47
|
+
const vegaspec = this.type === 'vega-lite'
|
|
48
|
+
? (0, vega_lite_1.compile)((0, vega_types_1.asVegaLiteSpec)(this.spec)).spec
|
|
49
|
+
: (0, vega_types_1.asVegaSpec)(this.spec);
|
|
50
|
+
this.view = new vega_1.View((0, vega_1.parse)(vegaspec))
|
|
51
|
+
.initialize(this.el)
|
|
52
|
+
.renderer('svg')
|
|
53
|
+
.hover();
|
|
54
|
+
if (this.width)
|
|
55
|
+
this.view.width(this.width);
|
|
56
|
+
if (this.height)
|
|
57
|
+
this.view.height(this.height);
|
|
58
|
+
this.view.run();
|
|
59
|
+
}
|
|
60
|
+
firstUpdated() {
|
|
61
|
+
this.el = this.shadowRoot.getElementById('vis');
|
|
62
|
+
this.setupView();
|
|
63
|
+
}
|
|
64
|
+
willUpdate(changedProperties) {
|
|
65
|
+
if (changedProperties.has('spec') || changedProperties.has('type')) {
|
|
66
|
+
if (this.el)
|
|
67
|
+
this.setupView();
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
if ((changedProperties.has('width') || changedProperties.has('height')) &&
|
|
71
|
+
this.view) {
|
|
72
|
+
if (this.width)
|
|
73
|
+
this.view.width(this.width);
|
|
74
|
+
if (this.height)
|
|
75
|
+
this.view.height(this.height);
|
|
76
|
+
this.view.run();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
render() {
|
|
81
|
+
return (0, lit_1.html) ` <div id="vis"></div> `;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
exports.VegaChart = VegaChart;
|
|
85
|
+
VegaChart.styles = (0, lit_1.css) `
|
|
86
|
+
#vis > svg {
|
|
87
|
+
display: block;
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
90
|
+
__decorate([
|
|
91
|
+
(0, decorators_js_1.property)({ attribute: false })
|
|
92
|
+
], VegaChart.prototype, "spec", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
(0, decorators_js_1.property)({ type: String })
|
|
95
|
+
], VegaChart.prototype, "type", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
(0, decorators_js_1.property)({ type: Number })
|
|
98
|
+
], VegaChart.prototype, "width", void 0);
|
|
99
|
+
__decorate([
|
|
100
|
+
(0, decorators_js_1.property)({ type: Number })
|
|
101
|
+
], VegaChart.prototype, "height", void 0);
|
|
102
|
+
exports.VegaChart = VegaChart = __decorate([
|
|
103
|
+
(0, decorators_js_1.customElement)('malloy-vega-chart')
|
|
104
|
+
], VegaChart);
|
|
105
|
+
//# sourceMappingURL=vega-chart.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.baseSpec = void 0;
|
|
4
|
+
const grayMedium = '#727883';
|
|
5
|
+
const gridGray = '#E5E7EB';
|
|
6
|
+
const baseSpec = () => ({
|
|
7
|
+
$schema: 'https://vega.github.io/schema/vega-lite/v5.json',
|
|
8
|
+
config: {
|
|
9
|
+
axisY: {
|
|
10
|
+
gridColor: gridGray,
|
|
11
|
+
tickColor: gridGray,
|
|
12
|
+
domain: false,
|
|
13
|
+
labelFont: 'Inter, sans-serif',
|
|
14
|
+
labelFontSize: 10,
|
|
15
|
+
labelFontWeight: 'normal',
|
|
16
|
+
labelColor: grayMedium,
|
|
17
|
+
labelPadding: 5,
|
|
18
|
+
titleColor: grayMedium,
|
|
19
|
+
titleFont: 'Inter, sans-serif',
|
|
20
|
+
titleFontSize: 12,
|
|
21
|
+
titleFontWeight: 'bold',
|
|
22
|
+
titlePadding: 10,
|
|
23
|
+
labelOverlap: false,
|
|
24
|
+
},
|
|
25
|
+
axisX: {
|
|
26
|
+
gridColor: gridGray,
|
|
27
|
+
tickColor: gridGray,
|
|
28
|
+
tickSize: 0,
|
|
29
|
+
domain: false,
|
|
30
|
+
labelFont: 'Inter, sans-serif',
|
|
31
|
+
labelFontSize: 10,
|
|
32
|
+
labelFontWeight: 'normal',
|
|
33
|
+
labelPadding: 5,
|
|
34
|
+
labelColor: grayMedium,
|
|
35
|
+
titleColor: grayMedium,
|
|
36
|
+
titleFont: 'Inter, sans-serif',
|
|
37
|
+
titleFontSize: 12,
|
|
38
|
+
titleFontWeight: 'bold',
|
|
39
|
+
titlePadding: 10,
|
|
40
|
+
},
|
|
41
|
+
view: {
|
|
42
|
+
strokeWidth: 0,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
params: [],
|
|
46
|
+
padding: 0,
|
|
47
|
+
autosize: {
|
|
48
|
+
type: 'none',
|
|
49
|
+
resize: true,
|
|
50
|
+
contains: 'content',
|
|
51
|
+
},
|
|
52
|
+
// for vega-lite, if width/height is not specificed in spec it will try to autosize. Set values to prevent
|
|
53
|
+
width: 1,
|
|
54
|
+
height: 1,
|
|
55
|
+
data: {
|
|
56
|
+
values: [],
|
|
57
|
+
},
|
|
58
|
+
layer: [],
|
|
59
|
+
});
|
|
60
|
+
exports.baseSpec = baseSpec;
|
|
61
|
+
//# sourceMappingURL=vega-lite-base-spec.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference path="../../src/vega.d.ts" />
|
|
2
|
+
import { Spec } from 'vega';
|
|
3
|
+
import { TopLevelSpec } from 'vega-lite';
|
|
4
|
+
/**
|
|
5
|
+
* TODO: create vega-lite-types package that exports types from vega-lite
|
|
6
|
+
* Because vega-lite typings are not available today, we are forced to use any
|
|
7
|
+
* */
|
|
8
|
+
export type VegaJSON = any;
|
|
9
|
+
export declare function asVegaSpec(v: VegaJSON): Spec;
|
|
10
|
+
export declare function asVegaLiteSpec(v: VegaJSON): TopLevelSpec;
|
|
@@ -0,0 +1,34 @@
|
|
|
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.asVegaLiteSpec = exports.asVegaSpec = void 0;
|
|
26
|
+
function asVegaSpec(v) {
|
|
27
|
+
return v;
|
|
28
|
+
}
|
|
29
|
+
exports.asVegaSpec = asVegaSpec;
|
|
30
|
+
function asVegaLiteSpec(v) {
|
|
31
|
+
return v;
|
|
32
|
+
}
|
|
33
|
+
exports.asVegaLiteSpec = asVegaLiteSpec;
|
|
34
|
+
//# sourceMappingURL=vega-types.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Meta } from '@storybook/html';
|
|
2
|
+
import './themes.css';
|
|
3
|
+
import '../component/render';
|
|
4
|
+
declare const meta: Meta;
|
|
5
|
+
export default meta;
|
|
6
|
+
export declare const Products2Column: {
|
|
7
|
+
args: {
|
|
8
|
+
source: string;
|
|
9
|
+
view: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare const Nested: {
|
|
13
|
+
args: {
|
|
14
|
+
source: string;
|
|
15
|
+
view: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare const Sparks: {
|
|
19
|
+
args: {
|
|
20
|
+
source: string;
|
|
21
|
+
view: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Sparks = exports.Nested = exports.Products2Column = void 0;
|
|
7
|
+
const bars_malloy_raw_1 = __importDefault(require("./static/bars.malloy?raw"));
|
|
8
|
+
const util_1 = require("./util");
|
|
9
|
+
require("./themes.css");
|
|
10
|
+
require("../component/render");
|
|
11
|
+
const meta = {
|
|
12
|
+
title: 'Malloy Next/Bars',
|
|
13
|
+
render: ({ classes }, context) => {
|
|
14
|
+
const parent = document.createElement('div');
|
|
15
|
+
parent.style.height = '1000px';
|
|
16
|
+
parent.style.position = 'relative';
|
|
17
|
+
const el = document.createElement('malloy-render');
|
|
18
|
+
if (classes)
|
|
19
|
+
el.classList.add(classes);
|
|
20
|
+
el.result = context.loaded['result'];
|
|
21
|
+
parent.appendChild(el);
|
|
22
|
+
return parent;
|
|
23
|
+
},
|
|
24
|
+
loaders: [(0, util_1.createLoader)(bars_malloy_raw_1.default)],
|
|
25
|
+
argTypes: {},
|
|
26
|
+
};
|
|
27
|
+
exports.default = meta;
|
|
28
|
+
exports.Products2Column = {
|
|
29
|
+
args: {
|
|
30
|
+
source: 'products',
|
|
31
|
+
view: 'category_bar',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
exports.Nested = {
|
|
35
|
+
args: {
|
|
36
|
+
source: 'products',
|
|
37
|
+
view: 'nested',
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
exports.Sparks = {
|
|
41
|
+
args: {
|
|
42
|
+
source: 'products',
|
|
43
|
+
view: 'sparks',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=bars.stories.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/render",
|
|
3
|
-
"version": "0.0.116-
|
|
3
|
+
"version": "0.0.116-dev240104225124",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@lit/context": "^1.1.0",
|
|
27
|
-
"@malloydata/malloy": "^0.0.116-
|
|
27
|
+
"@malloydata/malloy": "^0.0.116-dev240104225124",
|
|
28
28
|
"@types/luxon": "^2.4.0",
|
|
29
29
|
"lit": "^3.0.2",
|
|
30
30
|
"lodash": "^4.17.20",
|