1- import { expect , type Page , test } from "../../fixture.ts" ;
2-
3- type ChartPoint = { x : string | number | Date ; y : number | null } ;
4-
5- declare global {
6- interface Window {
7- charts ?: {
8- w : {
9- config : {
10- chart : { type : string ; stacked : boolean } ;
11- xaxis : { type ?: string ; tickAmount ?: number } ;
12- series : { name : string | number ; data ?: ChartPoint [ ] } [ ] ;
13- tooltip : {
14- custom ?: ( args : {
15- seriesIndex : number ;
16- dataPointIndex : number ;
17- w : unknown ;
18- } ) => string ;
19- } ;
20- } ;
21- globals : { labels : ( string | number ) [ ] } ;
22- } ;
23- } [ ] ;
24- }
25- }
1+ import { type ConsoleMessage , expect , type Page , test } from "../../fixture.ts" ;
262
273const MARKS =
284 ".apexcharts-bar-area, .apexcharts-rangebar-area, .apexcharts-treemap-rect, .apexcharts-pie-area, .apexcharts-heatmap-rect, .apexcharts-series .apexcharts-marker" ;
@@ -32,7 +8,7 @@ const ORANGE = "#f76707";
328const GREEN = "#37b24d" ;
339async function renderChart ( page : Page , fixture : string ) {
3410 const failures : string [ ] = [ ] ;
35- const recordError = ( message : { type ( ) : string ; text ( ) : string } ) => {
11+ const recordError = ( message : ConsoleMessage ) => {
3612 if ( message . type ( ) === "error" ) failures . push ( message . text ( ) ) ;
3713 } ;
3814 page . on ( "console" , recordError ) ;
@@ -46,13 +22,15 @@ async function renderChart(page: Page, fixture: string) {
4622 const container = document . getElementById ( "test-chart" ) ;
4723 if ( ! container ) throw new Error ( "Chart fixture did not render" ) ;
4824 const rendered = window . charts ?. [ 0 ] ;
49- const series = ( rendered ?. w . config . series ?? [ ] ) . map ( ( s ) => ( {
50- name : s . name ,
51- points : ( s . data ?? [ ] ) . map ( ( p ) => [
52- p . x instanceof Date ? p . x . toISOString ( ) : p . x ,
53- p . y ,
54- ] ) ,
55- } ) ) ;
25+ const series = ( rendered ?. w . config . series ?? [ ] )
26+ . filter ( ( s ) => typeof s !== "number" )
27+ . map ( ( s ) => ( {
28+ name : s . name ,
29+ points : s . data . map ( ( p ) => [
30+ p . x instanceof Date ? p . x . toISOString ( ) : p . x ,
31+ p . y ,
32+ ] ) ,
33+ } ) ) ;
5634 const drawnPerSeries = series . map ( ( { name } ) => {
5735 const markers = [
5836 ...container . querySelectorAll < SVGGraphicsElement > (
@@ -122,9 +100,12 @@ async function renderChart(page: Page, fixture: string) {
122100 tickAmount : rendered ?. w . config . xaxis . tickAmount ?? null ,
123101 } ,
124102 generatedLabels : rendered ?. w . globals . labels ?? [ ] ,
103+ threeDimensional : rendered ?. w . globals . isDataXYZ ?? null ,
125104 axisLabels,
126105 dataLabels : [
127- ...container . querySelectorAll ( ".apexcharts-datalabel" ) ,
106+ ...container . querySelectorAll (
107+ ".apexcharts-datalabel, .apexcharts-pie-label" ,
108+ ) ,
128109 ] . map ( ( label ) => label . textContent ) ,
129110 barGroups,
130111 series,
@@ -407,6 +388,16 @@ for (const type of ["area", "scatter", "heatmap"]) {
407388 } ) ;
408389}
409390
391+ test ( "counts a third dimension only where the rows carried one" , async ( {
392+ page,
393+ } ) => {
394+ const flat = await renderChart ( page , "index" ) ;
395+ const bubbles = await renderChart ( page , "bubble-categories" ) ;
396+
397+ expect ( flat . threeDimensional ) . toBe ( false ) ;
398+ expect ( bubbles . threeDimensional ) . toBe ( true ) ;
399+ } ) ;
400+
410401test ( "keeps the bubble size of the points it lined up" , async ( { page } ) => {
411402 const chart = await renderChart ( page , "bubble-categories" ) ;
412403
@@ -455,6 +446,22 @@ test("gives the tooltip title the color of the tooltip around it", async ({
455446 expect ( colors . title ) . toBe ( colors . tooltip ) ;
456447} ) ;
457448
449+ test ( "names the series of every bar of a range bar chart" , async ( { page } ) => {
450+ const chart = await renderChart ( page , "labeled-range-bar" ) ;
451+
452+ expect ( chart . failures ) . toEqual ( [ ] ) ;
453+ expect ( chart . dataLabels ) . toEqual ( [ "Design" , "Build" ] ) ;
454+ } ) ;
455+
456+ test ( "gives every slice of a pie chart its label and its share" , async ( {
457+ page,
458+ } ) => {
459+ const chart = await renderChart ( page , "labeled-pie" ) ;
460+
461+ expect ( chart . failures ) . toEqual ( [ ] ) ;
462+ expect ( chart . dataLabels ) . toEqual ( [ "Yes: 65%" , "No: 35%" ] ) ;
463+ } ) ;
464+
458465test ( "draws a reference line that carries no label" , async ( { page } ) => {
459466 const chart = await renderChart ( page , "unlabeled-reference-lines" ) ;
460467
@@ -601,11 +608,7 @@ test("labels each axis of a bubble tooltip with its own title", async ({
601608 const custom = chart . w . config . tooltip . custom ;
602609 if ( ! custom ) throw new Error ( "A bubble chart needs the custom tooltip" ) ;
603610 const holder = document . createElement ( "div" ) ;
604- holder . innerHTML = custom ( {
605- seriesIndex : 0 ,
606- dataPointIndex : 1 ,
607- w : chart . w ,
608- } ) ;
611+ holder . innerHTML = custom ( { seriesIndex : 0 , dataPointIndex : 1 } ) ;
609612 const values = holder . querySelectorAll ( ".apexcharts-tooltip-text-y-value" ) ;
610613 return [ ...holder . querySelectorAll ( ".apexcharts-tooltip-text-y-label" ) ] . map (
611614 ( label , i ) : [ string , string ] => [
0 commit comments