Skip to content

Commit

Permalink
add: data labels with absolute values for most diagrams
Browse files Browse the repository at this point in the history
add: outlined data labels to improve contrast
fix: additional formatting issues
  • Loading branch information
Fenrikur committed Jan 12, 2018
1 parent 0336f88 commit 4a7ab90
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions Nosecounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Nosecounter {
'axis_font' => 'Georgia',
'axis_font_size' => 10,
'grid_colour' => '#666',
'label_colour' => '#efefef',
'label_colour' => '#222',
'pad_right' => 20,
'pad_left' => 20,
'link_base' => '/',
Expand All @@ -98,7 +98,12 @@ class Nosecounter {
'semantic_classes' => TRUE,
'legend_shadow_opacity' => 0,
'legend_position' => 'outside right 5 0',
'auto_fit' => TRUE
'auto_fit' => TRUE,
'data_label_space' => 5,
'data_label_colour' => '#222',
'data_label_back_colour' => '#fff',
'data_label_outline_thickness' => 20,
'data_label_position' => 'top',
);

private $graphWidth = 1000;
Expand Down Expand Up @@ -181,7 +186,7 @@ public function generate($templateFile = null, $outputFile = null) {
$startTime = microtime(TRUE);

if(empty($this->registrationsStart) || empty($this->registrationsEnd) ||
empty($this->apiUrl) || empty($this->apiToken) || empty($this->year)) {
empty($this->apiUrl) || empty($this->apiToken) || empty($this->year)) {
error_log('Not all obligatory parameters (apiUrl, apiToken, year, registrationsStart and registrationsEnd) have been set!');
return FALSE;
}
Expand Down Expand Up @@ -285,7 +290,7 @@ private function generateAge() {
'axis_min_h' => $this->minAge,
'log_axis_y' => TRUE,
'log_axis_y_base' => 2,
'axis_min_v' => 0.9
'axis_min_v' => 0.9,
);
// Allows bar values of 0 to manifest on log scale in combination with axis_min_v = 0.9
$settings['axis_text_callback_y'] = function($v) { return $v < 1 ? 0 : $v; };
Expand All @@ -307,7 +312,7 @@ private function generateAgeComparison() {
'pad_right' => 120,
'log_axis_y' => TRUE,
'log_axis_y_base' => 2,
'axis_min_v' => 0.9
'axis_min_v' => 0.9,
)
);
// Allows bar values of 0 to manifest on log scale in combination with axis_min_v = 0.9
Expand Down Expand Up @@ -335,7 +340,8 @@ private function generateCountry() {
'grid_division_h' => 1,
'log_axis_y' => TRUE,
'log_axis_y_base' => 2,
'axis_min_v' => 0.9
'axis_min_v' => 0.9,
'show_data_labels' => TRUE,
);
// Allows bar values of 0 to manifest on log scale in combination with axis_min_v = 0.9
$settings['axis_text_callback_y'] = function($v) { return $v < 1 ? 0 : $v; };
Expand All @@ -349,7 +355,8 @@ private function generateCountryComparison() {
'pad_right' => 120,
'log_axis_y' => TRUE,
'log_axis_y_base' => 2,
'axis_min_v' => 0.9
'axis_min_v' => 0.9,
'show_data_labels' => TRUE,
);
// Allows bar values of 0 to manifest on log scale in combination with axis_min_v = 0.9
$settings['axis_text_callback_y'] = function($v) { return $v < 1 ? 0 : $v; };
Expand All @@ -361,20 +368,26 @@ private function generateCountryComparison() {

private function generateDemographics() {
$settings = array(
'pad_right' => 120
'pad_right' => 120,
'show_data_labels' => TRUE,
);

return $this->generateGroupedComparison('SpecialInterest', $settings, 'demographics', $this->specialInterestList);
}

private function generateGender() {
$settings = array('show_label_percent' => TRUE);
$settings = array(
'show_label_percent' => TRUE,
);

return $this->generatePieGraph('Gender', $settings, 'gender');
}

private function generateGenderComparison() {
$settings = array('data_label_callback' => $this->genderLabel, 'pad_right' => 100);
$settings = array(
'data_label_callback' => $this->genderLabel,
'pad_right' => 100,
);

return $this->generateStackedComparison('Gender', $settings, 'genderComparison', $this->genderList);
}
Expand All @@ -393,7 +406,7 @@ private function generateRegistrations() {
'datetime_keys' => TRUE,
'axis_text_angle_h' => -90,
'marker_size' => 1,
'line_stroke_width' => 0.5
'line_stroke_width' => 0.5,
)
);
$values = array();
Expand Down Expand Up @@ -470,15 +483,15 @@ private function generateShirts() {
$settings = array(
'legend_columns' => 2,
'data_label_callback' => $this->shirtSizeLabel,
'pad_right' => 130
'pad_right' => 130,
);

return $this->generateStackedComparison('ShirtSize', $settings, 'shirts', $this->shirtSizeList);
}

private function generateSponsors() {
$settings = array(
'show_label_percent' => TRUE
'show_label_percent' => TRUE,
);

return $this->generatePieGraph('Sponsor', $settings, 'sponsors');
Expand All @@ -487,7 +500,7 @@ private function generateSponsors() {
private function generateSponsorsComparison() {
$settings = array(
'data_label_callback' => $this->sponsorLabel,
'pad_right' => 140
'pad_right' => 140,
);

return $this->generateStackedComparison('Sponsor', $settings, 'sponsorsComparison', $this->sponsorList);
Expand All @@ -497,7 +510,8 @@ private function generateStatus() {
$settings = array(
'log_axis_y' => TRUE,
'log_axis_y_base' => 2,
'axis_min_v' => 0.9
'axis_min_v' => 0.9,
'show_data_labels' => TRUE,
);
// Allows bar values of 0 to manifest on log scale in combination with axis_min_v = 0.9
$settings['axis_text_callback_y'] = function($v) { return $v < 1 ? 0 : $v; };
Expand Down Expand Up @@ -545,7 +559,7 @@ private function generatePieGraph($fieldName, $settings, $fileName) {
$settings = array_merge(
$this->svgGraphDefaultSettings,
array(
'show_label_amount' => TRUE
'show_label_amount' => TRUE,
),
$settings
);
Expand All @@ -572,9 +586,7 @@ private function generateStackedComparison($fieldName, $settings, $fileName, $le
$this->svgGraphDefaultSettings,
array(
'show_data_labels' => TRUE,
'data_label_position' => 'top',
'data_label_colour' => '#efefef',
'axis_text_callback_y' => $this->axisPercentage
'axis_text_callback_y' => $this->axisPercentage,
),
$settings
);
Expand Down

0 comments on commit 4a7ab90

Please sign in to comment.