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