-
Notifications
You must be signed in to change notification settings - Fork 847
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
Add new Bar and Column Series property 'ColorMode' #1272
Conversation
…tive, zero or negative, respectively. Bar Chart - Position data labels right, level or left of bar if positive, zero or negative, respectively.
Hi @paulo-rico, Thank you for the PR. I think there a too many changes in the implementation and I can't follow all of them. Isn't it enough just to modify the PickColor method? Everything else should be the same. |
Hi @akorchev It's not as straight forward. When PickColor returns null, it uses the Series position in it's collection to get the color - I'll take a look at the code and see if it can be cleaned/reduced. (I was of the same thought, initially, that only the PickColor needed adjusting). PS - I don't know what happens to the code when pushed. In Visual Studio Git Changes panel, it shows the changes exactly as I would want to see them. In the Render methods, it showed the Regards Paul IMMEDIATE EDIT - Leave this with me. In talking it through, I think there may be a solution. |
This reverts commit 0729535.
Bar and Column Render methods improved.
My bad on the Render code. It was because of the initial tag This is why I love programming. It's a constant learning curve :) PS I checked the changes through GitHub Desktop before committing and they appeared to be OK. Regards Paul |
I think we can make it better by passing the ColorMode to PickColor itself. This would reduce a lot of checks for ColorMode. Also we should probably rename the enum as ColorMode is too generic. ChartSeriesColorMode is probably better. |
Existing check in Render method `
` In moving the ChartSeriesColorMode check to PickColor, I would also have to also pass in the 'Value' of the data in order to select the appropriate color if PositiveNegative. OK so far. But there would still be a need for the check in the Render method in order to get the className correctly based on the ChartSeriesColorMode. Would you prefer that a new method was implemented to PickColorClass that returns the class name, passing in ChartSeriesColorMode, BaseClass (i.e. 'rz-bar-series rz-series-'), Value and Series Index? If so, would you put this in CartesianSeries alongside PickColor? Regards Paul |
Maybe it would be easier just to extract the index
Then the rest could be:
|
Almost (I do prefer the concise version!). But we need to have a separate variable for the className as it's 'Series' value is not the same as the PickColor index, i.e.
If you're happy with this, I'll make the changes and fire it off EDIT: I'll fire it off anyway. Not that much of a change. |
There seems to be a major change in the rendering implementation too. All items should be in the same |
The same refactoring should be implemented in the Color property - there is some duplication to be removed. |
Ok, I've changed the svg so it all wraps in a tag as per original code and applied the className to the Path object. Not sure what Color property you mean for refactoring.
Is this what you meant? |
I mean |
Sorry @akorchev I may need a bit of a nudge in the right direction here. All I can find for that property in various charts is -
or something similar returning a single value with no logic. I can't find anything that suggests using an index. |
I was mislead by the diff UI. I was referring to this
Basically search for every use of ChartSeriesColorMode. By the way the name of the property should stay ColorMode - only the enum name should be ChartSeriesColorMode. |
Sorry @akorchev Ignore last Push. Not changed refactored code in TooltipStyle code |
Also make sure there are no breaking changes in the rendering. The |
Just seen comment. Ignore commit. The class name needs to be set if there are no custom colors (Fills) set. When this is by series, it is OK that it set before looping through the items as it's the same for all. But with PositiveNegative, its by each data item. What about we set the class in the We could then interrogate that variable and either output a Path with the new class (PositiveNegative) or output a Path without any class definition, as before. |
I don't know. Rendering |
Just going to throw some ideas out there to add to your thought process. The thing with the PositiveNegative view is that the color selection isn't really dynamic. You must have two colors. So, do we have two special properties for this (PositiveColor?, NegativeColor?) or do we insist that there are at least two colors defined in the Fills property when ColorMode = ColorModePositiveNegative? This way, we can ignore any class manipulation and not incorporate breaking changes. I'll give it further thought myself. Regards and stay well Paul |
This sounds better. I have to think a bit more.
Likewise! |
Inspired by this issue - #996, I think there is better, more generic way to achieve this. Instead of dealing with PositiveNegative, we instead set a list of color ranges -
This is a parameter on the Series In the Render methods, we include this in the PickColor call along with Value and ColorMode -
Then the PickColor method becomes -
This accomodates the ability to set the color of a data item to a specific color dependant on it's value. This means all the developer has to do to achieve PositiveNegative is -
Running demo here - radzen.delaci.co.uk This has reduced the changes to Series Render methods to adding the extra parameters to the PickColor call. I'll commit the changes now. I don't know if you can just check this commit against the original files. I've obviously made a lot of changes back and forth. Regards Paul |
I like the idea of color ranges a lot! It seems this makes the ColorMode option obsolete doesn't it? If ColorRanges is set then use it. Otherwise don't. The default value would be |
Excellent! I can make the changes necessary to the existing Pull/Commit chain. There have been a great deal of back and forths with this. Are you able to just see the latest changes against the original file? Or would it be easier for you if I created a fresh fork and made the changes on a fresh copy (there aren't that many changes now, so it's as easy for me either way)? I'll also make the same changes to the StackedBar and StackedColumn series. I can't see that there are any other series that would benefit from FillRange. Paul |
I think making the changes to the current commit chain would suffice. The diff should always compare with the current master branch.
Probably no indeed. Only series that render a single "item" per value need this change. |
… Apply to StackedSeries also.
Radzen.Blazor/CartesianSeries.cs
Outdated
{ | ||
return defaultValue; | ||
var result = colorRange.Where(r => r.Min <= value && r.Max > value).FirstOrDefault<SeriesColorRange>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be r => r.Min <= value && r.Max >= value
to include Max
Radzen.Blazor/CartesianSeries.cs
Outdated
} | ||
else | ||
{ | ||
if (!(colors == null || !colors.Any())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this harder to grok than the older code in the master branch if (colors == null || !colors.Any())
Radzen.Blazor/RadzenBarSeries.razor
Outdated
@@ -24,16 +24,17 @@ | |||
|
|||
var barHeight = BandHeight; | |||
var height = barHeight / barSeries.Count() - padding + padding / barSeries.Count();; | |||
var className = $"rz-bar-series rz-series-{Chart.Series.IndexOf(this)}"; | |||
var className = $"rz-column-series rz-series-{Chart.Series.IndexOf(this)}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be rz-bar-series
Radzen.Blazor/RadzenBarSeries.razor
Outdated
|
||
<Path @key="@path" D="@path" Stroke="@stroke" StrokeWidth="@StrokeWidth" Fill="@fill" LineType="@LineType" Style="@style" /> | ||
<Path class="@className" @key="@path" D="@path" Stroke="@stroke" StrokeWidth="@StrokeWidth" Fill="@fill" LineType="@LineType" Style="@style" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not set the class
of the <path>
.
var fill = PickColor(Items.IndexOf(data), Fills, Fill, FillRange, val); | ||
var stroke = PickColor(Items.IndexOf(data), Strokes, Stroke, StrokeRange, val); | ||
<Path class="@className" @key="@path" D="@path" Stroke="@stroke" StrokeWidth="@StrokeWidth" Fill="@fill" LineType="@LineType" Style="@style" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not set class here as well.
Last things (I promise)!
|
Radzen.Blazor/RadzenBarSeries.razor
Outdated
var radius = Chart.BarOptions.Radius; | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace
|
||
var fill = PickColor(Items.IndexOf(data), Fills, Fill, FillRange, itemValue); | ||
var stroke = PickColor(Items.IndexOf(data), Strokes, Stroke, StrokeRange, itemValue); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace
@@ -26,7 +26,7 @@ public partial class RadzenColumnSeries<TItem> : CartesianSeries<TItem>, IChartC | |||
[Parameter] | |||
public IEnumerable<string> Fills { get; set; } | |||
|
|||
/// <summary> | |||
/// <summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace.
Hi @akorchev A bit of help please, if you will. In VS2022 git panel, the diffs only show the differences from my last commit, so I'm not seeing some of these things you mention. Without starting afresh, is there a way that I can view diffs for my current source against the original source as opposed to my last commit? Cheers Paul |
To be honest I am not sure. IDEs usually show the difference since the last commit which is expected. You would have to constantly squash your commits and compare to master if you want that. I am looking at the "Files changed" tab in Github which shows the final result. |
I've been looking into this, and it appears there is a way to check current source against original source. I'll use this in future if any subsequent updates have taken a few turns/commits. Hopefully save us both some time :) Thanks for your patience @akorchev. Paul |
Don't mention it. Thank you for your cooperation as well! Would you mind creating a demo which shows this feature? You can add it to the column chart demos. |
Ok, I've added it to the 'Radzen Blazor Chart column series' page in RadzenBlazorDemos project. A cursory glance at RadzenExample component suggests that the source code is read from git. That would be why it ran, but 'Edit Source' showed the existing source. |
This property will enable the chart to color the bars by Series (as it is now) or by PositiveNegative, based on whether value is above or below zero.
Demo - razden.delaci.co.uk