CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static 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:
[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...
| 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

## 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 | $Tgt | Target array.
  array | $Data | Data to be added.

Definition at line 308 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 | $Data | Settings to merge.

Definition at line 298 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` | ) |

Get/set color palette.

Parameters

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

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

Parameters

  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.

Chart_Base::GenerateRgbColorString | ( |  | $DataIndex | ) |
| protected

Get RGB hex color when no color supplied.

Parameters

  string | $DataIndex | Index for data for which color will be used.

Returns
  string RGB hex color string.

Definition at line 289 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 | $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).

Parameters

  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)

Returns
  array|boolean $Labels Label strings for chart, indexed by the same values used to index chart data, or FALSE if no labels have been set.

Exceptions

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

Here is the caller graph for this function:

Chart_Base::LegendLabels | ( |  | $LegendLabels | ) |

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

Parameters

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

Here is the caller graph for this function:

Chart_Base::LegendPosition | ( |  | $Position | ) |

Set legend position.

Parameters

  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.

Exceptions

  Exception | If 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 | ( |  | ) |
| abstract protected

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

Here is the caller graph for this function:

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

static Chart_Base::RequireNeededFiles | ( |  | ) |
| static protected

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.

Parameters

  int | $NewValue | New width in pixels (OPTIONAL).

Definition at line 104 of file Chart_Base.php.

References $Width.

## Member Data Documentation

Chart_Base::$Chart = NULL
| protected

Definition at line 340 of file Chart_Base.php.

Chart_Base::$Colors = NULL
| protected

Definition at line 329 of file Chart_Base.php.

Referenced by Colors().

Chart_Base::$Data = []
| protected

Definition at line 325 of file Chart_Base.php.

Referenced by PieChart\__construct(), BarChart\__construct(), AddToArray(), AddToChart(), and BarChart\PrepareData().

Chart_Base::$Height = 600
| protected

Definition at line 332 of file Chart_Base.php.

Referenced by Display(), and Height().

Chart_Base::$Labels = []
| protected

Definition at line 330 of file Chart_Base.php.

Referenced by Labels().

Chart_Base::$LegendLabels = []
| protected

Definition at line 331 of file Chart_Base.php.

Referenced by LegendLabels().

Chart_Base::$LegendPosition = self::LEGEND_BOTTOM
| protected

Definition at line 328 of file Chart_Base.php.

Referenced by Display().

Chart_Base::$TooltipLabels = []
| protected

Definition at line 339 of file Chart_Base.php.

Chart_Base::$Width = 600
| protected

Definition at line 333 of file Chart_Base.php.

Referenced by Display(), and Width().

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.

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

- interface/default/objects/Chart_Base.php