1
- var d3 = require ( 'd3' ) ;
1
+ var helpers = require ( '@src/components/shapes/helpers' ) ;
2
+ var constants = require ( '@src/components/shapes/constants' ) ;
2
3
3
4
var Plotly = require ( '@lib/index' ) ;
4
- var Lib = require ( '@src/lib' ) ;
5
-
6
5
var PlotlyInternal = require ( '@src/plotly' ) ;
6
+ var Lib = require ( '@src/lib' ) ;
7
7
var Axes = PlotlyInternal . Axes ;
8
8
9
+ var d3 = require ( 'd3' ) ;
9
10
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
10
11
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
11
12
@@ -476,8 +477,8 @@ describe('Test shapes', function() {
476
477
function testShapeDrag ( dx , dy , layoutShape , node ) {
477
478
var xa = Axes . getFromId ( gd , layoutShape . xref ) ,
478
479
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 ) ;
481
482
482
483
var initialCoordinates = getShapeCoordinates ( layoutShape , x2p , y2p ) ;
483
484
@@ -503,8 +504,8 @@ describe('Test shapes', function() {
503
504
function testPathDrag ( dx , dy , layoutShape , node ) {
504
505
var xa = Axes . getFromId ( gd , layoutShape . xref ) ,
505
506
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 ) ;
508
509
509
510
var initialPath = layoutShape . path ,
510
511
initialCoordinates = getPathCoordinates ( initialPath , x2p , y2p ) ;
@@ -536,8 +537,8 @@ describe('Test shapes', function() {
536
537
function testShapeResize ( direction , dx , dy , layoutShape , node ) {
537
538
var xa = Axes . getFromId ( gd , layoutShape . xref ) ,
538
539
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 ) ;
541
542
542
543
var initialCoordinates = getShapeCoordinates ( layoutShape , x2p , y2p ) ;
543
544
@@ -578,65 +579,16 @@ describe('Test shapes', function() {
578
579
} ) ;
579
580
}
580
581
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
-
630
582
function getPathCoordinates ( pathString , x2p , y2p ) {
631
583
var coordinates = [ ] ;
632
584
633
- pathString . match ( segmentRE ) . forEach ( function ( segment ) {
585
+ pathString . match ( constants . segmentRE ) . forEach ( function ( segment ) {
634
586
var paramNumber = 0 ,
635
587
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 ) ;
640
592
641
593
if ( params ) {
642
594
params . forEach ( function ( param ) {
@@ -658,40 +610,6 @@ describe('Test shapes', function() {
658
610
}
659
611
} ) ;
660
612
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
-
695
613
var DBLCLICKDELAY = require ( '@src/plots/cartesian/constants' ) . DBLCLICKDELAY ;
696
614
697
615
function mouseDown ( node , x , y ) {
0 commit comments