-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(D3 plugin): add halo to scatter hover series (#394)
* feat(D3 plugin): add halo to scatter hover series * fix types * fix review(1)
- Loading branch information
Showing
21 changed files
with
253 additions
and
236 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
2 changes: 1 addition & 1 deletion
2
src/plugins/d3/renderer/hooks/useSeries/__tests__/prepare-line-series.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
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
73 changes: 73 additions & 0 deletions
73
src/plugins/d3/renderer/hooks/useSeries/prepare-scatter.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,73 @@ | ||
import {ScaleOrdinal} from 'd3'; | ||
import get from 'lodash/get'; | ||
import merge from 'lodash/merge'; | ||
import type {PreparedLegend, PreparedScatterSeries} from './types'; | ||
import type {ChartKitWidgetSeriesOptions, ScatterSeries} from '../../../../../types'; | ||
import {getSymbolType} from '../../utils'; | ||
|
||
import {prepareLegendSymbol} from './utils'; | ||
import {DEFAULT_HALO_OPTIONS, DEFAULT_POINT_MARKER_OPTIONS} from './constants'; | ||
|
||
import {PointMarkerOptions} from '../../../../../types/widget-data/marker'; | ||
import {getRandomCKId} from '../../../../../utils'; | ||
|
||
function prepareMarker( | ||
series: ScatterSeries, | ||
seriesOptions: ChartKitWidgetSeriesOptions | undefined, | ||
index: number, | ||
) { | ||
const seriesHoverState = get(seriesOptions, 'scatter.states.hover'); | ||
const markerNormalState: Required<PointMarkerOptions> = { | ||
...DEFAULT_POINT_MARKER_OPTIONS, | ||
enabled: true, | ||
symbol: (series as ScatterSeries).symbolType || getSymbolType(index), | ||
}; | ||
|
||
const hoveredMarkerDefaultOptions = { | ||
enabled: true, | ||
radius: markerNormalState.radius, | ||
borderWidth: 1, | ||
borderColor: '#ffffff', | ||
halo: DEFAULT_HALO_OPTIONS, | ||
}; | ||
|
||
return { | ||
states: { | ||
normal: markerNormalState, | ||
hover: merge(hoveredMarkerDefaultOptions, seriesHoverState?.marker), | ||
}, | ||
}; | ||
} | ||
|
||
interface PrepareScatterSeriesArgs { | ||
colorScale: ScaleOrdinal<string, string>; | ||
series: ScatterSeries[]; | ||
legend: PreparedLegend; | ||
seriesOptions?: ChartKitWidgetSeriesOptions; | ||
} | ||
|
||
export function prepareScatterSeries(args: PrepareScatterSeriesArgs): PreparedScatterSeries[] { | ||
const {colorScale, series, seriesOptions, legend} = args; | ||
|
||
return series.map<PreparedScatterSeries>((s, index) => { | ||
const id = getRandomCKId(); | ||
const name = 'name' in s && s.name ? s.name : ''; | ||
const symbolType = (s as ScatterSeries).symbolType || getSymbolType(index); | ||
|
||
const prepared: PreparedScatterSeries = { | ||
id, | ||
type: s.type, | ||
name, | ||
color: get(s, 'color', colorScale(name)), | ||
visible: get(s, 'visible', true), | ||
legend: { | ||
enabled: get(s, 'legend.enabled', legend.enabled), | ||
symbol: prepareLegendSymbol(s, symbolType), | ||
}, | ||
data: s.data, | ||
marker: prepareMarker(s, seriesOptions, index), | ||
}; | ||
|
||
return prepared; | ||
}, []); | ||
} |
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
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.