0

我想为我正在开发的 PM 工具创建一个图表(风险矩阵,PowerPoint 中的风险瀑布)。

在我在 Y 轴上创建的瀑布中,旋转标签。但是这些标签对代码中的厚度变化没有反应。矩形看起来很奇怪并且没有均匀的厚度,而是有奇怪的边缘。

如何将厚度与第一张图(左侧)的厚度相匹配?

示例 PowerPoint 导出的图形 导出的 PowerPoint 图形

风险瀑布标签测量

/*                           
                           -+-    -+-             -+- -+-    
                            |      |               |   |
                            |  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);
}
4

1 回答 1

0

通过在文本框上方绘制另一个矩形(没有边框)解决了这个问题。

        $shape = $currentSlide->createRichTextShape()->setHeight($heightRisk)->setWidth($halfLabelWidth); 
        $offsetX = self::$offsetWaterfallX - $halfLabelWidth;
        $offsetY = self::$offsetWaterfallY + $offsetRiskY;
        $shape->setOffsetX($offsetX);
        $shape->setOffsetY($offsetY);
        $shape->getBorder()->setColor(new Color('FF000000'))->setLineStyle(Border::LINE_SINGLE);
于 2017-10-16T03:55:33.087 回答