Skip to content

Commit

Permalink
refactor: check w/h at chart state level
Browse files Browse the repository at this point in the history
  • Loading branch information
markov00 committed Jun 3, 2020
1 parent 2b0c472 commit 72b6c36
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
7 changes: 3 additions & 4 deletions src/chart_types/partition_chart/layout/viewmodel/viewmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ function topGrooveAccessor(topGroovePx: Pixels) {
}

export const VerticalAlignments = Object.freeze({
top: 'top' as 'top',
middle: 'middle' as 'middle',
bottom: 'bottom' as 'bottom',
top: 'top' as const,
middle: 'middle' as const,
bottom: 'bottom' as const,
});

// we might add more in the future; also, the intent is to still be of CanvasTextBaseline
Expand Down Expand Up @@ -207,7 +207,6 @@ export function shapeViewModel(
partitionLayout,
sectorLineWidth,
} = config;

const innerWidth = width * (1 - Math.min(1, margin.left + margin.right));
const innerHeight = height * (1 - Math.min(1, margin.top + margin.bottom));

Expand Down
2 changes: 1 addition & 1 deletion src/chart_types/partition_chart/state/chart_state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class PartitionState implements InternalChartState {
}
chartType = ChartTypes.Partition;
isInitialized(globalState: GlobalChartState) {
return globalState.specsInitialized && getPieSpec(globalState) !== null;
return getPieSpec(globalState) !== null;
}
isBrushAvailable() {
return false;
Expand Down
13 changes: 3 additions & 10 deletions src/chart_types/xy_chart/renderer/canvas/xy_chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,12 @@ class XYChartComponent extends React.Component<XYChartProps> {
isChartEmpty,
chartContainerDimensions: { width, height },
} = this.props;
if (!initialized || width === 0 || height === 0) {

if (!initialized || isChartEmpty) {
this.ctx = null;
return null;
}

if (isChartEmpty) {
this.ctx = null;
return (
<div className="echReactiveChart_unavailable">
<p>No data to display</p>
</div>
);
}
return (
<canvas
ref={forwardStageRef}
Expand Down Expand Up @@ -192,7 +185,7 @@ const DEFAULT_PROPS: ReactiveChartStateProps = {
left: 0,
top: 0,
},
chartRotation: 0 as 0,
chartRotation: 0 as const,
chartDimensions: {
width: 0,
height: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/chart_types/xy_chart/state/chart_state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class XYAxisChartState implements InternalChartState {
this.legendId = htmlIdGenerator()('legend');
}
isInitialized(globalState: GlobalChartState) {
return globalState.specsInitialized && getSeriesSpecsSelector(globalState).length > 0;
return getSeriesSpecsSelector(globalState).length > 0;
}

isBrushAvailable(globalState: GlobalChartState) {
Expand Down
7 changes: 6 additions & 1 deletion src/components/chart_container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,19 @@ class ChartContainerComponent extends React.Component<ReactiveChartProps> {
};

render() {
const { initialized } = this.props;
const { initialized, isChartEmpty } = this.props;
if (!initialized) {
return null;
}

if (isChartEmpty) {
return (
<div className="echReactiveChart_unavailable">
<p>No data to display</p>
</div>
);
}

const { pointerCursor, internalChartRenderer, getChartContainerRef, forwardStageRef } = this.props;
return (
<div
Expand Down
11 changes: 9 additions & 2 deletions src/state/selectors/get_internal_is_intialized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ import { GlobalChartState } from '../chart_state';

/** @internal */
export const getInternalIsInitializedSelector = (state: GlobalChartState): boolean => {
const {
parentDimensions: { width, height },
specsInitialized,
} = state;

if (width <= 0 || height <= 0 || !specsInitialized) {
return false;
}
if (state.internalChartState) {
return state.internalChartState.isInitialized(state);
} else {
return false;
}
return false;
};

0 comments on commit 72b6c36

Please sign in to comment.