1- var d3 = require ( 'd3' ) ;
1+ var helpers = require ( '@src/components/shapes/helpers' ) ;
2+ var constants = require ( '@src/components/shapes/constants' ) ;
23
34var Plotly = require ( '@lib/index' ) ;
4- var Lib = require ( '@src/lib' ) ;
5-
65var PlotlyInternal = require ( '@src/plotly' ) ;
6+ var Lib = require ( '@src/lib' ) ;
77var Axes = PlotlyInternal . Axes ;
88
9+ var d3 = require ( 'd3' ) ;
910var createGraphDiv = require ( '../assets/create_graph_div' ) ;
1011var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
1112
@@ -476,8 +477,8 @@ describe('Test shapes', function() {
476477 function testShapeDrag ( dx , dy , layoutShape , node ) {
477478 var xa = Axes . getFromId ( gd , layoutShape . xref ) ,
478479 ya = Axes . getFromId ( gd , layoutShape . yref ) ,
479- x2p = getDataToPixel ( gd , xa ) ,
480- y2p = getDataToPixel ( gd , ya , true ) ;
480+ x2p = helpers . getDataToPixel ( gd , xa ) ,
481+ y2p = helpers . getDataToPixel ( gd , ya , true ) ;
481482
482483 var initialCoordinates = getShapeCoordinates ( layoutShape , x2p , y2p ) ;
483484
@@ -503,8 +504,8 @@ describe('Test shapes', function() {
503504 function testPathDrag ( dx , dy , layoutShape , node ) {
504505 var xa = Axes . getFromId ( gd , layoutShape . xref ) ,
505506 ya = Axes . getFromId ( gd , layoutShape . yref ) ,
506- x2p = getDataToPixel ( gd , xa ) ,
507- y2p = getDataToPixel ( gd , ya , true ) ;
507+ x2p = helpers . getDataToPixel ( gd , xa ) ,
508+ y2p = helpers . getDataToPixel ( gd , ya , true ) ;
508509
509510 var initialPath = layoutShape . path ,
510511 initialCoordinates = getPathCoordinates ( initialPath , x2p , y2p ) ;
@@ -536,8 +537,8 @@ describe('Test shapes', function() {
536537 function testShapeResize ( direction , dx , dy , layoutShape , node ) {
537538 var xa = Axes . getFromId ( gd , layoutShape . xref ) ,
538539 ya = Axes . getFromId ( gd , layoutShape . yref ) ,
539- x2p = getDataToPixel ( gd , xa ) ,
540- y2p = getDataToPixel ( gd , ya , true ) ;
540+ x2p = helpers . getDataToPixel ( gd , xa ) ,
541+ y2p = helpers . getDataToPixel ( gd , ya , true ) ;
541542
542543 var initialCoordinates = getShapeCoordinates ( layoutShape , x2p , y2p ) ;
543544
@@ -578,65 +579,16 @@ describe('Test shapes', function() {
578579 } ) ;
579580 }
580581
581- // Adapted from src/components/shapes/index.js
582- var segmentRE = / [ M L H V Q C T S Z ] [ ^ M L H V Q C T S Z ] * / g,
583- paramRE = / [ ^ \s , ] + / g,
584-
585- // which numbers in each path segment are x (or y) values
586- // drawn is which param is a drawn point, as opposed to a
587- // control point (which doesn't count toward autorange.
588- // TODO: this means curved paths could extend beyond the
589- // autorange bounds. This is a bit tricky to get right
590- // unless we revert to bounding boxes, but perhaps there's
591- // a calculation we could do...)
592- paramIsX = {
593- M : { 0 : true , drawn : 0 } ,
594- L : { 0 : true , drawn : 0 } ,
595- H : { 0 : true , drawn : 0 } ,
596- V : { } ,
597- Q : { 0 : true , 2 : true , drawn : 2 } ,
598- C : { 0 : true , 2 : true , 4 : true , drawn : 4 } ,
599- T : { 0 : true , drawn : 0 } ,
600- S : { 0 : true , 2 : true , drawn : 2 } ,
601- // A: {0: true, 5: true},
602- Z : { }
603- } ,
604-
605- paramIsY = {
606- M : { 1 : true , drawn : 1 } ,
607- L : { 1 : true , drawn : 1 } ,
608- H : { } ,
609- V : { 0 : true , drawn : 0 } ,
610- Q : { 1 : true , 3 : true , drawn : 3 } ,
611- C : { 1 : true , 3 : true , 5 : true , drawn : 5 } ,
612- T : { 1 : true , drawn : 1 } ,
613- S : { 1 : true , 3 : true , drawn : 5 } ,
614- // A: {1: true, 6: true},
615- Z : { }
616- } ,
617- numParams = {
618- M : 2 ,
619- L : 2 ,
620- H : 1 ,
621- V : 1 ,
622- Q : 4 ,
623- C : 6 ,
624- T : 2 ,
625- S : 4 ,
626- // A: 7,
627- Z : 0
628- } ;
629-
630582 function getPathCoordinates ( pathString , x2p , y2p ) {
631583 var coordinates = [ ] ;
632584
633- pathString . match ( segmentRE ) . forEach ( function ( segment ) {
585+ pathString . match ( constants . segmentRE ) . forEach ( function ( segment ) {
634586 var paramNumber = 0 ,
635587 segmentType = segment . charAt ( 0 ) ,
636- xParams = paramIsX [ segmentType ] ,
637- yParams = paramIsY [ segmentType ] ,
638- nParams = numParams [ segmentType ] ,
639- params = segment . substr ( 1 ) . match ( paramRE ) ;
588+ xParams = constants . paramIsX [ segmentType ] ,
589+ yParams = constants . paramIsY [ segmentType ] ,
590+ nParams = constants . numParams [ segmentType ] ,
591+ params = segment . substr ( 1 ) . match ( constants . paramRE ) ;
640592
641593 if ( params ) {
642594 params . forEach ( function ( param ) {
@@ -658,40 +610,6 @@ describe('Test shapes', function() {
658610 }
659611} ) ;
660612
661-
662- // getDataToPixel and decodeDate
663- // adapted from src/components/shapes.index.js
664- function getDataToPixel ( gd , axis , isVertical ) {
665- var gs = gd . _fullLayout . _size ,
666- dataToPixel ;
667-
668- if ( axis ) {
669- var d2l = axis . type === 'category' ? axis . c2l : axis . d2l ;
670-
671- dataToPixel = function ( v ) {
672- return axis . _offset + axis . l2p ( d2l ( v , true ) ) ;
673- } ;
674-
675- if ( axis . type === 'date' ) dataToPixel = decodeDate ( dataToPixel ) ;
676- }
677- else if ( isVertical ) {
678- dataToPixel = function ( v ) { return gs . t + gs . h * ( 1 - v ) ; } ;
679- }
680- else {
681- dataToPixel = function ( v ) { return gs . l + gs . w * v ; } ;
682- }
683-
684- return dataToPixel ;
685- }
686-
687- function decodeDate ( convertToPx ) {
688- return function ( v ) {
689- if ( v . replace ) v = v . replace ( '_' , ' ' ) ;
690- return convertToPx ( v ) ;
691- } ;
692- }
693-
694-
695613var DBLCLICKDELAY = require ( '@src/plots/cartesian/constants' ) . DBLCLICKDELAY ;
696614
697615function mouseDown ( node , x , y ) {
0 commit comments