Skip to content

Commit

Permalink
feat: 添加axis top
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed Feb 7, 2021
1 parent 3cf5ae9 commit a418476
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/components/src/axis/axisView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { jsx } from '@ali/f2-jsx';
import PolarX from './polar/polar-x';
import PolarY from './polar/polar-y';
import Top from './rect/top';
import Bottom from './rect/bottom';
import Right from './rect/right';
import Left from './rect/left';
Expand All @@ -24,7 +25,7 @@ export default (props: any) => {
}

if (position === 'top') {
return null;
return <Top { ...props } />;
}
return <Bottom { ...props } />
}
80 changes: 80 additions & 0 deletions packages/components/src/axis/rect/top.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { jsx } from '@ali/f2-jsx';

export default (props: any) => {
const { ticks, plot, style } = props;
const { tl, tr } = plot;
const { grid, tickLine, line, labelOffset, label } = style;

return (
<group>
{
grid ?
ticks.map(tick => {
const { points } = tick;
const start = points[0];
const end = points[points.length - 1];
return (
<line attrs={{
x1: start.x,
y1: start.y,
x2: end.x,
y2: end.y,
...grid,
}} />
);
})
:
null
}
{
tickLine && tickLine.length ?
ticks.map(tick => {
const { points } = tick;
const end = points[points.length - 1];
return (
<line attrs={{
x1: end.x,
y1: end.y,
x2: end.x,
y2: end.y - tickLine.length,
...tickLine,
}} />
);
})
:
null
}
{
line ?
<line attrs={{
x1: tl.x,
y1: tl.y,
x2: tr.x,
y2: tr.y,
...line,
}} />
:
null
}
{
label ?
ticks.map((tick, index) => {
const { points, text } = tick;
const end = points[points.length - 1];
return (
<text attrs={{
x: end.x,
y: end.y - labelOffset,
textAlign: 'center',
textBaseline: 'bottom',
text,
...label,
}} />
);
})
:
null
}
</group>
);
}
6 changes: 6 additions & 0 deletions packages/components/test/axis.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ describe('Axis', () => {
<Chart data={ data } context={ context } pixelRatio={ window.devicePixelRatio }>
<Axis
field="genre"
position="top"
// tickLine={{
// length: '10px',
// stroke: '#000',
// lineWidth: '4px',
// }}
/>
<Axis
field="sold"
Expand Down

0 comments on commit a418476

Please sign in to comment.