-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Distance between chart legend and the horizontal bar chart is to big in case of rotated labels #2138
Comments
I tried to investigate the For me it looks like a bug in the chart.xAxis.labelRotationAngle = 0.0 calculateLegendOffsets: offsetTop: 0.0 offsetRight: 0.0 offsetBottom: 29.93359375 offsetLeft: 0.0
Before Extra Offset: offsetTop: 0.0 offsetRight: 0.0 offsetBottom: 41.8671875 offsetLeft: 70.0
After Extra Offset: offsetTop: 0.0 offsetRight: 0.0 offsetBottom: 41.8671875 offsetLeft: 70.0
restrainViewPort: offsetTop: 10.0 offsetRight: 10.0 offsetBottom: 41.8671875 offsetLeft: 70.0 chart.xAxis.labelRotationAngle = -45.0 calculateLegendOffsets: offsetTop: 0.0 offsetRight: 0.0 offsetBottom: 63.93359375 offsetLeft: 0.0
Before Extra Offset: offsetTop: 0.0 offsetRight: 0.0 offsetBottom: 75.8671875 offsetLeft: 63.0
After Extra Offset: offsetTop: 0.0 offsetRight: 0.0 offsetBottom: 75.8671875 offsetLeft: 63.0
restrainViewPort: offsetTop: 10.0 offsetRight: 10.0 offsetBottom: 75.8671875 offsetLeft: 63.0 chart.xAxis.labelRotationAngle = -90.0 calculateLegendOffsets: offsetTop: 0.0 offsetRight: 0.0 offsetBottom: 69.93359375 offsetLeft: 0.0
Before Extra Offset: offsetTop: 0.0 offsetRight: 0.0 offsetBottom: 81.8671875 offsetLeft: 29.0
After Extra Offset: offsetTop: 0.0 offsetRight: 0.0 offsetBottom: 81.8671875 offsetLeft: 29.0
restrainViewPort: offsetTop: 10.0 offsetRight: 10.0 offsetBottom: 81.8671875 offsetLeft: 29.0 |
I think the root cause can be found in the function Is there a way to find out if we have a horizontal or vertical chart? What's the difference between BarLineChartViewBase.calculateLegendOffsets() case .horizontal:
print("calculateLegendOffsets->horizontal")
switch _legend.verticalAlignment
{
case .top:
offsetTop += min(_legend.neededHeight, _viewPortHandler.chartHeight * _legend.maxSizePercent) + _legend.yOffset
if xAxis.isEnabled && xAxis.isDrawLabelsEnabled
{
offsetTop += xAxis.labelRotatedHeight
print("calculateLegendOffsets(horizontal,top): offsetTop: \(xAxis.labelRotatedHeight)")
}
case .bottom:
offsetBottom += min(_legend.neededHeight, _viewPortHandler.chartHeight * _legend.maxSizePercent) + _legend.yOffset
if xAxis.isEnabled && xAxis.isDrawLabelsEnabled
{
offsetBottom += xAxis.labelRotatedHeight
print("calculateLegendOffsets(horizontal,bottom): offsetBottom: \(xAxis.labelRotatedHeight)")
}
|
One possible solution can be the following ( if rightAxis.isEnabled && rightAxis.isDrawLabelsEnabled
{
offsetBottom += rightAxis.getRequiredHeightSpace()
} By this modification I get the correct offset values for a horizontal chart. calculateLegendOffsets: offsetTop: 0.0 offsetRight: 0.0 offsetBottom: 29.8671875 offsetLeft: 0.0
Before Extra Offset: offsetTop: 0.0 offsetRight: 0.0 offsetBottom: 41.80078125 offsetLeft: 29.0
After Extra Offset: offsetTop: 0.0 offsetRight: 0.0 offsetBottom: 41.80078125 offsetLeft: 29.0
restrainViewPort: offsetTop: 10.0 offsetRight: 10.0 offsetBottom: 41.80078125 offsetLeft: 29.0 But how do I detect the horizontal chart view in Interim solution: case .bottom:
offsetBottom += min(_legend.neededHeight, _viewPortHandler.chartHeight * _legend.maxSizePercent) + _legend.yOffset
if _xAxisRenderer.isKind(of: XAxisRendererHorizontalBarChart.self) {
if rightAxis.isEnabled && rightAxis.isDrawLabelsEnabled
{
offsetBottom += rightAxis.getRequiredHeightSpace()
print("calculateLegendOffsets(horizintal,bottom): offsetBottom: \(rightAxis.getRequiredHeightSpace())")
}
} else {
if xAxis.isEnabled && xAxis.isDrawLabelsEnabled
{
offsetBottom += xAxis.labelRotatedHeight
print("calculateLegendOffsets(horizintal,bottom): offsetBottom: \(xAxis.labelRotatedHeight)")
}
} |
Thanks @SvenMuc ! Seems you did a lot of work. Mind to file a PR to fix? |
I can do so. But I don't like my solution (see above) very much. Is there a better way to identify whether the xAxis is really the xAxis or the rightAxis @liuxuan30 ? |
I saw some code like |
Filed pull request #2214 |
* 'master' of https://github.com/danielgindi/Charts: Fixed a duplicated assignment compared with obj-c code. (ChartsOrg#3179) Updated README for 3.0.5 (ChartsOrg#3183) Added custom text alignment for noData Fixes the distance issue between the legend and the horizontal bar chart (Fixes ChartsOrg#2138) (ChartsOrg#2214) call setNeedsDisplay() here to trigger render noDataText (ChartsOrg#3198)
…art (Fixes ChartsOrg#2138) (ChartsOrg#2214) * Fixes the distance issue between the legend and the horizontal bar chart (Fixes ChartsOrg#2138) Override the function calculateLegendOffsets in HorizontalBarChartView in order to select the correct axis for distance calculation. In case of horizontal chart the x-axis is described the the rightAxis (bottom) or the leftAxis(top). * Added guard for _legend status
* master: (55 commits) Refactors -[tableView:cellForRowAtIndexPath:] (ChartsOrg#3326) fix ChartsOrg#3311. Need one more key for iOS 11 camera roll saving revert a mistake, fix ChartsOrg#3299 add pie chart unit tests (ChartsOrg#3297) ChartsOrg#3287: align Objc and Swift demos balloon marker update changelog Min and Max reset when clearing ChartDataSet (Fixes ChartsOrg#3260) Restored old performance (ChartsOrg#3216) Support other bundle than main MarkerView.viewFromXib() (ChartsOrg#3215) For ChartsOrg#2840. add dataIndex parameter in `highlightValue()` calls (ChartsOrg#2852) Balloon Marker indicates position of data (ChartsOrg#3181) bump Info.plist version Fixed a duplicated assignment compared with obj-c code. (ChartsOrg#3179) Updated README for 3.0.5 (ChartsOrg#3183) BubbleChart uses correct colour for index now. Added custom text alignment for noData Fixes the distance issue between the legend and the horizontal bar chart (Fixes ChartsOrg#2138) (ChartsOrg#2214) call setNeedsDisplay() here to trigger render noDataText (ChartsOrg#3198) 添加定制TY的Mark 添加修改过的Mark到工程中 ... # Conflicts: # ICXCharts.podspec
I rechecked the issue with Charts 3.0.1. The behavior is the same. See images below.
See also my old issue #1360
The text was updated successfully, but these errors were encountered: