Skip to content

Commit edd14f7

Browse files
committed
Let scale value for pie diagrams denote diameter rather than area
1 parent 313163d commit edd14f7

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/core/diagram/qgspiediagram.cpp

+26-4
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,34 @@ QSizeF QgsPieDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsR
3636
{
3737
return QSizeF(); //zero size if attribute is missing
3838
}
39-
double value = attIt.value().toDouble();
39+
40+
bool scaleByArea = true;
41+
42+
double scaledValue = attIt.value().toDouble();
43+
double scaledLowerValue = is.lowerValue;
44+
double scaledUpperValue = is.upperValue;
45+
double scaledLowerSizeWidth = is.lowerSize.width();
46+
double scaledLowerSizeHeight = is.lowerSize.height();
47+
double scaledUpperSizeWidth = is.upperSize.width();
48+
double scaledUpperSizeHeight = is.upperSize.height();
49+
50+
// interpolate the squared value if scale by area
51+
if ( scaleByArea )
52+
{
53+
scaledValue = sqrt( scaledValue );
54+
scaledLowerValue = sqrt( scaledLowerValue );
55+
scaledUpperValue = sqrt( scaledUpperValue );
56+
scaledLowerSizeWidth = sqrt( scaledLowerSizeWidth );
57+
scaledLowerSizeHeight = sqrt( scaledLowerSizeHeight );
58+
scaledUpperSizeWidth = sqrt( scaledUpperSizeWidth );
59+
scaledUpperSizeHeight = sqrt( scaledUpperSizeHeight );
60+
}
4061

4162
//interpolate size
42-
double ratio = ( value - is.lowerValue ) / ( is.upperValue - is.lowerValue );
43-
QSizeF size = QSizeF( sqrt( is.upperSize.width() * ratio + is.lowerSize.width() * ( 1 - ratio ) ),
44-
sqrt( is.upperSize.height() * ratio + is.lowerSize.height() * ( 1 - ratio ) ) );
63+
double scaledRatio = ( scaledValue - scaledLowerValue ) / ( scaledUpperValue - scaledLowerValue );
64+
65+
QSizeF size = QSizeF( is.upperSize.width() * scaledRatio + is.lowerSize.width() * ( 1 - scaledRatio ),
66+
is.upperSize.height() * scaledRatio + is.lowerSize.height() * ( 1 - scaledRatio ) );
4567

4668
// Scale, if extension is smaller than the specified minimum
4769
if ( size.width() <= s.minimumSize && size.height() <= s.minimumSize )

0 commit comments

Comments
 (0)