Skip to content

Commit

Permalink
Refactor IQR logic and display - see #158
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-blackman committed Apr 27, 2023
1 parent fc8cee0 commit 6251d0e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion js/common/model/CAVModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ export default class CAVModel implements TModel {

// there is enough data to calculate quartiles
if ( sortedObjects.length >= 5 ) {
const splitIndex = Math.floor( sortedObjects.length / 2 );

// Split the array into lower and upper halves, ignoring the median value if there are an odd number of objects
const splitIndex = Math.floor( sortedObjects.length / 2 );
const lowerHalf: CAVObject[] = sortedObjects.slice( 0, splitIndex );
const upperHalf: CAVObject[] = sortedObjects.slice( sortedObjects.length % 2 !== 0 ? splitIndex + 1 : splitIndex );

Expand Down
8 changes: 3 additions & 5 deletions js/variability/view/IQRNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ export default class IQRNode extends CAVPlotNode {
const leftmostDot = sortedDots[ 0 ];
const rightmostDot = sortedDots[ sortedDots.length - 1 ];

boxWhiskerMedianLine.x1 = boxWhiskerMedianLine.x2 = this.modelViewTransform.modelToViewX( model.medianValueProperty.value! );

const boxLeft = this.modelViewTransform.modelToViewX( model.q1ValueProperty.value! );
const boxRight = this.modelViewTransform.modelToViewX( model.q3ValueProperty.value! );

boxWhiskerMedianLine.x1 = boxWhiskerMedianLine.x2 = this.modelViewTransform.modelToViewX( model.medianValueProperty.value! );

boxWhiskerBox.left = boxLeft;
boxWhiskerBox.rectWidth = boxRight - boxLeft;

Expand Down Expand Up @@ -164,9 +164,7 @@ export default class IQRNode extends CAVPlotNode {
iqrTextReadout.bottom = iqrBar.top - 5;
}

const showBoxAndWhiskerPlot = model.selectedVariabilityProperty.value === VariabilityMeasure.IQR && enoughData;

boxWhiskerNode.visible = showBoxAndWhiskerPlot;
boxWhiskerNode.visible = model.selectedVariabilityProperty.value === VariabilityMeasure.IQR && enoughData;

needAtLeastFiveKicks.center = this.modelViewTransform.modelToViewXY( 8, 2 );
needAtLeastFiveKicks.visible = !enoughData && ( options.parentContext === 'info' ||
Expand Down

0 comments on commit 6251d0e

Please sign in to comment.