Skip to content

Commit

Permalink
feat: 数据元素 marker 背景色支持自定义 (#1560)
Browse files Browse the repository at this point in the history
  • Loading branch information
susiwen8 committed Aug 10, 2022
1 parent 7406ce7 commit c7c4f7d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions packages/f2/src/components/tooltip/tooltipView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const defaultStyle = {
lineWidth: '2px',
},
showTooltipMarker: false,
markerBackgroundStyle: {
fill: '#CCD6EC',
opacity: 0.3,
padding: '6px',
},
tooltipMarkerStyle: {
fill: '#fff',
lineWidth: '3px',
Expand Down Expand Up @@ -87,9 +92,9 @@ function directionEnabled(mode: string, dir: string) {
}

const RenderItemMarker = (props) => {
const { records, coord, context } = props;
const { records, coord, context, markerBackgroundStyle } = props;
const point = coord.convertPoint({ x: 1, y: 1 });
const padding = context.px2hd('6px');
const padding = context.px2hd(markerBackgroundStyle.padding || '6px');
const xPoints = [
...records.map((record) => record.xMin),
...records.map((record) => record.xMax),
Expand Down Expand Up @@ -122,8 +127,7 @@ const RenderItemMarker = (props) => {
y,
width,
height,
fill: '#CCD6EC',
opacity: 0.3,
...markerBackgroundStyle
}}
/>
);
Expand Down Expand Up @@ -243,6 +247,7 @@ export default class TooltipView extends Component {
// showTitle,
// titleStyle,
showTooltipMarker = defaultStyle.showTooltipMarker,
markerBackgroundStyle = defaultStyle.markerBackgroundStyle,
showItemMarker = defaultStyle.showItemMarker,
itemMarkerStyle: customItemMarkerStyle,
nameStyle,
Expand Down Expand Up @@ -377,7 +382,7 @@ export default class TooltipView extends Component {
</group>
)}
{showTooltipMarker ? (
<RenderItemMarker coord={coord} context={context} records={records} />
<RenderItemMarker coord={coord} context={context} records={records} markerBackgroundStyle={markerBackgroundStyle} />
) : null}
{/* 辅助线 */}
{showCrosshairs ? (
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/f2/test/chart/landscape.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('横屏', () => {
<Axis field="genre" />
<Axis field="sold" />
<Interval x="genre" y="sold" color="genre" />
<Tooltip snap showTooltipMarker />
<Tooltip snap showTooltipMarker markerBackgroundStyle={{ fill: 'l(90) 0:#ffffff 0.5:#7ec2f3 1:#1890ff', opacity: .3 }} />
</Chart>
</Canvas>
);
Expand Down

0 comments on commit c7c4f7d

Please sign in to comment.