added simple math and charts modules
This commit is contained in:
152
web/modules/charts/src/Plugin/chart/Library/ChartBase.php
Executable file
152
web/modules/charts/src/Plugin/chart/Library/ChartBase.php
Executable file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\charts\Plugin\chart\Library;
|
||||
|
||||
use Drupal\Component\Plugin\PluginBase;
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* Base class Chart plugins.
|
||||
*/
|
||||
abstract class ChartBase extends PluginBase implements ChartInterface {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getChartName(): string {
|
||||
return $this->pluginDefinition['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSupportedChartTypes(): array {
|
||||
$types = $this->pluginDefinition['types'];
|
||||
$chart_plugin_id = $this->getPluginId();
|
||||
// @todo Add dependency injection for the next major version.
|
||||
\Drupal::moduleHandler()->alter('charts_plugin_supported_chart_types', $types, $chart_plugin_id);
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isSupportedChartType(string $chart_type_id): bool {
|
||||
$supported_chart_types = $this->getSupportedChartTypes();
|
||||
return !$supported_chart_types || in_array($chart_type_id, $supported_chart_types);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfiguration(): array {
|
||||
return $this->configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setConfiguration(array $configuration): void {
|
||||
$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(): array {
|
||||
return [
|
||||
'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(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default hex colors.
|
||||
*
|
||||
* @return array
|
||||
* The hex colors.
|
||||
*/
|
||||
public static function getDefaultColors(): array {
|
||||
return [
|
||||
'#2f7ed8',
|
||||
'#0d233a',
|
||||
'#8bbc21',
|
||||
'#910000',
|
||||
'#1aadce',
|
||||
'#492970',
|
||||
'#f28f43',
|
||||
'#77a1e5',
|
||||
'#c42525',
|
||||
'#a6c96a',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
69
web/modules/charts/src/Plugin/chart/Library/ChartInterface.php
Executable file
69
web/modules/charts/src/Plugin/chart/Library/ChartInterface.php
Executable file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\charts\Plugin\chart\Library;
|
||||
|
||||
use Drupal\Component\Plugin\ConfigurableInterface;
|
||||
use Drupal\Component\Plugin\PluginInspectionInterface;
|
||||
use Drupal\Core\Plugin\PluginFormInterface;
|
||||
|
||||
/**
|
||||
* Defines an interface for Chart plugins.
|
||||
*/
|
||||
interface ChartInterface extends PluginInspectionInterface, PluginFormInterface, ConfigurableInterface {
|
||||
|
||||
/**
|
||||
* Used to define a single axis.
|
||||
*
|
||||
* Constant used in chartsTypeInfo() to declare chart types with a
|
||||
* single axis. For example a pie chart only has a single dimension.
|
||||
*/
|
||||
const SINGLE_AXIS = 'y_only';
|
||||
|
||||
/**
|
||||
* Used to define a dual axis.
|
||||
*
|
||||
* Constant used in chartsTypeInfo() to declare chart types with a dual
|
||||
* axes. Most charts use this type of data, meaning multiple categories each
|
||||
* have multiple values. This type of data is usually represented as a table.
|
||||
*/
|
||||
const DUAL_AXIS = 'xy';
|
||||
|
||||
/**
|
||||
* Pre render.
|
||||
*
|
||||
* @param array $element
|
||||
* The element.
|
||||
*
|
||||
* @return array
|
||||
* The chart element.
|
||||
*/
|
||||
public function preRender(array $element);
|
||||
|
||||
/**
|
||||
* Return the name of the chart.
|
||||
*
|
||||
* @return string
|
||||
* Returns the name as a string.
|
||||
*/
|
||||
public function getChartName();
|
||||
|
||||
/**
|
||||
* Gets the supported chart types.
|
||||
*
|
||||
* @return array
|
||||
* The supported chart types.
|
||||
*/
|
||||
public function getSupportedChartTypes();
|
||||
|
||||
/**
|
||||
* Checks if a chart type is supported.
|
||||
*
|
||||
* @param string $chart_type_id
|
||||
* The chart type ID.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the chart type is supported, FALSE otherwise.
|
||||
*/
|
||||
public function isSupportedChartType(string $chart_type_id);
|
||||
|
||||
}
|
||||
47
web/modules/charts/src/Plugin/chart/Type/Type.php
Executable file
47
web/modules/charts/src/Plugin/chart/Type/Type.php
Executable file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\charts\Plugin\chart\Type;
|
||||
|
||||
use Drupal\Core\Plugin\PluginBase;
|
||||
|
||||
/**
|
||||
* Chart type class plugins.
|
||||
*/
|
||||
class Type extends PluginBase implements TypeInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->pluginDefinition['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLabel() {
|
||||
return $this->pluginDefinition['label'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAxis() {
|
||||
return $this->pluginDefinition['axis'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isAxisInverted() {
|
||||
return $this->pluginDefinition['axis_inverted'] == TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportStacking() {
|
||||
return $this->pluginDefinition['stacking'] == TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
50
web/modules/charts/src/Plugin/chart/Type/TypeInterface.php
Executable file
50
web/modules/charts/src/Plugin/chart/Type/TypeInterface.php
Executable file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\charts\Plugin\chart\Type;
|
||||
|
||||
/**
|
||||
* Defines an interface for Chart type plugins.
|
||||
*/
|
||||
interface TypeInterface {
|
||||
|
||||
/**
|
||||
* Gets the chart type ID.
|
||||
*
|
||||
* @return string
|
||||
* The chart type ID.
|
||||
*/
|
||||
public function getId();
|
||||
|
||||
/**
|
||||
* Gets the chart type label.
|
||||
*
|
||||
* @return string
|
||||
* The chart type label.
|
||||
*/
|
||||
public function getLabel();
|
||||
|
||||
/**
|
||||
* Gets the chart type axis.
|
||||
*
|
||||
* @return string
|
||||
* The chart type axis.
|
||||
*/
|
||||
public function getAxis();
|
||||
|
||||
/**
|
||||
* Gets whether the chart type axis is inverted.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the chart type axis is inverted, FALSE otherwise.
|
||||
*/
|
||||
public function isAxisInverted();
|
||||
|
||||
/**
|
||||
* Gets whether the chart type axis supports stacking.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the chart type axis supports stacking, FALSE otherwise.
|
||||
*/
|
||||
public function supportStacking();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user