-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpChart4mw.radar.class.php
executable file
·145 lines (122 loc) · 4.95 KB
/
pChart4mw.radar.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
class pChart4mwRadar extends pChart4mw {
// **************************************************************************************
//
// Static function to be called by the mediawiki system.
//
// **************************************************************************************
/**
* Generates a radar chart from the entered data and returns the HTML code to render the graph
*
* @param $input String Input between the <pBar> and </pBar> tags or null is the tag is closed (<pBar />)
* @param $args Array Tag arguments, which are entered like HTML tag attributes; this is an associative
* array indexed by attribute name
* @param $parser Object The parent parser; more advanced extensions use this to obtain the contextual Title,
* parse wiki text, expand braces, register link relationships and dependencies etc.
* @returns String HTML code to show the pie chart
*/
public static function render( $input, $args, $parser ) {
// Recursively parse the wikitext
$parsedText = $parser->recursiveTagParse( $input );
// Create the chart
$chart = new pChart4mwRadar();
return $chart->renderChart( $parsedText, $args );
}
/**
* Generates a bar chart from the entered data using a parser function
* and returns the HTML code to render the graph
*
* @param $parser Object The parent parser; more advanced extensions use this to obtain the contextual Title,
* parse wiki text, expand braces, register link relationships and dependencies etc.
* @returns String HTML code to show the bar chart
*/
public static function renderParserFunction() {
// Add this class name to the function
$args = func_get_args();
array_unshift( $args, "pChart4mwRadar" );
return call_user_func_array( array( 'pChart4mw', 'renderParserFunction' ), $args );
}
function __construct() {
$this->type = "radar";
}
// **************************************************************************************
//
// Methods for generating charts
//
// **************************************************************************************
/**
* Parses the parameters for the chart and sets them to the pChart object
*
* @param $args Array Associative array with arguments given by the user
* @returns pChart pChart object with parameters set
*/
public function parseArgs( $args, $default = false ) {
// Do all default parsing
parent::parseArgs( $args, $default );
// Draw a filled radar graph instead of an empty one
if( array_key_exists( "filled", $args ) ) {
if( $args[ "filled" ] != "false" ) {
$this->chartArgs[ "filled" ] = true;
}
}
// Draw stripes underneath the graph
if( array_key_exists( "striped", $args ) ) {
if( $args[ "striped" ] != "false" ) {
$this->chartArgs[ "striped" ] = true;
}
}
// What color should be used for the graph background
if( array_key_exists( "stripecolor", $args ) ) {
$this->chartArgs[ "stripecolor" ] = wfPChart4mwhtml2rgb( $args[ "stripecolor" ] );
}
return $this->chartArgs;
}
/**
* Returns the default properties for radar graphs
*
* @returns Array Associative array with default properties.
*/
public function getDefaultArgs() {
$args = parent::getDefaultArgs();
// Set radar-specific default arguments
$args[ "filled" ] = false;
$args[ "striped" ] = false;
$args[ "stripecolor" ] = array( 200, 200, 200 );
$args[ "opacity" ] = 50;
// Check whether the user has set defaults in the LocalSettings.php file
$name = "wgPChart4mw" . ucfirst( $this->type ) . "Defaults";
if( array_key_exists( $name, $GLOBALS ) ) {
$args = $this->parseArgs( $GLOBALS[ $name ], $args );
}
return $args;
}
/**
* Set the scale to the right values and draws the axes and grid
*
*/
public function drawScaleAndGrid() {
$args = $this->chartArgs;
// Draw and scale the axes and
$this->pChart->drawRadarAxis(
$this->pData,
$this->pDataDescription,
$args[ "striped" ],
2,
$args[ "axiscolor" ][ 0 ], $args[ "axiscolor" ][ 1 ], $args[ "axiscolor" ][ 2 ],
$args[ "stripecolor" ][ 0 ], $args[ "stripecolor" ][ 1 ], $args[ "stripecolor" ][ 2 ],
$args[ "ymax" ]
);
return $this->pChart;
}
/**
* Draws the chart, based on the type of chart
*/
public function drawChartSpecific() {
// Draw a Radar chart. If the user wants it to be filled, do so
if( $this->chartArgs[ "filled" ] ) {
$this->pChart->drawFilledRadar( $this->pData, $this->pDataDescription, $this->chartArgs[ "opacity" ], 2, $this->chartArgs[ "ymax" ] );
} else {
$this->pChart->drawRadar( $this->pData, $this->pDataDescription, 2, $this->chartArgs[ "ymax" ] );
}
}
}