4
var canvas = document.getElementById( 'canvas' );
5
var width = parseInt( canvas.style.width ) - 1;
6
var height = parseInt( canvas.style.height ) - 1;
7
var verticalPadding = height * 0.02;
8
var horzontalPadding = verticalPadding;
9
var cellWidth = width / historyLength;
10
var fontSizePixels = 10;
11
var lineHeight = 4; // ?
12
var barBase = Math.round( height - verticalPadding * 2 - fontSizePixels * 2 - lineHeight );
13
var maxBarHeight = barBase - verticalPadding * 2 - fontSizePixels;
14
var barWidth = cellWidth * 0.4;
15
var barPaddingLeft = ( cellWidth - barWidth ) / 2;
16
var barColor = '#0000ff';
17
var barBaseColor = '#808080';
18
var textColor = '#000000';
19
var minLimitColor = '#008000';
20
var maxLimitColor = '#ff0000';
21
var averageColor = '#0080ff';
23
var g = new jsGraphics( 'canvas' );
24
g.setFont( 'sans-serif', fontSizePixels + 'px', Font.PLAIN );
27
g.setColor( barColor );
30
for ( i = 0; i < historyLength; ++i )
32
if ( historyPoints[i][1] )
34
barHeight = Math.round( maxBarHeight * historyPoints[i][1] / maxValue );
35
g.fillRect( cellWidth * i + barPaddingLeft, barBase - barHeight, barWidth, barHeight );
39
g.setColor( averageColor );
40
var previousPoint = barBase - Math.round( maxBarHeight * historyPoints[0][2] / maxValue );
43
for ( i = 1; i < historyLength; ++i )
45
nextPoint = barBase - Math.round( maxBarHeight * historyPoints[i][2] / maxValue );
46
g.drawLine( cellWidth * ( i - 1 ) + cellWidth / 2, previousPoint, cellWidth * i + cellWidth / 2, nextPoint );
47
previousPoint = nextPoint;
50
g.setColor( barBaseColor );
51
g.drawLine( 0, barBase, width, barBase );
55
var minLimitPos = barBase - maxBarHeight * minLimit / maxValue;
56
g.setColor( minLimitColor );
57
g.drawLine( 0, minLimitPos, width, minLimitPos );
62
var maxLimitPos = barBase - maxBarHeight * maxLimit / maxValue;
63
g.setColor( maxLimitColor );
64
g.drawLine( 0, maxLimitPos, width, maxLimitPos );
67
g.setColor( textColor );
69
for ( i = 0; i < historyLength; ++i )
71
if ( historyPoints[i][1] )
73
barHeight = Math.round( maxBarHeight * historyPoints[i][1] / maxValue );
74
g.drawStringRect( historyPoints[i][1].toFixed(), cellWidth * ( i - 1 ) + cellWidth / 2, barBase - barHeight - verticalPadding - fontSizePixels, cellWidth * 2, 'center' );
77
g.drawStringRect( historyPoints[i][0], cellWidth * i, barBase + verticalPadding, cellWidth, 'center' );
83
function saveMinLimit( organisationUnitId, dataElementId )
85
var minLimitField = document.getElementById( "minLimit" );
86
var maxLimitField = document.getElementById( "maxLimit" );
88
var request = new Request();
89
request.setCallbackSuccess( refreshWindow );
90
request.setCallbackError( refreshWindow );
92
if ( minLimitField.value == '' )
94
request.send( 'removeMinMaxLimits.action?organisationUnitId=' + organisationUnitId + '&dataElementId=' + dataElementId );
98
var minLimit = Number( minLimitField.value );
99
var maxLimit = Number( maxLimitField.value );
108
if ( !maxLimit || maxLimit <= minLimit )
110
maxLimit = minLimit + 1;
113
request.send( 'saveMinMaxLimits.action?organisationUnitId=' + organisationUnitId + '&dataElementId=' + dataElementId + '&minLimit=' + minLimit + '&maxLimit=' + maxLimit );
122
function saveMaxLimit( organisationUnitId, dataElementId )
124
var minLimitField = document.getElementById( "minLimit" );
125
var maxLimitField = document.getElementById( "maxLimit" );
127
var request = new Request();
128
request.setCallbackSuccess( refreshWindow );
129
request.setCallbackError( refreshWindow );
131
if ( maxLimitField.value == '' )
133
request.send( 'removeMinMaxLimits.action?organisationUnitId=' + organisationUnitId + '&dataElementId=' + dataElementId );
137
var minLimit = Number( minLimitField.value );
138
var maxLimit = Number( maxLimitField.value );
151
else if ( minLimit >= maxLimit )
153
minLimit = maxLimit - 1;
156
request.send( 'saveMinMaxLimits.action?organisationUnitId=' + organisationUnitId + '&dataElementId=' + dataElementId + '&minLimit=' + minLimit + '&maxLimit=' + maxLimit );
165
function refreshWindow()
167
window.location.reload();