function scoreStair(p,orders)
if nargin < 2
orders = 3;
end
% Plot all entries.
x = [p.date];
y = normalize([p.score],orders);
plot(x,y,'x','markersize',3)
% Add red line through leaders.
isLeader = [p.isLeader];
hold on
stairs(x(isLeader),y(isLeader),'r.-')
set(gca,'ylim',[0 max(y(isLeader))])
% Format display.
datetick('keeplimits')
legend({'passing entry','leading entry'},1)
xlabel('submission time')
ylabel('normalized logarithmic score')
title('Contest History');
set(gca,'YScale','log');
% Find positions of all potential leader labels.
leaderInd = find(isLeader);
xl = x(isLeader);
yl = y(isLeader);
pl = p(isLeader);
t = text(xl(1),yl(1),'foo');
ydiff = zeros(size(xl));
xy = zeros(length(xl),2);
for i = 1:length(leaderInd)
set(t,'Units','pixels');
lastPos = get(t,'Position');
set(t,'Units','data','position',[xl(i) yl(i)]);
set(t,'Units','pixels');
pos = get(t,'position');
d = pos-lastPos;
ydiff(i) = d(2);
xy(i,:) = pos(1:2);
end
delete(t)
% Label biggest jumps to smallest jumps, skipping where there is no room.
toLabel = false(size(xl));
toLabel([1 end]) = true;
[null,ind] = sort(ydiff);
pos = 1:length(ind);
textHeight = 15; % was 12
for i = 1:length(ind)
next = ind(i);
if next ~= 1 && next ~=length(ind)
before = find((pos < next) & toLabel,1,'last');
after = find((pos > next) & toLabel,1);
if (xy(next,1)-xy(before,1)+xy(before,2)-xy(next,2)) > textHeight && ...
(xy(after,1)-xy(next,1)+xy(next,2)-xy(after,2)) > textHeight
toLabel(next) = true;
end
end
end
% Label corner points.
labelCornerPoints(xl(toLabel),yl(toLabel),{pl(toLabel).author});
line(xl(toLabel),yl(toLabel),'color','k','marker','o','markersize',6,'linestyle','none')
set(gca,'Position',get(gca,'Position')+[0 .3 0 -.3])