@figlinq/react-chart-editor
Version:
plotly.js chart editor react component UI
2 lines • 4.86 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{AnnotationRef,AnnotationArrowRef}from"../derived";import DropdownWidget from"../../widgets/Dropdown";import{PlotlyPanel}from"../../";import{TestEditor,fixtures,plotly,mount}from"../../../lib/test-utils";import{connectAnnotationToLayout,connectLayoutToPlot}from"../../../lib";import{jsx as _jsx}from"react/jsx-runtime";const LayoutAnnoPanel=connectLayoutToPlot(connectAnnotationToLayout(PlotlyPanel));describe("<AnnotationRef>",()=>{function render(props){return mount(_jsx(TestEditor,_objectSpread(_objectSpread({},_objectSpread(_objectSpread({onUpdate:jest.fn()},props),{},{plotly})),{},{children:_jsx(LayoutAnnoPanel,{name:"Layout",annotationIndex:0,children:_jsx(AnnotationRef,{attr:"yref"})})})))}it("computes axes options for all axes using title and ids as labels",()=>{const fixtureProps=fixtures.scatter({layout:{annotations:[{text:"thor"}]}});const drop=render(_objectSpread({},fixtureProps)).find(DropdownWidget);const options=drop.first().prop("options");expect(options.length).toBe(3);expect(options[0]).toEqual({label:"Canvas",value:"paper"});expect(options[1]).toEqual({label:"Y 1",value:"y"});expect(options[2]).toEqual({label:"Y: yaxis2 title",value:"y2"})});it("sends update for a[x|y]ref attr on [x|y]ref change",()=>{const beforeUpdateLayout=jest.fn();const fixtureProps=fixtures.scatter({layout:{annotations:[{text:"thor",ayref:"y"}]}});const drop=render(_objectSpread({beforeUpdateLayout},fixtureProps)).find(DropdownWidget);drop.prop("onChange")("y2");const{update}=beforeUpdateLayout.mock.calls[0][0];expect(update).toEqual({"annotations[0].ayref":"y2","annotations[0].yref":"y2"})});it("does not send update for a[x|y]ref attr on \"paper\" change",()=>{const beforeUpdateLayout=jest.fn();const fixtureProps=fixtures.scatter({layout:{annotations:[{text:"thor",ayref:"y"}]}});const drop=render(_objectSpread({beforeUpdateLayout},fixtureProps)).find(DropdownWidget);drop.prop("onChange")("paper");const{update}=beforeUpdateLayout.mock.calls[0][0];expect(update).toEqual({"annotations[0].yref":"paper"})});it("does not send update for a[x|y]ref when a[x|y]ref is pixel",()=>{const beforeUpdateLayout=jest.fn();const fixtureProps=fixtures.scatter({layout:{annotations:[{text:"thor",yref:"y",ayref:"pixel"}]}});const drop=render(_objectSpread({beforeUpdateLayout},fixtureProps)).find(DropdownWidget);drop.prop("onChange")("y2");const{update}=beforeUpdateLayout.mock.calls[0][0];expect(update).toEqual({"annotations[0].yref":"y2"})})});describe("<AnnotationArrowRef>",()=>{function render(props){return mount(_jsx(TestEditor,_objectSpread(_objectSpread({},_objectSpread(_objectSpread({onUpdate:jest.fn()},props),{},{plotly})),{},{children:_jsx(LayoutAnnoPanel,{name:"Layout",annotationIndex:0,children:_jsx(AnnotationArrowRef,{attr:"ayref"})})})))}it("uses current value of axis ref as axes option when [x|y]ref set",()=>{const fixtureProps=fixtures.scatter({layout:{annotations:[{text:"thor",yref:"y"}]}});const drop=render(_objectSpread({},fixtureProps)).find(DropdownWidget);const options=drop.first().prop("options");expect(options.length).toBe(2);expect(options[0]).toEqual({label:"in pixels",value:"pixel"});expect(options[1]).toEqual({label:"according to axis",value:"y"})});it("provides all axes options when [x|y]ref set to paper",()=>{const fixtureProps=fixtures.scatter({layout:{annotations:[{text:"thor",yref:"paper"}]}});const drop=render(_objectSpread({},fixtureProps)).find(DropdownWidget);const options=drop.first().prop("options");expect(options.length).toBe(3);expect(options[0]).toEqual({label:"in pixels",value:"pixel"});expect(options[1]).toEqual({label:"Y 1",value:"y"});expect(options[2]).toEqual({label:"Y: yaxis2 title",value:"y2"})})});
//# sourceMappingURL=AnnotationRef-test.js.map