Skip to content
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

fix: 修复折线的默认宽度和官网demo的报错 #1357

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/f2/src/components/tooltip/tooltipView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,13 @@ export default class TooltipView extends Component {
// 中心点
const { x } = record;
const { left: coordLeft, width: coordWidth } = coord;
const { y, width, height } = group.get('attrs');
const { y, width, height, radius } = group.get('attrs');
const halfWidth = width / 2;
// 让 tooltip 限制在 coord 的显示范围内
const offsetX = Math.min(Math.max(x - coordLeft - halfWidth, 0), coordWidth - width);
const offsetX = Math.min(
Math.max(x - coordLeft - halfWidth, -arrowWidth - radius),
coordWidth - width + arrowWidth + radius
);

// 因为默认是从 coord 的范围内显示的,所以要往上移,移出 coord,避免挡住 geometry
const offset = Math.min(y, height + arrowWidth); // 因为不能超出 canvas 画布区域,所以最大只能是 y
Expand Down
2 changes: 1 addition & 1 deletion packages/f2/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const Theme = {
shape: {
line: {
default: {
lineWidth: '2px',
lineWidth: '4px',
lineJoin: 'round',
lineCap: 'round',
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions packages/f2/test/components/geometry/attr.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ describe('Geometry - Attr', () => {
expect(geometryRef.current.records[0].children[0].shape).toEqual({
lineCap: 'round',
lineJoin: 'round',
lineWidth: 1,
lineWidth: 2,
});
});
it('shape = {shape}', () => {
Expand All @@ -657,7 +657,7 @@ describe('Geometry - Attr', () => {
expect(geometryRef.current.records[0].children[0].shape).toEqual({
lineCap: 'round',
lineJoin: 'round',
lineWidth: 1,
lineWidth: 2,
smooth: true,
});
});
Expand All @@ -682,12 +682,12 @@ describe('Geometry - Attr', () => {
expect(geometryRef.current.records[0].children[0].shape).toEqual({
lineCap: 'round',
lineJoin: 'round',
lineWidth: 1,
lineWidth: 2,
});
expect(geometryRef.current.records[1].children[0].shape).toEqual({
lineCap: 'round',
lineJoin: 'round',
lineWidth: 1,
lineWidth: 2,
lineDash: [2, 2],
});
});
Expand Down Expand Up @@ -722,13 +722,13 @@ describe('Geometry - Attr', () => {
expect(geometryRef.current.records[0].children[0].shape).toEqual({
lineCap: 'round',
lineJoin: 'round',
lineWidth: 1,
lineWidth: 2,
lineDash: [2, 2],
});
expect(geometryRef.current.records[1].children[0].shape).toEqual({
lineCap: 'round',
lineJoin: 'round',
lineWidth: 1,
lineWidth: 2,
smooth: true,
});
});
Expand Down Expand Up @@ -760,13 +760,13 @@ describe('Geometry - Attr', () => {
expect(geometryRef.current.records[0].children[0].shape).toEqual({
lineCap: 'round',
lineJoin: 'round',
lineWidth: 1,
lineWidth: 2,
smooth: true,
});
expect(geometryRef.current.records[1].children[0].shape).toEqual({
lineCap: 'round',
lineJoin: 'round',
lineWidth: 1,
lineWidth: 2,
lineDash: [2, 2],
});
});
Expand Down Expand Up @@ -806,12 +806,12 @@ describe('Geometry - Attr', () => {
expect(geometryRef.current.records[0].children[0].shape).toEqual({
lineCap: 'round',
lineJoin: 'round',
lineWidth: 1,
lineWidth: 2,
});
expect(geometryRef.current.records[1].children[0].shape).toEqual({
lineCap: 'round',
lineJoin: 'round',
lineWidth: 1,
lineWidth: 2,
lineDash: [2, 2],
});
});
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 0 additions & 87 deletions packages/site/examples/line/dynamic/demo/dynamic.js

This file was deleted.

62 changes: 62 additions & 0 deletions packages/site/examples/line/dynamic/demo/dynamic.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { jsx, Component, Canvas, Chart, Line, Axis } from '@antv/f2';

const context = document.getElementById('container').getContext('2d');

const data = [
{
time: new Date().getTime(),
value: 12,
},
];

// 添加数据,模拟数据,可以指定当前时间的偏移的秒
function getRecord() {
return {
time: new Date().getTime(),
value: Math.random() * 2 + 10,
};
}

class DynamicLine extends Component {
constructor(props) {
super(props);
this.state = {
data,
};
}

didMount() {
setInterval(() => {
const { data } = this.state;
const newData = [].concat(data);
newData.push(getRecord());
this.setState({ data: newData });
}, 1000);
}

render() {
const { data } = this.state;
return (
<Chart
data={data}
scale={{
value: {
min: 0,
},
}}
>
<Axis field="value" />
<Axis field="time" type="timeCat" tickCount={5} mask="mm:ss" />
<Line x="time" y="value" />
</Chart>
);
}
}
const { props } = (
<Canvas context={context} pixelRatio={window.devicePixelRatio}>
<DynamicLine />
</Canvas>
);

const canvas = new Canvas(props);
canvas.render();
Loading