forked from elastic/elastic-charts
-
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.
close elastic#846
- Loading branch information
Showing
7 changed files
with
188 additions
and
2 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
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
54 changes: 54 additions & 0 deletions
54
src/chart_types/xy_chart/state/selectors/get_projected_scaled_values.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,54 @@ | ||
/* | ||
* 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 { ProjectedValues } from '../../../../specs/settings'; | ||
import { getChartIdSelector } from '../../../../state/selectors/get_chart_id'; | ||
import { computeSeriesGeometriesSelector } from './compute_series_geometries'; | ||
import { getGeometriesIndexKeysSelector } from './get_geometries_index_keys'; | ||
import { getOrientedProjectedPointerPositionSelector } from './get_oriented_projected_pointer_position'; | ||
|
||
/** @internal */ | ||
export const getProjectedScaledValues = createCachedSelector( | ||
[getOrientedProjectedPointerPositionSelector, computeSeriesGeometriesSelector, getGeometriesIndexKeysSelector], | ||
( | ||
{ x, y, verticalPanelValue, horizontalPanelValue }, | ||
{ scales: { xScale, yScales } }, | ||
geometriesIndexKeys, | ||
): ProjectedValues | undefined => { | ||
if (!xScale) { | ||
return; | ||
} | ||
|
||
const xValue = xScale.invertWithStep(x, geometriesIndexKeys); | ||
if (!xValue) { | ||
return; | ||
} | ||
|
||
return { | ||
x: xValue.value, | ||
y: [...yScales.entries()].map(([groupId, yScale]) => { | ||
return { value: yScale.invert(y), groupId }; | ||
}), | ||
smVerticalValue: verticalPanelValue, | ||
smHorizontalValue: horizontalPanelValue, | ||
}; | ||
}, | ||
)(getChartIdSelector); |
62 changes: 62 additions & 0 deletions
62
src/chart_types/xy_chart/state/selectors/on_projection_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,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 createCachedSelector from 're-reselect'; | ||
import { Selector } from 'reselect'; | ||
|
||
import { ChartTypes } from '../../..'; | ||
import { GlobalChartState, PointerState } from '../../../../state/chart_state'; | ||
import { getLastClickSelector } from '../../../../state/selectors/get_last_click'; | ||
import { getSettingsSpecSelector } from '../../../../state/selectors/get_settings_specs'; | ||
import { isClicking } from '../../../../state/utils'; | ||
import { getProjectedScaledValues } from './get_projected_scaled_values'; | ||
|
||
/** | ||
* 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 | ||
* @internal | ||
*/ | ||
export function createOnProjectionClickCaller(): (state: GlobalChartState) => void { | ||
let prevClick: PointerState | null = null; | ||
let selector: Selector<GlobalChartState, void> | null = null; | ||
return (state: GlobalChartState) => { | ||
if (selector === null && state.chartType === ChartTypes.XYAxis) { | ||
selector = createCachedSelector( | ||
[getLastClickSelector, getSettingsSpecSelector, getProjectedScaledValues], | ||
(lastClick, { onProjectionClick }, values): void => { | ||
if (!onProjectionClick) { | ||
return; | ||
} | ||
|
||
if (values !== undefined && isClicking(prevClick, lastClick)) { | ||
onProjectionClick(values); | ||
} | ||
prevClick = lastClick; | ||
}, | ||
)({ | ||
keySelector: ({ chartId }) => chartId, | ||
}); | ||
} | ||
if (selector) { | ||
selector(state); | ||
} | ||
}; | ||
} |
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