|
297 | 297 |
|
298 | 298 | // Adjust axis bounds for annotations |
299 | 299 | for a in annotations { |
| 300 | + let sub-ctx = ctx |
| 301 | + |
| 302 | + // Register a stub-resolver that just forwards coordinates |
| 303 | + sub-ctx.resolve-coordinate.push((ctx, c) => { |
| 304 | + if type(c) == dictionary and "plot" in c { |
| 305 | + return c.plot |
| 306 | + } |
| 307 | + return c |
| 308 | + }) |
| 309 | + |
300 | 310 | let (x, y) = a.axes.map(name => axis-dict.at(name)) |
301 | | - (x, y) = calc-annotation-domain(ctx, x, y, a) |
| 311 | + (x, y) = calc-annotation-domain(sub-ctx, x, y, a) |
302 | 312 | axis-dict.at(a.axes.at(0)) = x |
303 | 313 | axis-dict.at(a.axes.at(1)) = y |
304 | 314 | } |
305 | 315 |
|
306 | 316 | // Set axis options |
307 | 317 | axis-dict = plot-util.setup-axes(ctx, axis-dict, options.named(), size) |
308 | 318 |
|
| 319 | + // Register axis coordinate systems |
| 320 | + let axis-coordinate-resolver(ctx, c) = { |
| 321 | + if type(c) == dictionary and "plot" in c { |
| 322 | + let pt = c.plot |
| 323 | + let names = c.at("axes", default: ("x", "y")) |
| 324 | + let (x, y) = names.map(name => axis-dict.at(name)) |
| 325 | + |
| 326 | + return axes.transform-vec(size, x, y, none, pt) |
| 327 | + } |
| 328 | + return c |
| 329 | + } |
| 330 | + draw.register-coordinate-resolver(axis-coordinate-resolver) |
| 331 | + |
309 | 332 | // Prepare styles |
310 | 333 | for i in range(data.len()) { |
311 | 334 | if "style" not in data.at(i) { continue } |
|
369 | 392 | let (x, y) = a.axes.map(name => axis-dict.at(name)) |
370 | 393 | let plot-ctx = make-ctx(x, y, size) |
371 | 394 |
|
372 | | - data-viewport(a, x, y, size, { |
373 | | - draw.anchor("default", (0, 0)) |
| 395 | + draw.scope({ |
374 | 396 | a.body |
375 | 397 | }) |
376 | 398 | } |
|
467 | 489 | let (x, y) = a.axes.map(name => axis-dict.at(name)) |
468 | 490 | let plot-ctx = make-ctx(x, y, size) |
469 | 491 |
|
470 | | - data-viewport(a, x, y, size, { |
471 | | - draw.anchor("default", (0, 0)) |
| 492 | + draw.scope({ |
472 | 493 | a.body |
473 | 494 | }) |
474 | 495 | } |
|
0 commit comments