MCPcopy Index your code
hub / github.com/MapServer/MapServer / msDrawBarChart

Function msDrawBarChart

mapchart.c:155–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153
154
155int msDrawBarChart(mapObj *map, imageObj *image, pointObj *center,
156 float *values, styleObj **styles, int numvalues,
157 float width, float height, float *maxVal, float *minVal, float barWidth)
158{
159
160 float upperLimit,lowerLimit;
161 float shapeMaxVal,shapeMinVal,pixperval;
162 int c;
163 float vertOrigin,vertOriginClipped,horizStart,y;
164 float left,top,bottom; /*shortcut to pixel boundaries of the chart*/
165
166 top=center->y-height/2.;
167 bottom=center->y+height/2.;
168 left=center->x-width/2.;
169
170 shapeMaxVal=shapeMinVal=values[0];
171 for(c=1;c<numvalues;c++)
172 {
173 if(maxVal==NULL || minVal==NULL) { /*compute bounds if not specified*/
174 if(values[c]>shapeMaxVal)
175 shapeMaxVal=values[c];
176 if(values[c]<shapeMinVal)
177 shapeMinVal=values[c];
178 }
179 }
180
181 /*
182 * use specified bounds if wanted
183 * if not, always show the origin
184 */
185 upperLimit = (maxVal!=NULL)? *maxVal : MS_MAX(shapeMaxVal,0);
186 lowerLimit = (minVal!=NULL)? *minVal : MS_MIN(shapeMinVal,0);
187 if(upperLimit==lowerLimit) {
188 /* treat the case where we would have an unspecified behavior */
189 upperLimit+=0.5;
190 lowerLimit-=0.5;
191 }
192
193 pixperval=(float)height/(upperLimit-lowerLimit);
194 vertOrigin=bottom+lowerLimit*pixperval;
195 vertOriginClipped=(vertOrigin<top) ? top :
196 (vertOrigin>bottom) ? bottom : vertOrigin;
197 horizStart=left;
198 /*
199 color = gdImageColorAllocate(image->img.gd, 0,0,0);
200 gdImageRectangle(image->img.gd, left-1,top-1, center.x+width/2.+1,bottom+1,color);
201 */
202 for(c=0;c<numvalues;c++)
203 {
204 int barHeight=values[c]*pixperval;
205 /*clip bars*/
206 y=((vertOrigin-barHeight)<top) ? top :
207 (vertOrigin-barHeight>bottom) ? bottom : vertOrigin-barHeight;
208 if(y!=vertOriginClipped) { /*don't draw bars of height == 0 (i.e. either values==0, or clipped)*/
209 if(values[c]>0)
210 drawRectangle(map, image, horizStart, y, horizStart+barWidth-1, vertOriginClipped, styles[c]);
211 else
212 drawRectangle(map,image, horizStart, vertOriginClipped, horizStart+barWidth-1 , y, styles[c]);

Callers 1

msDrawBarChartLayerFunction · 0.85

Calls 1

drawRectangleFunction · 0.85

Tested by

no test coverage detected