MCPcopy Create free account
hub / github.com/ajstarks/svgo / plot

Function plot

svgplot/svgplot.go:160–265  ·  view source on GitHub ↗

plot places a plot at the specified location with the specified dimemsions usinng the specified settings, using the specified data

(x, y, w, h int, settings plotset, d []rawdata)

Source from the content-addressed store, hash-verified

158// plot places a plot at the specified location with the specified dimemsions
159// usinng the specified settings, using the specified data
160func plot(x, y, w, h int, settings plotset, d []rawdata) {
161 nd := len(d)
162 if nd < 2 {
163 fmt.Fprintf(os.Stderr, "%d is not enough points to plot\n", len(d))
164 return
165 }
166 // Compute the minima and maxima
167 maxx, minx := d[0].x, d[0].x
168 maxy, miny := d[0].y, d[0].y
169 for _, v := range d {
170
171 if v.x > maxx {
172 maxx = v.x
173 }
174 if v.y > maxy {
175 maxy = v.y
176 }
177 if v.x < minx {
178 minx = v.x
179 }
180 if v.y < miny {
181 miny = v.y
182 }
183 }
184
185 if settings.size["ymin"] != smallint {
186 miny = float64(settings.size["ymin"])
187 }
188 if settings.size["ymax"] != smallint {
189 maxy = float64(settings.size["ymax"])
190 }
191 // Prepare for a area or line chart by allocating
192 // polygon coordinates; for the hrizon plot, you need two extra coordinates
193 // for the extrema.
194 needpoly := settings.opt["area"] || settings.opt["connect"]
195 var xpoly, ypoly []int
196 if needpoly {
197 xpoly = make([]int, nd+2)
198 ypoly = make([]int, nd+2)
199 // preload the extrema of the polygon,
200 // the bottom left and bottom right of the plot's rectangle
201 xpoly[0] = x
202 ypoly[0] = y + h
203 xpoly[nd+1] = x + w
204 ypoly[nd+1] = y + h
205 }
206 // Draw the plot's bounding rectangle
207 if settings.opt["showbg"] && !settings.opt["sameplot"] {
208 canvas.Rect(x, y, w, h, "fill:"+settings.attr["bgcolor"])
209 }
210 // Loop through the data, drawing items as specified
211 spacer := 10
212 canvas.Gstyle(fmt.Sprintf(globalfmt,
213 settings.attr["font"], settings.size["fontsize"], settings.size["linesize"]))
214
215 for i, v := range d {
216 xp := int(fmap(v.x, minx, maxx, float64(x), float64(x+w)))
217 yp := int(fmap(v.y, miny, maxy, float64(y), float64(y-h)))

Callers 1

doplotFunction · 0.85

Calls 9

fmapFunction · 0.85
RectMethod · 0.45
GstyleMethod · 0.45
LineMethod · 0.45
CircleMethod · 0.45
TextMethod · 0.45
PolygonMethod · 0.45
PolylineMethod · 0.45
GendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…