abstract class ChartBase in Charts 8.4
Same name and namespace in other branches
- 5.0.x src/Plugin/chart/Library/ChartBase.php \Drupal\charts\Plugin\chart\Library\ChartBase
Base class Chart plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\charts\Plugin\chart\Library\ChartBase implements ChartInterface uses StringTranslationTrait
Expanded class hierarchy of ChartBase
6 files declare their use of ChartBase
- Billboard.php in modules/
charts_billboard/ src/ Plugin/ chart/ Library/ Billboard.php - C3.php in modules/
charts_c3/ src/ Plugin/ chart/ Library/ C3.php - Chart.php in src/
Element/ Chart.php - Chartjs.php in modules/
charts_chartjs/ src/ Plugin/ chart/ Library/ Chartjs.php - Google.php in modules/
charts_google/ src/ Plugin/ chart/ Library/ Google.php
File
- src/
Plugin/ chart/ Library/ ChartBase.php, line 14
Namespace
Drupal\charts\Plugin\chart\LibraryView source
abstract class ChartBase extends PluginBase implements ChartInterface {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function getChartName() {
return $this->pluginDefinition['name'];
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = NestedArray::mergeDeep($this
->defaultConfiguration(), $configuration);
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* Gets defaults settings.
*
* @return array
* The defaults settings.
*/
public static function getDefaultSettings() {
$defaults = [
'type' => 'line',
'library' => NULL,
'grouping' => FALSE,
'fields' => [
'label' => NULL,
'data_providers' => NULL,
],
'display' => [
'title' => '',
'title_position' => 'out',
'data_labels' => FALSE,
'data_markers' => TRUE,
'legend' => TRUE,
'legend_position' => 'right',
'background' => '',
'three_dimensional' => FALSE,
'polar' => FALSE,
'tooltips' => TRUE,
'tooltips_use_html' => FALSE,
'dimensions' => [
'width' => NULL,
'width_units' => '%',
'height' => NULL,
'height_units' => 'px',
],
'gauge' => [
'green_to' => 100,
'green_from' => 85,
'yellow_to' => 85,
'yellow_from' => 50,
'red_to' => 50,
'red_from' => 0,
'max' => 100,
'min' => 0,
],
'colors' => self::getDefaultColors(),
],
];
return $defaults;
}
/**
* Gets the default hex colors.
*
* @return array
* The hex colors.
*/
public static function getDefaultColors() {
return [
'#2f7ed8',
'#0d233a',
'#8bbc21',
'#910000',
'#1aadce',
'#492970',
'#f28f43',
'#77a1e5',
'#c42525',
'#a6c96a',
];
}
/**
* Gets options properties.
*
* @param array $element
* The element.
*
* @return array
* The options.
*/
protected function getOptionsFromElementProperties(array $element) {
$options = [];
$properties_mapping = ChartsDefaultSettings::getLegacySettingsMappingKeys();
// Remove properties which don't have a mapping.
$filtered_element = array_filter($element, function ($property) use ($properties_mapping) {
$property = ltrim($property, '#');
return isset($properties_mapping[$property]);
});
foreach ($filtered_element as $property => $value) {
$property = ltrim($property, '#');
$property_map = $properties_mapping[$property];
if (substr($property_map, 0, 7) === 'display') {
// Stripping the 'display_' in front of the mapping key.
$property_map = substr($property_map, 8, strlen($property_map));
if (substr($property_map, 0, 10) === 'dimensions') {
// Stripping dimensions_.
$property_map = substr($property_map, 11, strlen($property_map));
$options['display']['dimensions'][$property_map] = $value;
}
elseif (substr($property_map, 0, 5) === 'gauge') {
// Stripping gauge_.
$property_map = substr($property_map, 6, strlen($property_map));
$options['display']['gauge'][$property_map] = $value;
}
else {
$options['display'][$property_map] = $value;
}
}
elseif (substr($property_map, 0, 5) === 'xaxis') {
// Stripping xaxis_.
$property_map = substr($property_map, 6, strlen($property_map));
$options['xaxis'][$property_map] = $value;
}
elseif (substr($property_map, 0, 5) === 'yaxis') {
// Stripping yaxis_.
$property_map = substr($property_map, 6, strlen($property_map));
if (substr($property_map, 0, 9) === 'secondary') {
// Stripping gauge_.
$property_map = substr($property_map, 10, strlen($property_map));
$options['yaxis']['secondary'][$property_map] = $value;
}
else {
$options['yaxis'][$property_map] = $value;
}
}
elseif (substr($property_map, 0, 6) === 'fields') {
// Stripping fields_.
$property_map = substr($property_map, 7, strlen($property_map));
if ($property_map === 'data_providers' && is_array($value)) {
$data_providers = !empty($options['fields']['data_providers']) ? $options['fields']['data_providers'] : [];
if ($property === 'data_fields' || $property == 'field_colors') {
$options['fields']['data_providers'] = ChartsDefaultSettings::getFieldsDataProviders($data_providers, $value);
}
}
else {
$options['fields'][$property_map] = $value;
}
}
else {
// We make sure that we handle the color unneeded array.
$options[$property_map] = $property_map !== 'color' ? $value : $value[0];
}
}
return $options;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ChartBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
5 |
ChartBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
1 |
ChartBase:: |
public | function |
Return the name of the chart. Overrides ChartInterface:: |
|
ChartBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ChartBase:: |
public static | function | Gets the default hex colors. | |
ChartBase:: |
public static | function | Gets defaults settings. | |
ChartBase:: |
protected | function | Gets options properties. | |
ChartBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ChartBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
1 |
ChartBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
ChartInterface:: |
constant | Used to define a dual axis. | ||
ChartInterface:: |
public | function | Pre render. | 5 |
ChartInterface:: |
constant | Used to define a single axis. | ||
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |