playbook_ui 13.18.0.pre.alpha.thor93bargraphoptions2211 → 13.18.0.pre.alpha.thor93bargraphoptions2219

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ceb325111d4662aa6a0491153e357222b4f304d21c247fcc44a3db3aafda347a
4
- data.tar.gz: 693e1c50633b9b8f309cd2c21ffaa457adbf54ed8a3bd3dfa965b9852c3f6ca6
3
+ metadata.gz: 8ec6af33629ba1cad2697168cca8e87e43f0481cbf12430fd62ddc174ac77388
4
+ data.tar.gz: 0a5976c59dbdbefbcb3fa4f1ecdd0a3572c8e01518388104b6daf5a315a1da06
5
5
  SHA512:
6
- metadata.gz: 64ae9216199a92f0559d7b524f6165f93698366b2d01e05669293b5a0fb974294148caf6415e97bcff6f8a09b1d2931cdc17cd28f2fc3b421be1532962061b97
7
- data.tar.gz: 8134787717615c18836ec47718dae3518c79500d1786b9076618a71d8f0e5605706bc355aa9398c8dea710c3604828d93aeb680f0c7a17f4a19aab9510dc00c8
6
+ metadata.gz: 87c9af5d361733440d37edc722958b83555195a33a59e44f7281eb6dfda06d73c454b9956161896ac35ebf090de5218543c88573e8dd1c87076d97633da824c8
7
+ data.tar.gz: d8eeae22de85db2a9a079a9773641065d8ba6fa69b6a68511596d9a92ec7bdb476ead501910d4d8664f1474b9f85488f719cd4154f12328c57ac403c98911c17
@@ -7,6 +7,7 @@ import Highcharts from "highcharts";
7
7
  import { highchartsTheme } from "../pb_dashboard/pbChartsLightTheme";
8
8
  import { highchartsDarkTheme } from "../pb_dashboard/pbChartsDarkTheme";
9
9
  import mapColors from "../pb_dashboard/pbChartsColorsHelper";
10
+ import { merge } from 'lodash'
10
11
 
11
12
  import classnames from "classnames";
12
13
 
@@ -130,7 +131,7 @@ const BarGraph = ({
130
131
  const [options, setOptions] = useState({});
131
132
 
132
133
  useEffect(() => {
133
- setOptions({ ...staticOptions, ...customOptions });
134
+ setOptions(merge(staticOptions, customOptions));
134
135
  }, [chartData]);
135
136
 
136
137
  return (
@@ -9,6 +9,7 @@ module Playbook
9
9
  prop :axis_title
10
10
  prop :chart_data, type: Playbook::Props::Array,
11
11
  default: []
12
+ prop :custom_options, default: {}
12
13
  prop :orientation, type: Playbook::Props::Enum,
13
14
  values: %w[vertical horizontal],
14
15
  default: "vertical"
@@ -39,7 +40,7 @@ module Playbook
39
40
  orientation == "horizontal" ? "bar" : "column"
40
41
  end
41
42
 
42
- def chart_options
43
+ def standard_options
43
44
  {
44
45
  align: align,
45
46
  id: id,
@@ -65,6 +66,10 @@ module Playbook
65
66
  }
66
67
  end
67
68
 
69
+ def chart_options
70
+ standard_options.deep_merge(custom_options)
71
+ end
72
+
68
73
  def classname
69
74
  generate_classname("pb_bar_graph")
70
75
  end
@@ -0,0 +1,39 @@
1
+ <% data = [{
2
+ name: 'Installation',
3
+ data: [1475,200,3000,654,656]
4
+ }, {
5
+ name: 'Manufacturing',
6
+ data: [4434,524,2320,440,500]
7
+ }, {
8
+ name: 'Sales & Distribution',
9
+ data: [3387,743,1344,434,440,]
10
+ }, {
11
+ name: 'Project Development',
12
+ data: [3227,878,999,780,1000]
13
+ }, {
14
+ name: 'Other',
15
+ data: [1111,677,3245,500,200]
16
+ }] %>
17
+
18
+ <% custom_options = {
19
+ customOptions: {
20
+ subtitle: {
21
+ text: "Overwritten subtitle",
22
+ style: {
23
+ color: "red",
24
+ fontSize: 20
25
+ }
26
+ }
27
+ }
28
+ } %>
29
+
30
+ <%= pb_rails("bar_graph", props: {
31
+ axis_title: 'Number of Employees',
32
+ chart_data: data,
33
+ id: "bar-default",
34
+ y_axis_min: 0,
35
+ x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
36
+ subtitle: 'Subtitle to replace',
37
+ title: 'Solar Employment Growth by Sector, 2010-2016',
38
+ custom_options: custom_options
39
+ }) %>
@@ -0,0 +1,65 @@
1
+ import React from 'react'
2
+
3
+ import BarGraph from '../_bar_graph'
4
+
5
+ const chartData = [{
6
+ name: 'Installation',
7
+ data: [1475, 200, 3000, 654, 656],
8
+ }, {
9
+ name: 'Manufacturing',
10
+ data: [4434, 524, 2320, 440, 500],
11
+ }, {
12
+ name: 'Sales & Distribution',
13
+ data: [3387, 743, 1344, 434, 440],
14
+ }, {
15
+ name: 'Project Development',
16
+ data: [3227, 878, 999, 780, 1000],
17
+ }, {
18
+ name: 'Other',
19
+ data: [1111, 677, 3245, 500, 200],
20
+ }]
21
+
22
+ const barGraphOptions = {
23
+ subtitle: {
24
+ text: "Overwritten subtitle"
25
+ },
26
+ xAxis: {
27
+ labels: {
28
+ useHTML: true,
29
+ formatter: function() {
30
+ switch (this.value) {
31
+ case 'Jan':
32
+ return `<i class="fa-regular fa-apple-whole"></i> ${this.value}`
33
+ case 'Feb':
34
+ return `<i class="far fa-strawberry"></i> ${this.value}`
35
+ case 'Mar':
36
+ return `<i class="far fa-lemon"></i> ${this.value}`
37
+ case 'Apr':
38
+ return `<i class="far fa-pear"></i> ${this.value}`
39
+ case 'May':
40
+ return `<i class="far fa-peach"></i> ${this.value}`
41
+ default:
42
+ return ''
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+
49
+ const BarGraphCustom = (props) => (
50
+ <div>
51
+ <BarGraph
52
+ axisTitle="Number of Employees"
53
+ chartData={chartData}
54
+ customOptions={barGraphOptions}
55
+ id="bar-custom"
56
+ subTitle="Subtitle to replace"
57
+ title="Bar Graph with Custom Overrides"
58
+ xAxisCategories={['Jan', 'Feb', 'Mar', 'Apr', 'May']}
59
+ yAxisMin={0}
60
+ {...props}
61
+ />
62
+ </div>
63
+ )
64
+
65
+ export default BarGraphCustom
@@ -8,6 +8,7 @@ examples:
8
8
  - bar_graph_height: Height
9
9
  - bar_graph_spline: Spline
10
10
  - bar_graph_colors: Color Overrides
11
+ - bar_graph_custom: Custom Overrides
11
12
 
12
13
 
13
14
  react:
@@ -18,3 +19,4 @@ examples:
18
19
  - bar_graph_height: Height
19
20
  - bar_graph_spline: Spline
20
21
  - bar_graph_colors: Color Overrides
22
+ - bar_graph_custom: Custom Overrides
@@ -5,3 +5,4 @@ export { default as BarGraphLegendNonClickable } from './_bar_graph_legend_non_c
5
5
  export { default as BarGraphHeight } from './_bar_graph_height.jsx'
6
6
  export { default as BarGraphSpline } from './_bar_graph_spline.jsx'
7
7
  export { default as BarGraphColors } from './_bar_graph_colors.jsx'
8
+ export { default as BarGraphCustom } from './_bar_graph_custom.jsx'