@malloydata/render 0.0.135-dev240322231911 → 0.0.135-dev240326020414

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.
Files changed (86) hide show
  1. package/dist/component/render-webcomponent.d.ts +6 -0
  2. package/dist/component/render.d.ts +7 -17
  3. package/dist/component/result-context.d.ts +2 -3
  4. package/dist/component/table/table-context.d.ts +9 -0
  5. package/dist/component/{table-layout.d.ts → table/table-layout.d.ts} +2 -2
  6. package/dist/component/table/table.d.ts +9 -0
  7. package/dist/html/html_view.d.ts +1 -1
  8. package/dist/module/index.mjs +145001 -0
  9. package/dist/module/index.umd.js +1643 -0
  10. package/dist/module/style.css +1 -0
  11. package/dist/stories/bars.stories.d.ts +1 -1
  12. package/dist/stories/tables.stories.d.ts +1 -1
  13. package/dist/stories/themes.stories.d.ts +1 -1
  14. package/dist/webcomponent/malloy-render.mjs +90572 -0
  15. package/dist/webcomponent/malloy-render.umd.js +1491 -0
  16. package/dist/webcomponent/style.css +1 -0
  17. package/package.json +21 -7
  18. package/vite.config.ts +25 -0
  19. package/vite.config.webcomponent.ts +25 -0
  20. package/dist/bundle/bundled_renderer.js +0 -139374
  21. package/dist/bundle/bundled_renderer.min.js +0 -2374
  22. package/dist/bundle/main.js +0 -29
  23. package/dist/bundle/renderer.js +0 -71
  24. package/dist/component/bar-chart.js +0 -130
  25. package/dist/component/chart-settings.js +0 -152
  26. package/dist/component/render-numeric-field.js +0 -104
  27. package/dist/component/render-result-metadata.js +0 -91
  28. package/dist/component/render.js +0 -155
  29. package/dist/component/result-context.js +0 -28
  30. package/dist/component/table-layout.js +0 -83
  31. package/dist/component/table.d.ts +0 -35
  32. package/dist/component/table.js +0 -375
  33. package/dist/component/util.js +0 -53
  34. package/dist/component/vega-chart.js +0 -105
  35. package/dist/component/vega-lite-base-spec.js +0 -61
  36. package/dist/component/vega-types.js +0 -34
  37. package/dist/data_styles.js +0 -50
  38. package/dist/drill.js +0 -124
  39. package/dist/html/area_sparkline.js +0 -118
  40. package/dist/html/bar_chart.js +0 -70
  41. package/dist/html/bar_sparkline.js +0 -119
  42. package/dist/html/boolean.js +0 -53
  43. package/dist/html/bytes.js +0 -47
  44. package/dist/html/cartesian_chart.js +0 -110
  45. package/dist/html/chart.js +0 -120
  46. package/dist/html/column_sparkline.js +0 -120
  47. package/dist/html/container.js +0 -44
  48. package/dist/html/currency.js +0 -75
  49. package/dist/html/dashboard.js +0 -242
  50. package/dist/html/data_volume.js +0 -94
  51. package/dist/html/date.js +0 -66
  52. package/dist/html/duration.js +0 -108
  53. package/dist/html/html_view.js +0 -187
  54. package/dist/html/image.js +0 -77
  55. package/dist/html/index.js +0 -28
  56. package/dist/html/json.js +0 -52
  57. package/dist/html/line_chart.js +0 -72
  58. package/dist/html/link.js +0 -57
  59. package/dist/html/list.js +0 -73
  60. package/dist/html/list_detail.js +0 -33
  61. package/dist/html/number.js +0 -73
  62. package/dist/html/percent.js +0 -50
  63. package/dist/html/point_map.js +0 -182
  64. package/dist/html/scatter_chart.js +0 -72
  65. package/dist/html/segment_map.js +0 -151
  66. package/dist/html/shape_map.js +0 -194
  67. package/dist/html/sparkline.js +0 -120
  68. package/dist/html/state_codes.js +0 -137
  69. package/dist/html/table.js +0 -475
  70. package/dist/html/text.js +0 -65
  71. package/dist/html/unsupported.js +0 -72
  72. package/dist/html/utils.js +0 -277
  73. package/dist/html/vega_spec.js +0 -544
  74. package/dist/index.js +0 -47
  75. package/dist/main_renderer_factory.js +0 -101
  76. package/dist/renderer.js +0 -34
  77. package/dist/renderer_factory.js +0 -57
  78. package/dist/renderer_types.js +0 -25
  79. package/dist/stories/bars.stories.js +0 -52
  80. package/dist/stories/basic.stories.js +0 -34
  81. package/dist/stories/image.stories.js +0 -34
  82. package/dist/stories/render-malloy-legacy.js +0 -27
  83. package/dist/stories/tables.stories.js +0 -65
  84. package/dist/stories/themes.stories.js +0 -47
  85. package/dist/stories/util.js +0 -25
  86. package/dist/tags_utils.js +0 -30
