Skip to content

Commit

Permalink
Color options for each data point (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Stas Gryumov <[email protected]>
Co-authored-by: artememelin <[email protected]>
  • Loading branch information
3 people authored May 18, 2024
1 parent 4afd246 commit 758b262
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 54 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.0.1"
version = "1.1.0"

[deps]
Serde = "db9b398d-9517-45f8-9a95-92af99003e0e"
Expand Down
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,26 @@ panel = lwc_panel(
map(
x -> LWCCandle(x.openTime, x.openPrice, x.highPrice, x.lowPrice, x.closePrice),
ohlc.result,
),
);
label_name = "lwc_candlestick",
up_color = "#52a49a",
down_color = "#de5e57",
border_visible = false,
price_scale_id = LWC_LEFT,
),
lwc_histogram(
map(x -> x.openTime, ohlc.result),
map(x -> x.volume, ohlc.result);
map(
x -> LWCSimpleChartData(
x.openTime,
x.volume,
color = x.openPrice > x.closePrice ? "#de5e5780" : "#52a49a80",
),
ohlc.result,
);
label_name = "lwc_histogram",
base = -100.0,
color = "rgba(47, 112, 181, 0.5)",
base = 0.0,
price_scale_id = LWC_RIGHT,
),
);
name = "ETHUSDT | Binance Spot",
)

Expand All @@ -106,11 +111,11 @@ layout = lwc_layout(
lwc_panel(
lwc_area(
NanoDate("2024-01-01") .+ Second.(1:500),
map(x -> rand(1:500), collect(1:500)),
map(x -> rand(1:500), collect(1:500));
label_name = "lwc_area",
line_color = "#49c7e3",
top_color = "#74d7ed",
bottom_color = "rgba(133, 242, 240, 0)",
bottom_color = "#85f2f000",
line_style = LWC_SOLID,
line_type = LWC_STEP,
line_width = 2,
Expand All @@ -126,7 +131,7 @@ layout = lwc_layout(
line_type = LWC_SIMPLE,
line_width = 3,
price_scale_id = LWC_RIGHT,
),
);
x = 1,
y = 1,
),
Expand All @@ -141,10 +146,10 @@ layout = lwc_layout(
line_width = 3,
precision = 4,
price_scale_id = LWC_RIGHT,
),
);
x = 2,
y = 1,
),
);
name = "LightweightCharts ❤️ Julia"
)

Expand Down Expand Up @@ -182,7 +187,7 @@ chart = lwc_panel(
line_color = "#cb3c33",
point_markers_visible = true,
line_visible = false,
),
);
max_y = 1.6
)

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.
29 changes: 17 additions & 12 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,26 @@ panel = lwc_panel(
map(
x -> LWCCandle(x.openTime, x.openPrice, x.highPrice, x.lowPrice, x.closePrice),
ohlc.result,
),
);
label_name = "lwc_candlestick",
up_color = "#52a49a",
down_color = "#de5e57",
border_visible = false,
price_scale_id = LWC_LEFT,
),
lwc_histogram(
map(x -> x.openTime, ohlc.result),
map(x -> x.volume, ohlc.result);
map(
x -> LWCSimpleChartData(
x.openTime,
x.volume,
color = x.openPrice > x.closePrice ? "#de5e5780" : "#52a49a80",
),
ohlc.result,
);
label_name = "lwc_histogram",
base = -100.0,
color = "rgba(47, 112, 181, 0.5)",
base = 0.0,
price_scale_id = LWC_RIGHT,
),
);
name = "ETHUSDT | Binance Spot",
)

Expand All @@ -96,11 +101,11 @@ layout = lwc_layout(
lwc_panel(
lwc_area(
NanoDate("2024-01-01") .+ Second.(1:500),
map(x -> rand(1:500), collect(1:500)),
map(x -> rand(1:500), collect(1:500));
label_name = "lwc_area",
line_color = "#49c7e3",
top_color = "#74d7ed",
bottom_color = "rgba(133, 242, 240, 0)",
bottom_color = "#85f2f000",
line_style = LWC_SOLID,
line_type = LWC_STEP,
line_width = 2,
Expand All @@ -116,7 +121,7 @@ layout = lwc_layout(
line_type = LWC_SIMPLE,
line_width = 3,
price_scale_id = LWC_RIGHT,
),
);
x = 1,
y = 1,
),
Expand All @@ -131,10 +136,10 @@ layout = lwc_layout(
line_width = 3,
precision = 4,
price_scale_id = LWC_RIGHT,
),
);
x = 2,
y = 1,
),
);
name = "LightweightCharts ❤️ Julia"
)

Expand Down Expand Up @@ -172,7 +177,7 @@ chart = lwc_panel(
line_color = "#cb3c33",
point_markers_visible = true,
line_visible = false,
),
);
max_y = 1.6
)

Expand Down
43 changes: 43 additions & 0 deletions docs/src/pages/charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,46 @@ nothing # hide
```@raw html
<iframe src="../bar_example.html" style="height:500px;width:100%;"></iframe>
```

## Multi-colors

```@docs
LWCSimpleChartData
```

### Example

```@example
using Dates
using LightweightCharts
import LightweightCharts: randcolor
t_range = 1:500
chart = lwc_baseline(
map(
x -> LWCSimpleChartData(
now() + Second(x),
cos.(x / 10);
color = randcolor(),
top_line_color = randcolor(),
top_fill_color_1 = randcolor(),
bottom_line_color = randcolor(),
bottom_fill_color_2 = randcolor(),
),
t_range,
);
label_name = "lwc_baseline",
line_type = LWC_STEP,
price_scale_id = LWC_RIGHT,
line_width = 4,
)
lwc_save("colors_example.html", chart)
nothing # hide
```

```@raw html
<iframe src="../colors_example.html" style="height:500px;width:100%;"></iframe>
```

4 changes: 2 additions & 2 deletions docs/src/pages/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ layout = lwc_layout(
line_width = 3,
precision = 4,
price_scale_id = LWC_RIGHT,
),
);
x = 1,
y = 1,
),
Expand All @@ -102,7 +102,7 @@ layout = lwc_layout(
line_type = LWC_SIMPLE,
line_width = 3,
price_scale_id = LWC_RIGHT,
),
);
x = 1,
y = 2,
);
Expand Down
5 changes: 5 additions & 0 deletions src/LightweightCharts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,14 @@ function Base.propertynames(h::AbstractChartSettings)
return to_camelcase.(n)
end

function Serde.SerJson.ser_name(::Type{A}, ::Val{T}) where {A<:AbstractChartData,T}
return to_camelcase(T)
end

function Serde.SerJson.ser_name(::Type{A}, ::Val{T}) where {A<:AbstractChartSettings,T}
return to_camelcase(T)
end

function Serde.SerJson.ser_name(::Type{A}, ::Val{T}) where {A<:AbstractPluginSettings,T}
return to_camelcase(T)
end
Expand Down
Loading

2 comments on commit 758b262

@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()

@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/107143

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

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.1.0 -m "<description of version>" 758b262b835dd9b95799cf26f6bfb3542d266a60
git push origin v1.1.0

Please sign in to comment.