CWIS Developer Documentation
|
Base class for generating and displaying a chart. More...
Public Member Functions | |
LegendPosition ($Position) | |
Set legend position. More... | |
LegendLabels ($LegendLabels) | |
Set shortened labels to be used in the legend of the chart. More... | |
Labels ($NewValue=NULL) | |
Get/set chart element labels (pie slices, bars, etc). More... | |
Colors ($NewValue=NULL) | |
Get/set color palette. More... | |
Height ($NewValue) | |
Get/Set height of the chart including the legend. More... | |
Width ($NewValue) | |
Get/Set width of the chart including the legend. More... | |
Display ($ContainerId) | |
Display a chart. More... | |
Static Public Member Functions | |
static | PrepForDisplayingCachedVersion () |
Set up the chart environment so that cached HTML from a previous Display() call will function properly. More... | |
Public Attributes | |
const | LEGEND_BOTTOM = "bottom" |
const | LEGEND_RIGHT = "right" |
const | LEGEND_INSET = "inset" |
const | LEGEND_NONE = "none" |
Protected Member Functions | |
PrepareData () | |
Massage data provided by the user into an appropriate format for plotting and do any necessary tweaks to $this->Chart. More... | |
DeclareStateVariables () | |
Output var declarations for any js state variables needed in this chart's display helper functions. More... | |
DeclareHelperFunctions () | |
Output function definitions for any needed javascript display helper functions. More... | |
GenerateRgbColorString ($DataIndex) | |
Get RGB hex color when no color supplied. More... | |
AddToChart ($Data) | |
Merge an array of settings into $this->Chart. More... | |
AddToArray (&$Tgt, $Data) | |
Merge elements from a source array into a dest array. More... | |
Static Protected Member Functions | |
static | RequireNeededFiles () |
Include necessary JS/CSS for chart generation. More... | |
Protected Attributes | |
$Data = [] | |
$LegendPosition = self::LEGEND_BOTTOM | |
$Colors = NULL | |
$Labels = [] | |
$LegendLabels = [] | |
$Height = 600 | |
$Width = 600 | |
$TooltipLabels = [] | |
$Chart = NULL | |
Base class for generating and displaying a chart.
Definition at line 13 of file Chart_Base.php.
|
protected |
Merge elements from a source array into a dest array.
array | $Tgt | Target array. |
array | $Data | Data to be added. |
Definition at line 308 of file Chart_Base.php.
References $Data.
Referenced by AddToChart().
|
protected |
Merge an array of settings into $this->Chart.
array | $Data | Settings to merge. |
Definition at line 298 of file Chart_Base.php.
References $Data, and AddToArray().
Referenced by PieChart\PrepareData(), and BarChart\PrepareData().
Chart_Base::Colors | ( | $NewValue = NULL | ) |
Get/set color palette.
array | $NewValue | Array of hex colors (e.g., '#1f77b4'), indexed by the keys used in the constructor (OPTIONAL). Bars with no color defined will use an autogenerated color. |
Definition at line 76 of file Chart_Base.php.
References $Colors.
Referenced by Display().
|
protected |
Output function definitions for any needed javascript display helper functions.
Note that all these functions must have names ending with _fn for the eval_fns() js helper to make them callable.
Definition at line 279 of file Chart_Base.php.
|
protected |
Output var declarations for any js state variables needed in this chart's display helper functions.
Definition at line 268 of file Chart_Base.php.
Chart_Base::Display | ( | $ContainerId | ) |
Display a chart.
These charts are currently generated with c3.js, which outputs SVG that is annotated with CSS classes for styling (C3 is only relevant insofar as it is reflected in the CSS class names). For example, if there is a data item called "Engineering", then the chart element for that item will be in a g.c3-target-Engineering. The text giving the label for that element can be changed to black with CSS like:
g.c3-target-Engineering text { fill: black; }
Similarly, the text for the corresponding legend item:
g.c3-legend-item-Engineering text { fill: green; }
Note that the foreground color of an SVG text is controlled by 'fill' rather than 'color' because consistency is overrated. A reference to the SVG elements and the CSS properties that they understand can be found at:
https://developer.mozilla.org/en-US/docs/Web/SVG/Element
In practice, it's often simplest to use a browser's "Inspect Element" feature to locate SVG elements in order to customize them.
string | $ContainerId | Id to use when generating the div to contain this chart. |
Definition at line 146 of file Chart_Base.php.
References $Height, $LegendPosition, $Width, Colors(), GenerateRgbColorString(), LegendPosition(), and PHP.
|
protected |
Get RGB hex color when no color supplied.
string | $DataIndex | Index for data for which color will be used. |
Definition at line 289 of file Chart_Base.php.
Referenced by Display().
Chart_Base::Height | ( | $NewValue | ) |
Get/Set height of the chart including the legend.
int | $NewValue | New height in pixels (OPTIONAL). |
Definition at line 90 of file Chart_Base.php.
References $Height.
Chart_Base::Labels | ( | $NewValue = NULL | ) |
Get/set chart element labels (pie slices, bars, etc).
array | boolean | $NewValue | Label strings for chart, indexed by the same values used to index chart data, or FALSE to clear any existing labels. (OPTIONAL) |
InvalidArgumentException | If invalid type of new value supplied. |
Definition at line 57 of file Chart_Base.php.
References $Labels.
Referenced by PieChart\PrepareData(), and BarChart\PrepareData().
Chart_Base::LegendLabels | ( | $LegendLabels | ) |
Set shortened labels to be used in the legend of the chart.
array | $LegendLabels | Array of legend labels to use, with keys matching the keys of the data passed to the constructor. Any labels that do not need shortening may be omitted. |
Definition at line 43 of file Chart_Base.php.
References $LegendLabels.
Referenced by PieChart\PrepareData(), BarChart\PrepareData(), and BarChart\ShortCategoryNames().
Chart_Base::LegendPosition | ( | $Position | ) |
Set legend position.
string | $Position | Legend position as a BarChart::LEGEND_ constant. LEGEND_BOTTOM will place the legend below the chart, LEGEND_RIGHT will place it at the right, LEGEND_INSET will display it as an inset within the graphic, and LEGEND_NONE will disable the legend entirely. |
Exception | If an invalid legend position is supplied. |
Definition at line 26 of file Chart_Base.php.
Referenced by BarChart\__construct(), and Display().
|
abstractprotected |
Massage data provided by the user into an appropriate format for plotting and do any necessary tweaks to $this->Chart.
Child classes MUST implement this method.
Referenced by RequireNeededFiles().
|
static |
Set up the chart environment so that cached HTML from a previous Display() call will function properly.
Definition at line 233 of file Chart_Base.php.
|
staticprotected |
Include necessary JS/CSS for chart generation.
Definition at line 249 of file Chart_Base.php.
References PrepareData().
Chart_Base::Width | ( | $NewValue | ) |
Get/Set width of the chart including the legend.
int | $NewValue | New width in pixels (OPTIONAL). |
Definition at line 104 of file Chart_Base.php.
References $Width.
|
protected |
Definition at line 340 of file Chart_Base.php.
|
protected |
Definition at line 329 of file Chart_Base.php.
Referenced by Colors().
|
protected |
Definition at line 325 of file Chart_Base.php.
Referenced by PieChart\__construct(), BarChart\__construct(), AddToArray(), AddToChart(), and BarChart\PrepareData().
|
protected |
Definition at line 332 of file Chart_Base.php.
|
protected |
Definition at line 330 of file Chart_Base.php.
Referenced by Labels().
|
protected |
Definition at line 331 of file Chart_Base.php.
Referenced by LegendLabels().
|
protected |
Definition at line 328 of file Chart_Base.php.
Referenced by Display().
|
protected |
Definition at line 339 of file Chart_Base.php.
|
protected |
Definition at line 333 of file Chart_Base.php.
const Chart_Base::LEGEND_BOTTOM = "bottom" |
Definition at line 239 of file Chart_Base.php.
const Chart_Base::LEGEND_INSET = "inset" |
Definition at line 241 of file Chart_Base.php.
const Chart_Base::LEGEND_NONE = "none" |
Definition at line 242 of file Chart_Base.php.
const Chart_Base::LEGEND_RIGHT = "right" |
Definition at line 240 of file Chart_Base.php.