我想为我正在开发的 PM 工具创建一个图表(风险矩阵,PowerPoint 中的风险瀑布)。
在我在 Y 轴上创建的瀑布中,旋转标签。但是这些标签对代码中的厚度变化没有反应。矩形看起来很奇怪并且没有均匀的厚度,而是有奇怪的边缘。
如何将厚度与第一张图(左侧)的厚度相匹配?
风险瀑布标签测量
/*
-+- -+- -+- -+-
| | | |
| offsetRiskY (High) | |
| | | |
---+--- -+- | offsetRiskY(Med) = offsetRiskY(High) + heightRiskHigh
| | | |
centerRiskY --------- + heightRisk (High) | |
| | | |
---+--- -+- | -+-
| | |
centerRiskY --------- + heightRisk (Med) offsetRiskYLow = offsetRiskYHigh + heightRiskHigh + heightRiskMed + waterfallHeight = heightHigh + heightMed + heightLow
| | |
---+--- -+- -+-
| |
centerRiskY --------- + heightRisk (Low)
| |
---+--- -+-
*
/ \
|
|
|
|
halfLabelWidth ------+
|------heightRisk/2-----+------heightRisk/2------|
+------------------------------------------------+
halfLabelWidth | |
+ Risk Label +
halfLabelWidth | |
+------------------------------------------------+
*/
代码
public function generateRiskWaterfallLabelYAxis($heightRisk, $offsetRiskY, $labelText)
{
$halfRiskHeight = $heightRisk/2;
$centerRiskY = $offsetRiskY + $halfRiskHeight;
$labelWidth = self::$waterfallHeight - $centerRiskY;
$halfLabelWidth = self::$waterfallLabelWidth/2;
$currentSlide = $this->riskPPT->getActiveSlide();
$shape = $currentSlide->createRichTextShape()->setHeight($halfLabelWidth)->setWidth($heightRisk); //swap width, height for rotation (90 degrees)
$shape->setOffsetX(-$halfRiskHeight);
$shape->setOffsetY($centerRiskY + self::$offsetWaterfallY);
$shape->setRotation(-90);
$offsetX = $shape->getOffsetX() + self::$offsetWaterfallX - $halfLabelWidth/2;
$offsetY = $shape->getOffsetY() - $halfLabelWidth/2;
$shape->setOffsetX($offsetX);
$shape->setOffsetY($offsetY);
$textRun = $shape->createTextRun($labelText); $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); $shape->getActiveParagraph()->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
$shape->getBorder()->setColor(new Color('FF'. self::$borderColor))->setLineStyle(Border::LINE_SINGLE)->setLineWidth(1);
}
public function generateRiskWaterfallLabelsYAxis()
{
$maxRisk = 1.0;
//High
$heightHigh = self::$waterfallHeight*($maxRisk-$this->minHigh);
$offsetRiskHigh = 0;
$riskTextHigh = 'High';
$this->generateRiskWaterfallLabelYAxis($heightHigh, $offsetRiskHigh, $riskTextHigh);
//Med
$heightMed = self::$waterfallHeight*($this->minHigh-$this->maxLow);
$offsetRiskMed = $heightHigh;
$riskTextMed = 'Med';
$this->generateRiskWaterfallLabelYAxis($heightMed, $offsetRiskMed, $riskTextMed);
//Low
$heightLow = self::$waterfallHeight*$this->maxLow;
$offsetRiskLow = $heightHigh + $heightMed;
$riskTextLow = 'Low';
$this->generateRiskWaterfallLabelYAxis($heightLow, $offsetRiskLow, $riskTextLow);
}