XSL-FO中的进度 - 径向,线性梯度

时间:2017-07-27 08:24:53

标签: svg progress-bar xsl-fo linear-gradients radial-gradients

是否可以使用SVG或其他方法在XSL-fo中创建径向进度条?

我有一项任务是从xsl-fo中编写的XSL生成pdf文档。我们的CSS专家对它进行了编码(但是对于pdf生成和xsl-fo无法帮助我),但不确定如何在xsl-fo中重新创建它,以便pdf文档也具有正确的进度条百分比。

这是我应该重新创建的: Radial progress bar 他的CSS代码的一部分是:

.progress-radial {
    float: left;
    margin-right: 30px;
    position: relative;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    border: 2px solid #aa94a8;
    background-color: #5d2f5d
}
.progress-radial .overlay {
    position: absolute;
    width: 100px;
    height: 100px;
    background-color: #fff;
    border-radius: 50%;
    margin-left: 20px;
    margin-top: 20px;
    text-align: center;
    line-height: 100px;
    font-size: 32px;
    color: #6c566a
}
.progress-0 {
    background-image: linear-gradient(90deg, #aa94a8 50%, transparent 50%, transparent), linear-gradient(90deg, #5d2f5d 50%, #aa94a8 50%, #aa94a8)
}
.progress-1 {
    background-image: linear-gradient(90deg, #aa94a8 50%, transparent 50%, transparent), linear-gradient(93.6deg, #5d2f5d 50%, #aa94a8 50%, #aa94a8)
}
.progress-2 {
    background-image: linear-gradient(90deg, #aa94a8 50%, transparent 50%, transparent), linear-gradient(97.2deg, #5d2f5d 50%, #aa94a8 50%, #aa94a8)
}

谢谢

2 个答案:

答案 0 :(得分:2)

这里有一些与之相关的灵感。鉴于此XML:

<charts>
   <chart percent="20"/>
   <chart percent="40"/>
   <chart percent="90"/>
</charts>

使用这个简单的XSL(我已经删除了所有的XSL FO页面内容):

<xsl:template match="charts">
    <xsl:apply-templates/>
</xsl:template>
<xsl:template match="chart">
    <fo:block>
        <fo:instream-foreign-object>
            <xsl:call-template name="drawchart">
                <xsl:with-param name="percent" select="@percent"/>
                <xsl:with-param name="r" select="90"/>
            </xsl:call-template>
        </fo:instream-foreign-object>
    </fo:block>
</xsl:template>
<xsl:template name="drawchart">
    <xsl:param name="percent"/>
    <xsl:param name="r"/>
    <xsl:variable name="c" select="2*3.1415926*$r"/>
    <xsl:variable name="pct" select="((100-number($percent)) div 100)*number($c)"/>
    <svg id="svg" width="200" height="200" viewport="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
        <circle r="{$r}" cx="100" cy="100" fill="none" stroke="#666" stroke-width="1em" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
        <circle id="bar" r="{$r}" cx="100" fill="none"  cy="100" stroke="#FF9F1E;" stroke-width="1em" stroke-dasharray="565.48" style="stroke-dashoffset: {$pct}px;"></circle>
    </svg>
</xsl:template>

您可以将此作为PDF格式的输出:

enter image description here

您可以在SVG中添加文本(百分比),根据需要更改笔触的颜色,大小和方向/开始。

答案 1 :(得分:0)

如果您使用AH Formatter,则可以使用public function findNextPageByBrandCategoryIds(array $cat_ids, $brand_id, $offset=0, $limit=8 ) { $qb = $this->createQueryBuilder('p'); if( !empty($cat_ids) ){ $cat_ids = implode(',', $cat_ids); $qb->join('p.categories', 'c') ->where($qb->expr()->in('c.id', $cat_ids ) ); } if( !empty($brand_id) ){ $qb->andWhere('p.brand = :brand') ->setParameter('brand', $brand_id); } if( $offset>0 ){ $qb->setFirstResult( $offset ); } $qb->setMaxResults( $limit ); return $qb->getQuery()->getResult(); } private function findNextPageByBrandCategoryIds($cat_id, $brand_id, $offset=0, $limit=8 ) { $em = $this->getDoctrine()->getManager(); $sql = "SELECT p.id, t.id AS translate_id " . "FROM product p INNER JOIN product_translation t ON t.translatable_id = p.id"; $where .= ' WHERE 1=1 ' ; $rsm = new ResultSetMappingBuilder($em); if( !empty($cat_id) ){ $sql .= " LEFT JOIN products_categories c ON c.product_id = p.id "; $where .= " AND c.category_id = ".$cat_id; } if( !empty($brand_id) ){ $where .= " AND p.brand = ".$brand_id; } $limit = ' LIMIT '.$limit; if( $offset>0 ){ $limit .= ' OFFSET '.$offset; } $sql = $sql.$where.$limit; $rsm->addRootEntityFromClassMetadata('AppBundle\Entity\Product', 'p'); $rsm->addJoinedEntityFromClassMetadata('AppBundle\Entity\ProductTranslation', 't', 'p', 'product', array('id' => 'translatable_id')); $query = $em->createNativeQuery($sql, $rsm); return $query->getResult(); } 。见https://www.antennahouse.com/product/ahf64/ahf-ext.html#linear-gradient。否则,您可以在linear-gradient()内生成所需的SVG。