Skip to content

Commit cc6f7f2

Browse files
committed
updated imgstretch logic
1 parent 02466a6 commit cc6f7f2

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

plotly/presentation_objs/presentation_objs.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
}
4949

5050

51-
5251
def list_of_options(iterable, conj='and', period=True):
5352
"""
5453
Returns an English listing of objects seperated by commas ','
@@ -886,16 +885,16 @@ class Presentation(dict):
886885
:param (str) style: the theme that the presentation will take on. The
887886
themes that are available now are 'martik' and 'moods'.
888887
Default = 'moods'.
889-
:param (bool) imgStretch: if set to True, all images in the presentation
888+
:param (bool) imgStretch: if set to False, all images in the presentation
890889
will not have heights and widths that will not exceed the parent
891890
container they belong to. In other words, images will keep their
892891
original aspect ratios.
893-
Default = False.
892+
Default = True.
894893
895894
For examples see the documentation:\n
896895
https://plot.ly/python/presentations-api/
897896
"""
898-
def __init__(self, markdown_string=None, style='moods', imgStretch=False):
897+
def __init__(self, markdown_string=None, style='moods', imgStretch=True):
899898
self['presentation'] = {
900899
'slides': [],
901900
'slidePreviews': [None for _ in range(496)],
@@ -1090,18 +1089,20 @@ def _markdown_to_presentation(self, markdown_string, style, imgStretch):
10901089
height=specs[2], width=specs[3],
10911090
slide=slide_num)
10921091

1093-
if imgStretch:
1094-
for slide in self['presentation']['slides']:
1095-
for child in slide['children']:
1092+
if not imgStretch:
1093+
for s, slide in enumerate(self['presentation']['slides']):
1094+
for c, child in enumerate(slide['children']):
10961095
if child['type'] in ['Image', 'Plotly']:
10971096
deep_child = child['props']['style']
10981097
width = deep_child['width']
10991098
height = deep_child['height']
11001099

11011100
if width >= height:
1102-
deep_child['max-width'] = deep_child.pop('width')
1101+
self['presentation']['slides'][s]['children'][c]['props']['style']['max-width'] = self['presentation']['slides'][s]['children'][c]['props']['style'].pop('width')
1102+
#deep_child['max-width'] = deep_child.pop('width')
11031103
else:
1104-
deep_child['max-height'] = deep_child.pop('height')
1104+
self['presentation']['slides'][s]['children'][c]['props']['style']['max-height'] = self['presentation']['slides'][s]['children'][c]['props']['style'].pop('height')
1105+
#deep_child['max-height'] = deep_child.pop('height')
11051106

11061107
def _add_empty_slide(self):
11071108
self['presentation']['slides'].append(

plotly/tests/test_core/test_spectacle_presentation/test_spectacle_presentation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ def test_invalid_code_language(self):
5151
markdown_string, style='moods'
5252
)
5353

54-
5554
def test_expected_pres(self):
5655
markdown_string = "# title\n---\ntransition: zoom, fade, fade\n# Colors\nColors are everywhere around us.\nPlotly(https://plot.ly/~AdamKulidjian/3564/)\nImage(https://raw.githubusercontent.com/jackparmer/gradient-backgrounds/master/moods1.png)\n```python\nx=1\n```\n---\nPlotly(https://plot.ly/~AdamKulidjian/3564/)\nPlotly(https://plot.ly/~AdamKulidjian/3564/)\nPlotly(https://plot.ly/~AdamKulidjian/3564/)\nPlotly(https://plot.ly/~AdamKulidjian/3564/)\nPlotly(https://plot.ly/~AdamKulidjian/3564/)\nPlotly(https://plot.ly/~AdamKulidjian/3564/)\nPlotly(https://plot.ly/~AdamKulidjian/3564/)\n---\n"
5756

5857
my_pres = pres.Presentation(
59-
markdown_string, style='moods', imgStretch=False
58+
markdown_string, style='moods', imgStretch=True
6059
)
6160

6261
exp_pres = {'presentation': {'paragraphStyles': {'Body': {'color': '#000016',

0 commit comments

Comments
 (0)