CWIS Developer Documentation
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Chart_Base Class Reference

Base class for generating and displaying a chart. More...

Inheritance diagram for Chart_Base:
Inheritance graph
[legend]

Public Member Functions

 LegendPosition ($Position)
 Set legend position. More...
 
 LegendLabels ($LegendLabels)
 Set shortened labels to be used in the legend of the chart. More...
 
 Colors ($NewValue=NULL)
 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...
 

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...
 

Protected Attributes

 $Data = []
 
 $LegendPosition = self::LEGEND_BOTTOM
 
 $Colors = NULL
 
 $LegendLabels = []
 
 $Height = 600
 
 $Width = 600
 
 $LabelLUT = []
 
 $Chart = NULL
 

Detailed Description

Base class for generating and displaying a chart.

Definition at line 13 of file Chart_Base.php.

Member Function Documentation

Chart_Base::AddToArray ( $Tgt,
  $Data 
)
protected

Merge elements from a source array into a dest array.

Parameters
array$TgtTarget array.
array$DataData to be added.

Definition at line 271 of file Chart_Base.php.

References $Data.

Referenced by AddToChart().

Here is the caller graph for this function:

Chart_Base::AddToChart (   $Data)
protected

Merge an array of settings into $this->Chart.

Parameters
array$DataSettings to merge.

Definition at line 261 of file Chart_Base.php.

References $Data, and AddToArray().

Referenced by PieChart\PrepareData(), and BarChart\PrepareData().

Here is the caller graph for this function:

Chart_Base::Colors (   $NewValue = NULL)

Set color palette.

Parameters
array$NewValueArray of hex colors (e.g., '#1f77b4'), indexed by the corresponding labels (OPTIONAL). Bars with no color defined will use an autogenerated color.

Definition at line 54 of file Chart_Base.php.

References $Colors.

Referenced by Display().

Here is the caller graph for this function:

Chart_Base::DeclareHelperFunctions ( )
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 242 of file Chart_Base.php.

Chart_Base::DeclareStateVariables ( )
protected

Output var declarations for any js state variables needed in this chart's display helper functions.

Definition at line 231 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.

Parameters
string$ContainerIdId to use when generating the div to contain this chart.

Definition at line 124 of file Chart_Base.php.

References $Height, $LegendPosition, $Width, Colors(), GenerateRgbColorString(), LegendPosition(), and PHP.

Chart_Base::GenerateRgbColorString (   $DataIndex)
protected

Get RGB hex color when no color supplied.

Parameters
string$DataIndexIndex for data for which color will be used.
Returns
string RGB hex color string.

Definition at line 252 of file Chart_Base.php.

Referenced by Display().

Here is the caller graph for this function:

Chart_Base::Height (   $NewValue)

Get/Set height of the chart including the legend.

Parameters
int$NewValueNew height in pixels (OPTIONAL).

Definition at line 68 of file Chart_Base.php.

References $Height.

Chart_Base::LegendLabels (   $LegendLabels)

Set shortened labels to be used in the legend of the chart.

Parameters
array$LegendLabelsArray 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().

Here is the caller graph for this function:

Chart_Base::LegendPosition (   $Position)

Set legend position.

Parameters
string$PositionLegend 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.
Exceptions
ExceptionIf an invalid legend position is supplied.

Definition at line 26 of file Chart_Base.php.

Referenced by BarChart\__construct(), and Display().

Here is the caller graph for this function:

Chart_Base::PrepareData ( )
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.

Chart_Base::Width (   $NewValue)

Get/Set width of the chart including the legend.

Parameters
int$NewValueNew width in pixels (OPTIONAL).

Definition at line 82 of file Chart_Base.php.

References $Width.

Member Data Documentation

Chart_Base::$Chart = NULL
protected

Definition at line 299 of file Chart_Base.php.

Chart_Base::$Colors = NULL
protected

Definition at line 292 of file Chart_Base.php.

Referenced by Colors().

Chart_Base::$Data = []
protected
Chart_Base::$Height = 600
protected

Definition at line 294 of file Chart_Base.php.

Referenced by Display(), and Height().

Chart_Base::$LabelLUT = []
protected

Definition at line 298 of file Chart_Base.php.

Chart_Base::$LegendLabels = []
protected

Definition at line 293 of file Chart_Base.php.

Referenced by LegendLabels().

Chart_Base::$LegendPosition = self::LEGEND_BOTTOM
protected

Definition at line 291 of file Chart_Base.php.

Referenced by Display().

Chart_Base::$Width = 600
protected

Definition at line 295 of file Chart_Base.php.

Referenced by Display(), and Width().

const Chart_Base::LEGEND_BOTTOM = "bottom"

Definition at line 213 of file Chart_Base.php.

const Chart_Base::LEGEND_INSET = "inset"

Definition at line 215 of file Chart_Base.php.

const Chart_Base::LEGEND_NONE = "none"

Definition at line 216 of file Chart_Base.php.

const Chart_Base::LEGEND_RIGHT = "right"

Definition at line 214 of file Chart_Base.php.


The documentation for this class was generated from the following file: