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

Function msDrawVBarChartLayer

mapchart.c:400–462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

398}
399
400int msDrawVBarChartLayer(mapObj *map, layerObj *layer, imageObj *image)
401{
402 shapeObj shape;
403 int status=MS_SUCCESS;
404 const char *chartSizeProcessingKey=msLayerGetProcessingKey( layer,"CHART_SIZE" );
405 const char *chartScaleProcessingKey=msLayerGetProcessingKey( layer,"CHART_SCALE" );
406 float barWidth,scale=1.0;
407 float *values;
408 styleObj **styles;
409 pointObj center;
410 int numvalues = layer->numclasses;
411 if(chartSizeProcessingKey==NULL)
412 {
413 barWidth=20;
414 }
415 else
416 {
417 if(sscanf(chartSizeProcessingKey ,"%f",&barWidth) != 1) {
418 msSetError(MS_MISCERR, "msDrawChart format error for processing key \"CHART_SIZE\"", "msDrawVBarChartLayer()");
419 return MS_FAILURE;
420 }
421 }
422
423 if(chartScaleProcessingKey){
424 if(sscanf(chartScaleProcessingKey,"%f",&scale)!=1) {
425 msSetError(MS_MISCERR, "Error reading value for processing key \"CHART_SCALE\"", "msDrawVBarChartLayer()");
426 return MS_FAILURE;
427 }
428 }
429 msInitShape(&shape);
430
431 values=(float*)calloc(numvalues,sizeof(float));
432 MS_CHECK_ALLOC(values, numvalues*sizeof(float), MS_FAILURE);
433 styles = (styleObj**)malloc(numvalues*sizeof(styleObj*));
434 if (styles == NULL)
435 {
436 msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msDrawVBarChartLayer()",
437 __FILE__, __LINE__, numvalues*sizeof(styleObj*));
438 free(values);
439 return MS_FAILURE;
440 }
441
442 while(MS_SUCCESS == getNextShape(map,layer,values,styles,&shape)) {
443 int i;
444 double h=0;
445 for(i=0;i<numvalues;i++) {
446 values[i]*=scale;
447 h += values[i];
448 }
449 msDrawStartShape(map, layer, image, &shape);
450 if(findChartPoint(map, &shape, barWidth,h, &center)==MS_SUCCESS) {
451 status = msDrawVBarChart(map,image,
452 &center,
453 values, styles, numvalues,
454 barWidth);
455 }
456 msDrawEndShape(map,layer,image,&shape);
457 msFreeShape(&shape);

Callers 1

msDrawChartLayerFunction · 0.85

Calls 9

msLayerGetProcessingKeyFunction · 0.85
msSetErrorFunction · 0.85
msInitShapeFunction · 0.85
getNextShapeFunction · 0.85
msDrawStartShapeFunction · 0.85
findChartPointFunction · 0.85
msDrawVBarChartFunction · 0.85
msDrawEndShapeFunction · 0.85
msFreeShapeFunction · 0.85

Tested by

no test coverage detected