Skip to content

Commit 9eb522c

Browse files
committed
comet3 support
1 parent 3829a38 commit 9eb522c

File tree

5 files changed

+210
-139
lines changed

5 files changed

+210
-139
lines changed

plotly/plotly_offline_aux/plotlyoffline.m

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@
66
% create dependency string unless not required
77
if plotlyfig.PlotOptions.IncludePlotlyjs
88
% grab the bundled dependencies
9-
userhome = getuserdir();
10-
plotly_config_folder = fullfile(userhome,'.plotly');
11-
plotly_js_folder = fullfile(plotly_config_folder, 'plotlyjs');
12-
bundle_name = 'plotly-matlab-offline-bundle.js';
13-
bundle_file = fullfile(plotly_js_folder, bundle_name);
9+
userHome = getuserdir();
10+
plotlyConfigFolder = fullfile(userHome,'.plotly');
11+
plotlyJSFolder = fullfile(plotlyConfigFolder, 'plotlyjs');
12+
bundleName = 'plotly-matlab-offline-bundle.js';
13+
bundleFile = fullfile(plotlyJSFolder, bundleName);
1414

1515
% check that the bundle exists
1616
try
17-
bundle = fileread(bundle_file);
17+
bundle = fileread(bundleFile);
1818
% template dependencies
19-
dep_script = sprintf('<script type="text/javascript">%s</script>\n', ...
19+
depScript = sprintf('<script type="text/javascript">%s</script>\n', ...
2020
bundle);
2121
catch
2222
error(['Error reading: %s.\nPlease download the required ', ...
2323
'dependencies using: >>getplotlyoffline \n', ...
2424
'or contact [email protected] for assistance.'], ...
25-
bundle_file);
25+
bundleFile);
2626
end
2727
else
28-
dep_script = '';
28+
depScript = '';
2929
end
3030

3131
% handle plot div specs
@@ -34,59 +34,59 @@
3434
height = [num2str(plotlyfig.layout.height) 'px'];
3535

3636
if plotlyfig.PlotOptions.ShowLinkText
37-
link_text = plotlyfig.PlotOptions.LinkText;
37+
linkText = plotlyfig.PlotOptions.LinkText;
3838
else
39-
link_text = '';
39+
linkText = '';
4040
end
4141

4242
% format the data and layout
43-
jdata = m2json(plotlyfig.data);
44-
jlayout = m2json(plotlyfig.layout);
45-
jframes = m2json(plotlyfig.frames);
46-
clean_jdata = escapechars(jdata);
47-
clean_jlayout = escapechars(jlayout);
48-
clean_jframes = escapechars(jframes);
43+
jData = m2json(plotlyfig.data);
44+
jLayout = m2json(plotlyfig.layout);
45+
jFrames = m2json(plotlyfig.frames);
46+
clean_jData = escapechars(jData);
47+
clean_jLayout = escapechars(jLayout);
48+
clean_jFrames = escapechars(jFrames);
4949

5050
% template environment vars
51-
plotly_domain = plotlyfig.UserData.PlotlyDomain;
52-
env_script = sprintf(['<script type="text/javascript">', ...
51+
plotlyDomain = plotlyfig.UserData.PlotlyDomain;
52+
envScript = sprintf(['<script type="text/javascript">', ...
5353
'window.PLOTLYENV=window.PLOTLYENV || {};', ...
5454
'window.PLOTLYENV.BASE_URL="%s";', ...
5555
'Plotly.LINKTEXT="%s";', ...
56-
'</script>'], plotly_domain, link_text);
56+
'</script>'], plotlyDomain, linkText);
5757

5858
% template Plotly.plot
5959
script = sprintf(['\n Plotly.plot("%s", {\n"data": %s,\n"layout": %s,\n"frames": %s\n}).then(function(){'...
6060
'\n $(".%s.loading").remove();' ...
6161
'\n $(".link--embedview").text("%s");'...
62-
'\n });'], id, clean_jdata, clean_jlayout, clean_jframes,...
63-
id, link_text);
62+
'\n });'], id, clean_jData, clean_jLayout, clean_jFrames,...
63+
id, linkText);
6464

65-
plotly_script = sprintf(['\n<div id="%s" style="height: %s;',...
65+
plotlyScript = sprintf(['\n<div id="%s" style="height: %s;',...
6666
'width: %s;" class="plotly-graph-div">' ...
6767
'</div> \n<script type="text/javascript">' ...
6868
'%s \n</script>'], id, height, width, ...
6969
script);
7070

7171
% template entire script
72-
offline_script = [dep_script env_script plotly_script];
72+
offlineScript = [depScript envScript plotlyScript];
7373
filename = plotlyfig.PlotOptions.FileName;
7474
if iscellstr(filename), filename = sprintf('%s ', filename{:}); end
7575

7676
% remove the whitespace from the filename
77-
clean_filename = filename(filename~=' ');
78-
html_filename = [clean_filename '.html'];
77+
cleanFilename = filename(filename~=' ');
78+
htmlFilename = [cleanFilename '.html'];
7979

8080
% save the html file in the working directory
81-
plotly_offline_file = fullfile(plotlyfig.PlotOptions.SaveFolder, html_filename);
82-
file_id = fopen(plotly_offline_file, 'w');
83-
fprintf(file_id, offline_script);
84-
fclose(file_id);
81+
plotlyOfflineFile = fullfile(plotlyfig.PlotOptions.SaveFolder, htmlFilename);
82+
fileID = fopen(plotlyOfflineFile, 'w');
83+
fprintf(fileID, offlineScript);
84+
fclose(fileID);
8585

86-
% remove any whitespace from the plotly_offline_file path
87-
plotly_offline_file = strrep(plotly_offline_file, ' ', '%20');
86+
% remove any whitespace from the plotlyOfflineFile path
87+
plotlyOfflineFile = strrep(plotlyOfflineFile, ' ', '%20');
8888

8989
% return the local file url to be rendered in the browser
90-
response = ['file:///' plotly_offline_file];
90+
response = ['file:///' plotlyOfflineFile];
9191

9292
end

plotly/plotlyfig.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
obj.PlotOptions.is_headmap_axis = false;
6363
obj.PlotOptions.Quality = -1;
6464
obj.PlotOptions.Zmin = [];
65+
obj.PlotOptions.FrameDuration = 1; % in ms.
66+
obj.PlotOptions.FrameTransitionDuration = 0; % in ms.
6567

6668
% offline options
6769
obj.PlotOptions.Offline = true;
@@ -253,6 +255,16 @@
253255
if(strcmpi(varargin{a},'Zmin'))
254256
obj.PlotOptions.Zmin = varargin{a+1};
255257
end
258+
if(strcmpi(varargin{a},'FrameDuration'))
259+
if varargin{a+1} > 0
260+
obj.PlotOptions.FrameDuration = varargin{a+1};
261+
end
262+
end
263+
if(strcmpi(varargin{a},'FrameTransitionDuration'))
264+
if varargin{a+1} >= 0
265+
obj.PlotOptions.FrameTransitionDuration = varargin{a+1};
266+
end
267+
end
256268
end
257269
end
258270

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@
219219
if obj.layout.isAnimation
220220
%- Play Button Options-%
221221
opts{1} = nan;
222-
opts{2}.frame.duration = 10;
222+
opts{2}.frame.duration = obj.PlotOptions.FrameDuration;
223223
opts{2}.frame.redraw = true;
224224
opts{2}.fromcurrent = true;
225225
opts{2}.mode = 'immediate';
226-
opts{2}.transition.duration = 0;
226+
opts{2}.transition.duration = obj.PlotOptions.FrameTransitionDuration;
227227

228228
button{1}.label = '&#9654;';
229229
button{1}.method = 'animate';

plotly/plotlyfig_aux/handlegraphics/updateAnimatedLine.m

Lines changed: 19 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,15 @@
11
function updateAnimatedLine(obj,plotIndex)
22

3-
%----SCATTER FIELDS----%
4-
5-
% x - [DONE]
6-
% y - [DONE]
7-
% r - [HANDLED BY SCATTER]
8-
% t - [HANDLED BY SCATTER]
9-
% mode - [DONE]
10-
% name - [NOT SUPPORTED IN MATLAB]
11-
% text - [DONE]
12-
% error_y - [HANDLED BY ERRORBAR]
13-
% error_x - [NOT SUPPORTED IN MATLAB]
14-
% connectgaps - [NOT SUPPORTED IN MATLAB]
15-
% fill - [HANDLED BY AREA]
16-
% fillcolor - [HANDLED BY AREA]
17-
% opacity --- [TODO]
18-
% textfont - [NOT SUPPORTED IN MATLAB]
19-
% textposition - [NOT SUPPORTED IN MATLAB]
20-
% xaxis [DONE]
21-
% yaxis [DONE]
22-
% showlegend [DONE]
23-
% stream - [HANDLED BY PLOTLYSTREAM]
24-
% visible [DONE]
25-
% type [DONE]
26-
27-
% MARKER
28-
% marler.color - [DONE]
29-
% marker.size - [DONE]
30-
% marker.line.color - [DONE]
31-
% marker.line.width - [DONE]
32-
% marker.line.dash - [NOT SUPPORTED IN MATLAB]
33-
% marker.line.opacity - [NOT SUPPORTED IN MATLAB]
34-
% marker.line.smoothing - [NOT SUPPORTED IN MATLAB]
35-
% marker.line.shape - [NOT SUPPORTED IN MATLAB]
36-
% marker.opacity --- [TODO]
37-
% marker.colorscale - [NOT SUPPORTED IN MATLAB]
38-
% marker.sizemode - [NOT SUPPORTED IN MATLAB]
39-
% marker.sizeref - [NOT SUPPORTED IN MATLAB]
40-
% marker.maxdisplayed - [NOT SUPPORTED IN MATLAB]
41-
42-
% LINE
43-
44-
% line.color - [DONE]
45-
% line.width - [DONE]
46-
% line.dash - [DONE]
47-
% line.opacity --- [TODO]
48-
% line.smoothing - [NOT SUPPORTED IN MATLAB]
49-
% line.shape - [NOT SUPPORTED IN MATLAB]
50-
51-
%-------------------------------------------------------------------------%
52-
533
%-AXIS INDEX-%
544
axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis);
555

566
%-PLOT DATA STRUCTURE- %
57-
plot_data = get(obj.State.Plot(plotIndex).Handle);
7+
plotData = get(obj.State.Plot(plotIndex).Handle);
588

599
animObjs = obj.State.Plot(plotIndex).AssociatedAxis.Children;
6010

6111
for i=1:numel(animObjs)
62-
if isequaln(get(animObjs(i)),plot_data)
12+
if isequaln(get(animObjs(i)),plotData)
6313
animObj = animObjs(i);
6414
end
6515
end
@@ -83,9 +33,9 @@ function updateAnimatedLine(obj,plotIndex)
8333
try
8434
[x,y,z] = getpoints(animObj);
8535
catch
86-
x=plot_data.XData;
87-
y=plot_data.YData;
88-
z=plot_data.ZData;
36+
x = plotData.XData;
37+
y = plotData.YData;
38+
z = plotData.ZData;
8939
end
9040

9141
%-------------------------------------------------------------------------%
@@ -110,7 +60,7 @@ function updateAnimatedLine(obj,plotIndex)
11060
%-------------------------------------------------------------------------%
11161

11262
%-scatter visible-%
113-
obj.data{plotIndex}.visible = strcmp(plot_data.Visible,'on');
63+
obj.data{plotIndex}.visible = strcmp(plotData.Visible,'on');
11464

11565
%-------------------------------------------------------------------------%
11666

@@ -155,17 +105,17 @@ function updateAnimatedLine(obj,plotIndex)
155105
%-------------------------------------------------------------------------%
156106

157107
%-scatter name-%
158-
obj.data{plotIndex}.name = plot_data.DisplayName;
108+
obj.data{plotIndex}.name = plotData.DisplayName;
159109

160110
%-------------------------------------------------------------------------%
161111

162112
%-scatter mode-%
163-
if ~strcmpi('none', plot_data.Marker) ...
164-
&& ~strcmpi('none', plot_data.LineStyle)
113+
if ~strcmpi('none', plotData.Marker) ...
114+
&& ~strcmpi('none', plotData.LineStyle)
165115
mode = 'lines+markers';
166-
elseif ~strcmpi('none', plot_data.Marker)
116+
elseif ~strcmpi('none', plotData.Marker)
167117
mode = 'markers';
168-
elseif ~strcmpi('none', plot_data.LineStyle)
118+
elseif ~strcmpi('none', plotData.LineStyle)
169119
mode = 'lines';
170120
else
171121
mode = 'none';
@@ -176,17 +126,17 @@ function updateAnimatedLine(obj,plotIndex)
176126
%-------------------------------------------------------------------------%
177127

178128
%-scatter line-%
179-
obj.data{plotIndex}.line = extractLineLine(plot_data);
129+
obj.data{plotIndex}.line = extractLineLine(plotData);
180130

181131
%-------------------------------------------------------------------------%
182132

183133
%-scatter marker-%
184-
obj.data{plotIndex}.marker = extractLineMarker(plot_data);
134+
obj.data{plotIndex}.marker = extractLineMarker(plotData);
185135

186136
%-------------------------------------------------------------------------%
187137

188138
%-scatter showlegend-%
189-
leg = get(plot_data.Annotation);
139+
leg = get(plotData.Annotation);
190140
legInfo = get(leg.LegendInformation);
191141

192142
switch legInfo.IconDisplayStyle
@@ -206,17 +156,17 @@ function updateAnimatedLine(obj,plotIndex)
206156
%-------------------------------------------------------------------------%
207157

208158
%-Create Frames-%
209-
DD = obj.data{plotIndex};
159+
frameData = obj.data{plotIndex};
210160

211161
for i = 1:length(x)
212-
sIdx = i - plot_data.MaximumNumPoints;
162+
sIdx = i - plotData.MaximumNumPoints;
213163
if sIdx < 0
214164
sIdx=0;
215165
end
216-
DD.x=x(sIdx+1:i);
217-
DD.y=y(sIdx+1:i);
166+
frameData.x=x(sIdx+1:i);
167+
frameData.y=y(sIdx+1:i);
218168
obj.frames{i}.name = ['f',num2str(i)];
219-
obj.frames{i}.data{plotIndex} = DD;
169+
obj.frames{i}.data{plotIndex} = frameData;
220170
end
221171

222172
end

0 commit comments

Comments
 (0)