ChartsOrg / ChartsOrg/Charts

Approach to more flexible value text attribute handling

Open
#94 2 comments 0 reactions 0 assignees View on GitHub
feature
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Amazing library, thanks! The following is half question, half enhancement request:

I'd created a pie chart with both light and dark slice colors. As a result, any one value text color would be fine for some slices but illegible in others. It doesn't appear that one can set different text colors for each value entry, so I cast about for a different solution. Ultimately, I enabled text shadows (behind a light text color) by modifying the PieChartRenderer.swift file's drawValues() method:

```
...
var valueFont = dataSet.valueFont;
var valueTextColor = dataSet.valueTextColor;

// Added the following to create shadow attribute
let valueTextShadow = NSShadow()
valueTextShadow.shadowColor = UIColor.darkGrayColor()
valueTextShadow.shadowOffset = CGSizeMake(1, 2)

// Use the following attributes array in each drawText call
// within the following "for" loop
let valueTextAttributes = [NSFontAttributeName: valueFont, NSForegroundColorAttributeName: valueTextColor, NSShadowAttributeName: valueTextShadow]
```

This works just fine, but obviously isn't generalized for normal use. I'm wondering how best to float this up to a higher level of the API?

It appears that ChartDataSet holds public properties for valueTextColor and valueTextFont. My thinking is to add a property for valueTextAttributes (a dictionary of attributes) and provide methods within the subclasses to set this property for the dataSet. This would require modifying the drawValues() methods of the renderers (per above) to look for this attribute, but would let users set any valid text attributes for the value text labels. It also occurs to me that if ChartDataSet held an array of attribute dictionaries, one could provide different attribute sets for each value, or a single element array to apply attributes across all dataSet values.

I'm wondering if this approach appeals to your sense of direction for the library, or if I should look into something different? I'm happy to work on this in a fork, but didn't want to go off on an irrelevant/duplicate tangent.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.