@@ -17,9 +17,10 @@ import { ContentWarning } from "@modules/_shared/components/ContentMessage/conte
1717import { Plot } from "@modules/_shared/components/Plot" ;
1818import { makeSubplots } from "@modules/_shared/Figure" ;
1919import { makeHistogramTrace } from "@modules/_shared/histogram" ;
20+ import { formatNumber } from "@modules/_shared/utils/numberFormatting" ;
2021
2122import type { Interfaces } from "./interfaces" ;
22- import { PlotType } from "./typesAndEnums" ;
23+ import { BarSortBy , PlotType } from "./typesAndEnums" ;
2324import { makeHoverText , makeHoverTextWithColor , makeTitleFromChannelContent } from "./utils/stringUtils" ;
2425import { calcTextSize } from "./utils/textSize" ;
2526
@@ -47,10 +48,16 @@ export const View = ({ viewContext, workbenchSettings }: ModuleViewProps<Interfa
4748 const [ prevNumBins , setPrevNumBins ] = React . useState < number | null > ( null ) ;
4849 const [ prevOrientation , setPrevOrientation ] = React . useState < "v" | "h" | null > ( null ) ;
4950 const [ prevSize , setPrevSize ] = React . useState < Size2D | null > ( null ) ;
51+ const [ prevSharedXAxes , setPrevSharedXAxes ] = React . useState < boolean | null > ( null ) ;
52+ const [ prevSharedYAxes , setPrevSharedYAxes ] = React . useState < boolean | null > ( null ) ;
53+ const [ prevBarSortBy , setPrevBarSortBy ] = React . useState < BarSortBy > ( BarSortBy . Value ) ;
5054
5155 const plotType = viewContext . useSettingsToViewInterfaceValue ( "plotType" ) ;
56+ const sharedXAxes = viewContext . useSettingsToViewInterfaceValue ( "sharedXAxes" ) ;
57+ const sharedYAxes = viewContext . useSettingsToViewInterfaceValue ( "sharedYAxes" ) ;
5258 const numBins = viewContext . useSettingsToViewInterfaceValue ( "numBins" ) ;
5359 const orientation = viewContext . useSettingsToViewInterfaceValue ( "orientation" ) ;
60+ const barSortBy = viewContext . useSettingsToViewInterfaceValue ( "barSortBy" ) ;
5461
5562 const statusWriter = useViewStatusWriter ( viewContext ) ;
5663
@@ -84,7 +91,10 @@ export const View = ({ viewContext, workbenchSettings }: ModuleViewProps<Interfa
8491 plotType !== prevPlotType ||
8592 numBins !== prevNumBins ||
8693 orientation !== prevOrientation ||
87- wrapperDivSize !== prevSize
94+ wrapperDivSize !== prevSize ||
95+ sharedXAxes !== prevSharedXAxes ||
96+ sharedYAxes !== prevSharedYAxes ||
97+ barSortBy !== prevBarSortBy
8898 ) {
8999 setRevNumberX ( receiverX . revisionNumber ) ;
90100 setRevNumberY ( receiverY . revisionNumber ) ;
@@ -93,6 +103,9 @@ export const View = ({ viewContext, workbenchSettings }: ModuleViewProps<Interfa
93103 setPrevNumBins ( numBins ) ;
94104 setPrevOrientation ( orientation ) ;
95105 setPrevSize ( wrapperDivSize ) ;
106+ setPrevSharedXAxes ( sharedXAxes ) ;
107+ setPrevSharedYAxes ( sharedYAxes ) ;
108+ setPrevBarSortBy ( barSortBy ) ;
96109
97110 startTransition ( function makeContent ( ) {
98111 if ( ! receiverX . channel ) {
@@ -167,8 +180,8 @@ export const View = ({ viewContext, workbenchSettings }: ModuleViewProps<Interfa
167180 numCols,
168181 width : wrapperDivSize . width ,
169182 height : wrapperDivSize . height ,
170- sharedXAxes : false ,
171- sharedYAxes : false ,
183+ sharedXAxes : sharedXAxes ,
184+ sharedYAxes : sharedYAxes ,
172185 verticalSpacing : 100 / ( wrapperDivSize . height - 50 ) ,
173186 horizontalSpacing : 0.2 / numCols ,
174187
@@ -255,9 +268,12 @@ export const View = ({ viewContext, workbenchSettings }: ModuleViewProps<Interfa
255268 const data = receiverX . channel . contents [ cellIndex ] ;
256269 const keyData = data . dataArray . map ( ( el : any ) => el . key ) ;
257270 const valueData = data . dataArray . map ( ( el : any ) => el . value ) ;
258-
259271 const dataTitle = makeTitleFromChannelContent ( data ) ;
260272 const kindOfKeyTitle = `${ receiverX . channel . kindOfKey } ` ;
273+ const hoverText = data . dataArray . map (
274+ ( el ) =>
275+ `${ kindOfKeyTitle } : <b>${ el . key } </b><br>${ dataTitle } : <b>${ formatNumber ( Number ( el . value ) ) } </b><extra></extra>` ,
276+ ) ;
261277
262278 const trace : Partial < PlotData > = {
263279 x : orientation === "h" ? valueData : keyData ,
@@ -269,18 +285,31 @@ export const View = ({ viewContext, workbenchSettings }: ModuleViewProps<Interfa
269285 showlegend : false ,
270286 type : "bar" ,
271287 orientation,
288+ hovertemplate : hoverText ,
289+ hoverlabel : {
290+ bgcolor : "white" ,
291+ font : { size : 12 , color : "black" } ,
292+ } ,
272293 } ;
273294
274- const xAxisTitle = orientation === "h" ? dataTitle : kindOfKeyTitle ;
275- const yAxisTitle = orientation === "h" ? kindOfKeyTitle : dataTitle ;
295+ const xAxisTitle = orientation === "h" ? dataTitle : ` ${ kindOfKeyTitle } (hover to see values)` ;
296+ const yAxisTitle = orientation === "h" ? ` ${ kindOfKeyTitle } (hover to see values)` : dataTitle ;
276297
277298 figure . addTrace ( trace , rowIndex + 1 , colIndex + 1 ) ;
299+ const xBinsInDescendingOrder = orientation === "v" && barSortBy === BarSortBy . Value ;
300+ const yBinsInDescendingOrder = orientation === "h" && barSortBy === BarSortBy . Value ;
278301 const patch : Partial < Layout > = {
279302 [ `xaxis${ cellIndex + 1 } ` ] : {
280303 title : { text : xAxisTitle } ,
304+ type : xBinsInDescendingOrder ? "category" : "linear" ,
305+ categoryorder : xBinsInDescendingOrder ? "total descending" : "trace" ,
306+ showticklabels : xBinsInDescendingOrder ? false : true ,
281307 } ,
282308 [ `yaxis${ cellIndex + 1 } ` ] : {
283309 title : { text : yAxisTitle } ,
310+ type : yBinsInDescendingOrder ? "category" : "linear" ,
311+ categoryorder : yBinsInDescendingOrder ? "total descending" : "trace" ,
312+ showticklabels : yBinsInDescendingOrder ? false : true ,
284313 } ,
285314 } ;
286315 figure . updateLayout ( patch ) ;
@@ -306,8 +335,8 @@ export const View = ({ viewContext, workbenchSettings }: ModuleViewProps<Interfa
306335 numCols : receiverY . channel . contents . length ,
307336 width : wrapperDivSize . width ,
308337 height : wrapperDivSize . height ,
309- sharedXAxes : true ,
310- sharedYAxes : true ,
338+ sharedXAxes : sharedXAxes ,
339+ sharedYAxes : sharedYAxes ,
311340 verticalSpacing : 20 / ( wrapperDivSize . height - 80 ) ,
312341 horizontalSpacing : 20 / ( wrapperDivSize . width - 80 ) ,
313342 margin : {
@@ -336,12 +365,11 @@ export const View = ({ viewContext, workbenchSettings }: ModuleViewProps<Interfa
336365
337366 let cellIndex = 0 ;
338367
339- receiverX . channel . contents . forEach ( ( contentX , rowIndex , rowArr ) => {
368+ receiverX . channel . contents . forEach ( ( contentX , rowIndex ) => {
340369 if ( ! receiverY . channel ) {
341370 return ;
342371 }
343372
344- const numRows = rowArr . length ;
345373 receiverY . channel . contents . forEach ( ( contentY , colIndex ) => {
346374 cellIndex ++ ;
347375
@@ -405,7 +433,7 @@ export const View = ({ viewContext, workbenchSettings }: ModuleViewProps<Interfa
405433 : undefined ,
406434 } ,
407435 showlegend : false ,
408- type : "scattergl " ,
436+ type : "scatter " ,
409437 hovertemplate : realizations . map ( ( real ) =>
410438 dataColor
411439 ? makeHoverTextWithColor ( contentX , contentY , dataColor , real )
@@ -415,22 +443,21 @@ export const View = ({ viewContext, workbenchSettings }: ModuleViewProps<Interfa
415443
416444 figure . addTrace ( trace , rowIndex + 1 , colIndex + 1 ) ;
417445
418- if ( rowIndex === numRows - 1 ) {
419- const patch : Partial < Layout > = {
420- [ `xaxis${ cellIndex } ` ] : {
421- title : {
422- text : makeTitleFromChannelContent ( contentX ) ,
423- font,
424- } ,
446+ const patch : Partial < Layout > = {
447+ [ `xaxis${ cellIndex } ` ] : {
448+ title : {
449+ text : makeTitleFromChannelContent ( contentY ) ,
450+ font,
425451 } ,
426- } ;
427- figure . updateLayout ( patch ) ;
428- }
452+ } ,
453+ } ;
454+ figure . updateLayout ( patch ) ;
455+
429456 if ( colIndex === 0 ) {
430457 const patch : Partial < Layout > = {
431458 [ `yaxis${ cellIndex } ` ] : {
432459 title : {
433- text : makeTitleFromChannelContent ( contentY ) ,
460+ text : makeTitleFromChannelContent ( contentX ) ,
434461 font,
435462 } ,
436463 } ,
0 commit comments