Skip to content

Features/lightweight charts v5 #524

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tran-thanh-phong
Copy link

No description provided.

@emma-uw
Copy link

emma-uw commented Mar 8, 2025

Thank you for the migration. Maybe add resize and remove methods as well?

def resize_pane(self, pane_index: int, height: int):
        self.run_script(
            f"""
            if ({self.id}.chart.panes().length > {pane_index}) {{
                {self.id}.chart.panes()[{pane_index}].setHeight({height});
            }}
        """
        )

def remove_pane(self, pane_index: int):
   self.run_script(
       f"""
            {self.id}.chart.removePane({pane_index});
       """
   )

Seems like panes need to be in reverse order to autoresize correctly

chart.resize_pane(2, 100)
chart.resize_pane(1, 100)
chart.resize_pane(0, 800)

EDIT:
To keep old watermark functionality (background ticker) it needs to be something like this now

def watermark(self, text: str, font_size: int = 44, color: str = 'rgba(180, 180, 200, 0.5)'):
        """
        Adds a watermark to the chart.
        """
        self.run_script(f'''{self._chart.id}.createWatermark('{text}', {font_size}, '{color}')''')
public watermark: any;

createWatermark(text: string, fontSize: number, color: string) {
        if (!this.watermark) {
            this.watermark = createTextWatermark(this.chart.panes()[0], {
                horzAlign: 'center',
                vertAlign: 'center',
                lines: [{
                    text: text,
                    color: color,
                    fontSize: fontSize,
                }],
            });

            return;
        }

        this.watermark.applyOptions({
            lines: [{
                text: text,
                color: color,
                fontSize: fontSize,
            }]
        });
    }

And for markers

public seriesMarkers: any;

this.seriesMarkers = createSeriesMarkers(this.series, []);
def _update_markers(self):
        self.run_script(f'{self.id}.seriesMarkers.setMarkers({json.dumps(list(self.markers.values()))})')

@HEUDavid
Copy link

Awesome work! I tried lightweight-charts-v5, and it seems that chart.marker(**data) is incompatible.
The entire chart becomes unresponsive, with no clicking or scrolling. Switching back to lightweight-charts resolves the issue.
@tran-thanh-phong

@tran-thanh-phong
Copy link
Author

Awesome work! I tried lightweight-charts-v5, and it seems that chart.marker(**data) is incompatible. The entire chart becomes unresponsive, with no clicking or scrolling. Switching back to lightweight-charts resolves the issue. @tran-thanh-phong

Thank you @HEUDavid for your feedback! Could you also attach error images, so I can better navigate the issue, please?

@tran-thanh-phong
Copy link
Author

_update_markers

Hi @emma-uw, I have just updated the PR followed your comments. Please take a look again, thanks!

@jechaviz
Copy link

is this branch compatilble with latest python version?

@HEUDavid
Copy link

Awesome work! I tried lightweight-charts-v5, and it seems that chart.marker(**data) is incompatible. The entire chart becomes unresponsive, with no clicking or scrolling. Switching back to lightweight-charts resolves the issue. @tran-thanh-phong

Thank you @HEUDavid for your feedback! Could you also attach error images, so I can better navigate the issue, please?

I have tried your latest code branch[features/lightweight-charts-v5], and everything works great. It seems to run smoothly with no apparent bugs.

However, when drawing a vertical line, "No-text" label appears on the time axis. I looked into the code, and it seems to be controlled by the text() function in axis-view.tx, which returns "No-text".

When I draw a custom vertical line, I do not need the label. I have tried using labelVisible, axisLabelVisible, etc., but none of them work. (Apologies, I’m just a backend engineer...)

@tran-thanh-phong
Copy link
Author

is this branch compatilble with latest python version?

I haven't test it with latest python version yet but I works fine on 3.11.6. Let's me also check with the latest one.

@One-sixth
Copy link

@tran-thanh-phong Very useful. I tried it out and it was very smooth. Found a small bug. The legend color is incorrect, everything else is fine.
PixPin_2025-04-01_22-55-33
PixPin_2025-04-01_22-37-23

@debegr92
Copy link

@louisnw01 can we merge this PR? Update to v5 would be really great!

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

Successfully merging this pull request may close these issues.

6 participants