From 89695717c2758338940f337949d537795d62cfa3 Mon Sep 17 00:00:00 2001 From: Janrey Licas Date: Mon, 1 Jan 2024 17:41:33 +0800 Subject: [PATCH 01/14] feat(abstract): introduce other 4.1 `PriceScaleOptions` --- lightweight_charts/abstract.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lightweight_charts/abstract.py b/lightweight_charts/abstract.py index d2737f5..ff66e64 100644 --- a/lightweight_charts/abstract.py +++ b/lightweight_charts/abstract.py @@ -2,7 +2,7 @@ import asyncio import os from base64 import b64decode from datetime import datetime -from typing import Union, Literal, List +from typing import Union, Literal, List, Optional import pandas as pd from .table import Table @@ -645,19 +645,25 @@ class Candlestick(SeriesCommon): self.update(bar, _from_tick=True) def price_scale( - self, mode: PRICE_SCALE_MODE = 'normal', align_labels: bool = True, border_visible: bool = False, - border_color: str = None, text_color: str = None, entire_text_only: bool = False, - ticks_visible: bool = False, scale_margin_top: float = 0.2, scale_margin_bottom: float = 0.2): + self, auto_scale: bool = True, mode: PRICE_SCALE_MODE = 'normal', invert_scale: bool = False, + align_labels: bool = True, scale_margin_top: float = 0.2, scale_margin_bottom: float = 0.2, + border_visible: bool = False, border_color: Optional[str] = None, text_color: Optional[str] = None, + entire_text_only: bool = False, visible: bool = True, ticks_visible: bool = False, minimum_width: int = 0 + ): self.run_script(f''' {self.id}.series.priceScale().applyOptions({{ + autoScale: {jbool(auto_scale)} mode: {price_scale_mode(mode)}, + invertScale: {jbool(invert_scale)} alignLabels: {jbool(align_labels)}, + scaleMargins: {{top: {scale_margin_top}, bottom: {scale_margin_bottom}}} borderVisible: {jbool(border_visible)}, {f'borderColor: "{border_color}",' if border_color else ''} {f'textColor: "{text_color}",' if text_color else ''} entireTextOnly: {jbool(entire_text_only)}, + visible: {jbool(visible)}, ticksVisible: {jbool(ticks_visible)}, - scaleMargins: {{top: {scale_margin_top}, bottom: {scale_margin_bottom}}} + minimumWidth: {str(minimum_width)} }})''') def candle_style( From 036af899886047787e99befa10ced5b766988eb7 Mon Sep 17 00:00:00 2001 From: Janrey Licas Date: Mon, 1 Jan 2024 17:44:09 +0800 Subject: [PATCH 02/14] docs(abstract-chart): reflect changes from `Abstract` API --- docs/source/reference/abstract_chart.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/source/reference/abstract_chart.md b/docs/source/reference/abstract_chart.md index 13067d6..da922e1 100644 --- a/docs/source/reference/abstract_chart.md +++ b/docs/source/reference/abstract_chart.md @@ -12,6 +12,10 @@ ___ Sets the initial data for the chart. + self, auto_scale: bool = True, mode: PRICE_SCALE_MODE = 'normal', invert_scale: bool = False, + align_labels: bool = True, scale_margin_top: float = 0.2, scale_margin_bottom: float = 0.2, + border_visible: bool = False, border_color: Optional[str] = None, text_color: Optional[str] = None, + entire_text_only: bool = False, visible: bool = True, ticks_visible: bool = False, minimum_width: int = 0 Columns should be named: : `time | open | high | low | close | volume` @@ -206,7 +210,7 @@ ___ -```{py:method} price_scale(mode: PRICE_SCALE_MODE, align_labels: bool, border_visible: bool, border_color: COLOR, text_color: COLOR, entire_text_only: bool, ticks_visible: bool, scale_margin_top: float, scale_margin_bottom: float) +```{py:method} price_scale(auto_scale: bool = True, mode: PRICE_SCALE_MODE = 'normal', invert_scale: bool = False, align_labels: bool = True, scale_margin_top: float = 0.2, scale_margin_bottom: float = 0.2, border_visible: bool = False, border_color: Optional[str] = None, text_color: Optional[str] = None, entire_text_only: bool = False, visible: bool = True, ticks_visible: bool = False, minimum_width: int = 0) Price scale options for the chart. ``` From be65adfd39bae76fe451c929081dbf71e0279a69 Mon Sep 17 00:00:00 2001 From: Janrey Licas Date: Mon, 1 Jan 2024 20:15:55 +0800 Subject: [PATCH 03/14] init: `.gitignore` for doc files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1446251 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +docs/build/** +docs/source/_ext/** From 75cc4260ac5ca05ca64f4ee0f7b946cc6f0b7cdb Mon Sep 17 00:00:00 2001 From: Janrey Licas Date: Mon, 1 Jan 2024 21:06:33 +0800 Subject: [PATCH 04/14] docs(format): add quote block for consistency --- docs/source/reference/charts.md | 2 +- docs/source/reference/index.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/reference/charts.md b/docs/source/reference/charts.md index a0480c5..0e7adfc 100644 --- a/docs/source/reference/charts.md +++ b/docs/source/reference/charts.md @@ -1,4 +1,4 @@ -# Charts +# `Charts` This page contains a reference to all chart objects that can be used within the library. diff --git a/docs/source/reference/index.md b/docs/source/reference/index.md index c0c38e3..13bd22f 100644 --- a/docs/source/reference/index.md +++ b/docs/source/reference/index.md @@ -19,7 +19,7 @@ tables 2. [`Line`](#Line) 3. [`Histogram`](#Histogram) 3. [`HorizontalLine`](#HorizontalLine) -4. [Charts](#charts) +4. [`Charts`](#charts) 5. [`Events`](./events.md) 6. [`Toolbox`](#ToolBox) -7. [`Table`](#Table) \ No newline at end of file +7. [`Table`](#Table) From 63b8c6bcf34f783525cd2365123ca619391f3299 Mon Sep 17 00:00:00 2001 From: Janrey Licas Date: Tue, 2 Jan 2024 18:10:46 +0800 Subject: [PATCH 05/14] fix(abstract): fix f-string structure --- lightweight_charts/abstract.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lightweight_charts/abstract.py b/lightweight_charts/abstract.py index ff66e64..482f88e 100644 --- a/lightweight_charts/abstract.py +++ b/lightweight_charts/abstract.py @@ -652,18 +652,18 @@ class Candlestick(SeriesCommon): ): self.run_script(f''' {self.id}.series.priceScale().applyOptions({{ - autoScale: {jbool(auto_scale)} + autoScale: {jbool(auto_scale)}, mode: {price_scale_mode(mode)}, - invertScale: {jbool(invert_scale)} + invertScale: {jbool(invert_scale)}, alignLabels: {jbool(align_labels)}, - scaleMargins: {{top: {scale_margin_top}, bottom: {scale_margin_bottom}}} + scaleMargins: {{top: {scale_margin_top}, bottom: {scale_margin_bottom}}}, borderVisible: {jbool(border_visible)}, {f'borderColor: "{border_color}",' if border_color else ''} {f'textColor: "{text_color}",' if text_color else ''} entireTextOnly: {jbool(entire_text_only)}, visible: {jbool(visible)}, ticksVisible: {jbool(ticks_visible)}, - minimumWidth: {str(minimum_width)} + minimumWidth: {minimum_width} }})''') def candle_style( From 2fb842a149a242e2e7b9f1d03c5c7c91a7060082 Mon Sep 17 00:00:00 2001 From: Janrey Licas Date: Tue, 2 Jan 2024 18:11:36 +0800 Subject: [PATCH 06/14] docs(abstract): remove residual --- docs/source/reference/abstract_chart.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/source/reference/abstract_chart.md b/docs/source/reference/abstract_chart.md index da922e1..4faf0fa 100644 --- a/docs/source/reference/abstract_chart.md +++ b/docs/source/reference/abstract_chart.md @@ -12,11 +12,6 @@ ___ Sets the initial data for the chart. - self, auto_scale: bool = True, mode: PRICE_SCALE_MODE = 'normal', invert_scale: bool = False, - align_labels: bool = True, scale_margin_top: float = 0.2, scale_margin_bottom: float = 0.2, - border_visible: bool = False, border_color: Optional[str] = None, text_color: Optional[str] = None, - entire_text_only: bool = False, visible: bool = True, ticks_visible: bool = False, minimum_width: int = 0 - Columns should be named: : `time | open | high | low | close | volume` From 164cbcdf46cc29b454a1afe3931103fe4b5fb384 Mon Sep 17 00:00:00 2001 From: Janrey Licas Date: Tue, 2 Jan 2024 18:38:30 +0800 Subject: [PATCH 07/14] docs(abstract): reflect docs style of `def price_scale` --- docs/source/reference/abstract_chart.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/reference/abstract_chart.md b/docs/source/reference/abstract_chart.md index 4faf0fa..ec441cc 100644 --- a/docs/source/reference/abstract_chart.md +++ b/docs/source/reference/abstract_chart.md @@ -11,7 +11,7 @@ ___ ```{py:method} set(data: pd.DataFrame, render_drawings: bool = False) Sets the initial data for the chart. - +- Columns should be named: : `time | open | high | low | close | volume` @@ -205,7 +205,7 @@ ___ -```{py:method} price_scale(auto_scale: bool = True, mode: PRICE_SCALE_MODE = 'normal', invert_scale: bool = False, align_labels: bool = True, scale_margin_top: float = 0.2, scale_margin_bottom: float = 0.2, border_visible: bool = False, border_color: Optional[str] = None, text_color: Optional[str] = None, entire_text_only: bool = False, visible: bool = True, ticks_visible: bool = False, minimum_width: int = 0) +```{py:method} price_scale(auto_scale: bool, mode: PRICE_SCALE_MODE, invert_scale: bool, align_labels: bool, scale_margin_top: float, scale_margin_bottom: float, border_visible: bool, border_color: COLOR, text_color: COLOR, entire_text_only: bool, visible: bool, ticks_visible: bool, minimum_width: float) Price scale options for the chart. ``` From fb773954fdd1aa44dbb66af992edc78f30060aca Mon Sep 17 00:00:00 2001 From: Janrey Licas Date: Tue, 2 Jan 2024 18:40:28 +0800 Subject: [PATCH 08/14] docs(abstract): remove extra symbols to relect from original --- docs/source/reference/abstract_chart.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/reference/abstract_chart.md b/docs/source/reference/abstract_chart.md index ec441cc..dcca55c 100644 --- a/docs/source/reference/abstract_chart.md +++ b/docs/source/reference/abstract_chart.md @@ -11,7 +11,7 @@ ___ ```{py:method} set(data: pd.DataFrame, render_drawings: bool = False) Sets the initial data for the chart. -- + Columns should be named: : `time | open | high | low | close | volume` From 91ebbdb52930c4938cd925ff98fa6d6d74431aaf Mon Sep 17 00:00:00 2001 From: Janrey Licas Date: Tue, 2 Jan 2024 18:56:40 +0800 Subject: [PATCH 09/14] init(example): `price_scale_options.py` --- .../price_scale_options.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/7_price_scale_options/price_scale_options.py diff --git a/examples/7_price_scale_options/price_scale_options.py b/examples/7_price_scale_options/price_scale_options.py new file mode 100644 index 0000000..19ee85f --- /dev/null +++ b/examples/7_price_scale_options/price_scale_options.py @@ -0,0 +1,25 @@ +import pandas as pd +from lightweight_charts import Chart + +reset_price_scale = lambda chart: chart.price_scale(auto_scale=True) +invert_price_scale = lambda chart: chart.price_scale(invert_scale=True) +mode_idx_to_100 = lambda chart: chart.price_scale(mode='index100') +visible_off = lambda chart: chart.price_scale(visible=False) +disable_aligned_label = lambda chart: chart.price_scale(align_labels = False) +min_width_to_100 = lambda chart: chart.price_scale(minimum_width = 100) + + +if __name__ == "__main__": + df = pd.read_csv(filepath_or_buffer="../1_setting_data/ohlcv.csv") + + chart = Chart() + chart.set(df) + + chart.topbar.button("Auto", "Auto", func=reset_price_scale) + chart.topbar.button("Invert", "Invert", func=invert_price_scale) + chart.topbar.button("Mode to Indexed 100", "Mode to Indexed 100", func=mode_idx_to_100) + chart.topbar.button("Hide Price Scale", "Price Scale", func=visible_off) + chart.topbar.button("Disable Align", "Disable Align", func=disable_aligned_label) + chart.topbar.button("Min Width to 100", "Min Width to 100", func=min_width_to_100) + + chart.show(block=True) From 8aa95905909be1d9c25136647b46f13b8da046f8 Mon Sep 17 00:00:00 2001 From: Janrey Licas Date: Tue, 2 Jan 2024 19:04:57 +0800 Subject: [PATCH 10/14] chore(example): code `format` --- examples/7_price_scale_options/price_scale_options.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/7_price_scale_options/price_scale_options.py b/examples/7_price_scale_options/price_scale_options.py index 19ee85f..9b8ab60 100644 --- a/examples/7_price_scale_options/price_scale_options.py +++ b/examples/7_price_scale_options/price_scale_options.py @@ -3,10 +3,10 @@ from lightweight_charts import Chart reset_price_scale = lambda chart: chart.price_scale(auto_scale=True) invert_price_scale = lambda chart: chart.price_scale(invert_scale=True) -mode_idx_to_100 = lambda chart: chart.price_scale(mode='index100') +mode_idx_to_100 = lambda chart: chart.price_scale(mode="index100") visible_off = lambda chart: chart.price_scale(visible=False) -disable_aligned_label = lambda chart: chart.price_scale(align_labels = False) -min_width_to_100 = lambda chart: chart.price_scale(minimum_width = 100) +disable_aligned_label = lambda chart: chart.price_scale(align_labels=False) +min_width_to_100 = lambda chart: chart.price_scale(minimum_width=100) if __name__ == "__main__": @@ -17,7 +17,9 @@ if __name__ == "__main__": chart.topbar.button("Auto", "Auto", func=reset_price_scale) chart.topbar.button("Invert", "Invert", func=invert_price_scale) - chart.topbar.button("Mode to Indexed 100", "Mode to Indexed 100", func=mode_idx_to_100) + chart.topbar.button( + "Mode to Indexed 100", "Mode to Indexed 100", func=mode_idx_to_100 + ) chart.topbar.button("Hide Price Scale", "Price Scale", func=visible_off) chart.topbar.button("Disable Align", "Disable Align", func=disable_aligned_label) chart.topbar.button("Min Width to 100", "Min Width to 100", func=min_width_to_100) From ff0cbf10a28d1f9bc05e95d9780b0e8afe78c6a2 Mon Sep 17 00:00:00 2001 From: Janrey Licas Date: Sat, 13 Jan 2024 23:30:42 +0800 Subject: [PATCH 11/14] chore(.gitignore): remove `docs/source/_ext/**` entry --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1446251..e35662d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ docs/build/** -docs/source/_ext/** From 3f06e6411aa7e19676a1da4aa0895e071cec66cd Mon Sep 17 00:00:00 2001 From: Janrey Licas Date: Sat, 13 Jan 2024 23:32:01 +0800 Subject: [PATCH 12/14] chore(example): remove `7_price_scale_options` --- .../price_scale_options.py | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100644 examples/7_price_scale_options/price_scale_options.py diff --git a/examples/7_price_scale_options/price_scale_options.py b/examples/7_price_scale_options/price_scale_options.py deleted file mode 100644 index 9b8ab60..0000000 --- a/examples/7_price_scale_options/price_scale_options.py +++ /dev/null @@ -1,27 +0,0 @@ -import pandas as pd -from lightweight_charts import Chart - -reset_price_scale = lambda chart: chart.price_scale(auto_scale=True) -invert_price_scale = lambda chart: chart.price_scale(invert_scale=True) -mode_idx_to_100 = lambda chart: chart.price_scale(mode="index100") -visible_off = lambda chart: chart.price_scale(visible=False) -disable_aligned_label = lambda chart: chart.price_scale(align_labels=False) -min_width_to_100 = lambda chart: chart.price_scale(minimum_width=100) - - -if __name__ == "__main__": - df = pd.read_csv(filepath_or_buffer="../1_setting_data/ohlcv.csv") - - chart = Chart() - chart.set(df) - - chart.topbar.button("Auto", "Auto", func=reset_price_scale) - chart.topbar.button("Invert", "Invert", func=invert_price_scale) - chart.topbar.button( - "Mode to Indexed 100", "Mode to Indexed 100", func=mode_idx_to_100 - ) - chart.topbar.button("Hide Price Scale", "Price Scale", func=visible_off) - chart.topbar.button("Disable Align", "Disable Align", func=disable_aligned_label) - chart.topbar.button("Min Width to 100", "Min Width to 100", func=min_width_to_100) - - chart.show(block=True) From e389be5ea41797eaad43965a419b637977edee41 Mon Sep 17 00:00:00 2001 From: Janrey Licas Date: Sat, 13 Jan 2024 23:35:03 +0800 Subject: [PATCH 13/14] docs(title): removed back ticks from Charts --- docs/source/reference/charts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/reference/charts.md b/docs/source/reference/charts.md index 0e7adfc..a0480c5 100644 --- a/docs/source/reference/charts.md +++ b/docs/source/reference/charts.md @@ -1,4 +1,4 @@ -# `Charts` +# Charts This page contains a reference to all chart objects that can be used within the library. From 223842bd1416df2ea35174729d8e3adf9cc72fe0 Mon Sep 17 00:00:00 2001 From: Janrey Licas Date: Sun, 14 Jan 2024 00:57:28 +0800 Subject: [PATCH 14/14] docs(index): remove back tick from the index --- docs/source/reference/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/reference/index.md b/docs/source/reference/index.md index 13bd22f..364f165 100644 --- a/docs/source/reference/index.md +++ b/docs/source/reference/index.md @@ -19,7 +19,7 @@ tables 2. [`Line`](#Line) 3. [`Histogram`](#Histogram) 3. [`HorizontalLine`](#HorizontalLine) -4. [`Charts`](#charts) +4. [Charts](#charts) 5. [`Events`](./events.md) 6. [`Toolbox`](#ToolBox) 7. [`Table`](#Table)