@figlinq/react-chart-editor
Version:
plotly.js chart editor react component UI
2 lines • 3.45 kB
JavaScript
function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==typeof i?i:i+""}function _toPrimitive(t,r){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}import Dropdown from"./Dropdown";import PropTypes from"prop-types";import{Component}from"react";import nestedProperty from"plotly.js/src/lib/nested_property";import{tooLight}from"../../lib";import{COLORS,MULTI_VALUED}from"../../lib/constants";import{jsx as _jsx}from"react/jsx-runtime";const strokeDashes=[{value:"solid",strokeDasharray:""},{value:"dot",strokeDasharray:"3px, 3px"},{value:"dash",strokeDasharray:"9px, 9px"},{value:"longdash",strokeDasharray:"15px, 15px"},{value:"dashdot",strokeDasharray:"9px, 3px, 3px, 3px"},{value:"longdashdot",strokeDasharray:"15px, 6px, 3px, 6px"}];const strokeShapes=[{d:"M2,14L14,2",value:"linear"},{d:"M2,14C4,4 16,16 18,2",value:"spline"},{d:"M2,14H14V2",value:"hv"},{d:"M2,14V2H14",value:"vh"},{d:"M2,14H8V2H14",value:"hvh"},{d:"M2,14V8H14V2",value:"vhv"}];const computeOptions=(strokeData,stroke)=>strokeData.map(_ref=>{let{value,strokeDasharray,d="M0,8h100"}=_ref;return{label:_jsx("svg",{width:"100",height:"16",children:_jsx("g",{children:_jsx("path",{d:d,style:{fill:"none",strokeWidth:"4px",stroke:!stroke||stroke===MULTI_VALUED?COLORS.mutedBlue:stroke,strokeDasharray}})})}),value}});export const LineShapeSelector=props=>_jsx(LineSelector,_objectSpread(_objectSpread({},props),{},{computeOptions:computeOptions.bind(null,strokeShapes)}));export const LineDashSelector=props=>_jsx(LineSelector,_objectSpread(_objectSpread({},props),{},{computeOptions:lineColor=>computeOptions(strokeDashes,lineColor).concat([{label:"",value:null}])}));class LineSelector extends Component{constructor(props,context){super(props,context);this.setLocals(props,context)}UNSAFE_componentWillReceiveProps(nextProps,nextContext){this.setLocals(nextProps,nextContext)}setLocals(nextProps,nextContext){const{fullContainer}=nextContext;const lineColor=nestedProperty(fullContainer,"line.color").get();if(!this.options||this.lineColor!==lineColor){this.options=this.props.computeOptions(lineColor);this.lineColor=lineColor}}render(){return _jsx(Dropdown,_objectSpread(_objectSpread({},this.props),{},{options:this.options,backgroundDark:tooLight(this.lineColor)}))}}LineSelector.propTypes=_objectSpread({computeOptions:PropTypes.func},Dropdown.propTypes);LineSelector.defaultProps={clearable:false};LineSelector.contextTypes={fullContainer:PropTypes.object};
//# sourceMappingURL=LineSelectors.js.map