Skip to content

Commit

Permalink
Coalesce model view transforms, see #168
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed May 7, 2023
1 parent beba9b4 commit d411f82
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
3 changes: 2 additions & 1 deletion js/common/view/CAVPlotNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class CAVPlotNode extends Node {

const numberLinePositionY = 127;

// Empirically determined
// View size of a data point in the chart
const dataPointHeight = 17;

// Coordinates here are somewhat unusual, since x dimension is based off of meters, and y dimension is based off of
Expand All @@ -57,6 +57,7 @@ export default class CAVPlotNode extends Node {

const numberLineNode = new NumberLineNode(
sceneModel.meanValueProperty,
modelViewTransform,
model instanceof MeanAndMedianModel ? model.isShowingTopMeanProperty : new BooleanProperty( false ),
sceneModel.dataRangeProperty, {
color: 'black',
Expand Down
8 changes: 6 additions & 2 deletions js/common/view/CAVScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ export default class CAVScreenView extends ScreenView {
public constructor( model: CAVModel, providedOptions: CAVScreenViewOptions ) {
const options = optionize<CAVScreenViewOptions, SelfOptions, ScreenViewOptions>()( {}, providedOptions );

// View size of a soccer ball
const objectHeight = 41;

// The ground is at y=0
const modelViewTransform = ModelViewTransform2.createRectangleInvertedYMapping(
new Bounds2( CAVConstants.PHYSICAL_RANGE.min, 0, CAVConstants.PHYSICAL_RANGE.max, CAVConstants.PHYSICAL_RANGE.getLength() ),
new Bounds2( CAVConstants.NUMBER_LINE_MARGIN_X, GROUND_POSITION_Y - CAVConstants.CHART_VIEW_WIDTH, CAVConstants.NUMBER_LINE_MARGIN_X + CAVConstants.CHART_VIEW_WIDTH, GROUND_POSITION_Y )
new Bounds2( CAVConstants.PHYSICAL_RANGE.min, 0, CAVConstants.PHYSICAL_RANGE.max, 1 ),
new Bounds2( CAVConstants.NUMBER_LINE_MARGIN_X, GROUND_POSITION_Y - objectHeight, CAVConstants.NUMBER_LINE_MARGIN_X + CAVConstants.CHART_VIEW_WIDTH, GROUND_POSITION_Y )
);

super( options );
Expand Down Expand Up @@ -127,6 +130,7 @@ export default class CAVScreenView extends ScreenView {
new DynamicProperty( model.selectedSceneModelProperty, {
derive: 'meanValueProperty'
} ),
modelViewTransform,
model.isShowingPlayAreaMeanProperty,
new DynamicProperty( model.selectedSceneModelProperty, {
derive: 'dataRangeProperty'
Expand Down
10 changes: 1 addition & 9 deletions js/common/view/NumberLineNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import CAVColors from '../CAVColors.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import ModelViewTransform2 from '../../../../phetcommon/js/view/ModelViewTransform2.js';
import Bounds2 from '../../../../dot/js/Bounds2.js';
import CAVConstants from '../CAVConstants.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import Multilink from '../../../../axon/js/Multilink.js';
Expand All @@ -40,6 +39,7 @@ export default class NumberLineNode extends Node {

public constructor(
meanValueProperty: TReadOnlyProperty<number | null>,
modelViewTransform: ModelViewTransform2,
isShowingMeanIndicatorProperty: TReadOnlyProperty<boolean>,
rangeProperty: TReadOnlyProperty<Range | null>,
providedOptions?: NumberLineNodeOptions
Expand Down Expand Up @@ -105,14 +105,6 @@ export default class NumberLineNode extends Node {
this.addChild( rangeNode );
}

// TODO: See see https://github.com/phetsims/center-and-variability/issues/168, Can we make a 1d MVT since that's
// all that's needed here, or should this be using the same MVT as the outer MVT? Like the one that positions the number line node,
// and puts objects in the right spots.
const modelViewTransform = ModelViewTransform2.createRectangleInvertedYMapping(
new Bounds2( CAVConstants.PHYSICAL_RANGE.min, 0, CAVConstants.PHYSICAL_RANGE.max, CAVConstants.PHYSICAL_RANGE.getLength() ),
new Bounds2( 0, -CAVConstants.CHART_VIEW_WIDTH, CAVConstants.CHART_VIEW_WIDTH, CAVConstants.CHART_VIEW_WIDTH )
);

const meanIndicatorNode = NumberLineNode.createMeanIndicatorNode( options.includeMeanStroke, false );
this.addChild( meanIndicatorNode );

Expand Down

0 comments on commit d411f82

Please sign in to comment.