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

Set axes color and added AxesTextColor property #3316

Open
wants to merge 5 commits into
base: ucr
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions appinventor/components-ios/src/AxisChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ open class AxisChartView : ChartView {
(chart as? BarLineChartViewBase)?.leftAxis.granularity = 1
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

We probably don't need an extra blank line.

Copy link
Member

Choose a reason for hiding this comment

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

Please reset this file as mentioned.


// sets whether the X origin should be fixed to 0
public func setXMinimum (zero: Bool) {
Expand Down
22 changes: 21 additions & 1 deletion appinventor/components-ios/src/Chart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ import DGCharts
var _gridEnabled = true
var _labels = [String]()
var _dataComponents: Array<ChartDataBase> = []

var _axesTextColor: UIColor

@objc public override init(_ parent: ComponentContainer) {
XFromZero = false
YFromZero = false
_backgroundColor = parent.form?.isDarkTheme == true ? UIColor.black : UIColor.white
_backgroundColor = parent.form?.isDarkTheme == true ? UIColor.white : UIColor.black
_axesTextColor = parent.form?.isDarkTheme == true ? UIColor.white : UIColor.black
super.init(parent)
setDelegate(self)
parent.add(self)
Expand Down Expand Up @@ -112,6 +115,21 @@ import DGCharts
_chartView?.backgroundColor = _backgroundColor
}
}

@objc open var AxesTextColor: Int32 {
get {
return colorToArgb(_axesTextColor)
}
set {
_axesTextColor = argbToColor(newValue)
Copy link
Member

Choose a reason for hiding this comment

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

Make sure to appropriately handle if newValue is COLOR_DEFAULT, which itself is a 0-alpha value that would otherwise make the text invisible.

print("changing label color to")
print(_axesTextColor)
if let chartView = _chartView?.chart as? BarLineChartViewBase {
chartView.xAxisRenderer.axis.labelTextColor = _axesTextColor
chartView.leftYAxisRenderer.axis.labelTextColor = _axesTextColor
}
}
}

@objc open var Description: String {
get {
Expand Down Expand Up @@ -287,6 +305,8 @@ import DGCharts
Labels = _labels
LegendEnabled = _legendEnabled
PieRadius = _pieRadius

AxesTextColor = colorToArgb(_axesTextColor)
}

func addDataComponent(_ dataComponent: ChartDataBase) {
Expand Down
4 changes: 2 additions & 2 deletions appinventor/components-ios/src/TinyDB.swift
Copy link
Member

Choose a reason for hiding this comment

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

We will need to reset this since the change is already in ucr.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ open class TinyDB: NonvisibleComponent {

fileprivate var _database: Connection!
fileprivate var _table = Table("TinyDB1")
fileprivate let _key = Expression<String>("_key")
fileprivate let _value = Expression<String>("_value")
fileprivate let _key = SQLite.Expression<String>("_key")
fileprivate let _value = SQLite.Expression<String>("_value")
private var _namespace = "TinyDB1"

public override init(_ parent: ComponentContainer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class Chart extends AndroidViewComponent
private boolean zeroY;
private YailList labels;

private int axesTextColor;

// Synced tick value across all Data Series (used for real-time entries)
// Start the value from 1 (in contrast to starting from 0 as in Chart
// Data Base) to lessen off-by-one offsets for multiple Chart Data Series.
Expand Down Expand Up @@ -104,6 +106,8 @@ public Chart(ComponentContainer container) {
XFromZero(false);
YFromZero(false);

AxesTextColor(Component.COLOR_DEFAULT);

// Register onInitialize event of the Chart
$form().registerForOnInitialize(this);
}
Expand Down Expand Up @@ -234,6 +238,8 @@ private void reinitializeChart() {
LegendEnabled(legendEnabled);
GridEnabled(gridEnabled);
Labels(labels);

AxesTextColor(axesTextColor);
}

/**
Expand Down Expand Up @@ -289,6 +295,37 @@ public void BackgroundColor(int argb) {
chartView.setBackgroundColor(argb);
}

/**
* Returns the chart's axes text color as an alpha-red-green-blue
* integer.
*
* @return axes text RGB color with alpha
*/
@SimpleProperty(
category = PropertyCategory.APPEARANCE)
public int AxesTextColor() {
return axesTextColor;
}

/**
* Specifies the chart's axes text color as an alpha-red-green-blue
* integer.
*
* @param argb background RGB color with alpha
*/
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_COLOR,
defaultValue = Component.DEFAULT_VALUE_COLOR_DEFAULT)
@SimpleProperty
public void AxesTextColor(int argb) {
if (argb == Component.COLOR_DEFAULT) {
argb = $form().isDarkTheme() ? Component.COLOR_BLACK : Component.COLOR_WHITE;
}
axesTextColor = argb;
if (chartView instanceof PointChartView){
((PointChartView) chartView).setAxesTextColor(argb);
}
}

/**
* Sets the Pie Radius of the Chart. If the current type is
* not the Pie Chart, the value has no effect.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.data.BarLineScatterCandleBubbleData;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.renderer.XAxisRenderer;
import com.github.mikephil.charting.renderer.YAxisRenderer;

import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;

Expand Down Expand Up @@ -51,4 +53,14 @@ protected void initializeDefaultSettings() {
public View getView() {
return chart;
}
/**
Copy link
Member

Choose a reason for hiding this comment

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

Code style: Include a blank line before the Javadoc to visually separate it from the previous function body.

* Sets the color of the axes text of the Point Chart.
*
* @param color color to set text to.
*/
public void setAxesTextColor(int color){
System.out.println("the color is" + color);
XAxisRenderer xAxisRenderer = chart.getRendererXAxis();
xAxisRenderer.getPaintAxisLabels().setColor(color);
}
}
4 changes: 4 additions & 0 deletions appinventor/docs/markdown/reference/components/charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ The Chart component plots data originating from it's attached Data components. F

{:.properties}

{:id="Chart.AxesTextColor" .color} *AxesTextColor*
: Specifies the chart's axes text color as an alpha-red-green-blue
integer.

{:id="Chart.BackgroundColor" .color} *BackgroundColor*
: Specifies the chart's background color as an alpha-red-green-blue
integer.
Expand Down