Skip to content

Commit

Permalink
fix(update): skip empty selection (close: #4490)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Jan 3, 2023
1 parent 2b4a5fe commit 4fa237a
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions __tests__/integration/animations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export { sexIntervalKeyframe } from './sex-interval-keyframe';
export { soldIntervalKeyframe } from './sold-interval-keyframe';
export { soldIntervalPieKeyframe } from './sold-interval-pie-keyframe';
export { aaplAreaKeyframe } from './aapl-area-keyframe';
export { profitIntervalRange } from './profit-interval-range';
64 changes: 64 additions & 0 deletions __tests__/integration/animations/profit-interval-range.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { G2Spec } from '../../../src';
import { profit } from '../data/profit';

export async function profitIntervalRange(): Promise<G2Spec> {
return {
type: 'timingKeyframe',
children: [
{
type: 'view',
paddingLeft: 60,
children: [
{
type: 'interval',
key: 'interval',
data: profit,
axis: { y: { labelFormatter: '~s' } },
encode: {
x: 'month',
y: ['end', 'start'],
color: (d) =>
d.month === 'Total'
? 'Total'
: d.profit > 0
? 'Increase'
: 'Decrease',
},
},
],
},
{
type: 'view',
paddingLeft: 60,
children: [
{
type: 'interval',
key: 'interval',
data: profit,
axis: { y: { labelFormatter: '~s' } },
encode: {
x: 'month',
y: ['end', 'start'],
color: (d) =>
d.month === 'Total'
? 'Total'
: d.profit > 0
? 'Increase'
: 'Decrease',
},
},
{
type: 'rangeY',
data: [{ y: [0, 2000000] }],
encode: { y: 'y' },
animate: {
enterType: 'fadeIn',
},
},
],
},
],
};
}

profitIntervalRange.intervals = [false, false, [500]];
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/runtime/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,11 @@ function shapeName(mark: G2Mark, name: string): string {
*/
function updateLayers(selection: Selection, marks: G2Mark[]) {
const facet = (d) => (d.class !== undefined ? `${d.class}` : '');

// Skip for empty selection, it can't append nodes.
const nodes = selection.nodes();
if (nodes.length === 0) return;

selection
.selectAll(className(MAIN_LAYER_CLASS_NAME))
.data(marks, (d) => d.key)
Expand Down

0 comments on commit 4fa237a

Please sign in to comment.