-
Notifications
You must be signed in to change notification settings - Fork 122
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
fix(treemap): align onElementClick parameters to sunburst #636
Merged
markov00
merged 1 commit into
elastic:master
from
markov00:2020_04_17-fix_partition_click
Apr 21, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
src/chart_types/partition_chart/state/selectors/picked_shapes.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. */ | ||
|
||
import { chartStoreReducer, GlobalChartState } from '../../../../state/chart_state'; | ||
import { createStore, Store } from 'redux'; | ||
import { PartitionSpec } from '../../specs'; | ||
import { upsertSpec, specParsed, specParsing } from '../../../../state/actions/specs'; | ||
import { MockGlobalSpec, MockSeriesSpec } from '../../../../mocks/specs'; | ||
import { updateParentDimensions } from '../../../../state/actions/chart_settings'; | ||
import { partitionGeometries } from './geometries'; | ||
import { onMouseDown, onMouseUp, onPointerMove } from '../../../../state/actions/mouse'; | ||
import { createOnElementClickCaller } from './on_element_click_caller'; | ||
import { SettingsSpec, XYChartElementEvent, PartitionElementEvent } from '../../../../specs'; | ||
|
||
describe('Picked shapes selector', () => { | ||
markov00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
function initStore() { | ||
const storeReducer = chartStoreReducer('chartId'); | ||
return createStore(storeReducer); | ||
} | ||
function addSeries(store: Store<GlobalChartState>, spec: PartitionSpec, settings?: Partial<SettingsSpec>) { | ||
store.dispatch(specParsing()); | ||
store.dispatch(upsertSpec(MockGlobalSpec.settings(settings))); | ||
store.dispatch(upsertSpec(spec)); | ||
store.dispatch(specParsed()); | ||
store.dispatch(updateParentDimensions({ width: 300, height: 300, top: 0, left: 0 })); | ||
} | ||
let store: Store<GlobalChartState>; | ||
let treemapSpec: PartitionSpec; | ||
let sunburstSpec: PartitionSpec; | ||
beforeEach(() => { | ||
store = initStore(); | ||
const common = { | ||
valueAccessor: (d: { v: number }) => { | ||
return d.v; | ||
}, | ||
data: [ | ||
{ g1: 'a', g2: 'a', v: 1 }, | ||
{ g1: 'a', g2: 'b', v: 1 }, | ||
{ g1: 'b', g2: 'a', v: 1 }, | ||
{ g1: 'b', g2: 'b', v: 1 }, | ||
], | ||
layers: [ | ||
{ | ||
groupByRollup: (datum: { g1: string }) => datum.g1, | ||
}, | ||
{ | ||
groupByRollup: (datum: { g2: string }) => datum.g2, | ||
}, | ||
], | ||
}; | ||
treemapSpec = MockSeriesSpec.treemap(common); | ||
sunburstSpec = MockSeriesSpec.sunburst(common); | ||
}); | ||
test('check initial geoms', () => { | ||
addSeries(store, treemapSpec); | ||
const treemapGeometries = partitionGeometries(store.getState()); | ||
expect(treemapGeometries.quadViewModel).toHaveLength(6); | ||
|
||
addSeries(store, sunburstSpec); | ||
const sunburstGeometries = partitionGeometries(store.getState()); | ||
expect(sunburstGeometries.quadViewModel).toHaveLength(6); | ||
}); | ||
test('treemap check picked geometries', () => { | ||
const onClickListener = jest.fn<undefined, Array<(XYChartElementEvent | PartitionElementEvent)[]>>( | ||
(): undefined => undefined, | ||
); | ||
addSeries(store, treemapSpec, { | ||
onElementClick: onClickListener, | ||
}); | ||
const geometries = partitionGeometries(store.getState()); | ||
expect(geometries.quadViewModel).toHaveLength(6); | ||
|
||
const onElementClickCaller = createOnElementClickCaller(); | ||
store.subscribe(() => { | ||
onElementClickCaller(store.getState()); | ||
}); | ||
store.dispatch(onPointerMove({ x: 200, y: 200 }, 0)); | ||
store.dispatch(onMouseDown({ x: 200, y: 200 }, 1)); | ||
store.dispatch(onMouseUp({ x: 200, y: 200 }, 2)); | ||
expect(onClickListener).toBeCalled(); | ||
expect(onClickListener.mock.calls[0][0]).toEqual([ | ||
[ | ||
[ | ||
{ groupByRollup: 'b', value: 2 }, | ||
{ groupByRollup: 'b', value: 1 }, | ||
], | ||
{ | ||
specId: treemapSpec.id, | ||
key: `spec{${treemapSpec.id}}`, | ||
}, | ||
], | ||
]); | ||
}); | ||
test('sunburst check picked geometries', () => { | ||
const onClickListener = jest.fn<undefined, Array<(XYChartElementEvent | PartitionElementEvent)[]>>( | ||
(): undefined => undefined, | ||
); | ||
addSeries(store, sunburstSpec, { | ||
onElementClick: onClickListener, | ||
}); | ||
const geometries = partitionGeometries(store.getState()); | ||
expect(geometries.quadViewModel).toHaveLength(6); | ||
|
||
const onElementClickCaller = createOnElementClickCaller(); | ||
store.subscribe(() => { | ||
onElementClickCaller(store.getState()); | ||
}); | ||
store.dispatch(onPointerMove({ x: 200, y: 200 }, 0)); | ||
store.dispatch(onMouseDown({ x: 200, y: 200 }, 1)); | ||
store.dispatch(onMouseUp({ x: 200, y: 200 }, 2)); | ||
expect(onClickListener).toBeCalled(); | ||
expect(onClickListener.mock.calls[0][0]).toEqual([ | ||
[ | ||
[ | ||
{ groupByRollup: 'b', value: 2 }, | ||
{ groupByRollup: 'b', value: 1 }, | ||
], | ||
{ | ||
specId: sunburstSpec.id, | ||
key: `spec{${sunburstSpec.id}}`, | ||
}, | ||
], | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice extraction! Should it be placed above the line in which we use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've extracted that because I was having a hard time understanding the code.
My Place them the above the line that uses it, do you mean moving that function declaration before
const quadViewModel = makeQuadViewModel(
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Robert is referring to preventing the
function was used before it was declared
error. Basically best practice even though hoisting prevents any errors.