@@ -509,7 +509,13 @@ private void TriggerGridDrawing(CompositeDisposable disposables)
509509 // Events starting a grid redraw
510510 Observable
511511 . Merge (
512- this . WhenAnyValue ( x => x . IsTransposed ) . Select ( _ => false ) ,
512+ this . WhenAnyValue ( x => x . IsTransposed )
513+ . Do ( isTransposed =>
514+ {
515+ /* Need to adapt headers size on transpose */
516+ SetHeadersDimension ( isTransposed ) ;
517+ } )
518+ . Select ( _ => false ) ,
513519 this . WhenAnyValue ( x => x . Theme ) . WhereNotNull ( ) . Select ( _ => false ) ,
514520 SelectionChanged . DistinctUntilChanged ( ) . Select ( _ => false ) ,
515521 gridLayoutEventsObservable . Select ( _ => false ) ,
@@ -523,6 +529,42 @@ private void TriggerGridDrawing(CompositeDisposable disposables)
523529 . DisposeWith ( disposables ) ;
524530 }
525531
532+ private void SetHeadersDimension ( bool isTransposed , bool preserveSizes = false )
533+ {
534+ var rowDefinitions = ! isTransposed
535+ ? Producers . Cast < HierarchyDefinition > ( )
536+ : Consumers . Cast < HierarchyDefinition > ( ) ;
537+ var columnDefinitions = ! isTransposed
538+ ? Consumers . Cast < HierarchyDefinition > ( )
539+ : Producers . Cast < HierarchyDefinition > ( ) ;
540+
541+ RowsHeadersWidth =
542+ [
543+ .. Enumerable . Range ( 0 , rowDefinitions . TotalDepth ( ) ) . Select ( _ => DefaultHeaderWidth ) ,
544+ ] ;
545+
546+ ColumnsHeadersHeight =
547+ [
548+ .. Enumerable . Range ( 0 , columnDefinitions . TotalDepth ( ) ) . Select ( _ => DefaultHeaderHeight ) ,
549+ ] ;
550+
551+ var columnsCount = columnDefinitions . TotalCount ( true ) ;
552+ if ( ! preserveSizes || columnsCount != ColumnsWidths . Count )
553+ {
554+ ColumnsWidths . Clear ( ) ;
555+ for ( int x = 0 ; x <= columnsCount ; x ++ )
556+ ColumnsWidths . Add ( x , DefaultColumnWidth ) ;
557+ }
558+
559+ var rowsCount = rowDefinitions . TotalCount ( true ) ;
560+ if ( ! preserveSizes || rowsCount != RowsHeights . Count )
561+ {
562+ RowsHeights . Clear ( ) ;
563+ for ( int x = 0 ; x <= rowsCount ; x ++ )
564+ RowsHeights . Add ( x , DefaultRowHeight ) ;
565+ }
566+ }
567+
526568 /// <summary>
527569 /// Registers default interaction handlers for the specified <see cref="HierarchyGridViewModel"/> instance.
528570 /// Those interactions do nothing but prevent exceptions if called without real implementation.
@@ -623,36 +665,7 @@ public void Set(HierarchyDefinitions hierarchyDefinitions, bool preserveSizes =
623665 Producers = hierarchyDefinitions . Producers ;
624666 Consumers = hierarchyDefinitions . Consumers ;
625667
626- // TODO: change if transposed is implemented
627- var rowDefinitions = Producers ;
628- var columnDefinitions = Consumers ;
629-
630- RowsHeadersWidth =
631- [
632- .. Enumerable . Range ( 0 , rowDefinitions . TotalDepth ( ) ) . Select ( _ => DefaultHeaderWidth ) ,
633- ] ;
634-
635- ColumnsHeadersHeight =
636- [
637- .. Enumerable . Range ( 0 , columnDefinitions . TotalDepth ( ) ) . Select ( _ => DefaultHeaderHeight ) ,
638- ] ;
639-
640- var columnsCount = columnDefinitions . TotalCount ( true ) ;
641- if ( ! preserveSizes || columnsCount != ColumnsWidths . Count )
642- {
643- ColumnsWidths . Clear ( ) ;
644- for ( int x = 0 ; x <= columnsCount ; x ++ )
645- ColumnsWidths . Add ( x , DefaultColumnWidth ) ;
646- }
647-
648- var rowsCount = rowDefinitions . TotalCount ( true ) ;
649- if ( ! preserveSizes || rowsCount != RowsHeights . Count )
650- {
651- RowsHeights . Clear ( ) ;
652- for ( int x = 0 ; x <= rowsCount ; x ++ )
653- RowsHeights . Add ( x , DefaultRowHeight ) ;
654- }
655-
668+ SetHeadersDimension ( IsTransposed , preserveSizes ) ;
656669 Observable . Return ( true ) . InvokeCommand ( DrawGridCommand ) ;
657670 }
658671
@@ -1095,19 +1108,33 @@ private void HoverHeader(Option<PositionedDefinition> definition, double x, doub
10951108 s =>
10961109 {
10971110 HoveredElementId = s . Definition . DefinitionId ;
1111+
1112+ // Reset first
1113+ HoveredRow = - 1 ;
1114+ HoveredColumn = - 1 ;
1115+
10981116 switch ( s . Definition )
10991117 {
11001118 case ConsumerDefinition consumer when consumer . Count ( ) == 1 :
1101- HoveredColumn = ColumnsDefinitions . GetPosition ( consumer ) ;
1102- HoveredRow = - 1 ;
1119+ {
1120+ if ( IsTransposed )
1121+ HoveredRow = RowsDefinitions . GetPosition ( consumer ) ;
1122+ else
1123+ HoveredColumn = ColumnsDefinitions . GetPosition ( consumer ) ;
11031124 break ;
1125+ }
1126+
11041127 case ProducerDefinition producer when producer . Count ( ) == 1 :
1105- HoveredRow = RowsDefinitions . GetPosition ( producer ) ;
1106- HoveredColumn = - 1 ;
1128+ {
1129+ if ( IsTransposed )
1130+ HoveredColumn = ColumnsDefinitions . GetPosition ( producer ) ;
1131+ else
1132+ HoveredRow = RowsDefinitions . GetPosition ( producer ) ;
11071133 break ;
1134+ }
1135+
11081136 default :
1109- HoveredColumn = - 1 ;
1110- HoveredRow = - 1 ;
1137+ // Already reset above; nothing to do
11111138 break ;
11121139 }
11131140 } ,
0 commit comments