5 # Part of the Collection Workflow Integration System (CWIS) 6 # Copyright 2017 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu/cwis/ 15 # ---- PUBLIC INTERFACE -------------------------------------------------- 32 $this->Precision = $Prec;
45 if (!in_array($LabelType,
46 [static::LABEL_PERCENT, static::LABEL_NAME, static::LABEL_RAW]))
48 throw new Exception(
"Unsupported slice label type: ".$LabelType);
63 if (!in_array($LabelType,
64 [static::TOOLTIP_PERCENT, static::TOOLTIP_VALUE,
65 static::TOOLTIP_BOTH]))
67 throw new Exception(
"Unsupported tooltip label type: ".$LabelType);
70 $this->TooltipLabelType = $LabelType;
73 # label type constants 78 # tooltip type constants 83 # ---- PRIVATE INTERFACE -------------------------------------------------- 90 # see http://c3js.org/reference.html#data-columns for format of 'columns' element. 91 # since C3 always uses the label in 'columns' for the legend, 92 # we'll need to populate the TooltipLabels array that is keyed 93 # by legend label where values give the tooltip label 94 $this->Chart[
"data"][
"columns"] = [];
95 foreach ($this->Data as $Index => $Value)
97 $Label = isset($this->
Labels[$Index]) ?
98 $this->
Labels[$Index] : $Index ;
103 $this->TooltipLabels[$MyLabel] = $Label;
110 $this->Chart[
"data"][
"columns"][]= [$MyLabel, $Value];
119 "format" =>
"label_format_fn",
124 "value" =>
"tooltip_value_fn",
138 function tooltip_value_fn(value, ratio,
id, index) {
139 <?
PHP if ($this->TooltipLabelType == self::TOOLTIP_BOTH) { ?>
140 return (
new Number(100*ratio)).toFixed(<?= $this->Precision ?>)+
"% ("+value+
")";
141 <?
PHP } elseif ($this->TooltipLabelType == self::TOOLTIP_PERCENT){ ?>
142 return (
new Number(100*ratio)).toFixed(<?= $this->Precision ?>)+
"%";
143 <?
PHP } elseif ($this->TooltipLabelType == self::TOOLTIP_VALUE){ ?>
148 function label_format_fn(value, ratio,
id, index) {
150 return (
new Number(100*ratio)).toFixed(<?= $this->Precision ?>)+
"%";
161 private $SliceLabelType = self::LABEL_PERCENT;
162 private $TooltipLabelType = self::TOOLTIP_BOTH;
163 private $Precision = 1;
PrepareData()
Prepare data for display.
Base class for generating and displaying a chart.
Labels($NewValue=NULL)
Get/set chart element labels (pie slices, bars, etc).
LegendLabels($LegendLabels)
Set shortened labels to be used in the legend of the chart.
SliceLabelType($LabelType)
Set the style for slice labels.
__construct($Data)
Class constructor.
AddToChart($Data)
Merge an array of settings into $this->Chart.
PercentPrecision($Prec)
Set the precision used to display percentages.
TooltipType($LabelType)
Set the style for values shown in the tooltip.
Class for generating and displaying a pie chart.
DeclareHelperFunctions()
Output javascript that declares helper functions used to display the chart.