Skip to content
Permalink
Browse files

Add option to scale by area/scale by diameter for PieChart and Text D…

…iagram
  • Loading branch information
m-kuhn committed Aug 10, 2012
1 parent 2c9a3a7 commit 468650bad6b595b6ea6cdfbb21efc06cc3b3b1d9
@@ -862,6 +862,15 @@ void QgsVectorLayerProperties::apply()
ds.labelPlacementMethod = QgsDiagramSettings::XHeight;
}

if ( tr( "Area" ) == mScaleDependencyComboBox->currentText() )
{
ds.scaleByArea = true;
}
else
{
ds.scaleByArea = false;
}

if ( mIncreaseSmallDiagramsCheckBox->isChecked() )
{
ds.minimumSize = mIncreaseMinimumSizeSpinBox->value();
@@ -1374,6 +1383,17 @@ void QgsVectorLayerProperties::handleDiagramTypeChanged( const QString& itemtext
mDiagramOptionsGroupBox->hide();
mBarWidthLabel->hide();
}

if ( tr( "Text diagram" ) == itemtext || tr( "Pie chart" ) == itemtext )
{
mScaleDependencyComboBox->show();
mScaleDependencyLabel->show();
}
else
{
mScaleDependencyComboBox->hide();
mScaleDependencyLabel->hide();
}
}

void QgsVectorLayerProperties::on_mIncreaseSmallDiagramsCheckBox_stateChanged( int state )
@@ -1672,6 +1692,9 @@ void QgsVectorLayerProperties::initDiagramTab()
mLabelPlacementComboBox->addItem( tr( "Height" ) );
mLabelPlacementComboBox->addItem( tr( "x-height" ) );

mScaleDependencyComboBox->addItem( tr( "Area" ) );
mScaleDependencyComboBox->addItem( tr( "Diameter" ) );

//insert all attributes into the combo boxes
const QgsFieldMap& layerFields = layer->pendingFields();
QgsFieldMap::const_iterator fieldIt = layerFields.constBegin();
@@ -36,8 +36,6 @@ QSizeF QgsPieDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsR
{
return QSizeF(); //zero size if attribute is missing
}

bool scaleByArea = true;

double scaledValue = attIt.value().toDouble();
double scaledLowerValue = is.lowerValue;
@@ -48,7 +46,7 @@ QSizeF QgsPieDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsR
double scaledUpperSizeHeight = is.upperSize.height();

// interpolate the squared value if scale by area
if ( scaleByArea )
if ( s.scaleByArea )
{
scaledValue = sqrt( scaledValue );
scaledLowerValue = sqrt( scaledLowerValue );
@@ -32,17 +32,37 @@ QgsTextDiagram::~QgsTextDiagram()

QSizeF QgsTextDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is )
{
QgsAttributeMap::const_iterator attIt = attributes.find( is.classificationAttribute );
QgsAttributeMap::const_iterator attIt = attributes.find( is.classificationAttribute );
if ( attIt == attributes.constEnd() )
{
return QSizeF(); //zero size if attribute is missing
}
double value = attIt.value().toDouble();

double scaledValue = attIt.value().toDouble();
double scaledLowerValue = is.lowerValue;
double scaledUpperValue = is.upperValue;
double scaledLowerSizeWidth = is.lowerSize.width();
double scaledLowerSizeHeight = is.lowerSize.height();
double scaledUpperSizeWidth = is.upperSize.width();
double scaledUpperSizeHeight = is.upperSize.height();

// interpolate the squared value if scale by area
if ( s.scaleByArea )
{
scaledValue = sqrt( scaledValue );
scaledLowerValue = sqrt( scaledLowerValue );
scaledUpperValue = sqrt( scaledUpperValue );
scaledLowerSizeWidth = sqrt( scaledLowerSizeWidth );
scaledLowerSizeHeight = sqrt( scaledLowerSizeHeight );
scaledUpperSizeWidth = sqrt( scaledUpperSizeWidth );
scaledUpperSizeHeight = sqrt( scaledUpperSizeHeight );
}

//interpolate size
double ratio = ( value - is.lowerValue ) / ( is.upperValue - is.lowerValue );
QSizeF size = QSizeF( sqrt( is.upperSize.width() * ratio + is.lowerSize.width() * ( 1 - ratio ) ),
sqrt( is.upperSize.height() * ratio + is.lowerSize.height() * ( 1 - ratio ) ) );
double scaledRatio = ( scaledValue - scaledLowerValue ) / ( scaledUpperValue - scaledLowerValue );

QSizeF size = QSizeF( is.upperSize.width() * scaledRatio + is.lowerSize.width() * ( 1 - scaledRatio ),
is.upperSize.height() * scaledRatio + is.lowerSize.height() * ( 1 - scaledRatio ) );

// Scale, if extension is smaller than the specified minimum
if ( size.width() <= s.minimumSize && size.height() <= s.minimumSize )
@@ -124,6 +124,7 @@ struct CORE_EXPORT QgsDiagramSettings
LabelPlacementMethod labelPlacementMethod;
DiagramOrientation diagramOrientation;
double barWidth;
bool scaleByArea;

//scale range (-1 if no lower / upper bound )
double minScaleDenominator;
@@ -1457,6 +1457,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="mScaleDependencyLabel">
<property name="text">
<string>Scale</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mScaleDependencyComboBox"/>
</item>
</layout>
</item>
<item row="0" column="2">

0 comments on commit 468650b

Please sign in to comment.
You can’t perform that action at this time.