-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgante.m
54 lines (50 loc) · 1.73 KB
/
gante.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
function gante(a,VArray)
%% Draw gante chart
K=size(VArray,2);
Vsum=max(a(:,2));
figure;
w=0.5;
set(gcf,'color','w');
for ii=1:Vsum
x=a(ii,[3 3 4 4]);
y=a(ii,1)+[-w/2 w/2 w/2 -w/2];
if K == 2
if ii<=VArray(1)
patch('xdata',x,'ydata',y,'facecolor','red','edgecolor','red','LineWidth',2,'FaceAlpha',.2);
else
patch('xdata',x,'ydata',y,'facecolor','blue','edgecolor','blue','LineWidth',2,'FaceAlpha',.2);
end
else
p=patch('xdata',x,'ydata',y,'facecolor','red','edgecolor','red','LineWidth',2,'FaceAlpha',.2);
end
txt=sprintf('J_{%d}=%.1f',a(ii,2),a(ii,4)-a(ii,3));
text(a(ii,3)+0.5,a(ii,1),txt,'fontsize',7);
end
tmax=max(a(:,4));
if Vsum > VArray(1)
x=[tmax-7 tmax-7 tmax-3 tmax-3];
y=1+[-w/2 w/2 w/2 -w/2];
patch('xdata',x,'ydata',y,'facecolor','blue','edgecolor','blue','LineWidth',2,'FaceAlpha',.2);
x=[tmax-7 tmax-7 tmax-3 tmax-3];
y=2+[-w/2 w/2 w/2 -w/2];
patch('xdata',x,'ydata',y,'facecolor','red','edgecolor','red','LineWidth',2,'FaceAlpha',.2);
text(tmax-2.5,1,'Project 2','fontsize',10);
text(tmax-2.5,2,'Project 1','fontsize',10);
else
x=[tmax-7 tmax-7 tmax-3 tmax-3];
y=1+[-w/2 w/2 w/2 -w/2];
p=patch('xdata',x,'ydata',y,'facecolor','red','edgecolor','red','LineWidth',2,'FaceAlpha',.2);
text(tmax-2.5,1,'Project 1','fontsize',10);
end
title('Scheduling Gantt Chart');
xlabel('time/week');
ylabel('Task Number');
xmax=max(a(:,2));
ymax=max(a(:,3));
axis([0 ymax+10 0 xmax+1]);
set(gca,'Box','on');
set(gca,'YTick',0:Vsum);
set(gca,'YTickLabel',[{''};num2str((1:Vsum)','J_{%d}');{''}]);
x_width=30 ;y_width=25;
set(gcf, 'PaperPosition', [0 0 x_width y_width]); %
saveas(gcf,'images/project_gante.png')