Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

feat: add Wrapper support and bounding box for dynamic width/height #215

Merged
merged 4 commits into from
Sep 4, 2019

Conversation

kristw
Copy link
Contributor

@kristw kristw commented Aug 28, 2019

馃弳 Enhancements

1. Add bounding box for dynamic width/height calculation

When either width or height is already known, such as width="100%" height={500}.
Default <ParentSize> behavior will set the container style to {width: '100%', height: '100%'}, which may exceed the known width or height values, resulting in undesired blank space on the page. This PR add another <div> to wrap it (only when necessary). If both width and height are dynamic then no bounding box will be added.

e.g. when want 100% width and 500px height.

<div style={{width: '100%', height: 500}}>
  <ParentSize>
    {...}
  </ParentSize>
</div>

Alternative

Consider including these functionalities in the @vx/responsive rewrite.

2. Add Wrapper prop for SuperChart

Problem

Inspired by use case in dataportal.

// SuperChart with dynamic width/height
<SuperChart width="100%" height="400" chartType="line /> 
// Rough hierarchy of the code above in the DOM is like this. 
<SuperChart width="100%" height="400"> // can compute dynamic width/height
  <ChartPlugin /> // for illustration purpose only, this is abstracted by SuperChart
</SuperChart>

There is a situation when a wrapper needs to be added to fix z-index issue such as tooltip.
This won't work because the wrapper will mess with the dynamic width/height calculation.

<div style={{position: 'fixed'}}>
  // with the wrapper, now width and height become 0.
  // so the chart will disappear 馃槺
  <SuperChart width="100%" height="100%" chartType="line" /> 
</div>

If we want to insert something in between SuperChart and ChartPlugin to avoid messing with dynamic width/height, you either have to

A. Do not use the built-in SuperChart way of determining auto width and height. Use your own way of computing dynamic width & height, which is pretty much re-implementing a lot of logic in SuperChart.

<div style={{ width="100%", height: 400 }}>
  <ParentSize>
    // ...
    <div style={{position: 'fixed'}}>
      <SuperChart width={width} height={height} chartType="line" /> // can compute dynamic width/height
    </div>
    // ...
  </ParentSize>
</div>

B. Modify the ChartPlugin to add the wrapper. Sounds like an overkill.

Both options are undesirable extra work.

Solution

With the changes in this PR.

const Wrapper = ({children}) => (
  <div style={{position: 'fixed'}}>{children}</div>
);

return (
  <SuperChart Wrapper={Wrapper} width="100%" height="400" /> 
);

馃彔 Internal

  • Add unit test for one missing branch that makes the coverage ~99%. Now the chart package is 100% again.

@kristw kristw requested a review from a team as a code owner August 28, 2019 22:13
@codecov
Copy link

codecov bot commented Aug 28, 2019

Codecov Report

Merging #215 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #215      +/-   ##
==========================================
+ Coverage   99.92%   99.93%   +<.01%     
==========================================
  Files         130      157      +27     
  Lines        1406     1602     +196     
  Branches      354      419      +65     
==========================================
+ Hits         1405     1601     +196     
  Partials        1        1
Impacted Files Coverage 螖
...es/superset-ui-chart/src/components/SuperChart.tsx 100% <100%> (酶) 猬嗭笍
...set-ui-encodeable/src/parsers/scale/applyDomain.ts 100% <0%> (酶)
...codeable/src/parsers/createGetterFromChannelDef.ts 100% <0%> (酶)
...le/src/parsers/scale/createScaleFromScaleConfig.ts 100% <0%> (酶)
...src/parsers/scale/getScaleCategoryFromScaleType.ts 100% <0%> (酶)
...erset-ui-encodeable/src/parsers/scale/applyZero.ts 100% <0%> (酶)
...rset-ui-encodeable/src/parsers/scale/applyRound.ts 100% <0%> (酶)
...ages/superset-ui-encodeable/src/typeGuards/Base.ts 100% <0%> (酶)
...set-ui-encodeable/src/parsers/fallbackFormatter.ts 100% <0%> (酶)
...ages/superset-ui-encodeable/src/utils/isEnabled.ts 100% <0%> (酶)
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 2793be2...e98f670. Read the comment docs.

@netlify
Copy link

netlify bot commented Aug 28, 2019

Deploy preview for superset-ui ready!

Built with commit e98f670

https://deploy-preview-215--superset-ui.netlify.com

@kristw kristw added #enhancement New feature or request reviewable Ready for review labels Aug 28, 2019
@kristw kristw closed this Aug 28, 2019
@kristw kristw reopened this Aug 28, 2019
@kristw kristw closed this Aug 29, 2019
@kristw kristw reopened this Aug 29, 2019
onRenderSuccess={onRenderSuccess}
onRenderFailure={onRenderFailure}
/>
<Wrapper width={width} height={height}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

width and height are invalid props for React.Fragment right? Ideally we don't get propType errors in that case 馃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const heightInfo = parseLength(height);

const style = {
height: heightInfo.isDynamic ? '100%' : heightInfo.value,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be simplified so parseLength sets value to 100% if isDynamic is true?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not, below we use multiplier, why not use multiplier here instead of 100% or is this slightly different?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea.

)
}
</ParentSize>
// bounding box will ensure that when
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could probably consolidate to fewer lines here? I also wonder if this could be moved to the BoundingBox selector to give more context to the Fragment vs div logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments moved as suggested.

@kristw kristw merged commit c83ba1f into master Sep 4, 2019
@delete-merged-branch delete-merged-branch bot deleted the kristw--super-height branch September 4, 2019 00:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
#enhancement New feature or request reviewable Ready for review size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants