Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Highcharts plugin): add props paneSplitOrientation and onSplitPaneOrientationChange #501

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ export class HighchartsComponent extends React.PureComponent<Props, State> {
options={options}
highcharts={Highcharts}
onSplitPaneMountCallback={this.state.callback || undefined}
onSplitPaneOrientationChange={this.props.onSplitPaneOrientationChange}
paneSplitOrientation={this.props.paneSplitOrientation}
callback={this.extendChartInstance}
constructorType={options?.useHighStock ? 'stockChart' : 'chart'}
containerProps={{className: 'chartkit-graph'}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import SplitPane, {Pane, Split, SplitPaneProps} from 'react-split-pane';
import SplitPane, {Pane, SplitPaneProps} from 'react-split-pane';

import {cn} from '../../../../../utils/cn';

Expand All @@ -9,8 +9,6 @@ import './StyledSplitPane.scss';
const b = cn('styled-split-pane');
const resizerClassName = b('pane-resizer');

export type PaneSplit = Split;

type Props = SplitPaneProps & {
paneOneRender: () => React.ReactNode;
paneTwoRender: () => React.ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export const withSplitPane = <ComposedComponentProps extends {}>(
type WrapperComponentProps = ComposedComponentProps & {
onPaneChange?: () => void;
onSplitPaneMountCallback?: (chart: Highcharts.Chart) => void;
paneSplitOrientation?: PaneSplits;
onSplitPaneOrientationChange?: (orientation?: PaneSplits) => void;
};

type WrapperComponentPropsWithForwardedRef = WrapperComponentProps & {
Expand All @@ -126,9 +128,10 @@ export const withSplitPane = <ComposedComponentProps extends {}>(
paneSize: undefined,
maxPaneSize: undefined,
paneSplit:
window.innerWidth > window.innerHeight
this.props.paneSplitOrientation ||
(window.innerWidth > window.innerHeight
? PaneSplits.VERTICAL
: PaneSplits.HORIZONTAL,
: PaneSplits.HORIZONTAL),
componentKey: getRandomCKId(),
};

Expand Down Expand Up @@ -236,19 +239,20 @@ export const withSplitPane = <ComposedComponentProps extends {}>(
const handleResizeAfterOrientationChange = () => {
const deviceWidth = window.innerWidth;
const deviceHeight = window.innerHeight;
const aspectRatioOrientation =
deviceWidth > deviceHeight ? PaneSplits.VERTICAL : PaneSplits.HORIZONTAL;

this.setState(
{
paneSplit:
deviceWidth > deviceHeight
? PaneSplits.VERTICAL
: PaneSplits.HORIZONTAL,
paneSplit: this.props.paneSplitOrientation || aspectRatioOrientation,
},
() => {
this.setInitialState(true);
},
);

this.props.onSplitPaneOrientationChange?.(aspectRatioOrientation);

window.removeEventListener('resize', handleResizeAfterOrientationChange);
};

Expand Down
4 changes: 4 additions & 0 deletions src/types/widget.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type {Split} from 'react-split-pane';

import type {Highcharts, HighchartsWidgetData, StringParams} from '../plugins/highcharts/types';
import type {IndicatorWidgetData} from '../plugins/indicator/types';
import type {CustomTooltipProps, Yagr, YagrWidgetData} from '../plugins/yagr/types';
Expand All @@ -21,6 +23,8 @@ export interface ChartKitWidget {
hoistConfigError?: boolean;
nonBodyScroll?: boolean;
splitTooltip?: boolean;
paneSplitOrientation?: Split;
onSplitPaneOrientationChange?: (orientation: Split) => void;
onChange?: (
data: {type: 'PARAMS_CHANGED'; data: {params: StringParams}},
state: {forceUpdate: boolean},
Expand Down
Loading