4747 )
4848 $randomNegativePie
4949 ) save ./RandomPieGraphWithNegativeMorph.svg
50+ . EXAMPLE
51+ # Multiple pie graphs
52+ turtle PieGraph 400 (1,2,4,8,4,2,1) jump 800 rotate 180 PieGraph 400 (1,2,4,8,4,2,1) save ./pg.svg
5053#>
5154param (
5255# The radius of the bar graph
@@ -97,6 +100,11 @@ $Slices = @(
97100 }
98101 $richSlices = $true
99102 }
103+ elseif ($DataPoint -is ' Microsoft.PowerShell.Commands.GroupInfo' ) {
104+ $total += $dataPoint.Count
105+ $dataPoint.Count
106+ $richSlices = $true
107+ }
100108 }
101109)
102110
@@ -108,28 +116,22 @@ $relativeSlices =
108116if (-not $relativeSlices ) { return $this }
109117
110118# Next let's figure out the maximum delta x and delta y
111- $dx = $this.X + ( $Radius * 2 )
112- $dy = $this.Y + ( $Radius * 2 )
119+ $dx = $this.X + $Radius
120+ $dy = $this.Y + $Radius
113121# and resize our viewbox with respect to our radius
114122$null = $this.ResizeViewBox ($Radius )
115123
116- # Calulate the midpoint of the circle
117- $midX = $this.X + $dx / 2
118- $midY = $this.Y + $dy / 2
119-
120- # and teleport to it
121- $null = $this.Teleport ($midX , $midY )
122-
123- # If we are not rendering "rich" slices, we can draw the arcs as one path.
124+ # If we are not rendering "rich" slices, we can draw the arcs as one path
124125if (-not $richSlices ) {
126+ # and we do not need to teleport
125127 for ($sliceNumber = 0 ; $sliceNumber -lt $Slices.Length ; $sliceNumber ++ ) {
126128 # Turn each ratio into an angle
127129 $Angle = $relativeSlices [$sliceNumber ] * 360
128130 $this = $this .
129131 # Draw an arc of that angle,
130132 CircleArc($Radius , $Angle ).
131133 # then rotate by the angle.
132- Rotate($angle )
134+ Rotate($angle )
133135 }
134136}
135137else {
@@ -138,11 +140,14 @@ else {
138140 # The idea is the same, but the implementation is more complicated
139141 $heading = $this.Heading
140142 if (-not $heading ) { $heading = 0.0 }
143+ # Calulate the midpoint of the circle
144+ $midX = $this.X + ($dx - $this.X )/ 2
145+ $midY = $this.Y + ($dy - $this.Y )/ 2
141146 for ($sliceNumber = 0 ; $sliceNumber -lt $Slices.Length ; $sliceNumber ++ ) {
142147 $Angle = $relativeSlices [$sliceNumber ] * 360
143- $sliceName = " slice$sliceNumber "
148+ $sliceName = " slice$sliceNumber "
144149 # created a nested turtle at the midpoint
145- $nestedTurtles [" slice$sliceNumber " ] = turtle teleport $midX $midY
150+ $nestedTurtles [" slice$sliceNumber " ] = turtle teleport $this .X $this .Y
146151 # with the current heading
147152 $nestedTurtles [" slice$sliceNumber " ].Heading = $this.Heading
148153 # and arc by the angle
0 commit comments