PluginProbe
M Chart / 2.3
M Chart v2.3
2.3.2 2.3.1 2.3 2.2.2 2.2.1 2.2 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.10 1.10.1 1.11 1.11.1 1.11.2 1.12 1.2 1.2.1 1.3 1.3.1 1.3.2 All 53 releases
m-chart / components / templates / table.php

table.php in M Chart 2.3, at components/templates/table.php

144 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) { exit; } ?>
2 <table class="<?php echo esc_attr( $classes ); ?> table">
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 // Rows parsing collects the data as raw_data[ row ][ column ] while columns parsing collects it as raw_data[ column ][ row ]
17 $row_column = M_Chart_Parse::PARSE_ROWS === m_chart()->parse()->parse_in;
18 ?>
19 <thead>
20 <tr>
21 <td></td>
22 <?php
23 foreach ( $first_row as $label ) {
24 ?>
25 <th scope="col"><?php echo esc_html( $label ); ?></th>
26 <?php
27 }
28 ?>
29 </tr>
30 </thead>
31 <tbody>
32 <?php
33 foreach ( $labels as $row => $label ) {
34 ?>
35 <tr>
36 <th scope="row"><?php echo esc_html( $label ); ?></th>
37 <?php
38 foreach ( $first_row as $column => $label ) {
39 if ( $row_column ) {
40 $raw = m_chart()->parse()->raw_data[ $row ][ $column ] ?? null;
41 } else {
42 $raw = m_chart()->parse()->raw_data[ $column ][ $row ] ?? null;
43 }
44 ?>
45 <td><?php echo esc_html( m_chart()->parse()->format_raw( $raw ) ); ?></td>
46 <?php
47 }
48 ?>
49 </tr>
50 <?php
51 }
52 ?>
53 </tbody>
54 <?php
55 } elseif (
56 M_Chart_Parse::LABELS_FIRST_COLUMN === m_chart()->parse()->value_labels_position
57 && M_Chart_Parse::PARSE_ROWS === m_chart()->parse()->parse_in
58 && [] !== m_chart()->parse()->value_labels
59 ) {
60 // The labels came from the first column of the spreadsheet
61 // Render one table row per label so the table matches the spreadsheet's vertical arrangement
62 $labels = m_chart()->parse()->value_labels;
63 $raw = m_chart()->parse()->raw_data;
64 $per_row = (int) ceil( count( $raw ) / count( $labels ) );
65 $chunks = $per_row ? array_chunk( $raw, $per_row ) : [];
66 ?>
67 <tbody>
68 <?php
69 foreach ( $labels as $row => $label ) {
70 ?>
71 <tr>
72 <th scope="row"><?php echo esc_html( $label ); ?></th>
73 <?php
74 foreach ( $chunks[ $row ] ?? [] as $raw ) {
75 ?>
76 <td><?php echo esc_html( m_chart()->parse()->format_raw( $raw ) ); ?></td>
77 <?php
78 }
79 ?>
80 </tr>
81 <?php
82 }
83 ?>
84 </tbody>
85 <?php
86 } else {
87 $first_row = m_chart()->parse()->value_labels;
88
89 // Chunk the flat cell stream into rows of one label-width each
90 // Multi-row bodies get a generated row header so every data cell has row context
91 $columns = count( $first_row );
92 $rows = $columns ? array_chunk( m_chart()->parse()->raw_data, $columns ) : [];
93 $multi_row = 1 < count( $rows );
94 ?>
95 <thead>
96 <tr>
97 <?php
98 if ( $multi_row ) {
99 ?>
100 <td></td>
101 <?php
102 }
103
104 foreach ( $first_row as $label ) {
105 ?>
106 <th scope="col"><?php echo esc_html( $label ); ?></th>
107 <?php
108 }
109 ?>
110 </tr>
111 </thead>
112 <tbody>
113 <?php
114 foreach ( $rows as $row => $cells ) {
115 ?>
116 <tr>
117 <?php
118 if ( $multi_row ) {
119 ?>
120 <th scope="row">
121 <?php
122 // translators: %d is the row number in the chart's data table
123 echo esc_html( sprintf( __( 'Row %d', 'm-chart' ), $row + 1 ) );
124 ?>
125 </th>
126 <?php
127 }
128
129 foreach ( $cells as $raw ) {
130 ?>
131 <td><?php echo esc_html( m_chart()->parse()->format_raw( $raw ) ); ?></td>
132 <?php
133 }
134 ?>
135 </tr>
136 <?php
137 }
138 ?>
139 </tbody>
140 <?php
141 }
142 ?>
143 </table>
144