-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpChart4mw.bars.class.php
executable file
·144 lines (121 loc) · 4.53 KB
/
pChart4mw.bars.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
<?php
class pChart4mwBars extends pChart4mw {
// **************************************************************************************
//
// Static functions to be called by the mediawiki system.
//
// **************************************************************************************
/**
* Generates a bar 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 bar chart
*/
public static function render( $input, $args, $parser ) {
// Recursively parse the wikitext
$parsedText = $parser->recursiveTagParse( $input );
// Create the chart
$chart = new pChart4mwBars();
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, "pChart4mwBars" );
return call_user_func_array( array( 'pChart4mw', 'renderParserFunction' ), $args );
}
function __construct() {
$this->type = "bars";
}
// **************************************************************************************
//
// 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 ) {
if( !$default ) {
$chartArgs = $this->getDefaultArgs();
}
// Do all default parsing
parent::parseArgs( $args, $default );
// Check whether the graph should be stacked
if( array_key_exists( "stacked", $args ) ) {
if( $args[ "stacked" ] != "false" ) {
$this->chartArgs[ "stacked" ] = true;
}
}
// Check whether the graph should be overlay
if( array_key_exists( "overlay", $args ) ) {
if( $args[ "overlay" ] != "false" ) {
$this->chartArgs[ "overlay" ] = true;
// Change default opacity to 50
$this->chartArgs[ "opacity" ] = 50;
}
}
return $this->chartArgs;
}
/**
* Returns the default properties for bar graphs
*
* @returns Array Associative array with default properties.
*/
public function getDefaultArgs() {
$args = parent::getDefaultArgs();
// Set bar-specific default arguments
$args[ "stacked" ] = false;
$args[ "overlay" ] = false;
$args[ "opacity" ] = 100;
// 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;
}
/**
* Draws the chart, based on the type of chart
*/
public function drawChartSpecific() {
if( $this->chartArgs[ "stacked" ] ) {
// Draw bar graph
$this->pChart->drawStackedBarGraph(
$this->pData,
$this->pDataDescription,
$this->chartArgs[ "opacity" ]
);
} elseif( $this->chartArgs[ "overlay" ] ) {
// Draw bar graph
$this->pChart->drawOverlayBarGraph(
$this->pData,
$this->pDataDescription,
$this->chartArgs[ "opacity" ]
);
} else {
// Draw bar graph
$this->pChart->drawBarGraph(
$this->pData,
$this->pDataDescription,
TRUE,
$this->chartArgs[ "opacity" ]
);
}
}
}