Skip to content

Commit ba4a7d3

Browse files
nlafleurmattijnbinste
authored
Enhancement of Vega-Embed CSS for Improved Display and Flexibility (#2867)
* Update html.py * include output_div tag and inline_html_template * include note in changes.rst * include style within universal template * remove trailing whitespace * update changes.rst * Update doc/releases/changes.rst Co-authored-by: Stefan Binder <[email protected]> --------- Co-authored-by: Mattijn van Hoek <[email protected]> Co-authored-by: Stefan Binder <[email protected]>
1 parent c273c0a commit ba4a7d3

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

altair/utils/html.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@
1010
<head>
1111
{%- endif %}
1212
<style>
13-
.error {
14-
color: red;
13+
#{{ output_div }}.vega-embed {
14+
width: 100%;
15+
display: flex;
16+
}
17+
18+
#{{ output_div }}.vega-embed details,
19+
#{{ output_div }}.vega-embed details summary {
20+
position: relative;
1521
}
1622
</style>
1723
{%- if not requirejs %}
@@ -60,7 +66,7 @@
6066
var embedOpt = {{ embed_options }};
6167
6268
function showError(el, error){
63-
el.innerHTML = ('<div class="error" style="color:red;">'
69+
el.innerHTML = ('<div style="color:red;">'
6470
+ '<p>JavaScript Error: ' + error.message + '</p>'
6571
+ "<p>This usually means there's a typo in your chart specification. "
6672
+ "See the javascript console for the full traceback.</p>"
@@ -83,6 +89,17 @@
8389

8490
HTML_TEMPLATE_UNIVERSAL = jinja2.Template(
8591
"""
92+
<style>
93+
#{{ output_div }}.vega-embed {
94+
width: 100%;
95+
display: flex;
96+
}
97+
98+
#{{ output_div }}.vega-embed details,
99+
#{{ output_div }}.vega-embed details summary {
100+
position: relative;
101+
}
102+
</style>
86103
<div id="{{ output_div }}"></div>
87104
<script type="text/javascript">
88105
var VEGA_DEBUG = (typeof VEGA_DEBUG == "undefined") ? {} : VEGA_DEBUG;
@@ -151,6 +168,17 @@
151168
<!DOCTYPE html>
152169
<html>
153170
<head>
171+
<style>
172+
#{{ output_div }}.vega-embed {
173+
width: 100%;
174+
display: flex;
175+
}
176+
177+
#{{ output_div }}.vega-embed details,
178+
#{{ output_div }}.vega-embed details summary {
179+
position: relative;
180+
}
181+
</style>
154182
<script type="text/javascript">
155183
// vega.js v{{ vega_version }}
156184
{{ vega_script }}

doc/releases/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Enhancements
2424
- Substantially improved error handling. Both in terms of finding the more relevant error (#2842), and in terms of improving the formatting and clarity of the error messages (#2824, #2568, #2979, #3009).
2525
- Include experimental support for the DataFrame Interchange Protocol (through ``__dataframe__`` attribute). This requires ``pyarrow>=11.0.0`` (#2888).
2626
- Support data type inference for columns with special characters (#2905).
27+
- Responsive width support using ``width="container"`` when saving charts to html or displaying them with the default `html` renderer (#2867).
2728

2829
Grammar Changes
2930
~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)