Skip to content

Commit

Permalink
Add min_y and max_y for left and right axes (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: artememelin <[email protected]>
  • Loading branch information
eliza-eliza and artememelin authored May 22, 2024
1 parent 758b262 commit ab484bd
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "LightweightCharts"
uuid = "d6998af1-87ca-4e7f-83d4-864c79a249fa"
version = "1.1.0"
version = "1.2.0"

[deps]
Serde = "db9b398d-9517-45f8-9a95-92af99003e0e"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ panel = lwc_panel(
price_scale_id = LWC_RIGHT,
);
name = "ETHUSDT | Binance Spot",
right_max_y = 8000000,
left_min_y = 1000,
)

lwc_show(panel)
Expand Down
Binary file modified docs/src/assets/panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ panel = lwc_panel(
price_scale_id = LWC_RIGHT,
);
name = "ETHUSDT | Binance Spot",
right_max_y = 8000000,
left_min_y = 1000,
)

lwc_show(panel)
Expand Down
2 changes: 1 addition & 1 deletion frontend/dist/index_boundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/dist/index_boundle.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* TradingView Lightweight Charts™ v4.1.3
* TradingView Lightweight Charts™ v4.1.4
* Copyright (c) 2024 TradingView, Inc.
* Licensed under Apache License 2.0 https://www.apache.org/licenses/LICENSE-2.0
*/
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"lightweight-charts": "^4.1.3",
"lightweight-charts": "^4.1.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^3.0.1",
Expand Down
23 changes: 16 additions & 7 deletions frontend/src/components/chart_panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,25 @@ const ChartPanel = ({ settings, id, setPanels }) => {

charts[chart.id].applyOptions({
autoscaleInfoProvider: (original) => {
const res = original();
if (res !== null) {
if (settings.minY != null) {
res.priceRange.minValue = settings.minY;
const scaleSettings = original();
if (scaleSettings !== null) {
let isLeftPriceScaleId = chart.settings.priceScaleId === "left";
const minYValue = isLeftPriceScaleId
? (settings.leftMinY ?? settings.minY)
: (settings.rightMinY ?? settings.minY);

const maxYValue = isLeftPriceScaleId
? (settings.leftMaxY ?? settings.maxY)
: (settings.rightMaxY ?? settings.maxY);

if (minYValue !== null) {
scaleSettings.priceRange.minValue = minYValue;
}
if (settings.maxY != null) {
res.priceRange.maxValue = settings.maxY;
if (maxYValue !== null) {
scaleSettings.priceRange.maxValue = maxYValue;
}
}
return res;
return scaleSettings;
},
});

Expand Down
18 changes: 17 additions & 1 deletion src/LightweightCharts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ mutable struct LWCPanel <: AbstractChartSettings
y::Int64
name::String
min_y::Union{Real,Nothing}
left_min_y::Union{Real,Nothing}
right_min_y::Union{Real,Nothing}
max_y::Union{Real,Nothing}
left_max_y::Union{Real,Nothing}
right_max_y::Union{Real,Nothing}
seconds_visible::Bool
bar_spacing::Real
min_bar_spacing::Real
Expand All @@ -153,7 +157,11 @@ Creates a panel combining several [`charts`](@ref charts).
| `y::Int64` | `-999` | Panel's vertical coordinates |
| `name::String` |` "LightweightCharts ❤️ Julia"` | Panel name (will be displayed in the browser tab title). |
| `min_y::Union{Real,Nothing}` | `nothing` | Lower bound on the y-axis. |
| `max_y::Union{Real,Nothing}` | `nothing` | Lower bound on the y-axis. |
| `left_min_y::Union{Real,Nothing}` | `nothing` | Lower bound on the left y-axis. |
| `right_min_y::Union{Real,Nothing}` | `nothing` | Lower bound on the right y-axis. |
| `max_y::Union{Real,Nothing}` | `nothing` | Upper bound on the y-axis. |
| `left_max_y::Union{Real,Nothing}` | `nothing` | Upper bound on the left y-axis. |
| `right_max_y::Union{Real,Nothing}` | `nothing` | Upper bound on the right y-axis. |
| `seconds_visible::Bool` | `false` | Seconds visibility on the x-axis. |
| `bar_spacing::Real` | `6` | Distance between the stripes in pixels. |
| `min_bar_spacing::Real` | `0.5` | Minimum distance between the stripes in pixels. |
Expand All @@ -166,7 +174,11 @@ function lwc_panel(
y::Int64 = -999,
name::String = "LightweightCharts ❤️ Julia",
min_y::Union{Real,Nothing} = nothing,
left_min_y::Union{Real,Nothing} = nothing,
right_min_y::Union{Real,Nothing} = nothing,
max_y::Union{Real,Nothing} = nothing,
left_max_y::Union{Real,Nothing} = nothing,
right_max_y::Union{Real,Nothing} = nothing,
seconds_visible::Bool = false,
bar_spacing::Real = 6,
min_bar_spacing::Real = 0.5,
Expand All @@ -178,7 +190,11 @@ function lwc_panel(
y,
name,
min_y,
left_min_y,
right_min_y,
max_y,
left_max_y,
right_max_y,
seconds_visible,
bar_spacing,
min_bar_spacing,
Expand Down

2 comments on commit ab484bd

@gryumov
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

Release notes:

Add min_y and max_y for left and right axes

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/107388

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.2.0 -m "<description of version>" ab484bdb3c46e9a278f4225f027ae88a7966207b
git push origin v1.2.0

Please sign in to comment.