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

[demo] add AxisRight to axis demo #280

Merged
merged 2 commits into from
Apr 28, 2018
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
158 changes: 92 additions & 66 deletions packages/vx-demo/components/tiles/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Group } from '@vx/group';
import { curveBasis } from '@vx/curve';
import { GradientOrangeRed } from '@vx/gradient';
import { genDateValue } from '@vx/mock-data';
import { AxisLeft, AxisBottom } from '@vx/axis';
import { AxisLeft, AxisRight, AxisBottom } from '@vx/axis';
import { AreaClosed, LinePath, Line } from '@vx/shape';
import { scaleTime, scaleLinear } from '@vx/scale';
import { extent, max } from 'd3-array';
Expand Down Expand Up @@ -88,71 +88,97 @@ export default ({ width, height, margin }) => {
curve={curveBasis}
/>
</Group>
<AxisLeft
top={margin.top}
left={margin.left}
scale={yScale}
hideZero
numTicks={numTicksForHeight(height)}
label="value"
labelProps={{
fill: '#8e205f',
textAnchor: 'middle',
fontSize: 12,
fontFamily: 'Arial'
}}
stroke="#1b1a1e"
tickStroke="#8e205f"
tickLabelProps={(value, index) => ({
fill: '#8e205f',
textAnchor: 'end',
fontSize: 10,
fontFamily: 'Arial',
dx: '-0.25em',
dy: '0.25em'
})}
tickComponent={({ formattedValue, ...tickProps }) => (
<text {...tickProps}>{formattedValue}</text>
)}
/>
<AxisBottom
top={height - margin.bottom}
left={margin.left}
scale={xScale}
numTicks={numTicksForWidth(width)}
label="time"
>
{props => {
const tickLabelSize = 10;
const tickRotate = 45;
const tickColor = '#8e205f';
const axisCenter = (props.axisToPoint.x - props.axisFromPoint.x) / 2;
return (
<g className="my-custom-bottom-axis">
{props.ticks.map((tick, i) => {
const tickX = tick.to.x;
const tickY = tick.to.y + tickLabelSize + props.tickLength;
return (
<Group key={`vx-tick-${tick.value}-${i}`} className={'vx-axis-tick'}>
<Line from={tick.from} to={tick.to} stroke={tickColor} />
<text
transform={`translate(${tickX}, ${tickY}) rotate(${tickRotate})`}
fontSize={tickLabelSize}
textAnchor="middle"
fill={tickColor}
>
{tick.formattedValue}
</text>
</Group>
);
})}
<text textAnchor="middle" transform={`translate(${axisCenter}, 50)`} fontSize="8">
{props.label}
</text>
</g>
);
}}
</AxisBottom>
<Group left={margin.left}>
<AxisLeft
top={margin.top}
left={0}
scale={yScale}
hideZero
numTicks={numTicksForHeight(height)}
label="Axis Left Label"
labelProps={{
fill: '#8e205f',
textAnchor: 'middle',
fontSize: 12,
fontFamily: 'Arial'
}}
stroke="#1b1a1e"
tickStroke="#8e205f"
tickLabelProps={(value, index) => ({
fill: '#8e205f',
textAnchor: 'end',
fontSize: 10,
fontFamily: 'Arial',
dx: '-0.25em',
dy: '0.25em'
})}
tickComponent={({ formattedValue, ...tickProps }) => (
<text {...tickProps}>{formattedValue}</text>
)}
/>
<AxisRight
top={margin.top}
left={xMax}
scale={yScale}
hideZero
numTicks={numTicksForHeight(height)}
label="Axis Right Label"
labelProps={{
fill: '#8e205f',
textAnchor: 'middle',
fontSize: 12,
fontFamily: 'Arial'
}}
stroke="#1b1a1e"
tickStroke="#8e205f"
tickLabelProps={(value, index) => ({
fill: '#8e205f',
textAnchor: 'start',
fontSize: 10,
fontFamily: 'Arial',
dx: '0.25em',
dy: '0.25em'
})}
/>
<AxisBottom
top={height - margin.bottom}
left={0}
scale={xScale}
numTicks={numTicksForWidth(width)}
label="Time"
>
{props => {
const tickLabelSize = 10;
const tickRotate = 45;
const tickColor = '#8e205f';
const axisCenter = (props.axisToPoint.x - props.axisFromPoint.x) / 2;
return (
<g className="my-custom-bottom-axis">
{props.ticks.map((tick, i) => {
const tickX = tick.to.x;
const tickY = tick.to.y + tickLabelSize + props.tickLength;
return (
<Group key={`vx-tick-${tick.value}-${i}`} className={'vx-axis-tick'}>
<Line from={tick.from} to={tick.to} stroke={tickColor} />
<text
transform={`translate(${tickX}, ${tickY}) rotate(${tickRotate})`}
fontSize={tickLabelSize}
textAnchor="middle"
fill={tickColor}
>
{tick.formattedValue}
</text>
</Group>
);
})}
<text textAnchor="middle" transform={`translate(${axisCenter}, 50)`} fontSize="8">
{props.label}
</text>
</g>
);
}}
</AxisBottom>
</Group>
</svg>
);
};
Loading