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

docs: create more log axis examples #277

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/components/Axis/Axis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function Axis({
labelStyle,
hidden = false,
tickLabelStyle,
tickLabelFormat = scale === 'time' ? undefined : (value) => String(value),
tickLabelFormat,
hiddenLine = false,
lineStyle,
primaryGridLineStyle,
Expand Down
7 changes: 6 additions & 1 deletion src/components/Axis/LinearAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ interface LinearAxisProps extends AxisChildProps {
}

export default function LinearAxis(props: LinearAxisProps) {
const { position, tickLabelFormat, scale, ...otherProps } = props;
const {
position,
tickLabelFormat = (value) => String(value),
scale,
...otherProps
} = props;

const axisRef = useRef<SVGGElement>(null);

Expand Down
7 changes: 6 additions & 1 deletion src/components/Axis/LogAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ interface LogAxisProps extends AxisChildProps {
}

export default function LinearAxis(props: LogAxisProps) {
const { position, tickLabelFormat, scale, ...otherProps } = props;
const {
position,
scale,
tickLabelFormat = scale.tickFormat(),
...otherProps
} = props;

const axisRef = useRef<SVGGElement>(null);

Expand Down
46 changes: 44 additions & 2 deletions stories/control/logaxis.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,36 @@ const data = [
{ x: 0.01, y: 10000 },
{ x: 0.1, y: 100000 },
];
const dataB = [
{ x: 0.0000000001, y: 10000000000 },
{ x: 0.000000001, y: 1000000000 },
{ x: 0.00000001, y: 100000000 },
{ x: 0.0000001, y: 10000000 },
{ x: 0.000001, y: 1000000 },
{ x: 0.00001, y: 100000 },
{ x: 0.0001, y: 10000 },
{ x: 0.001, y: 1000 },
{ x: 0.01, y: 100 },
{ x: 0.1, y: 10 },
{ x: 1, y: 1 },
{ x: 10, y: 0.1 },
{ x: 100, y: 0.01 },
{ x: 1000, y: 0.001 },
{ x: 10000, y: 0.0001 },
{ x: 100000, y: 0.00001 },
{ x: 1000000, y: 0.000001 },
{ x: 10000000, y: 0.0000001 },
{ x: 100000000, y: 0.00000001 },
{ x: 1000000000, y: 0.000000001 },
{ x: 10000000000, y: 0.0000000001 },
];

const logSeries = (
<LineSeries data={data} lineStyle={{ stroke: '#777' }} xAxis="x" yAxis="y" />
);
const logSeriesB = (
<LineSeries data={dataB} lineStyle={{ stroke: '#777' }} xAxis="x" yAxis="y" />
);

export function AxisLeftLogControl(props: AxisControlProps) {
return (
Expand All @@ -40,7 +66,15 @@ export function AxisLeftLogControl(props: AxisControlProps) {
</Plot>
);
}

export function AxisLeftLogControlB(props: AxisControlProps) {
return (
<Plot {...DEFAULT_PLOT_CONFIG}>
{logSeriesB}
<Axis id="x" position="bottom" label="Label" />
<Axis id="y" position="left" scale="log" {...props} />
</Plot>
);
}
export function AxisBottomLogControl(props: AxisControlProps) {
return (
<Plot {...DEFAULT_PLOT_CONFIG}>
Expand All @@ -50,7 +84,15 @@ export function AxisBottomLogControl(props: AxisControlProps) {
</Plot>
);
}

export function AxisBottomLogControlB(props: AxisControlProps) {
return (
<Plot {...DEFAULT_PLOT_CONFIG}>
{logSeriesB}
<Axis id="x" position="bottom" scale="log" {...props} />
<Axis id="y" position="left" label="Label" />
</Plot>
);
}
export function AxisRightLogControl(props: AxisControlProps) {
return (
<Plot {...DEFAULT_PLOT_CONFIG}>
Expand Down