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

How to increase the size of div instead of re rendering audio graph #463

Open
sagharfrancis20 opened this issue Sep 13, 2022 · 5 comments
Open

Comments

@sagharfrancis20
Copy link

I am using Peak,js in my react app. I am also using the backend library for pre-processing the waveform data. The default behavior of zoom functionality re-renders the graph when it reaches to end. What I want to do is I want to increase the size of div instead of re-rendering it.

Currently what I am doing is when I click on the zoom button I increase my parent div width and use the auto-fit property to fully cover the width but that's not giving me a good result. Instead of this, I want to use the zoom functionality with respect to seconds. But this is not working correctly. Still, at some point, it re-renders the canvas.

I want to want to increase the div size not want to re-render the canvas.

@sagharfrancis20
Copy link
Author

sagharfrancis20 commented Sep 13, 2022

zoomLevels: [512, 1024, 2048, 4096]

How much do the above values increase the pixels or percentages in the graph?

Can I use the values other than the above and what is the maximum and minimum range?

@chrisn
Copy link
Member

chrisn commented Sep 13, 2022

How much do the above values increase the pixels or percentages in the graph?

Can I use the values other than the above and what is the maximum and minimum range?

Each value is a number of audio samples per pixel. With the default values you quoted, calling the zoomOut() method will double the amount of audio that is visible.

You can use any values you choose, yes, but only positive integer values are meaningful.

@chrisn
Copy link
Member

chrisn commented Sep 13, 2022

I am using Peak,js in my react app. I am also using the backend library for pre-processing the waveform data. The default behavior of zoom functionality re-renders the graph when it reaches to end. What I want to do is I want to increase the size of div instead of re-rendering it.

Currently what I am doing is when I click on the zoom button I increase my parent div width and use the auto-fit property to fully cover the width but that's not giving me a good result. Instead of this, I want to use the zoom functionality with respect to seconds. But this is not working correctly. Still, at some point, it re-renders the canvas.

I want to want to increase the div size not want to re-render the canvas.

I'm not sure what you mean by re-rendering. If you change the size of the container div, you should call view.fitToContainer() to resize the waveform to fit the div.

You can also use view.setZoom() to fit a given number of seconds in the div width.

@sagharfrancis20
Copy link
Author

How much do the above values increase the pixels or percentages in the graph?
Can I use the values other than the above and what is the maximum and minimum range?

Each value is a number of audio samples per pixel. With the default values you quoted, calling the zoomOut() method will double the amount of audio that is visible.

You can use any values you choose, yes, but only positive integer values are meaningful.

I mean let's suppose I have audio have a 20-sec stream and the div with 600px width on which I am showing the audio waveform and on initial, the zoom value is 256 if I change the value to 512 how much it will decrease the space between seconds [256, 512, 1024, 2048, 4096]

@chrisn
Copy link
Member

chrisn commented Sep 14, 2022

Changing from 256 to 512 will decrease the space by half. You can work out how many pixels for 1 second of audio by calculating sampleRate / zoom, e.g., 44100 / 256 = 172 px.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants