1
1
/*
2
2
* DELETE THIS FILE. EVERYTHING NEEDS TO FIND A HOME.
3
3
*/
4
+ import isNumeric from 'fast-isnumeric' ;
4
5
import { list } from 'plotly.js/src/plots/cartesian/axis_ids' ;
5
6
import { UnconnectedNumeric } from './components/fields/Numeric' ;
6
7
import {
@@ -22,20 +23,69 @@ class NumericNoArrows extends UnconnectedNumeric {}
22
23
NumericNoArrows . propTypes = UnconnectedNumeric . propTypes ;
23
24
NumericNoArrows . defaultProps = {
24
25
showArrows : false ,
26
+ postfix : '%' ,
25
27
} ;
26
28
27
- export const BoxGap = connectLayoutToPlot (
29
+ // Workaround the issue with nested layouts inside trace component.
30
+ // See:
31
+ // https://github.com/plotly/react-plotly.js-editor/issues/58#issuecomment-345492794
32
+ const supplyLayoutPlotProps = ( props , context ) => {
33
+ return unpackPlotProps ( props , {
34
+ ...context ,
35
+ ...getLayoutContext ( context ) ,
36
+ } ) ;
37
+ } ;
38
+
39
+ export const BoxWidth = connectLayoutToPlot (
28
40
connectToContainer ( NumericNoArrows , {
29
- supplyPlotProps : ( props , context ) => {
30
- // workaround the issue with nested layouts inside trace component.
31
- // See
32
- // https://github.com/plotly/react-plotly.js-editor/issues/58#issuecomment-345492794
33
- const plotProps = unpackPlotProps ( props , {
34
- ...context ,
35
- ...getLayoutContext ( context ) ,
36
- } ) ;
37
-
38
- // Full value should multiply by percentage if number.
41
+ supplyPlotProps : supplyLayoutPlotProps ,
42
+ modifyPlotProps : ( props , context , plotProps ) => {
43
+ const { fullValue, updatePlot} = plotProps ;
44
+ plotProps . fullValue = ( ) => {
45
+ let fv = fullValue ( ) ;
46
+ if ( isNumeric ( fv ) ) {
47
+ fv = Math . round ( ( 1 - fv ) * 100 ) ;
48
+ }
49
+ return fv ;
50
+ } ;
51
+
52
+ plotProps . updatePlot = v => {
53
+ if ( isNumeric ( v ) ) {
54
+ updatePlot ( 1 - v / 100 ) ;
55
+ } else {
56
+ updatePlot ( v ) ;
57
+ }
58
+ } ;
59
+
60
+ plotProps . max = 100 ;
61
+
62
+ return plotProps ;
63
+ } ,
64
+ } )
65
+ ) ;
66
+
67
+ export const BoxPad = connectLayoutToPlot (
68
+ connectToContainer ( NumericNoArrows , {
69
+ supplyPlotProps : supplyLayoutPlotProps ,
70
+ modifyPlotProps : ( props , context , plotProps ) => {
71
+ const { fullValue, updatePlot} = plotProps ;
72
+ plotProps . fullValue = ( ) => {
73
+ let fv = fullValue ( ) ;
74
+ if ( isNumeric ( fv ) ) {
75
+ fv = fv * 100 ;
76
+ }
77
+ return fv ;
78
+ } ;
79
+
80
+ plotProps . updatePlot = v => {
81
+ if ( isNumeric ( v ) ) {
82
+ updatePlot ( v / 100 ) ;
83
+ } else {
84
+ updatePlot ( v ) ;
85
+ }
86
+ } ;
87
+
88
+ plotProps . max = 100 ;
39
89
40
90
return plotProps ;
41
91
} ,
0 commit comments