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

Y-Axis as time causes values to be reverted #2306

Closed
nhtoby311 opened this issue Apr 26, 2023 · 9 comments
Closed

Y-Axis as time causes values to be reverted #2306

nhtoby311 opened this issue Apr 26, 2023 · 9 comments
Labels

Comments

@nhtoby311
Copy link

Issue

It seems like having time axis as Yaxis cause the display data to be reversed. I'm using a mock data like this to measure the elapse time data with its corresponding data.

<ResponsiveLine
                enableSlices="x"
                curve="monotoneX"
                lineWidth={3}
                enableGridX={false}
                enableGridY={false}
                enablePoints={false}
                enableCrosshair={false}
                colors={{ scheme: 'blues' }}
                data={[
                    {
                        id: 'fake corp. A',
                        data: [
                            { x: 'Week 1', y: '3:00' },
                            { x: 'Week 2', y: '2:00' },
                            { x: 'Week 3', y: '14:20' },
                            { x: 'Week 4', y: '12:00' },
                            { x: 'Week 5', y: '22:00' },
                            { x: 'Week 6', y: '32:00' },
                            { x: 'Week 7', y: '5:00' },
                        ],
                    },
                ]}
                yScale={{
                    type: 'time',
                    format: '%M:%S',
                    precision: 'second',
                }}
                axisLeft={{
                    format: '%M:%S',
                }}
            />

image

Is there a way to fix this? Or a work around such as revert the Yaxis values, or having y as number represent seconds, then have a method to format it to "MM:SS" in order to display.

@plouc
Copy link
Owner

plouc commented Apr 27, 2023

Unfortunately, a time scale cannot be reversed, using numbers representing seconds might work, but converting the value back would be tedious.

@nhtoby311
Copy link
Author

So is it a bug for type time on yAxis?

Can I use yFormat or other attribute to display as minute value? Or it can only be done inside the code of the package?

@plouc
Copy link
Owner

plouc commented Apr 27, 2023

So is it a bug for type time on yAxis?

I would need to spend more time to properly investigate what's happening.

Can I use yFormat or other attribute to display as minute value? Or it can only be done inside the code of the package?

Yes, but you still need to specify it separately for the axes config.

@nhtoby311
Copy link
Author

Yes, but you still need to specify it separately for the axes config.

Is there an example on how can I do this?

@plouc
Copy link
Owner

plouc commented Apr 27, 2023

No, sorry.

@nhtoby311
Copy link
Author

I tried this workaround and it works for me! The data value is seconds, and I pass through a function to convert it to minute:second format.

const formatTime = (time: number) => {
    return [
        Math.floor((time % 3600) / 60), // minutes
        ('00' + Math.floor(time % 60)).slice(-2), // seconds
    ].join(':')
}

<ResponsiveLine
    margin={{ top: 20, right: 40, bottom: 60, left: 60 }}
    animate={true}
    enableSlices="x"
    curve="monotoneX"
    lineWidth={3}
    theme={theme as any}
    enableGridX={false}
    enableGridY={false}
    enablePoints={false}
    enableCrosshair={false}
    colors={{ scheme: 'blues' }}
    data={[
        {
            id: 'fake corp. A',
            data: [
                { x: 'Week 1', y: 1 },
                { x: 'Week 2', y: 2 },
                { x: 'Week 3', y: 4 },
                { x: 'Week 4', y: 5 },
                { x: 'Week 5', y: 7 },
                { x: 'Week 6', y: 3 },
                { x: 'Week 7', y: 8 },
            ],
        },
    ]}
    axisLeft={{
        format: (value) => `${formatTime(Number(value))}`,
    }}
/>

image

@plouc
Copy link
Owner

plouc commented Apr 27, 2023

I'm glad that you found a workaround.

@stale
Copy link

stale bot commented Aug 7, 2023

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@stale stale bot added the stale label Aug 7, 2023
@stale
Copy link

stale bot commented Sep 17, 2023

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

@stale stale bot closed this as completed Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants