-
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
feat: debug state for the heatmap chart #976
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1eef3a1
feat: debug state
darnautov 26aa2f5
Merge remote-tracking branch 'upstream/master' into swimlane-debug-data
darnautov faa8296
feat: use common debug state
darnautov 1f5208a
Merge remote-tracking branch 'upstream/master' into swimlane-debug-data
darnautov a54e683
feat: update charts.api.md, add api:check:local command
darnautov 7540d5f
feat: update storybook with cells seleciton actions
darnautov a86c4f2
feat: debug state control
darnautov ebc9123
feat: log debug state
darnautov 077a91b
feat: add highlighted data to the debug state
darnautov 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
90 changes: 90 additions & 0 deletions
90
src/chart_types/heatmap/state/selectors/get_debug_state.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,90 @@ | ||
/* | ||
* 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 { LegendItem } from '../../../../commons/legend'; | ||
import { Line } from '../../../../geoms/types'; | ||
import { getChartIdSelector } from '../../../../state/selectors/get_chart_id'; | ||
import { DebugState, DebugStateLegend } from '../../../../state/types'; | ||
import { RGBtoString } from '../../../partition_chart/layout/utils/color_library_wrappers'; | ||
import { Cell } from '../../layout/types/viewmodel_types'; | ||
import { computeLegendSelector } from './compute_legend'; | ||
import { geometries } from './geometries'; | ||
import { getHighlightedAreaSelector } from './get_highlighted_area'; | ||
|
||
type CellDebug = Pick<Cell, 'value' | 'formatted' | 'x' | 'y'> & { fill: string }; | ||
|
||
interface DebugStateAxis { | ||
labels: string[]; | ||
gridlines: Line[]; | ||
} | ||
|
||
interface DebugStateAxes { | ||
x: DebugStateAxis; | ||
y: DebugStateAxis; | ||
} | ||
|
||
export type HeatmapDebugState = Pick<DebugState, 'legend'> & { | ||
cells: CellDebug[]; | ||
selectedArea: { x: number; y: number; width: number; height: number } | null; | ||
axes: DebugStateAxes; | ||
}; | ||
|
||
/** | ||
* Returns a stringified version of the `debugState` | ||
* @internal | ||
*/ | ||
export const getDebugStateSelector = createCachedSelector( | ||
[geometries, computeLegendSelector, getHighlightedAreaSelector], | ||
(geoms, legend, pickedArea): HeatmapDebugState => { | ||
return { | ||
legend: getLegendState(legend), | ||
axes: { | ||
x: { | ||
labels: geoms.heatmapViewModel.xValues.map(({ text }) => text), | ||
gridlines: geoms.heatmapViewModel.gridLines.x, | ||
}, | ||
y: { | ||
labels: geoms.heatmapViewModel.yValues.map(({ text }) => text), | ||
gridlines: geoms.heatmapViewModel.gridLines.y, | ||
}, | ||
}, | ||
cells: geoms.heatmapViewModel.cells.map(({ x, y, fill, formatted, value }) => ({ | ||
x, | ||
y, | ||
fill: RGBtoString(fill.color), | ||
formatted, | ||
value, | ||
})), | ||
selectedArea: pickedArea, | ||
}; | ||
}, | ||
)(getChartIdSelector); | ||
|
||
function getLegendState(legendItems: LegendItem[]): DebugStateLegend { | ||
const items = legendItems | ||
.filter(({ isSeriesHidden }) => !isSeriesHidden) | ||
.map(({ label: name, color, seriesIdentifier: { key } }) => ({ | ||
key, | ||
name, | ||
color, | ||
})); | ||
|
||
return { items }; | ||
} |
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.
We had talked about using a single
DebugState
type for all chart types to simplify the API. In that case, we would add these additional keys on theDebugState
as optional.@markov00 any thoughts?
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'm also for simplifying the API here if possible
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.
hey @nickofthyme @markov00 , I've updated the
DebugState
interface, please take a look at the recent changes