AbstractChart.java 文件源码

java
阅读 22 收藏 0 点赞 0 评论 0

项目:iOffice 作者:
/**
 * single legend width and height
 * @param renderer
 * @param titles
 * @param paint
 * @param chartWidth
 * @return
 */
public Rectangle getSingleAutoLegendSize(DefaultRenderer renderer, String[] titles, Paint paint, int legendWidth)
{
 float width = -1f;
 float height = -1f;

 paint.setTextSize(renderer.getLegendTextSize() * renderer.getZoomRate());
 int seriesCnt = Math.min(titles.length, renderer.getSeriesRendererCount());
    for (int i = 0; i < seriesCnt; i++)
    {
      String text = titles[i].replace("\n", " ");
      //the rest cell
        FontMetrics fm = paint.getFontMetrics();        
        // 文本高度
        height = Math.max((float)(Math.ceil(fm.descent - fm.ascent)), height);  
        // 文本宽度
        width = Math.max((float)(paint.measureText(text)), width);
    }

    float maxLegendTextWidth = legendWidth - getLegendShapeWidth(0) * renderer.getZoomRate() * 2;
    if(width > maxLegendTextWidth)
 {
  //the max width legend shape layout more than one lines
  int lines = (int)Math.ceil(width / maxLegendTextWidth);
  return new Rectangle(legendWidth, (int)Math.ceil(height) * lines);
 }
 else
 {
  return new Rectangle((int)Math.ceil(width + getLegendShapeWidth(0) * renderer.getZoomRate() * 2), (int)Math.ceil(height));
 }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号