-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixing issue 162 + issue 233 #270
Changes from all commits
7206dff
bac9bfa
803a54a
cc6740d
17c6471
46ba39c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,12 +253,42 @@ | |
|
||
%-xaxis range-% | ||
xaxis.range = log10(axis_data.XLim); | ||
%-xaxis autotick-% | ||
xaxis.autotick = true; | ||
%-xaxis nticks-% | ||
xaxis.nticks = length(axis_data.XTick) + 1; | ||
|
||
elseif strcmp(xaxis.type,'linear') | ||
|
||
if strcmp(axis_data.XTickLabelMode,'auto') | ||
%-xaxis range-% | ||
xaxis.range = axis_data.XLim; | ||
if isnumeric(axis_data.XLim) | ||
xaxis.range = axis_data.XLim; | ||
|
||
elseif isduration(axis_data.XLim) | ||
[temp,type] = convertDuration(axis_data.XLim); | ||
|
||
if (~isduration(temp)) | ||
xaxis.range = temp; | ||
xaxis.type = 'duration'; | ||
xaxis.title = type; | ||
else | ||
xaxis.autorange = true; | ||
xaxis.type = 'duration - specified format'; | ||
end | ||
|
||
elseif isdatetime(axis_data.XLim) | ||
xaxis.range = convertDate(axis_data.XLim); | ||
xaxis.type = 'date'; | ||
else | ||
% data is a category type | ||
end | ||
|
||
%-xaxis autotick-% | ||
xaxis.autotick = true; | ||
%-xaxis numticks-% | ||
xaxis.nticks = length(axis_data.XTick)+1; | ||
|
||
else | ||
%-xaxis show tick labels-% | ||
if isempty(axis_data.XTickLabel) | ||
|
@@ -267,45 +297,29 @@ | |
%-xaxis autorange-% | ||
xaxis.autorange = true; | ||
else | ||
try datevec(axis_data.XTickLabel(1,:),axis_data.UserData.plotly.xdateformat); | ||
%-xaxis type date-% | ||
xaxis.type = 'date'; | ||
try | ||
%find numbers in labels | ||
labelnums = find(~isnan(xlabels)); | ||
%-yaxis type linear-% | ||
xaxis.type = 'linear'; | ||
%-range (overwrite)-% | ||
xaxis.range = [convertDate(datenum(axis_data.XTickLabel(1,:),axis_data.UserData.plotly.xdateformat)), ... | ||
convertDate(datenum(axis_data.XTickLabel(end,:),axis_data.UserData.plotly.xdateformat))]; | ||
delta = (xlabels(labelnums(2)) - xlabels(labelnums(1)))/(labelnums(2)-labelnums(1)); | ||
xaxis.range = [xlabels(labelnums(1))-delta*(labelnums(1)-1) xlabels(labelnums(1)) + (length(xlabels)-labelnums(1))*delta]; | ||
%-yaxis autotick-% | ||
xaxis.autotick = true; | ||
%-yaxis numticks-% | ||
xaxis.nticks = length(axis_data.XTick) + 1; | ||
catch | ||
%x-axis labels | ||
xlabels = str2double(axis_data.XTickLabel); | ||
try | ||
%find numbers in labels | ||
labelnums = find(~isnan(xlabels)); | ||
%-yaxis type linear-% | ||
xaxis.type = 'linear'; | ||
%-range (overwrite)-% | ||
delta = (xlabels(labelnums(2)) - xlabels(labelnums(1)))/(labelnums(2)-labelnums(1)); | ||
xaxis.range = [xlabels(labelnums(1))-delta*(labelnums(1)-1) xlabels(labelnums(1)) + (length(xlabels)-labelnums(1))*delta]; | ||
%-yaxis autotick-% | ||
xaxis.autotick = true; | ||
%-yaxis numticks-% | ||
xaxis.nticks = length(axis_data.XTick) + 1; | ||
catch | ||
%-yaxis type category-% | ||
xaxis.type = 'category'; | ||
%-range (overwrite)-% | ||
xaxis.autorange = true; | ||
%-yaxis autotick-% | ||
xaxis.autotick = true; | ||
end | ||
%-yaxis type category-% | ||
xaxis.type = 'category'; | ||
%-range (overwrite)-% | ||
xaxis.autorange = true; | ||
%-yaxis autotick-% | ||
xaxis.autotick = true; | ||
end | ||
end | ||
end | ||
end | ||
|
||
%-xaxis autotick-% | ||
xaxis.autotick = true; | ||
%-xaxis numticks-% | ||
xaxis.nticks = length(axis_data.XTick) + 1; | ||
|
||
end | ||
|
||
%-------------------------------------------------------------------------% | ||
|
@@ -387,11 +401,6 @@ | |
|
||
%-------------------------------------------------------------------------% | ||
|
||
%-yaxis range-% | ||
yaxis.range = axis_data.YLim; | ||
|
||
%-------------------------------------------------------------------------% | ||
|
||
%-yaxis show tick labels-% | ||
yaxis.showticklabels = true; | ||
|
||
|
@@ -450,12 +459,34 @@ | |
%-xaxis nticks-% | ||
yaxis.nticks = length(axis_data.YTick) + 1; | ||
|
||
elseif strcmp(yaxis.type,'linear') | ||
|
||
%-xaxis range-% | ||
yaxis.range = axis_data.YLim; | ||
elseif strcmp(yaxis.type,'linear') | ||
|
||
if strcmp(axis_data.YTickLabelMode,'auto') | ||
|
||
%-xaxis range-% | ||
if isnumeric(axis_data.YLim) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way that you can make this more DRY? It seems like you have essentially the same code for the X and Y access. Can you put this into a function that works for both axes for example? https://en.wikipedia.org/wiki/Don%27t_repeat_yourself There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually a lot of field are changed and we're not changing the same field each time so it won't be optimal to write everything in a function don't you think |
||
yaxis.range = axis_data.YLim; | ||
|
||
elseif isduration(axis_data.YLim) | ||
|
||
[temp,type] = convertDuration(axis_data.YLim); | ||
|
||
if (~isduration(temp)) | ||
yaxis.range = temp; | ||
yaxis.type = 'duration'; | ||
yaxis.title = type; | ||
else | ||
yaxis.autorange = true; | ||
yaxis.type = 'duration - specified format'; | ||
end | ||
|
||
elseif isdatetime(axis_data.YLim) | ||
yaxis.range = convertDate(axis_data.YLim); | ||
yaxis.type = 'date'; | ||
else | ||
% data is a category type | ||
end | ||
|
||
%-yaxis autotick-% | ||
yaxis.autotick = true; | ||
%-yaxis numticks-% | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
function converted = convertDate(date) | ||
converted = (date - datenum(1969,12,31,19,00,00))*1000*60*60*24; | ||
end | ||
function convertedDate = convertDate(date) | ||
date.Format = 'yyyy-MM-dd HH:mm:ss'; | ||
convertedDate = char(date); | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function [converted,type] = convertDuration(duration) | ||
switch (duration.Format) | ||
case 's' | ||
converted = seconds(duration); | ||
type = 'sec'; | ||
case 'm' | ||
converted = minutes(duration); | ||
type = 'min'; | ||
case 'h' | ||
converted = hours(duration); | ||
type = 'hr'; | ||
case 'd' | ||
converted = days(duration); | ||
type = 'days'; | ||
case 'y' | ||
converted = years(duration); | ||
type = 'yrs'; | ||
otherwise | ||
%no convertion is applied | ||
converted = duration; | ||
type = ''; | ||
|
||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice