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 -------------------------------------------------- 28 if (!in_array($Position,
29 [self::LEGEND_BOTTOM, self::LEGEND_RIGHT,
30 self::LEGEND_INSET, self::LEGEND_NONE]))
32 throw new Exception(
"Unsupported legend position: ".$Position);
57 public function Labels($NewValue = NULL)
59 if ($NewValue !== NULL)
61 if (!is_array($NewValue) && ($NewValue !== FALSE))
63 throw new InvalidArgumentException(
"Invalid new value (".$NewValue.
").");
76 public function Colors($NewValue=NULL)
78 if (!is_null($NewValue))
92 if (!is_null($NewValue))
106 if (!is_null($NewValue))
108 $this->
Width = $NewValue;
148 self::RequireNeededFiles();
150 # declare the chart data that we will give to c3.generate 151 # for function callbacks, give the function a name ending with 152 # '_fn' and include the function name as a string 154 "bindto" =>
"#".$ContainerId,
161 "name" =>
"tooltip_name_fn",
166 # set up legend positioning 169 $this->Chart[
"legend"][
"show"] = FALSE;
176 # if the user provided a color palette, set that up as will 177 if (!is_null($this->
Colors()))
179 # sort user-provided colors into the correct order 181 foreach ($this->Data as $Index => $Value)
183 $Palette[]= isset($this->
Colors[$Index]) ?
188 $this->Chart[
"color"][
"pattern"] = $Palette;
191 static::PrepareData();
194 ?><div
id=
"<?= $ContainerId ?>" class=
"cw-<?= strtolower(get_called_class()) ?>"></div>
195 <script type=
"text/javascript">
196 $(document).ready(
function(){
198 var label_lut = <?= json_encode($this->TooltipLabels) ?>;
199 <?
PHP static::DeclareStateVariables(); ?>
202 function tooltip_name_fn(name, ratio,
id, index) {
203 return name in label_lut ? label_lut[name] : name;
205 <?
PHP static::DeclareHelperFunctions(); ?>
208 var chart_spec = <?= json_encode($this->Chart) ?>;
211 function eval_fns(obj){
212 for (var prop in obj) {
213 if (typeof obj[prop] ==
"object") {
215 }
else if (typeof obj[prop] ==
"string" && obj[prop].match(/_fn$/)) {
216 obj[prop] = eval(obj[prop]);
220 eval_fns(chart_spec);
223 c3.generate(chart_spec);
235 self::RequireNeededFiles();
238 # legend position constants 244 # ---- PRIVATE INTERFACE -------------------------------------------------- 251 $GLOBALS[
"AF"]->RequireUIFile(
"d3.js");
252 $GLOBALS[
"AF"]->RequireUIFile(
"c3.js");
253 $GLOBALS[
"AF"]->RequireUIFile(
"c3.css");
254 $GLOBALS[
"AF"]->RequireUIFile(
"Chart_Base.css");
291 return "#".substr(md5($DataIndex), 0, 6);
310 foreach (
$Data as $Key => $Val)
312 if (isset($Tgt[$Key]) &&
313 is_array($Tgt[$Key]) && is_array($Val))
324 # data provided by caller 327 # chart parameters that can be changed prior to generation 335 # internal variables used to generate the chart 337 # map legend labels (which C3 uses for item identifiers) to the 338 # labels we want in the tooltip
Base class for generating and displaying a chart.
DeclareStateVariables()
Output var declarations for any js state variables needed in this chart's display helper functions...
Height($NewValue)
Get/Set height of the chart including the legend.
Labels($NewValue=NULL)
Get/set chart element labels (pie slices, bars, etc).
Width($NewValue)
Get/Set width of the chart including the legend.
LegendLabels($LegendLabels)
Set shortened labels to be used in the legend of the chart.
Display($ContainerId)
Display a chart.
DeclareHelperFunctions()
Output function definitions for any needed javascript display helper functions.
static PrepForDisplayingCachedVersion()
Set up the chart environment so that cached HTML from a previous Display() call will function properl...
AddToArray(&$Tgt, $Data)
Merge elements from a source array into a dest array.
AddToChart($Data)
Merge an array of settings into $this->Chart.
static RequireNeededFiles()
Include necessary JS/CSS for chart generation.
Colors($NewValue=NULL)
Get/set color palette.
PrepareData()
Massage data provided by the user into an appropriate format for plotting and do any necessary tweaks...
LegendPosition($Position)
Set legend position.
GenerateRgbColorString($DataIndex)
Get RGB hex color when no color supplied.