Skip to content

Commit

Permalink
Improved visibility sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Jul 14, 2022
1 parent 6f2c782 commit fcc69b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 39 deletions.
47 changes: 20 additions & 27 deletions src/Blocks/Treemap/Treemap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { compose } from 'redux';
import loadable from '@loadable/component';
import config from '@plone/volto/registry';
import { connectToProviderData } from '@eeacms/volto-datablocks/hocs';
import { Placeholder } from '@eeacms/volto-datablocks/components';
import { VisibilitySensor } from '@eeacms/volto-datablocks/components';

const LoadablePlotly = loadable(() =>
import(
Expand Down Expand Up @@ -53,32 +53,25 @@ function Treemap(props) {

return (
<div className="treemap-chart">
<Placeholder
className="connected-chart"
partialVisibility={true}
offset={{ top: -100, bottom: -100 }}
delayedCall={true}
>
{() => (
<div className="connected-chart-wrapper">
<LoadablePlotly
data={traces}
layout={layout}
frames={[]}
config={{
displayModeBar: false,
editable: false,
responsive: true,
useResizeHandler: true,
}}
style={{
maxWidth: '100%',
margin: 'auto',
}}
/>
</div>
)}
</Placeholder>
<VisibilitySensor className="connected-chart">
<div className="connected-chart-wrapper">
<LoadablePlotly
data={traces}
layout={layout}
frames={[]}
config={{
displayModeBar: false,
editable: false,
responsive: true,
useResizeHandler: true,
}}
style={{
maxWidth: '100%',
margin: 'auto',
}}
/>
</div>
</VisibilitySensor>
</div>
);
}
Expand Down
16 changes: 4 additions & 12 deletions src/ConnectedChart/ConnectedChartWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import React from 'react';
import ConnectedChart from './ConnectedChart';

import { Placeholder } from '@eeacms/volto-datablocks/components';
import { VisibilitySensor } from '@eeacms/volto-datablocks/components';

/*
* @param { object } data The chart data, layout, extra config, etc.
Expand All @@ -16,17 +16,9 @@ import { Placeholder } from '@eeacms/volto-datablocks/components';
function ConnectedChartWrapper(props) {
return (
<>
<Placeholder
getDOMElement={(val) => {
return val?.el;
}}
className="connected-chart"
partialVisibility={true}
offset={{ top: -50, bottom: -50 }}
delayedCall={true}
>
{() => <ConnectedChart {...props} />}
</Placeholder>
<VisibilitySensor className="connected-chart">
<ConnectedChart {...props} />
</VisibilitySensor>
</>
);
}
Expand Down

0 comments on commit fcc69b4

Please sign in to comment.