@@ -1014,11 +1014,11 @@ function dragDimension(d) {
1014
1014
var categoryY = dragCategory . model . dragY ;
1015
1015
1016
1016
// Check for category drag swaps
1017
- var categoryInd = dragCategory . model . categoryInd ;
1017
+ var catDisplayInd = dragCategory . model . displayInd ;
1018
1018
var dimCategoryViews = dragDimension . categories ;
1019
1019
1020
- var catAbove = dimCategoryViews [ categoryInd - 1 ] ;
1021
- var catBelow = dimCategoryViews [ categoryInd + 1 ] ;
1020
+ var catAbove = dimCategoryViews [ catDisplayInd - 1 ] ;
1021
+ var catBelow = dimCategoryViews [ catDisplayInd + 1 ] ;
1022
1022
1023
1023
// Check for overlap above
1024
1024
if ( catAbove !== undefined ) {
@@ -1027,7 +1027,7 @@ function dragDimension(d) {
1027
1027
1028
1028
// Swap display inds
1029
1029
dragCategory . model . displayInd = catAbove . model . displayInd ;
1030
- catAbove . model . displayInd = categoryInd ;
1030
+ catAbove . model . displayInd = catDisplayInd ;
1031
1031
}
1032
1032
}
1033
1033
@@ -1037,7 +1037,7 @@ function dragDimension(d) {
1037
1037
1038
1038
// Swap display inds
1039
1039
dragCategory . model . displayInd = catBelow . model . displayInd ;
1040
- catBelow . model . displayInd = categoryInd ;
1040
+ catBelow . model . displayInd = catDisplayInd ;
1041
1041
}
1042
1042
}
1043
1043
@@ -1121,20 +1121,31 @@ function dragDimensionEnd(d) {
1121
1121
}
1122
1122
1123
1123
// ### Handle category reordering ###
1124
- // var anyCatsReordered = false;
1125
- // if(d.dragCategoryDisplayInd !== null) {
1126
- // var finalDragCategoryDisplayInds = d.model.categories.map(function(c) {
1127
- // return c.displayInd;
1128
- // });
1129
- //
1130
- // anyCatsReordered = d.initialDragCategoryDisplayInds.some(function(initCatDisplay, catInd) {
1131
- // return initCatDisplay !== finalDragCategoryDisplayInds[catInd];
1132
- // });
1133
- //
1134
- // if(anyCatsReordered) {
1135
- // restyleData['dimensions[' + d.model.containerInd + '].catDisplayInds'] = [finalDragCategoryDisplayInds];
1136
- // }
1137
- // }
1124
+ var anyCatsReordered = false ;
1125
+ if ( d . dragCategoryDisplayInd !== null ) {
1126
+ var finalDragCategoryDisplayInds = d . model . categories . map ( function ( c ) {
1127
+ return c . displayInd ;
1128
+ } ) ;
1129
+
1130
+ anyCatsReordered = d . initialDragCategoryDisplayInds . some ( function ( initCatDisplay , catInd ) {
1131
+ return initCatDisplay !== finalDragCategoryDisplayInds [ catInd ] ;
1132
+ } ) ;
1133
+
1134
+ if ( anyCatsReordered ) {
1135
+
1136
+ // Sort a shallow copy of the category models by display index
1137
+ var sortedCategoryModels = d . model . categories . slice ( ) . sort (
1138
+ function ( a , b ) { return a . displayInd - b . displayInd } ) ;
1139
+
1140
+ // Get new categoryarray and categorylabels values
1141
+ var newCategoryArray = sortedCategoryModels . map ( function ( v ) { return v . categoryValue } ) ;
1142
+ var newCategoryLabels = sortedCategoryModels . map ( function ( v ) { return v . categoryLabel } ) ;
1143
+
1144
+ restyleData [ 'dimensions[' + d . model . containerInd + '].categoryarray' ] = [ newCategoryArray ] ;
1145
+ restyleData [ 'dimensions[' + d . model . containerInd + '].categorylabels' ] = [ newCategoryLabels ] ;
1146
+ restyleData [ 'dimensions[' + d . model . containerInd + '].categoryorder' ] = [ 'array' ] ;
1147
+ }
1148
+ }
1138
1149
1139
1150
// Handle potential click event
1140
1151
// ----------------------------
@@ -1520,6 +1531,12 @@ function updatePathViewModels(parcatsViewModel) {
1520
1531
} ) ;
1521
1532
} ) ;
1522
1533
1534
+ // Array from category index to category display index for each true dimension index
1535
+ var catToDisplayIndPerDim = parcatsViewModel . model . dimensions . map (
1536
+ function ( d ) {
1537
+ return d . categories . map ( function ( c ) { return c . displayInd ; } ) ;
1538
+ } ) ;
1539
+
1523
1540
// Array from true dimension index to dimension display index
1524
1541
var dimToDisplayInd = parcatsViewModel . model . dimensions . map ( function ( d ) { return d . displayInd ; } ) ;
1525
1542
var displayToDimInd = parcatsViewModel . dimensions . map ( function ( d ) { return d . model . dimensionInd ; } ) ;
@@ -1541,12 +1558,21 @@ function updatePathViewModels(parcatsViewModel) {
1541
1558
}
1542
1559
}
1543
1560
1561
+ // Compute category display inds to use for sorting paths
1562
+ function pathDisplayCategoryInds ( pathModel ) {
1563
+ var dimensionInds = pathModel . categoryInds . map ( function ( catInd , dimInd ) { return catToDisplayIndPerDim [ dimInd ] [ catInd ] ; } ) ;
1564
+ var displayInds = displayToDimInd . map ( function ( dimInd ) {
1565
+ return dimensionInds [ dimInd ] ;
1566
+ } ) ;
1567
+ return displayInds ;
1568
+ }
1569
+
1544
1570
// Sort in ascending order by display index array
1545
1571
pathModels . sort ( function ( v1 , v2 ) {
1546
1572
1547
1573
// Build display inds for each path
1548
- var sortArray1 = v1 . categoryInds ;
1549
- var sortArray2 = v2 . categoryInds ;
1574
+ var sortArray1 = pathDisplayCategoryInds ( v1 ) ;
1575
+ var sortArray2 = pathDisplayCategoryInds ( v2 ) ;
1550
1576
1551
1577
// Handle path sort order
1552
1578
if ( parcatsViewModel . sortpaths === 'backward' ) {
@@ -1599,14 +1625,15 @@ function updatePathViewModels(parcatsViewModel) {
1599
1625
var pathYs = new Array ( nextYPositions . length ) ;
1600
1626
for ( var d = 0 ; d < pathModel . categoryInds . length ; d ++ ) {
1601
1627
var catInd = pathModel . categoryInds [ d ] ;
1628
+ var catDisplayInd = catToDisplayIndPerDim [ d ] [ catInd ] ;
1602
1629
var dimDisplayInd = dimToDisplayInd [ d ] ;
1603
1630
1604
1631
// Update next y position
1605
- pathYs [ dimDisplayInd ] = nextYPositions [ dimDisplayInd ] [ catInd ] ;
1606
- nextYPositions [ dimDisplayInd ] [ catInd ] += pathHeight ;
1632
+ pathYs [ dimDisplayInd ] = nextYPositions [ dimDisplayInd ] [ catDisplayInd ] ;
1633
+ nextYPositions [ dimDisplayInd ] [ catDisplayInd ] += pathHeight ;
1607
1634
1608
1635
// Update category color information
1609
- var catViewModle = parcatsViewModel . dimensions [ dimDisplayInd ] . categories [ catInd ] ;
1636
+ var catViewModle = parcatsViewModel . dimensions [ dimDisplayInd ] . categories [ catDisplayInd ] ;
1610
1637
var numBands = catViewModle . bands . length ;
1611
1638
var lastCatBand = catViewModle . bands [ numBands - 1 ] ;
1612
1639
@@ -1641,7 +1668,7 @@ function updatePathViewModels(parcatsViewModel) {
1641
1668
}
1642
1669
1643
1670
pathViewModels [ pathNumber ] = {
1644
- key : pathModel . categoryInds + '-' + pathModel . valueInds [ 0 ] ,
1671
+ key : pathModel . valueInds [ 0 ] ,
1645
1672
model : pathModel ,
1646
1673
height : pathHeight ,
1647
1674
leftXs : leftXPositions ,
@@ -1730,14 +1757,23 @@ function createDimensionViewModel(parcatsViewModel, dimensionModel) {
1730
1757
nextCatHeight ,
1731
1758
nextCatModel ,
1732
1759
nextCat ,
1733
- catInd ;
1760
+ catInd ,
1761
+ catDisplayInd ;
1734
1762
1735
1763
// Compute starting Y offset
1736
1764
var nextCatY = ( maxCats - numCats ) * catSpacing / 2.0 ;
1737
1765
1738
1766
// Compute category ordering
1739
- for ( catInd = 0 ; catInd < numCats ; catInd ++ ) {
1767
+ var categoryIndInfo = dimensionModel . categories . map ( function ( c ) {
1768
+ return { displayInd : c . displayInd , categoryInd : c . categoryInd } ;
1769
+ } ) ;
1770
+
1771
+ categoryIndInfo . sort ( function ( a , b ) {
1772
+ return a . displayInd - b . displayInd ;
1773
+ } ) ;
1740
1774
1775
+ for ( catDisplayInd = 0 ; catDisplayInd < numCats ; catDisplayInd ++ ) {
1776
+ catInd = categoryIndInfo [ catDisplayInd ] . categoryInd ;
1741
1777
nextCatModel = dimensionModel . categories [ catInd ] ;
1742
1778
1743
1779
if ( totalCount > 0 ) {
@@ -1747,7 +1783,7 @@ function createDimensionViewModel(parcatsViewModel, dimensionModel) {
1747
1783
}
1748
1784
1749
1785
nextCat = {
1750
- key : catInd ,
1786
+ key : nextCatModel . valueInds [ 0 ] ,
1751
1787
model : nextCatModel ,
1752
1788
width : dimWidth ,
1753
1789
height : nextCatHeight ,
0 commit comments