forked from piermorel/gramm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeom_line.m
99 lines (82 loc) · 4.82 KB
/
geom_line.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function obj=geom_line(obj,varargin)
% geom_line Display data as lines
%
% This will add a layer that will display data as lines
% If the data is not properly grouped/ordered things can look weird.
p=inputParser;
my_addParameter(p,'dodge',0);
my_addParameter(p,'alpha',1);
parse(p,varargin{:});
obj.geom=vertcat(obj.geom,{@(dobj,dd)my_line(dobj,dd,p.Results)});
obj.results.geom_line_handle={};
end
function hndl=my_line(obj,draw_data,params)
if obj.continuous_color_options.active
obj.plot_lim.maxc(obj.current_row,obj.current_column)=max(obj.plot_lim.maxc(obj.current_row,obj.current_column),max(comb(draw_data.continuous_color)));
obj.plot_lim.minc(obj.current_row,obj.current_column)=min(obj.plot_lim.minc(obj.current_row,obj.current_column),min(comb(draw_data.continuous_color)));
if isempty(draw_data.z)
[x,y]=to_polar(obj,draw_data.x,draw_data.y);
%We fake continuous colors lines by creating patch objects
%without fill. Since they need to be closed we draw the
%line twice
if iscell(x)
for k=1:length(x)
if iscell(draw_data.continuous_color) %Within-line continuous color given
hndl=patch([shiftdim(x{k}) ; flipud(shiftdim(x{k}))],...
[shiftdim(y{k}) ; flipud(shiftdim(y{k}))],...
[shiftdim(draw_data.continuous_color{k}) ; flipud(shiftdim(draw_data.continuous_color{k}))],...
'faceColor','none','EdgeColor','interp','lineWidth',draw_data.line_size,'LineStyle',draw_data.line_style);
else %Per-line continuous color given
hndl=patch([shiftdim(x{k}) ; flipud(shiftdim(x{k}))],...
[shiftdim(y{k}) ; flipud(shiftdim(y{k}))],...
repmat(draw_data.continuous_color(k),length(x{k})*2,1),...
'faceColor','none','EdgeColor','interp','lineWidth',draw_data.line_size,'LineStyle',draw_data.line_style);
end
end
else
hndl=patch([shiftdim(x) ; flipud(shiftdim(x))],...
[shiftdim(y) ; flipud(shiftdim(y))],...
[shiftdim(draw_data.continuous_color) ; flipud(shiftdim(draw_data.continuous_color))],...
'faceColor','none','EdgeColor','interp','lineWidth',draw_data.line_size,'LineStyle',draw_data.line_style);
end
else
if iscell(draw_data.x)
for k=1:length(draw_data.x)
if iscell(draw_data.continuous_color) %Within-line continuous color given
hndl=patch([shiftdim(draw_data.x{k}) ; flipud(shiftdim(draw_data.x{k}))],...
[shiftdim(draw_data.y{k}) ; flipud(shiftdim(draw_data.y{k}))],...
[shiftdim(draw_data.z{k}) ; flipud(shiftdim(draw_data.z{k}))],...
[shiftdim(draw_data.continuous_color{k}) ; flipud(shiftdim(draw_data.continuous_color{k}))],...
'faceColor','none','EdgeColor','interp','lineWidth',draw_data.line_size,'LineStyle',draw_data.line_style);
else %Per-line continuous color given
hndl=patch([shiftdim(draw_data.x{k}) ; flipud(shiftdim(draw_data.x{k}))],...
[shiftdim(draw_data.y{k}) ; flipud(shiftdim(draw_data.y{k}))],...
[shiftdim(draw_data.z{k}) ; flipud(shiftdim(draw_data.z{k}))],...
repmat(draw_data.continuous_color(k),length(draw_data.x{k})*2,1),...
'faceColor','none','EdgeColor','interp','lineWidth',draw_data.line_size,'LineStyle',draw_data.line_style);
end
end
else
hndl=patch([shiftdim(draw_data.x) ; flipud(shiftdim(draw_data.x))],...
[shiftdim(draw_data.y) ; flipud(shiftdim(draw_data.y))],...
[shiftdim(draw_data.z) ; flipud(shiftdim(draw_data.z))],...
[shiftdim(draw_data.continuous_color) ; flipud(shiftdim(draw_data.continuous_color))],...
'faceColor','none','EdgeColor','interp','lineWidth',draw_data.line_size,'LineStyle',draw_data.line_style);
end
end
else
%Combnan allows for drawing multiple lines without loops
%(it adds a NaN between lines that have to be separated)
if isempty(draw_data.z)
x=combnan(draw_data.x);
y=combnan(draw_data.y);
x=dodger(x,draw_data,params.dodge);
[x,y]=to_polar(obj,x,y);
hndl=line(combnan(x),combnan(y),'LineStyle',draw_data.line_style,'lineWidth',draw_data.line_size,'Color',draw_data.color);
else
hndl=line(combnan(draw_data.x),combnan(draw_data.y),combnan(draw_data.z),'LineStyle',draw_data.line_style,'lineWidth',draw_data.line_size,'Color',draw_data.color);
end
end
set_alpha(hndl,params.alpha,1);
obj.results.geom_line_handle{obj.result_ind,1}=hndl;
end