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 all 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
Copy link
Member

Choose a reason for hiding this comment

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

It looks like you need to add the function for upgrading the ChartData2D component.

Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,10 @@ private static int upgradeChartProperties(Map<String, JSONValue> componentProper
// The ExtendDomainToInclude and ExtendRangeToInclude methods were added.
srcCompVersion = 3;
}
if (srcCompVersion < 4) {
// The axesTextColor and dataLabelColor properties were added.
srcCompVersion = 4;
}
return srcCompVersion;
}

Expand Down
7 changes: 5 additions & 2 deletions appinventor/blocklyeditor/src/versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -1853,12 +1853,15 @@ Blockly.Versioning.AllUpgradeMaps =
// AI2: The SetDomain and SetRange methods were added.
2: "noUpgrade",
// AI2: The ExtendDomainToInclude and ExtendRangeToInclude methods were added.
3: "noUpgrade"
3: "noUpgrade",
// AI2: The property axesTextColor and method setAxesTextColor were added.
4: "noUpgrade"

}, // End Chart upgraders

"ChartData2D": {

// - The property dataLabelColor and method setDataLabelColor were added.
2: "noUpgrade"
}, // End ChartData2D upgraders

"ChatBot" : {
Expand Down
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
16 changes: 16 additions & 0 deletions appinventor/components-ios/src/ChartDataBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import DGCharts
var _color: Int32 = AIComponentKit.Color.black.int32
var _colors: [UIColor] = []
var _label: String?

var _dataLabelColor: Int32 = AIComponentKit.Color.black.int32
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to make this conditional on dark theme similar to what you did in Chart.swift?


var dataFileColumns: Array<String> = []
var _lineType = AIComponentKit.LineType.Linear
Expand Down Expand Up @@ -54,6 +56,7 @@ import DGCharts
ElementsFromPairs = elements
}
_chartDataModel?.setColor(argbToColor(_color))
_chartDataModel?.setDataLabelColor(argbToColor(_dataLabelColor))
if !_colors.isEmpty {
_chartDataModel?.setColors(_colors)
}
Expand Down Expand Up @@ -94,6 +97,18 @@ import DGCharts
onDataChange()
}
}

@objc open var DataLabelColor: Int32 {
get {
return _dataLabelColor
}
set {
_dataLabelColor = newValue
_chartDataModel?.dataset?.valueTextColor = argbToColor(newValue)
print("changing data text color", _dataLabelColor)
refreshChart()
}
}

func initChartData() {
print("in initChartData")
Expand All @@ -102,6 +117,7 @@ import DGCharts
// set default values
_chartDataModel?.setColor(argbToColor(_color))
_chartDataModel?.setLabel(_label ?? "")
_chartDataModel?.setDataLabelColor(argbToColor(_dataLabelColor))
}

@objc open var LineType: LineType {
Expand Down
4 changes: 4 additions & 0 deletions appinventor/components-ios/src/ChartDataModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ open class ChartDataModel {
print("got in here")
dataset?.label = text
}

func setDataLabelColor(_ argb: UIColor) {
dataset?.valueTextColor = argb
}

func setElements(_ elements: String) {
let tupleSize = 2
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 @@ -887,9 +887,15 @@ private YaVersion() {
// For CHART_COMPONENT_VERSION 3:
// - The ExtendDomainToInclude and ExtendRangeToInclude methods were added
// - The Type getter block was made visible
public static final int CHART_COMPONENT_VERSION = 3;

public static final int CHART_DATA_2D_COMPONENT_VERSION = 1;
// For CHART_COMPONENT_VERSION 4:
// - The axesTextColor property was added
// - The setAxesTextColor method was added
public static final int CHART_COMPONENT_VERSION = 4;

// For CHART_DATA_2D_COMPONENT_VERSION 2:
// - The dataLabelColor property was added
// - The setDataLabelColor method was added
public static final int CHART_DATA_2D_COMPONENT_VERSION = 2;

// For CHATBOT_COMPONENT_VERSION: Initial Version
// For CHATBOT_COMPONENT_VERSION 2:
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 @@ -29,6 +29,8 @@
import java.util.ArrayList;
import java.util.List;

import com.github.mikephil.charting.data.ChartData;

/**
* Base class for Chart Data components. Contains functionality common
* to any Chart Data component. The component corresponds to a single
Expand All @@ -45,6 +47,8 @@ public abstract class ChartDataBase extends DataCollection<Chart, ChartDataModel
private int color;
private YailList colors;

private int dataLabelColor;

/**
* Creates a new Chart Data component.
*/
Expand All @@ -57,6 +61,8 @@ protected ChartDataBase(Chart chartContainer) {
Color(Component.COLOR_BLACK);
DataSourceKey("");
Label("");

DataLabelColor(Component.COLOR_BLACK);
Copy link
Member

Choose a reason for hiding this comment

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

See my note on the iOS version about whether we need to adjust this for dark theme.

}

/**
Expand Down Expand Up @@ -160,6 +166,31 @@ public void Colors(YailList colors) {
onDataChange();
}

/**
* Returns the data label color as an alpha-red-green-blue integer.
*
* @return background RGB color with alpha
*/
@SimpleProperty(
category = PropertyCategory.APPEARANCE)
public int DataLabelColor() {
return dataLabelColor;
}

/**
* Specifies the data points label 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_BLACK)
@SimpleProperty
public void DataLabelColor(int argb) {
dataLabelColor = argb;
dataModel.setDataLabelColor(argb);
onDataChange();
}

/**
* Returns the label text of the data series.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ public void setColors(List<Integer> colors) {
}
}

/**
* Changes the color of the labels of the data set.
*
* @param argb new color
*/
public void setDataLabelColor(int argb) {
data.setValueTextColor(argb);
}

/**
* Changes the label of the data set.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public void setColor(int argb) {
}
}


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 since this is a whitespace only change.

@Override
public void setColors(List<Integer> colors) {
super.setColors(colors);
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);
}
}
7 changes: 7 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 Expand Up @@ -160,6 +164,9 @@ A ChartData2D component represents a single two-dimensional Data Series in the C
for the y values. If a value here is not specified, default values for the
y values will be generated instead.

{:id="ChartData2D.DataLabelColor" .color} *DataLabelColor*
: Specifies the data points label color as an alpha-red-green-blue integer.

{:id="ChartData2D.DataSourceKey" .text .wo .do} *DataSourceKey*
: Sets the Data Source key identifier for the value to import from the
attached Data Source.
Expand Down