@figlinq/react-chart-editor
Version:
plotly.js chart editor react component UI
2 lines • 5.92 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 Field from"./Field";import PropTypes from"prop-types";import{Component}from"react";import DropdownWidget from"../widgets/Dropdown";import TextInput from"../widgets/TextInput";import{connectToContainer}from"../../lib";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const operations=_=>({inequality:[{value:"!=",label:_("Target \u2260 Reference")},{value:"<",label:_("Target < Reference")},{value:"<=",label:_("Target \u2264 Reference")},{value:"=",label:_("Target = Reference")},{value:">",label:_("Target > Reference")},{value:">=",label:_("Target \u2265 Reference")}],inrange:[{value:"[]",label:_("Lower \u2264 Target \u2264 Upper")},{value:"()",label:_("Lower < Target < Upper")},{value:"[)",label:_("Lower \u2264 Target < Upper")},{value:"(]",label:_("Lower < Target \u2264 Upper")}],exrange:[{value:")(",label:_("Lower \u2264 Target \u2264 Upper")},{value:"][",label:_("Lower < Target < Upper")},{value:")[",label:_("Lower \u2264 Target < Upper")},{value:"](",label:_("Lower < Target \u2264 Upper")}],inset:[{value:"{}",label:_("Include")}],exset:[{value:"}{",label:_("Exclude")}]});const findOperation=(operator,_)=>{let op="inequality";const ops=operations(_);for(const key in ops){if(ops.hasOwnProperty(key)&&ops[key].map(o=>o.value).indexOf(operator)!==-1){op=key;break}}return op};class UnconnectedFilterOperation extends Component{constructor(props,context){super(props,context);const{localize:_}=context;this.state={operation:findOperation(this.props.fullValue,_),operator:operations(_).inequality[0].value};this.setOperation=this.setOperation.bind(this)}setOperation(value){const{localize:_}=this.context;const operator=operations(_)[value][0].value;this.setState({operation:value,operator:operator});this.props.updatePlot(operator)}render(){const{fullValue,updatePlot,backgroundDark,attr}=this.props;const{localize:_}=this.context;const operators=[{label:_("Inequality"),value:"inequality"},{label:_("Include Range"),value:"inrange"},{label:_("Exclude Range"),value:"exrange"},{label:_("Include Values"),value:"inset"},{label:_("Exclude Values"),value:"exset"}];const opValue=fullValue&&fullValue.length>0?fullValue:this.state.operator;return _jsx("div",{children:_jsxs(Field,_objectSpread(_objectSpread({},this.props),{},{attr:attr,children:[_jsx(DropdownWidget,{backgroundDark:backgroundDark,options:operators,value:findOperation(opValue,_),onChange:this.setOperation,clearable:false}),this.state.operation==="inset"||this.state.operation==="exset"?null:_jsx(DropdownWidget,{backgroundDark:backgroundDark,options:operations(_)[this.state.operation],value:opValue,onChange:updatePlot,clearable:false})]}))})}}UnconnectedFilterOperation.propTypes=_objectSpread({fullValue:PropTypes.any,updatePlot:PropTypes.func},Field.propTypes);UnconnectedFilterOperation.contextTypes={localize:PropTypes.func};class UnconnectedFilterValue extends Component{constructor(props,context){super(props,context);this.state={value:"",valueMax:""};this.setValue=this.setValue.bind(this);this.setValueMax=this.setValueMax.bind(this)}setValue(v){const{localize:_,container}=this.context;const op=findOperation(container.operation,_);this.setState({value:v});let val;val=op==="inrange"||op==="exrange"?[v,this.state.valueMax]:v;if(op==="inset"||op==="exset"){val=val.split(",");val=val.map(v=>v.trim())}this.props.updatePlot(val)}setValueMax(v){this.setState({valueMax:v});this.props.updatePlot([this.state.value,v])}render(){const{localize:_,container}=this.context;const operation=container&&container.operation?container.operation:"=";const{fullValue,attr,defaultValue}=this.props;const op=findOperation(operation,_);let label1=_("Reference");if(op==="inrange"||op==="exrange"){label1=_("Lower Bound")}else if(op==="inset"||op==="exset"){label1=_("Values")}let val1=fullValue;if((op==="inset"||op==="exset")&&Array.isArray(fullValue)){val1=fullValue.join(", ")}else if(Array.isArray(fullValue)){val1=fullValue[0]}return _jsxs("div",{children:[_jsx(Field,_objectSpread(_objectSpread({},this.props),{},{label:label1,children:_jsx(TextInput,{value:val1,defaultValue:val1,onUpdate:this.setValue})})),!(op==="inrange"||op==="exrange")?null:_jsx(Field,_objectSpread(_objectSpread({},this.props),{},{label:_("Upper Bound"),attr:attr,children:_jsx(TextInput,{value:Array.isArray(fullValue)?fullValue[1]:fullValue,defaultValue:defaultValue,onUpdate:this.setValueMax})}))]})}}UnconnectedFilterValue.propTypes=_objectSpread({defaultValue:PropTypes.string,fullValue:PropTypes.any,updatePlot:PropTypes.func},Field.propTypes);UnconnectedFilterValue.contextTypes={localize:PropTypes.func,container:PropTypes.object};export const FilterOperation=connectToContainer(UnconnectedFilterOperation);export const FilterValue=connectToContainer(UnconnectedFilterValue);
//# sourceMappingURL=FilterOperation.js.map