File tree Expand file tree Collapse file tree 5 files changed +97
-1
lines changed
docs/smoke-all/jupyter/subfigures Expand file tree Collapse file tree 5 files changed +97
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ title : " Bugged plotly figure: phantom subfigure"
3+ keep-ipynb : true
4+ keep-md : true
5+ _quarto :
6+ tests :
7+ html :
8+ ensureHtmlElements :
9+ -
10+ - ' figure.quarto-float-fig div#fig-gapminder-1 figure.quarto-subfloat-fig div.plotly-graph-div'
11+ - ' figure.quarto-float-fig div#fig-gapminder-2 figure.quarto-subfloat-fig div.plotly-graph-div'
12+ ensureHtmlElementContents :
13+ selectors :
14+ - ' div#fig-gapminder-1 figcaption.quarto-subfloat-caption'
15+ - ' div#fig-gapminder-2 figcaption.quarto-subfloat-caption'
16+ matches : ['\((a|b)\) Gapminder: (1957|2007)']
17+ ensureHtmlElementCount :
18+ selectors : ['figure.quarto-float-fig figure.quarto-subfloat-fig']
19+ counts : [2]
20+ ---
21+
22+ ``` {python}
23+ #| label: fig-gapminder
24+ #| fig-cap: "Life Expectancy and GDP"
25+ #| fig-subcap:
26+ #| - "Gapminder: 1957"
27+ #| - "Gapminder: 2007"
28+ #| layout-ncol: 2
29+ #| column: page
30+
31+ import plotly.express as px
32+ import plotly.io as pio
33+ gapminder = px.data.gapminder()
34+ def gapminder_plot(year):
35+ gapminderYear = gapminder.query("year == " +
36+ str(year))
37+ fig = px.scatter(gapminderYear,
38+ x="gdpPercap", y="lifeExp",
39+ size="pop", size_max=60,
40+ hover_name="country")
41+ fig.show()
42+
43+ gapminder_plot(1957)
44+ gapminder_plot(2007)
45+ ```
Original file line number Diff line number Diff line change @@ -18,4 +18,5 @@ dependencies = [
1818 " great-tables>=0.17.0" ,
1919 " polars>=1.29.0" ,
2020 " pyarrow>=20.0.0" ,
21+ " plotly>=6.1.1" ,
2122]
Original file line number Diff line number Diff line change @@ -36,7 +36,8 @@ import {
3636 ensureLatexFileRegexMatches ,
3737 printsMessage ,
3838 shouldError ,
39- ensureHtmlElementContents
39+ ensureHtmlElementContents ,
40+ ensureHtmlElementCount ,
4041} from "../verify.ts" ;
4142import { readYamlFromMarkdown } from "../../src/core/yaml.ts" ;
4243import { findProjectDir , findProjectOutputDir , outputForInput } from "../utils.ts" ;
@@ -130,6 +131,7 @@ function resolveTestSpecs(
130131 ensureEpubFileRegexMatches,
131132 ensureHtmlElements,
132133 ensureHtmlElementContents,
134+ ensureHtmlElementCount,
133135 ensureFileRegexMatches,
134136 ensureLatexFileRegexMatches,
135137 ensureTypstFileRegexMatches,
Original file line number Diff line number Diff line change @@ -402,6 +402,39 @@ export const ensureHtmlElementContents = (
402402
403403}
404404
405+ export const ensureHtmlElementCount = (
406+ file : string ,
407+ options : {
408+ selectors : string [ ] | string ,
409+ counts : number [ ] | number
410+ }
411+ ) : Verify => {
412+ return {
413+ name : "Verify number of elements for selectors" ,
414+ verify : async ( _output : ExecuteOutput [ ] ) => {
415+ const htmlInput = await Deno . readTextFile ( file ) ;
416+ const doc = new DOMParser ( ) . parseFromString ( htmlInput , "text/html" ) ! ;
417+
418+ // Convert single values to arrays for unified processing
419+ const selectorsArray = Array . isArray ( options . selectors ) ? options . selectors : [ options . selectors ] ;
420+ const countsArray = Array . isArray ( options . counts ) ? options . counts : [ options . counts ] ;
421+
422+ if ( selectorsArray . length !== countsArray . length ) {
423+ throw new Error ( "Selectors and counts arrays must have the same length" ) ;
424+ }
425+
426+ selectorsArray . forEach ( ( selector , index ) => {
427+ const expectedCount = countsArray [ index ] ;
428+ const elements = doc . querySelectorAll ( selector ) ;
429+ assert (
430+ elements . length === expectedCount ,
431+ `Selector '${ selector } ' matched ${ elements . length } elements, expected ${ expectedCount } .`
432+ ) ;
433+ } ) ;
434+ }
435+ } ;
436+ } ;
437+
405438export const ensureSnapshotMatches = (
406439 file : string ,
407440) : Verify => {
You can’t perform that action at this time.
0 commit comments