3

我正在尝试这个图表示例:

funs          = map (flip (^)) [2..6]
visualize f   = stroke' (with & vertexNames .~ [[0 .. 6 :: Int]] )
                    (regPoly 7 1)
                  # lw none
                  # showLabels
                  # fontSize (Local 0.6)
             <> star (StarFun f) (regPoly 7 1)
                  # stroke # lw thick # lc red
example       = center . hcat' (with & sep .~ 0.5) $ map visualize funs

结果如下:

在此处输入图像描述

一切看起来都如预期的那样,一些数字(或更准确地说,这些数字的中心)位于图像边缘附近,因此最终它们看起来像是被切断了。

有没有办法解决这个问题?

4

2 回答 2

9

问题是文本没有信封,因此没有考虑到它的大小。frame您可以使用为信封添加边框的功能来解决您的问题。

example = frame 2 . center . hcat' (with & sep .~ 5) $ map visualize funs

例子

于 2015-03-24T21:13:18.470 回答
1

我通过创建一个新功能部分解决了这个问题addMargin

{-# LANGUAGE NoMonomorphismRestriction #-}

import Diagrams.Prelude
import Diagrams.Backend.SVG.CmdLine



funs          = map (flip (^)) [2..6]
visualize f   = stroke' (with & vertexNames .~ [[0 .. 6 :: Int]] )
                    p
                  # lw none
                  # showLabels
                  # fontSize (Local 1.6)
             <> star (StarFun f) p
                  # stroke # lw thick # lc red
             where
               p = (regPoly 7 2)

example       = center . hcat' (with & sep .~ 5) $ map visualize funs

addMargin m a = c where
  c = s === b === s where
    s = strutY m
    b = s' ||| a ||| s' where
      s' = strutX m


main = mainWith (addMargin 33 example :: Diagram B R2)

在此处输入图像描述

一切看起来都很好,只是右侧的 0 仍然被某些东西覆盖,不知何故。

于 2015-03-24T20:16:11.423 回答