| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { exit; } ?> |
| 2 |
<table class="<?php echo esc_attr( $classes ); ?>"> |
| 3 |
<?php |
| 4 |
$set_name = ''; |
| 5 |
|
| 6 |
if ( $multiple ) { |
| 7 |
$set_name = ': ' . $post_meta['set_names'][ $set ]; |
| 8 |
} |
| 9 |
?> |
| 10 |
<caption><?php echo esc_html( get_the_title( $post_id ) . $set_name ); ?></caption> |
| 11 |
<?php |
| 12 |
if ( isset( m_chart()->parse()->value_labels[ M_Chart_Parse::LABELS_FIRST_ROW ] ) ) { |
| 13 |
$first_row = m_chart()->parse()->value_labels[ M_Chart_Parse::LABELS_FIRST_ROW ]; |
| 14 |
$labels = m_chart()->parse()->value_labels[ M_Chart_Parse::LABELS_FIRST_COLUMN ]; |
| 15 |
|
| 16 |
$row_column = false; |
| 17 |
|
| 18 |
if ( isset( m_chart()->parse()->raw_data[0] ) && count( $first_row ) == count( m_chart()->parse()->raw_data[0] ) ) { |
| 19 |
$row_column = true; |
| 20 |
} |
| 21 |
?> |
| 22 |
<thead> |
| 23 |
<tr> |
| 24 |
<td></td> |
| 25 |
<?php |
| 26 |
foreach ( $first_row as $label ) { |
| 27 |
?> |
| 28 |
<th scope="col"><?php echo esc_html( $label ); ?></th> |
| 29 |
<?php |
| 30 |
} |
| 31 |
?> |
| 32 |
</tr> |
| 33 |
</thead> |
| 34 |
<tbody> |
| 35 |
<?php |
| 36 |
foreach ( $labels as $row => $label ) { |
| 37 |
?> |
| 38 |
<tr> |
| 39 |
<th scope="row"><?php echo esc_html( $label ); ?></th> |
| 40 |
<?php |
| 41 |
foreach ( $first_row as $column => $label ) { |
| 42 |
if ( $row_column ) { |
| 43 |
$raw = m_chart()->parse()->raw_data[ $row ][ $column ] ?? null; |
| 44 |
} else { |
| 45 |
$raw = m_chart()->parse()->raw_data[ $column ][ $row ] ?? null; |
| 46 |
} |
| 47 |
?> |
| 48 |
<td><?php echo esc_html( m_chart()->parse()->format_raw( $raw ) ); ?></td> |
| 49 |
<?php |
| 50 |
} |
| 51 |
?> |
| 52 |
</tr> |
| 53 |
<?php |
| 54 |
} |
| 55 |
?> |
| 56 |
</tbody> |
| 57 |
<?php |
| 58 |
} else { |
| 59 |
$first_row = m_chart()->parse()->value_labels; |
| 60 |
|
| 61 |
// Chunk the flat cell stream into rows of one label-width each |
| 62 |
// Multi-row bodies get a generated row header so every data cell has row context |
| 63 |
$columns = count( $first_row ); |
| 64 |
$rows = $columns ? array_chunk( m_chart()->parse()->raw_data, $columns ) : []; |
| 65 |
$multi_row = 1 < count( $rows ); |
| 66 |
?> |
| 67 |
<thead> |
| 68 |
<tr> |
| 69 |
<?php |
| 70 |
if ( $multi_row ) { |
| 71 |
?> |
| 72 |
<td></td> |
| 73 |
<?php |
| 74 |
} |
| 75 |
|
| 76 |
foreach ( $first_row as $label ) { |
| 77 |
?> |
| 78 |
<th scope="col"><?php echo esc_html( $label ); ?></th> |
| 79 |
<?php |
| 80 |
} |
| 81 |
?> |
| 82 |
</tr> |
| 83 |
</thead> |
| 84 |
<tbody> |
| 85 |
<?php |
| 86 |
foreach ( $rows as $row => $cells ) { |
| 87 |
?> |
| 88 |
<tr> |
| 89 |
<?php |
| 90 |
if ( $multi_row ) { |
| 91 |
?> |
| 92 |
<th scope="row"> |
| 93 |
<?php |
| 94 |
// translators: %d is the row number in the chart's data table |
| 95 |
echo esc_html( sprintf( __( 'Row %d', 'm-chart' ), $row + 1 ) ); |
| 96 |
?> |
| 97 |
</th> |
| 98 |
<?php |
| 99 |
} |
| 100 |
|
| 101 |
foreach ( $cells as $raw ) { |
| 102 |
?> |
| 103 |
<td><?php echo esc_html( m_chart()->parse()->format_raw( $raw ) ); ?></td> |
| 104 |
<?php |
| 105 |
} |
| 106 |
?> |
| 107 |
</tr> |
| 108 |
<?php |
| 109 |
} |
| 110 |
?> |
| 111 |
</tbody> |
| 112 |
<?php |
| 113 |
} |
| 114 |
?> |
| 115 |
</table> |
| 116 |
|