Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
charts
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
charts
Commits
3b1e2deb
Commit
3b1e2deb
authored
9 months ago
by
Daniel Cothran
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3426704
by andileco, nikathone, jwilson3: Ability to disable some chart types
parent
61bf28c6
No related branches found
No related tags found
1 merge request
!89
Issue #3426704: Ability to disable some chart types
Pipeline
#157636
passed with warnings
9 months ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
charts.api.php
+34
-0
34 additions, 0 deletions
charts.api.php
src/Plugin/chart/Library/ChartBase.php
+13
-11
13 additions, 11 deletions
src/Plugin/chart/Library/ChartBase.php
with
47 additions
and
11 deletions
charts.api.php
+
34
−
0
View file @
3b1e2deb
...
...
@@ -133,3 +133,37 @@ function hook_chart_definition_alter(array &$definition, array $element, $chart_
*/
function
hook_chart_definition_CHART_ID_alter
(
array
&
$definition
,
array
$element
,
$chart_id
)
{
}
/**
* Alter the list of supported chart types for a chart plugin.
*
* To use this hook, first define the chart types you want to add in a file
* named <module>.charts_types.yml to your module's root directory. For example,
* if your module is named "charts_foo", the file should be named
* "charts_foo.charts_types.yml".
*
* The contents of this file will look something like:
*
* @code
* candlestick:
* label: 'Candlestick'
* axis: 'xy'
* axis_inverted: false
* stacking: false
* @endcode
*
* @see charts.charts_types.yml
*
* With that file in place, you can now implement this hook. See below for an
* example adding the 'candlestick' chart type to the 'highcharts' chart plugin.
*
* @param array $types
* An array of supported chart types.
* @param string $chart_plugin_id
* The chart plugin ID.
*/
function
hook_charts_plugin_supported_chart_types_alter
(
array
&
$types
,
string
$chart_plugin_id
)
{
if
(
$chart_plugin_id
===
'highcharts'
)
{
$types
[]
=
'candlestick'
;
}
}
This diff is collapsed.
Click to expand it.
src/Plugin/chart/Library/ChartBase.php
+
13
−
11
View file @
3b1e2deb
...
...
@@ -17,21 +17,25 @@ abstract class ChartBase extends PluginBase implements ChartInterface {
/**
* {@inheritdoc}
*/
public
function
getChartName
()
{
public
function
getChartName
()
:
string
{
return
$this
->
pluginDefinition
[
'name'
];
}
/**
* {@inheritdoc}
*/
public
function
getSupportedChartTypes
()
{
return
$this
->
pluginDefinition
[
'types'
];
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
)
{
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
);
}
...
...
@@ -39,14 +43,14 @@ abstract class ChartBase extends PluginBase implements ChartInterface {
/**
* {@inheritdoc}
*/
public
function
getConfiguration
()
{
public
function
getConfiguration
()
:
array
{
return
$this
->
configuration
;
}
/**
* {@inheritdoc}
*/
public
function
setConfiguration
(
array
$configuration
)
{
public
function
setConfiguration
(
array
$configuration
)
:
void
{
$this
->
configuration
=
NestedArray
::
mergeDeep
(
$this
->
defaultConfiguration
(),
$configuration
);
}
...
...
@@ -82,8 +86,8 @@ abstract class ChartBase extends PluginBase implements ChartInterface {
* @return array
* The defaults settings.
*/
public
static
function
getDefaultSettings
()
{
$defaults
=
[
public
static
function
getDefaultSettings
()
:
array
{
return
[
'type'
=>
'line'
,
'library'
=>
NULL
,
'grouping'
=>
FALSE
,
...
...
@@ -122,8 +126,6 @@ abstract class ChartBase extends PluginBase implements ChartInterface {
'colors'
=>
self
::
getDefaultColors
(),
],
];
return
$defaults
;
}
/**
...
...
@@ -132,7 +134,7 @@ abstract class ChartBase extends PluginBase implements ChartInterface {
* @return array
* The hex colors.
*/
public
static
function
getDefaultColors
()
{
public
static
function
getDefaultColors
()
:
array
{
return
[
'#2f7ed8'
,
'#0d233a'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment