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

charts enhancement #113

Closed
wants to merge 25 commits into from

Conversation

maelsar
Copy link
Contributor

@maelsar maelsar commented Sep 13, 2023

fixes #97
fixes #74

NOTE: I still have further improvements in the pipeline (add more chart options, formatting, layout), but this should be stable enough for the MVP and for testing by the community in the meantime.
#74

In the meantime, if its alright, I will work on the Price Info component so we can get most of the components ready for the MVP.
17

@netlify
Copy link

netlify bot commented Sep 13, 2023

Deploy Preview for chipper-sunburst-578cfe ready!

Name Link
🔨 Latest commit 8a8160e
🔍 Latest deploy log https://app.netlify.com/sites/chipper-sunburst-578cfe/deploys/650e4ca68322ff00079bc89c
😎 Deploy Preview https://deploy-preview-113--chipper-sunburst-578cfe.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines 106 to 127
//Aysnc Thunk for the update the legend using current candle when site is first loaded
export const fetchCandlesForInitialPeriod = createAsyncThunk(
"priceChart/fetchCandlesForInitialPeriod",
async (_, { dispatch }) => {
const candlesMap = adex.clientState.currentPairCandlesList;
const ohlcvData = convertAlphaDEXData(candlesMap);
if (ohlcvData && ohlcvData.length > 0) {
const latestOHLCVData = ohlcvData[ohlcvData.length - 1];

dispatch(setLegendCandlePrice(latestOHLCVData));
dispatch(setLegendChange(latestOHLCVData));
dispatch(
setLegendPercChange({
currentOpen: latestOHLCVData.open,
currentClose: latestOHLCVData.close,
})
);
dispatch(setLegendCurrentVolume(latestOHLCVData.value));
}
}
);

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to create a separate thunk for that, we are not doing any network requests here or something like this, all the data comes from adex - we need to update every time adex updates (and this is just not the same as triggering it in useEffect (it will most likely work because data variable will be updated more often than anything else, but still it's not the most straightforward way).

I suggest to create updateAdex in priceChartSlice reducers, accept action: PayloadAction<adex.StaticState> as the second param there, and update all the necessary state changes from it, this way we won't miss the updates and we won't need to call fetch... in the component (we already subscribe to the changes of adex state).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i refactored the code not to use a thunk. Important to note this is only meant to initialize the legend only when the page is first loaded or move to a different time selector.
Since the crosshair is functional and updates the legend to the candle pointed, I didn't want the legend to update to the current candle data when a new candle is printed. It might be disruptive if a user is on a 5m timeframe and points to a certain candle.

Copy link
Member

Choose a reason for hiding this comment

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

I don't really get the reason behind initializeLegend, why can't we always show what adex provides? Like you did in priceInfoSlice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@EvgeniiaVak I have tried the approach initialize the data with adex.clientState.currentPairCandlesList (similar to what you mentioned priceInfoSlice). The issue might be with initialization timing, the state is being initialized before the data in adex.clientState.currentPairCandlesList is populated thus making the legends all initially empty when i first load the page.

I purposely wanted to prevent updating the legend when a new candle appears that why i did not go with the approach to update the legend on state change.

@EvgeniiaVak
Copy link
Member

Screenshot 2023-09-15 at 10 37 26

Maybe making this padding smaller?

@maelsar
Copy link
Contributor Author

maelsar commented Sep 15, 2023

Screenshot 2023-09-15 at 10 37 26 Maybe making this padding smaller?

that space doesn't have contain any padding. That is coming from lightweight charts. I am still looking into if there is an option to remove that from the chart for a future PR since I wanted avoid doing something like negative margins.

@maelsar maelsar requested a review from EvgeniiaVak September 15, 2023 09:51
@maelsar
Copy link
Contributor Author

maelsar commented Sep 15, 2023

21

@EvgeniiaVak
Copy link
Member

oh, I there probably was a reason for this padding... now on some screen widths the chart jumps on the page (becomes taller0 when there are lots of digits displayed:
Screenshot 2023-09-18 at 11 22 26
Screenshot 2023-09-18 at 11 22 16

but it definitely looks better without the padding when there are few digits 🤔 maybe we can round up the digits? we have functions for that in utils, but I don't know if this is a place where traders expect precision
@fliebenberg what do you think?

@fliebenberg
Copy link
Contributor

It should be fine to round these numbers. No one should be interested in more than 8 decimals as that is what AlphaDEX works with.
Also, if we are going to be showing the high/low and other stats in the graph, then we do not need the 24h stats above the graph. It is basically giving the same values, although I am not sure how the Trading View values are calculated.

@EvgeniiaVak
Copy link
Member

we do not need the 24h stats above

in the chart we can choose not only 1 day period, it can be something different like 5 minutes, so it's not always duplicating info and I think it's ok to always have the price info also

volumeSeries.setData(
data.map((datum) => ({
...datum,
color: datum.close - datum.open <= 0 ? "#ef5350" : "#26a69a",
Copy link
Member

Choose a reason for hiding this comment

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

These colors should come from css variables. As strings in code they can be represented as hsl(var(--su)) for green, hsl(var(--er)) for red.

Copy link
Member

Choose a reason for hiding this comment

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

When I tried to use the hsl(var(--su)) variables it cause the chart to be black (randomly hit or miss), I suspect it was because the library does some extra steps with the string
image

Copy link
Member

@EvgeniiaVak EvgeniiaVak Oct 3, 2023

Choose a reason for hiding this comment

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

Ok, probably we can import tailwind config object then and take the color from there (I guess only if it goes inside the canvas), we'll need to handle dark/light switching ourselves (but that's after-mvp).

Copy link
Member

Choose a reason for hiding this comment

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

I did find this fiddle that will help with that after the mvp.
https://jsfiddle.net/TradingView/6yLzrbtd/

Comment on lines +41 to +51
background: { color: "#181c27" },
textColor: "#DDD",
},
//MODIFY THEME COLOR HERE
grid: {
vertLines: { color: "#444" },
horzLines: { color: "#444" },
},
timeScale: {
//MODIFY THEME COLOR HERE
borderColor: "#d3d3d4",
Copy link
Member

Choose a reason for hiding this comment

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

These colors probably can also come from the theme settings. You can find what colors we currently have at tailwind.config.js under daisyui objects (only dark theme currently).

Here is the list of color names and variables that you can use - https://daisyui.com/docs/colors/#-2 . Here in the chart settings you can use them as variables (e.g. hsl(var(--b1))). In other places where you style an html element in .tsx you can specify them as classes, e.g. for background bg-base-100 or for text color text-base-100.

Comment on lines +142 to +163
className={`px-[0.5vw] py-[0.5vw] text-sm font-roboto text-#d4e7df hover:bg-white hover:bg-opacity-30 hover:rounded-md ${
candlePeriod === period ? "text-blue-500" : ""
}`}
onClick={() => dispatch(setCandlePeriod(period))}
>
{period}
</button>
))}
</div>
<div className="flex justify-between text-sm font-roboto">
<div className="ml-4">
Open:{" "}
<span
className={isNegativeOrZero ? "text-red-500" : "text-green-500"}
>
{candlePrice?.open}
</span>
</div>
<div>
High:{" "}
<span
className={isNegativeOrZero ? "text-red-500" : "text-green-500"}
Copy link
Member

Choose a reason for hiding this comment

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

Here and below (and you probably can specify {isNegativeOrZero ? ...} one time in the enclosing div (the one with the <div className="flex justify-between) also please use the theme colors to make page look consistent.

Please also remove font-roboto I think it should be set up for the whole app.

Copy link
Member

Choose a reason for hiding this comment

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

I removed the font-roboto and swapped colors where I could in #145

@maelsar
Copy link
Contributor Author

maelsar commented Sep 23, 2023

I think I updated the code when you saw this that why it no longer showed that large spacing between the legend and chart.

24

@EvgeniiaVak
Copy link
Member

I think I updated the code when you saw this that why it no longer showed that large spacing between the legend and chart.

24

That's fine, given that we can shorten them we probably won't have this problem. @maelsar would you like to update this PR with using utils for shorter numbers and other changes I requested above (styling using the theme config, etc.)?

@EvgeniiaVak
Copy link
Member

these commits are included in #145

@EvgeniiaVak EvgeniiaVak closed this Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Price Chart styling Price Chart updates
4 participants