Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
CargoPieChartFormat | |
0.00% |
0 / 34 |
|
0.00% |
0 / 2 |
156 | |
0.00% |
0 / 1 |
allowedParameters | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
queryAndDisplay | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
132 |
1 | <?php |
2 | /** |
3 | * @author Kris Field |
4 | * @ingroup Cargo |
5 | */ |
6 | |
7 | class CargoPieChartFormat extends CargoDeferredFormat { |
8 | |
9 | public static function allowedParameters() { |
10 | return [ |
11 | 'height' => [ 'type' => 'int', 'label' => wfMessage( 'cargo-viewdata-heightparam' )->parse() ], |
12 | 'width' => [ 'type' => 'int', 'label' => wfMessage( 'cargo-viewdata-widthparam' )->parse() ], |
13 | 'colors' => [ 'type' => 'string', 'label' => wfMessage( 'cargo-viewdata-colorsparam' )->parse() ], |
14 | 'hide legend' => [ 'type' => 'boolean', 'label' => wfMessage( 'cargo-viewdata-hidelegendparam' )->parse() ] |
15 | ]; |
16 | } |
17 | |
18 | /** |
19 | * @param array $sqlQueries |
20 | * @param array $displayParams |
21 | * @param array|null $querySpecificParams Unused |
22 | * @return string HTML |
23 | */ |
24 | public function queryAndDisplay( $sqlQueries, $displayParams, $querySpecificParams = null ) { |
25 | $this->mOutput->addModules( [ 'ext.cargo.nvd3' ] ); |
26 | $ce = SpecialPage::getTitleFor( 'CargoExport' ); |
27 | $queryParams = $this->sqlQueriesToQueryParams( $sqlQueries ); |
28 | $queryParams['format'] = 'nvd3chart'; |
29 | |
30 | $svgAttrs = []; |
31 | if ( array_key_exists( 'width', $displayParams ) && $displayParams['width'] != '' ) { |
32 | $width = $displayParams['width']; |
33 | // Add on "px", if no unit is defined. |
34 | if ( is_numeric( $width ) ) { |
35 | $width .= "px"; |
36 | } |
37 | $svgAttrs['width'] = $width; |
38 | } else { |
39 | $svgAttrs['width'] = '700px'; |
40 | } |
41 | if ( array_key_exists( 'height', $displayParams ) && $displayParams['height'] != '' ) { |
42 | $height = $displayParams['height']; |
43 | // Add on "px", if no unit is defined. |
44 | if ( is_numeric( $height ) ) { |
45 | $height .= "px"; |
46 | } |
47 | $svgAttrs['height'] = $height; |
48 | } else { |
49 | $svgAttrs['height'] = '400px'; |
50 | } |
51 | |
52 | $svgText = Html::element( 'svg', $svgAttrs, '' ); |
53 | |
54 | $divAttrs = [ |
55 | 'class' => 'cargoPieChart', |
56 | 'dataurl' => $ce->getFullURL( $queryParams ), |
57 | ]; |
58 | if ( array_key_exists( 'colors', $displayParams ) && $displayParams['colors'] != '' ) { |
59 | $divAttrs['data-colors'] = json_encode( explode( ',', $displayParams['colors'] ) ); |
60 | } |
61 | if ( array_key_exists( 'hide legend', $displayParams ) ) { |
62 | $divAttrs['data-hide-legend'] = ( $displayParams['hide legend'] == 'yes' ) ? 1 : 0; |
63 | } |
64 | $text = Html::rawElement( 'div', $divAttrs, $svgText ); |
65 | |
66 | return $text; |
67 | } |
68 | |
69 | } |