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);
54 public function Colors($NewValue=NULL)
56 if (!is_null($NewValue))
70 if (!is_null($NewValue))
82 public function Width($NewValue)
84 if (!is_null($NewValue))
86 $this->
Width = $NewValue;
126 # be sure the necessary js and css are loaded 127 $GLOBALS[
"AF"]->RequireUIFile(
"d3.js");
128 $GLOBALS[
"AF"]->RequireUIFile(
"c3.js");
129 $GLOBALS[
"AF"]->RequireUIFile(
"c3.css");
130 $GLOBALS[
"AF"]->RequireUIFile(
"Chart_Base.css");
132 # declare the chart data that we will give to c3.generate 133 # for function callbacks, give the function a name ending with 134 # '_fn' and include the function name as a string 136 "bindto" =>
"#".$ContainerId,
143 "name" =>
"tooltip_name_fn",
148 # set up legend positioning 151 $this->Chart[
"legend"][
"show"] = FALSE;
158 # if the user provided a color palette, set that up as will 159 if (!is_null($this->
Colors()))
161 # sort user-provided colors into the correct order 163 foreach ($this->Data as $Label => $Value)
165 $Palette[]= isset($this->
Colors[$Label]) ?
170 $this->Chart[
"color"][
"pattern"] = $Palette;
173 static::PrepareData();
177 ?><div
id=
"<?= $ContainerId ?>" class=
"cw-<?= strtolower(get_called_class()) ?>"></div>
178 <script type=
"text/javascript">
179 $(document).ready(
function(){
181 var label_lut = <?= json_encode($this->LabelLUT) ?>;
182 <?
PHP static::DeclareStateVariables(); ?>
185 function tooltip_name_fn(name, ratio,
id, index) {
186 return name in label_lut ? label_lut[name] : name;
188 <?
PHP static::DeclareHelperFunctions(); ?>
191 var chart_spec = <?= json_encode($this->Chart) ?>;
194 function eval_fns(obj){
195 for (var prop in obj) {
196 if (typeof obj[prop] ==
"object") {
198 }
else if (typeof obj[prop] ==
"string" && obj[prop].match(/_fn$/)) {
199 obj[prop] = eval(obj[prop]);
203 eval_fns(chart_spec);
206 c3.generate(chart_spec);
212 # legend position constants 218 # ---- PRIVATE INTERFACE -------------------------------------------------- 254 return "#".substr(md5($DataIndex), 0, 6);
273 foreach (
$Data as $Key => $Val)
275 if (isset($Tgt[$Key]) &&
276 is_array($Tgt[$Key]) && is_array($Val))
287 # data provided by caller 290 # chart parameters that can be changed prior to generation 297 # internal variables used to generate the chart
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.
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.
AddToArray(&$Tgt, $Data)
Merge elements from a source array into a dest array.
AddToChart($Data)
Merge an array of settings into $this->Chart.
Colors($NewValue=NULL)
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.