11/*
22 * DELETE THIS FILE. EVERYTHING NEEDS TO FIND A HOME.
33 */
4+ import isNumeric from 'fast-isnumeric' ;
45import { list } from 'plotly.js/src/plots/cartesian/axis_ids' ;
56import { UnconnectedNumeric } from './components/fields/Numeric' ;
67import {
@@ -22,20 +23,69 @@ class NumericNoArrows extends UnconnectedNumeric {}
2223NumericNoArrows . propTypes = UnconnectedNumeric . propTypes ;
2324NumericNoArrows . defaultProps = {
2425 showArrows : false ,
26+ postfix : '%' ,
2527} ;
2628
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 (
2840 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 ;
3989
4090 return plotProps ;
4191 } ,
0 commit comments