@@ -1,50 +0,0 @@
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.PercentRendererFactory = exports.HTMLPercentRenderer = void 0;
26
- const number_1 = require("./number");
27
- const renderer_factory_1 = require("../renderer_factory");
28
- class HTMLPercentRenderer extends number_1.HTMLNumberRenderer {
29
- getText(data) {
30
- if (data.isNull()) {
31
- return null;
32
- }
33
- const num = data.number.value;
34
- return num === null
35
- ? num
36
- : (num * 100).toLocaleString('en', { maximumFractionDigits: 2 }) + '%';
37
- }
38
- }
39
- exports.HTMLPercentRenderer = HTMLPercentRenderer;
40
- class PercentRendererFactory extends renderer_factory_1.RendererFactory {
41
- create(document, _styleDefaults, _rendererOptions, _field, options) {
42
- return new HTMLPercentRenderer(document, options);
43
- }
44
- get rendererName() {
45
- return 'percent';
46
- }
47
- }
48
- exports.PercentRendererFactory = PercentRendererFactory;
49
- PercentRendererFactory.instance = new PercentRendererFactory();
50
- //# sourceMappingURL=percent.js.map
@@ -1,182 +0,0 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
25
- return (mod && mod.__esModule) ? mod : { "default": mod };
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.PointMapRendererFactory = exports.HTMLPointMapRenderer = void 0;
29
- const malloy_1 = require("@malloydata/malloy");
30
- const states_10m_json_1 = __importDefault(require("us-atlas/states-10m.json"));
31
- const chart_1 = require("./chart");
32
- const utils_1 = require("./utils");
33
- const renderer_factory_1 = require("../renderer_factory");
34
- class HTMLPointMapRenderer extends chart_1.HTMLChartRenderer {
35
- getDataValue(data) {
36
- if (data.isNumber() || data.isString()) {
37
- return data.value;
38
- }
39
- else if (data.isTimestamp() || data.isDate()) {
40
- return (0, utils_1.timeToString)(data.value, data.field.timeframe || malloy_1.TimestampTimeframe.Second, this.timezone);
41
- }
42
- throw new Error('Invalid field type for point map chart.');
43
- }
44
- getDataType(field) {
45
- if (field.isAtomicField()) {
46
- if (field.isDate() || field.isTimestamp() || field.isString()) {
47
- return 'nominal';
48
- }
49
- else if (field.isNumber()) {
50
- return 'quantitative';
51
- }
52
- }
53
- throw new Error('Invalid field type for point map.');
54
- }
55
- isTimeFieldDef(field) {
56
- if (field.isAtomicField()) {
57
- if (field.isDate() || field.isTimestamp()) {
58
- return true;
59
- }
60
- }
61
- return false;
62
- }
63
- getVegaLiteSpec(data) {
64
- if (data.isNull()) {
65
- throw new Error('Expected struct value not to be null.');
66
- }
67
- const fields = data.field.intrinsicFields;
68
- const latField = fields[0];
69
- const lonField = fields[1];
70
- const colorField = fields[2];
71
- const sizeField = fields[3];
72
- const shapeField = fields[4];
73
- const colorType = colorField ? this.getDataType(colorField) : undefined;
74
- const sizeType = sizeField ? this.getDataType(sizeField) : undefined;
75
- const shapeType = shapeField ? this.getDataType(shapeField) : undefined;
76
- const colorDef = colorField !== undefined
77
- ? {
78
- field: colorField.name,
79
- type: colorType,
80
- axis: {
81
- title: (0, utils_1.formatTitle)(this.options, colorField, undefined, this.timezone),
82
- },
83
- scale: (0, utils_1.getColorScale)(colorType, false),
84
- }
85
- : undefined;
86
- const sizeDef = sizeField
87
- ? {
88
- field: sizeField.name,
89
- type: sizeType,
90
- axis: {
91
- title: (0, utils_1.formatTitle)(this.options, sizeField, undefined, this.timezone),
92
- },
93
- }
94
- : { value: 5 };
95
- const shapeDef = shapeField
96
- ? {
97
- field: shapeField.name,
98
- type: shapeType,
99
- axis: {
100
- title: (0, utils_1.formatTitle)(this.options, shapeField, undefined, this.timezone),
101
- },
102
- }
103
- : { value: 'circle' };
104
- return {
105
- ...this.getSize(),
106
- data: {
107
- values: this.mapData(data),
108
- },
109
- projection: {
110
- type: 'albersUsa',
111
- },
112
- layer: [
113
- {
114
- data: {
115
- values: states_10m_json_1.default,
116
- format: {
117
- type: 'topojson',
118
- feature: 'states',
119
- },
120
- },
121
- mark: {
122
- type: 'geoshape',
123
- fill: '#efefef',
124
- stroke: 'white',
125
- },
126
- },
127
- {
128
- mark: 'point',
129
- encoding: {
130
- latitude: { field: latField.name, type: 'quantitative' },
131
- longitude: { field: lonField.name, type: 'quantitative' },
132
- size: sizeDef,
133
- color: colorDef,
134
- shape: shapeDef,
135
- },
136
- },
137
- ],
138
- background: 'transparent',
139
- config: {
140
- axis: {
141
- labelFont: 'var(--malloy-font-family, Roboto)',
142
- titleFont: 'var(--malloy-font-family, Roboto)',
143
- titleFontWeight: 500,
144
- titleColor: 'var(--malloy-title-color, #505050)',
145
- labelColor: 'var(--malloy-label-color, #000000)',
146
- titleFontSize: 12,
147
- },
148
- legend: {
149
- labelFont: 'var(--malloy-font-family, Roboto)',
150
- titleFont: 'var(--malloy-font-family, Roboto)',
151
- titleFontWeight: 500,
152
- titleColor: 'var(--malloy-title-color, #505050)',
153
- labelColor: 'var(--malloy-label-color, #000000)',
154
- titleFontSize: 12,
155
- },
156
- header: {
157
- labelFont: 'var(--malloy-font-family, Roboto)',
158
- titleFont: 'var(--malloy-font-family, Roboto)',
159
- titleFontWeight: 500,
160
- },
161
- mark: { font: 'var(--malloy-Roboto' },
162
- title: {
163
- font: 'var(--malloy-font-family, Roboto)',
164
- subtitleFont: 'var(--malloy-font-family, Roboto)',
165
- fontWeight: 500,
166
- },
167
- },
168
- };
169
- }
170
- }
171
- exports.HTMLPointMapRenderer = HTMLPointMapRenderer;
172
- class PointMapRendererFactory extends renderer_factory_1.RendererFactory {
173
- create(document, styleDefaults, rendererOptions, _field, options, timezone) {
174
- return new HTMLPointMapRenderer(document, styleDefaults, rendererOptions, options, timezone);
175
- }
176
- get rendererName() {
177
- return 'point_map';
178
- }
179
- }
180
- exports.PointMapRendererFactory = PointMapRendererFactory;
181
- PointMapRendererFactory.instance = new PointMapRendererFactory();
182
- //# sourceMappingURL=point_map.js.map
@@ -1,72 +0,0 @@
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.ScatterChartRendererFactory = exports.HTMLScatterChartRenderer = void 0;
26
- const cartesian_chart_1 = require("./cartesian_chart");
27
- const renderer_factory_1 = require("../renderer_factory");
28
- class HTMLScatterChartRenderer extends cartesian_chart_1.HTMLCartesianChartRenderer {
29
- getMark() {
30
- return 'point';
31
- }
32
- getDataType(field) {
33
- if (field.isAtomicField()) {
34
- if (field.isDate() || field.isTimestamp()) {
35
- return 'temporal';
36
- }
37
- else if (field.isString()) {
38
- return 'nominal';
39
- }
40
- else if (field.isNumber()) {
41
- return 'quantitative';
42
- }
43
- }
44
- throw new Error('Invalid field type for scatter chart.');
45
- }
46
- getDataValue(data) {
47
- if (data.isNull()) {
48
- return null;
49
- }
50
- else if (data.isTimestamp() ||
51
- data.isDate() ||
52
- data.isNumber() ||
53
- data.isString()) {
54
- return data.value;
55
- }
56
- else {
57
- throw new Error('Invalid field type for scatter chart.');
58
- }
59
- }
60
- }
61
- exports.HTMLScatterChartRenderer = HTMLScatterChartRenderer;
62
- class ScatterChartRendererFactory extends renderer_factory_1.RendererFactory {
63
- create(document, styleDefaults, rendererOptions, _field, options, timezone) {
64
- return new HTMLScatterChartRenderer(document, styleDefaults, rendererOptions, options, timezone);
65
- }
66
- get rendererName() {
67
- return 'scatter_chart';
68
- }
69
- }
70
- exports.ScatterChartRendererFactory = ScatterChartRendererFactory;
71
- ScatterChartRendererFactory.instance = new ScatterChartRendererFactory();
72
- //# sourceMappingURL=scatter_chart.js.map
@@ -1,151 +0,0 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
25
- return (mod && mod.__esModule) ? mod : { "default": mod };
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.SegmentMapRendererFactory = exports.HTMLSegmentMapRenderer = void 0;
29
- const states_10m_json_1 = __importDefault(require("us-atlas/states-10m.json"));
30
- const chart_1 = require("./chart");
31
- const utils_1 = require("./utils");
32
- const renderer_factory_1 = require("../renderer_factory");
33
- class HTMLSegmentMapRenderer extends chart_1.HTMLChartRenderer {
34
- getDataValue(data) {
35
- if (data.isNull() || data.isNumber() || data.isString()) {
36
- return data.value;
37
- }
38
- throw new Error('Invalid field type for segment map.');
39
- }
40
- getDataType(field) {
41
- if (field.isAtomicField()) {
42
- if (field.isString()) {
43
- return 'nominal';
44
- }
45
- else if (field.isNumber()) {
46
- return 'quantitative';
47
- }
48
- // TODO dates nominal?
49
- }
50
- throw new Error('Invalid field type for segment map.');
51
- }
52
- getVegaLiteSpec(data) {
53
- if (data.isNull()) {
54
- throw new Error('Expected struct value not to be null.');
55
- }
56
- const fields = data.field.intrinsicFields;
57
- const lat1Field = fields[0];
58
- const lon1Field = fields[1];
59
- const lat2Field = fields[2];
60
- const lon2Field = fields[3];
61
- const colorField = fields[4];
62
- const colorType = colorField ? this.getDataType(colorField) : undefined;
63
- const colorDef = colorField !== undefined
64
- ? {
65
- field: colorField.name,
66
- type: colorType,
67
- axis: {
68
- title: (0, utils_1.formatTitle)(this.options, colorField, undefined, this.timezone),
69
- },
70
- scale: (0, utils_1.getColorScale)(colorType, false),
71
- }
72
- : undefined;
73
- return {
74
- ...this.getSize(),
75
- data: {
76
- values: this.mapData(data),
77
- },
78
- projection: {
79
- type: 'albersUsa',
80
- },
81
- layer: [
82
- {
83
- data: {
84
- values: states_10m_json_1.default,
85
- format: {
86
- type: 'topojson',
87
- feature: 'states',
88
- },
89
- },
90
- mark: {
91
- type: 'geoshape',
92
- fill: 'lightgray',
93
- stroke: 'white',
94
- },
95
- },
96
- {
97
- mark: 'line',
98
- encoding: {
99
- latitude: { field: lat1Field.name, type: 'quantitative' },
100
- longitude: { field: lon1Field.name, type: 'quantitative' },
101
- latitude2: { field: lat2Field.name, type: 'quantitative' },
102
- longitude2: { field: lon2Field.name, type: 'quantitative' },
103
- color: colorDef,
104
- },
105
- },
106
- ],
107
- background: 'transparent',
108
- config: {
109
- axis: {
110
- labelFont: 'var(--malloy-font-family, Roboto)',
111
- titleFont: 'var(--malloy-font-family, Roboto)',
112
- titleFontWeight: 500,
113
- titleColor: 'var(--malloy-title-color, #505050)',
114
- labelColor: 'var(--malloy-label-color, #000000)',
115
- titleFontSize: 12,
116
- },
117
- legend: {
118
- labelFont: 'var(--malloy-font-family, Roboto)',
119
- titleFont: 'var(--malloy-font-family, Roboto)',
120
- titleFontWeight: 500,
121
- titleColor: 'var(--malloy-title-color, #505050)',
122
- labelColor: 'var(--malloy-label-color, #000000)',
123
- titleFontSize: 12,
124
- },
125
- header: {
126
- labelFont: 'var(--malloy-font-family, Roboto)',
127
- titleFont: 'var(--malloy-font-family, Roboto)',
128
- titleFontWeight: 500,
129
- },
130
- mark: { font: 'var(--malloy-font-family, Roboto)' },
131
- title: {
132
- font: 'var(--malloy-font-family, Roboto)',
133
- subtitleFont: 'var(--malloy-font-family, Roboto)',
134
- fontWeight: 500,
135
- },
136
- },
137
- };
138
- }
139
- }
140
- exports.HTMLSegmentMapRenderer = HTMLSegmentMapRenderer;
141
- class SegmentMapRendererFactory extends renderer_factory_1.RendererFactory {
142
- create(document, styleDefaults, rendererOptions, _field, options, timezone) {
143
- return new HTMLSegmentMapRenderer(document, styleDefaults, rendererOptions, options, timezone);
144
- }
145
- get rendererName() {
146
- return 'segment_map';
147
- }
148
- }
149
- exports.SegmentMapRendererFactory = SegmentMapRendererFactory;
150
- SegmentMapRendererFactory.instance = new SegmentMapRendererFactory();
151
- //# sourceMappingURL=segment_map.js.map
@@ -1,194 +0,0 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
25
- return (mod && mod.__esModule) ? mod : { "default": mod };
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.ShapeMapRendererFactory = exports.HTMLShapeMapRenderer = void 0;
29
- const states_10m_json_1 = __importDefault(require("us-atlas/states-10m.json"));
30
- const chart_1 = require("./chart");
31
- const state_codes_1 = require("./state_codes");
32
- const utils_1 = require("./utils");
33
- const renderer_factory_1 = require("../renderer_factory");
34
- class HTMLShapeMapRenderer extends chart_1.HTMLChartRenderer {
35
- getRegionField(explore) {
36
- return explore.intrinsicFields[0];
37
- }
38
- getColorField(explore) {
39
- return explore.intrinsicFields[1];
40
- }
41
- getDataValue(data) {
42
- if (data.isNumber()) {
43
- return data.value;
44
- }
45
- else if (data.isString()) {
46
- if (data.field === this.getRegionField(data.field.parentExplore)) {
47
- const id = state_codes_1.STATE_CODES[data.value];
48
- if (id === undefined) {
49
- return undefined;
50
- }
51
- return id;
52
- }
53
- else {
54
- return data.value;
55
- }
56
- }
57
- else if (data.isNull()) {
58
- // ignore nulls
59
- return undefined;
60
- }
61
- else {
62
- throw new Error('Invalid field type for shape map.');
63
- }
64
- }
65
- getDataType(field) {
66
- if (field.isAtomicField()) {
67
- if (field.isDate() || field.isTimestamp()) {
68
- return 'nominal';
69
- }
70
- else if (field.isString()) {
71
- if (field === this.getRegionField(field.parentExplore)) {
72
- return 'quantitative';
73
- }
74
- else {
75
- return 'nominal';
76
- }
77
- }
78
- else if (field.isNumber()) {
79
- return 'quantitative';
80
- }
81
- }
82
- throw new Error('Invalid field type for shape map.');
83
- }
84
- getVegaLiteSpec(data) {
85
- if (data.isNull()) {
86
- throw new Error('Expected struct value not to be null.');
87
- }
88
- if (!data.isArray()) {
89
- throw new Error('Invalid data for shape map');
90
- }
91
- const regionField = this.getRegionField(data.field);
92
- const colorField = this.getColorField(data.field);
93
- const colorType = colorField ? this.getDataType(colorField) : undefined;
94
- const colorDef = colorField !== undefined
95
- ? {
96
- field: colorField.name,
97
- type: colorType,
98
- axis: {
99
- title: (0, utils_1.formatTitle)(this.options, colorField, undefined, this.timezone),
100
- },
101
- scale: (0, utils_1.getColorScale)(colorType, false),
102
- }
103
- : undefined;
104
- const mapped = this.mapData(data).filter(row => row[regionField.name] !== undefined);
105
- return {
106
- ...this.getSize(),
107
- data: { values: mapped },
108
- projection: {
109
- type: 'albersUsa',
110
- },
111
- layer: [
112
- {
113
- data: {
114
- values: states_10m_json_1.default,
115
- format: {
116
- type: 'topojson',
117
- feature: 'states',
118
- },
119
- },
120
- mark: {
121
- type: 'geoshape',
122
- fill: '#efefef',
123
- stroke: 'white',
124
- },
125
- },
126
- {
127
- transform: [
128
- {
129
- lookup: regionField.name,
130
- from: {
131
- data: {
132
- values: states_10m_json_1.default,
133
- format: {
134
- type: 'topojson',
135
- feature: 'states',
136
- },
137
- },
138
- key: 'id',
139
- },
140
- as: 'geo',
141
- },
142
- ],
143
- mark: 'geoshape',
144
- encoding: {
145
- shape: { field: 'geo', type: 'geojson' },
146
- color: colorDef,
147
- },
148
- },
149
- ],
150
- background: 'transparent',
151
- config: {
152
- axis: {
153
- labelFont: 'var(--malloy-font-family, Roboto)',
154
- titleFont: 'var(--malloy-font-family, Roboto)',
155
- titleFontWeight: 500,
156
- titleColor: 'var(--malloy-title-color, #505050)',
157
- labelColor: 'var(--malloy-label-color, #000000)',
158
- titleFontSize: 12,
159
- },
160
- legend: {
161
- labelFont: 'var(--malloy-font-family, Roboto)',
162
- titleFont: 'var(--malloy-font-family, Roboto)',
163
- titleFontWeight: 500,
164
- titleColor: 'var(--malloy-title-color, #505050)',
165
- labelColor: 'var(--malloy-label-color, #000000)',
166
- titleFontSize: 12,
167
- },
168
- header: {
169
- labelFont: 'var(--malloy-font-family, Roboto)',
170
- titleFont: 'var(--malloy-font-family, Roboto)',
171
- titleFontWeight: 500,
172
- },
173
- mark: { font: 'var(--malloy-font-family, Roboto)' },
174
- title: {
175
- font: 'var(--malloy-font-family, Roboto)',
176
- subtitleFont: 'var(--malloy-font-family, Roboto)',
177
- fontWeight: 500,
178
- },
179
- },
180
- };
181
- }
182
- }
183
- exports.HTMLShapeMapRenderer = HTMLShapeMapRenderer;
184
- class ShapeMapRendererFactory extends renderer_factory_1.RendererFactory {
185
- create(document, styleDefaults, rendererOptions, _field, options, timezone) {
186
- return new HTMLShapeMapRenderer(document, styleDefaults, rendererOptions, options, timezone);
187
- }
188
- get rendererName() {
189
- return 'shape_map';
190
- }
191
- }
192
- exports.ShapeMapRendererFactory = ShapeMapRendererFactory;
193
- ShapeMapRendererFactory.instance = new ShapeMapRendererFactory();
194
- //# sourceMappingURL=shape_map.js.map