forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(partition): add element click, over and out events (opensearch-p…
…roject#578) This commit adds the element click, over and out events to the Partition chart. The over and click listeners are called with a value `groupByRollup` for each configured chart layer and the associated value.
- Loading branch information
Showing
23 changed files
with
597 additions
and
123 deletions.
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
Binary file added
BIN
+47 KB
...ll-stories-interactions-sunburst-slice-clicks-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+49.4 KB
.../interactions-test-ts-tooltips-rotation-90-shows-tooltip-on-sunburst-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
76 changes: 76 additions & 0 deletions
76
...ges/osd-charts/src/chart_types/partition_chart/state/selectors/on_element_click_caller.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,76 @@ | ||
/* | ||
* 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 createCachedSelector from 're-reselect'; | ||
import { Selector } from 'reselect'; | ||
import { GlobalChartState, PointerState } from '../../../../state/chart_state'; | ||
import { getSettingsSpecSelector } from '../../../../state/selectors/get_settings_specs'; | ||
import { SettingsSpec, LayerValue } from '../../../../specs'; | ||
import { getPickedShapesLayerValues } from './picked_shapes'; | ||
import { getPieSpecOrNull } from './pie_spec'; | ||
import { ChartTypes } from '../../..'; | ||
import { SeriesIdentifier } from '../../../xy_chart/utils/series'; | ||
import { isClicking } from '../../../../state/utils'; | ||
import { getLastClickSelector } from '../../../../state/selectors/get_last_click'; | ||
|
||
/** | ||
* Will call the onElementClick listener every time the following preconditions are met: | ||
* - the onElementClick listener is available | ||
* - we have at least one highlighted geometry | ||
* - the pointer state goes from down state to up state | ||
*/ | ||
export function createOnElementClickCaller(): (state: GlobalChartState) => void { | ||
let prevClick: PointerState | null = null; | ||
let selector: Selector<GlobalChartState, void> | null = null; | ||
return (state: GlobalChartState) => { | ||
if (selector === null && state.chartType === ChartTypes.Partition) { | ||
selector = createCachedSelector( | ||
[getPieSpecOrNull, getLastClickSelector, getSettingsSpecSelector, getPickedShapesLayerValues], | ||
(pieSpec, lastClick: PointerState | null, settings: SettingsSpec, pickedShapes): void => { | ||
if (!pieSpec) { | ||
return; | ||
} | ||
if (!settings.onElementClick) { | ||
return; | ||
} | ||
const nextPickedShapesLength = pickedShapes.length; | ||
if (nextPickedShapesLength > 0 && isClicking(prevClick, lastClick)) { | ||
if (settings && settings.onElementClick) { | ||
const elements = pickedShapes.map<[Array<LayerValue>, SeriesIdentifier]>((values) => { | ||
return [ | ||
values, | ||
{ | ||
specId: pieSpec.id, | ||
key: `spec{${pieSpec.id}}`, | ||
}, | ||
]; | ||
}); | ||
settings.onElementClick(elements); | ||
} | ||
} | ||
prevClick = lastClick; | ||
}, | ||
)({ | ||
keySelector: (state: GlobalChartState) => state.chartId, | ||
}); | ||
} | ||
if (selector) { | ||
selector(state); | ||
} | ||
}; | ||
} |
62 changes: 62 additions & 0 deletions
62
packages/osd-charts/src/chart_types/partition_chart/state/selectors/on_element_out_caller.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,62 @@ | ||
/* | ||
* 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 { getSettingsSpecSelector } from '../../../../state/selectors/get_settings_specs'; | ||
import createCachedSelector from 're-reselect'; | ||
import { getPickedShapesLayerValues } from './picked_shapes'; | ||
import { getPieSpecOrNull } from './pie_spec'; | ||
import { GlobalChartState } from '../../../../state/chart_state'; | ||
import { Selector } from 'react-redux'; | ||
import { ChartTypes } from '../../../index'; | ||
import { getChartIdSelector } from '../../../../state/selectors/get_chart_id'; | ||
|
||
/** | ||
* Will call the onElementOut listener every time the following preconditions are met: | ||
* - the onElementOut listener is available | ||
* - the highlighted geometries list goes from a list of at least one object to an empty one | ||
*/ | ||
export function createOnElementOutCaller(): (state: GlobalChartState) => void { | ||
let prevPickedShapes: number | null = null; | ||
let selector: Selector<GlobalChartState, void> | null = null; | ||
return (state: GlobalChartState) => { | ||
if (selector === null && state.chartType === ChartTypes.Partition) { | ||
selector = createCachedSelector( | ||
[getPieSpecOrNull, getPickedShapesLayerValues, getSettingsSpecSelector], | ||
(pieSpec, pickedShapes, settings): void => { | ||
if (!pieSpec) { | ||
return; | ||
} | ||
if (!settings.onElementOut) { | ||
return; | ||
} | ||
const nextPickedShapes = pickedShapes.length; | ||
|
||
if (prevPickedShapes !== null && prevPickedShapes > 0 && nextPickedShapes === 0) { | ||
settings.onElementOut(); | ||
} | ||
prevPickedShapes = nextPickedShapes; | ||
}, | ||
)({ | ||
keySelector: getChartIdSelector, | ||
}); | ||
} | ||
if (selector) { | ||
selector(state); | ||
} | ||
}; | ||
} |
95 changes: 95 additions & 0 deletions
95
...ages/osd-charts/src/chart_types/partition_chart/state/selectors/on_element_over_caller.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,95 @@ | ||
/* | ||
* 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 { getSettingsSpecSelector } from '../../../../state/selectors/get_settings_specs'; | ||
import createCachedSelector from 're-reselect'; | ||
import { LayerValue } from '../../../../specs'; | ||
import { GlobalChartState } from '../../../../state/chart_state'; | ||
import { Selector } from 'react-redux'; | ||
import { ChartTypes } from '../../../index'; | ||
import { getChartIdSelector } from '../../../../state/selectors/get_chart_id'; | ||
import { getPieSpecOrNull } from './pie_spec'; | ||
import { getPickedShapesLayerValues } from './picked_shapes'; | ||
import { SeriesIdentifier } from '../../../xy_chart/utils/series'; | ||
|
||
function isOverElement(prevPickedShapes: Array<Array<LayerValue>> = [], nextPickedShapes: Array<Array<LayerValue>>) { | ||
if (nextPickedShapes.length === 0) { | ||
return; | ||
} | ||
if (nextPickedShapes.length !== prevPickedShapes.length) { | ||
return true; | ||
} | ||
return !nextPickedShapes.every((nextPickedShapeValues, index) => { | ||
const prevPickedShapeValues = prevPickedShapes[index]; | ||
if (prevPickedShapeValues === null) { | ||
return false; | ||
} | ||
if (prevPickedShapeValues.length !== nextPickedShapeValues.length) { | ||
return false; | ||
} | ||
return nextPickedShapeValues.every((layerValue, i) => { | ||
const prevPickedValue = prevPickedShapeValues[i]; | ||
if (!prevPickedValue) { | ||
return false; | ||
} | ||
return layerValue.value === prevPickedValue.value && layerValue.groupByRollup === prevPickedValue.groupByRollup; | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Will call the onElementOver listener every time the following preconditions are met: | ||
* - the onElementOver listener is available | ||
* - we have a new set of highlighted geometries on our state | ||
*/ | ||
export function createOnElementOverCaller(): (state: GlobalChartState) => void { | ||
let prevPickedShapes: Array<Array<LayerValue>> = []; | ||
let selector: Selector<GlobalChartState, void> | null = null; | ||
return (state: GlobalChartState) => { | ||
if (selector === null && state.chartType === ChartTypes.Partition) { | ||
selector = createCachedSelector( | ||
[getPieSpecOrNull, getPickedShapesLayerValues, getSettingsSpecSelector], | ||
(pieSpec, nextPickedShapes, settings): void => { | ||
if (!pieSpec) { | ||
return; | ||
} | ||
if (!settings.onElementOver) { | ||
return; | ||
} | ||
|
||
if (isOverElement(prevPickedShapes, nextPickedShapes)) { | ||
const elements = nextPickedShapes.map<[Array<LayerValue>, SeriesIdentifier]>((values) => [ | ||
values, | ||
{ | ||
specId: pieSpec.id, | ||
key: `spec{${pieSpec.id}}`, | ||
}, | ||
]); | ||
settings.onElementOver(elements); | ||
} | ||
prevPickedShapes = nextPickedShapes; | ||
}, | ||
)({ | ||
keySelector: getChartIdSelector, | ||
}); | ||
} | ||
if (selector) { | ||
selector(state); | ||
} | ||
}; | ||
} |
Oops, something went wrong.