@@ -53,10 +53,11 @@ def _make_html(examples):
53
53
accum .append ('<div class="section">\n ' )
54
54
accum .append (' <div class="row auto-eg-padding">\n ' )
55
55
56
- accum . append ( _make_html_name (path , header ) )
56
+ _make_html_name (accum , path , header )
57
57
58
58
accum .append (' <div class="row">\n ' )
59
- accum .append (_make_html_text (path , header , content ))
59
+ _make_html_text (accum , path , header , content )
60
+ _make_plot_url (accum , path , header , content )
60
61
accum .append (" </div>\n " )
61
62
62
63
accum .append (" </div>\n " )
@@ -74,12 +75,12 @@ def _make_html(examples):
74
75
"""
75
76
76
77
77
- def _make_html_name (path , header ):
78
+ def _make_html_name (accum , path , header ):
78
79
"""Make example name block."""
79
80
name = header ["name" ] if header ["name" ] else ""
80
81
_log (not name , f"{ path } does not have name" )
81
82
name = _strip_html (name .replace (" " , "-" ).replace ("," , "" ).lower ())
82
- return HTML_NAME .format (name = name )
83
+ accum . append ( HTML_NAME .format (name = name ) )
83
84
84
85
85
86
HTML_TEXT = """\
@@ -103,7 +104,7 @@ def _make_html_name(path, header):
103
104
"""
104
105
105
106
106
- def _make_html_text (path , header , content ):
107
+ def _make_html_text (accum , path , header , content ):
107
108
"""Make text of example."""
108
109
columns = "twelve" if "horizontal" in header .get ("arrangement" , "" ) else "six"
109
110
markdown_content = markdown (header .get ("markdown_content" , "" ))
@@ -112,12 +113,58 @@ def _make_html_text(path, header, content):
112
113
)
113
114
description = header .get ("description" , "" )
114
115
description = HTML_TEXT_DESCRIPTION .format (text = description ) if description else ""
115
- return HTML_TEXT .format (
116
+ accum . append ( HTML_TEXT .format (
116
117
columns = columns ,
117
118
markdown_content = markdown_content ,
118
119
page_content = page_content ,
119
120
description = description ,
120
- )
121
+ ))
122
+
123
+
124
+
125
+ PLOT_URL = """\
126
+ <div class="{columns} columns">
127
+ {plot_url_img}
128
+ {plot_url_embed}
129
+ </div>
130
+ """
131
+
132
+ PLOT_URL_IMG = """\
133
+ <img src="{plot_url}" />
134
+ """
135
+
136
+ PLOT_URL_EMBED = """\
137
+ <iframe id="auto-examples" src="{plot_url}{embed_class}"
138
+ style="width: {width} height: {height} border: none;"></iframe>
139
+ """
140
+
141
+ def _make_plot_url (accum , path , header , content ):
142
+ """Handle specified plot URL."""
143
+ plot_url = header .get ("plot_url" )
144
+ if not plot_url :
145
+ return
146
+ columns = "twelve" if "horizontal" in header .get ("arrangement" , "" ) else "six"
147
+
148
+ plot_url_img = ""
149
+ plot_url_embed = ""
150
+ if (".gif" in plot_url ) or (".png" in plot_url ):
151
+ plot_url_img = PLOT_URL_IMG .format (plot_url = plot_url )
152
+ else :
153
+ embed_class = ".embed" if "plot.ly" in plot_url else ""
154
+ width = f"{ header .get ('width' , '550' )} px"
155
+ height = f"{ header .get ('height' , '550' )} px"
156
+ plot_url_embed = PLOT_URL_EMBED .format (
157
+ plot_url = plot_url ,
158
+ embed_class = embed_class ,
159
+ width = width ,
160
+ height = height ,
161
+ )
162
+ accum .append (PLOT_URL .format (
163
+ columns = columns ,
164
+ plot_url = plot_url ,
165
+ plot_url_img = plot_url_img ,
166
+ plot_url_embed = plot_url_embed ,
167
+ ))
121
168
122
169
123
170
def _parse_args ():
0 commit comments