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

fix(md-3857): android minichart expose #147

Merged
merged 4 commits into from
Nov 28, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ private void setupUrl() {
String qText = value.get("qText");
urlLabel = qText != null ? qText : "";
} else {
urlLabel = column.representation.urlPosition.equals("dimension") ? (column.representation.linkUrl != null ? column.representation.linkUrl : "") : (cell.qText != null ? cell.qText : "");
if(column.representation.urlPosition != null) {
urlLabel = column.representation.urlPosition.equals("dimension") ? (column.representation.linkUrl != null ? column.representation.linkUrl : "") : (cell.qText != null ? cell.qText : "");
} else {
urlLabel = cell.qText == null ? "" : cell.qText;
}
}
String urlText = cell.qText;
int attrIndex = column.stylingInfo.indexOf("url");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DataCell {
boolean isDim = false;
int rawRowIdx;
int rawColIdx;
boolean isNumber;
boolean isNumber = false;
qMiniChart miniChart;
Indicator indicator;
int cellForegroundColor;
Expand All @@ -45,8 +45,10 @@ public DataCell(ReadableMap source, DataColumn column) {
columnIndex = column.columnIndex;
rawRowIdx = source.getInt("rawRowIdx");
rawColIdx = source.getInt("rawColIdx");
ReadableType qNumType = source.getType("qNum");
isNumber = qNumType == ReadableType.Number;
if(source.hasKey("qNum")) {
ReadableType qNumType = source.getType("qNum");
isNumber = qNumType == ReadableType.Number;
}
if (source.hasKey("isDim")) {
isDim = source.getBoolean("isDim");
}
Expand Down Expand Up @@ -101,8 +103,12 @@ public JSONObject toEvent() throws JSONException {
cell.put("rawRowIdx", rawRowIdx);
cell.put("rawColIdx", rawColIdx);
cell.put("isNumber", isNumber);
cell.put("miniChart", miniChart);
cell.put("indicator", indicator);
if(miniChart != null) {
cell.put("qMiniChart", miniChart.toEvent());
}
if(indicator != null) {
cell.put("indicator", indicator.toEvent());
}

return cell;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public class DataColumn {
public DataColumn(ReadableMap source, int index) {
ReadableMap representationMap = source.getMap("representation");
representation = new Representation(representationMap);
stylingInfo = source.getArray("stylingInfo").toArrayList();
if(source.hasKey("stylingInfo")) {
stylingInfo = source.getArray("stylingInfo").toArrayList();
}
align = source.getString("align");
isDim = source.getBoolean("isDim");
label = source.getString("label");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public static void sendOnHeaderTapped(View contextView, DataColumn column) {
WritableMap event = Arguments.createMap();
try {
String columnJSONString = column.toEvent().toString();
Log.d("foo", columnJSONString);
event.putString("column", columnJSONString);
EventUtils.sendEventToJSFromView(contextView, "onHeaderPressed", event);
} catch (JSONException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import com.facebook.react.bridge.ReadableMap;

import org.json.JSONException;
import org.json.JSONObject;

public class Indicator {
boolean applySegmentColors = false;
int color = Color.BLACK;
Expand All @@ -28,6 +31,15 @@ private void parseColor(ReadableMap data) {
getIcon(data);
}

public JSONObject toEvent() throws JSONException {
JSONObject json = new JSONObject();
json.put("applySegmentColors", applySegmentColors);
json.put("showTextValues", showTextValues);
json.put("position", position);
json.put("index", index);
return json;
}

private void getIcon(ReadableMap data) {
if (data.hasKey("icon")) {
hasIcon = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import com.facebook.react.bridge.ReadableMap;

import org.json.JSONException;
import org.json.JSONObject;

public class MiniChartInfo {
public String type;
public Boolean showDots;
Expand All @@ -17,6 +20,13 @@ public YAxis(ReadableMap data) {
position = data.hasKey("position") ? data.getString("position") : "";
scale = data.hasKey("scale") ? data.getString("scale") : "";
}

public JSONObject toEvent() throws JSONException {
JSONObject json = new JSONObject();
json.put("position", position);
json.put("scale", scale);
return json;
}
}

class MiniChartColor {
Expand All @@ -32,6 +42,14 @@ public MiniChartColor(ReadableMap data) {
valid = true;
}
}

public JSONObject toEvent() throws JSONException {
JSONObject json = new JSONObject();
json.put("index", index);
json.put("color", colorValue);
json.put("valid", valid);
return json;
}
}

class ChartColors {
Expand Down Expand Up @@ -59,6 +77,19 @@ public void resetChartColors(ReadableMap data) {
positive = getMiniChartColor("positive", data);
main = getMiniChartColor("main", data);
}

public JSONObject toEvent() throws JSONException {
JSONObject json = new JSONObject();
json.put("first", first.toEvent());
json.put("last", last.toEvent());
json.put("min", min.toEvent());
json.put("max", max.toEvent());
json.put("negative", negative.toEvent());
json.put("positive", positive.toEvent());
json.put("main", main.toEvent());

return json;
}
}

MiniChartInfo(ReadableMap data) {
Expand All @@ -67,4 +98,13 @@ public void resetChartColors(ReadableMap data) {
yAxis = data.hasKey("yAxis") ? new YAxis(data.getMap("yAxis")) : null;
colors = data.hasKey("colors") ? new ChartColors(data.getMap("colors")) : null;
}

public JSONObject toEvent() throws JSONException {
JSONObject json = new JSONObject();
json.put("type", type);
json.put("showDots", showDots);
json.put("yAxis", yAxis.toEvent());
json.put("colors", colors.toEvent());
return json;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class MiniChartView extends View implements Content {
Rect bounds = new Rect();
Paint paint = new Paint();
DataCell dataCell = null;
DataColumn dataColumn = null;
MiniChartRenderer miniChartRenderer = null;

public MiniChartView(Context context) {
Expand All @@ -28,6 +29,8 @@ public MiniChartView(Context context) {
}

public void setData(DataCell cell, DataColumn column) {
this.dataCell = cell;
this.dataColumn = column;
if(miniChartRenderer == null) {
if (cell.miniChart != null && column.representation != null) {
if (column.representation.miniChart != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.qliktrialreactnativestraighttable;

import android.annotation.SuppressLint;
import android.os.Build;
import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.annotations.ReactProp;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MiniChartViewManager extends SimpleViewManager<View> {
public static final String REACT_CLASS = "MiniChartView";
public ReadableMap column = null;
public ReadableMap cell = null;
@Override
@NonNull
public String getName() {
return REACT_CLASS;
}

@SuppressLint("NewApi")
@Override
@NonNull
public View createViewInstance(ThemedReactContext reactContext) {
MiniChartView miniChartView = new MiniChartView(reactContext);
return miniChartView;
}

@ReactProp(name = "colData")
public void setCol(View view, ReadableMap col) {
MiniChartView miniChartView = (MiniChartView) view;
column = col;

if (cell != null) {
setupMiniChart(miniChartView);
}
}

@ReactProp(name = "rowData")
public void setCell(View view, ReadableMap cell) {
MiniChartView miniChartView = (MiniChartView) view;
this.cell = cell;

if (column != null) {
setupMiniChart(miniChartView);
}
}

public void setupMiniChart(MiniChartView miniChartView) {
DataColumn dataColumn = new DataColumn(column, 0);
DataCell dataCell = new DataCell(cell, dataColumn);

miniChartView.setData(dataCell, dataColumn);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public List<NativeModule> createNativeModules(ReactApplicationContext reactConte

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Arrays.<ViewManager>asList(new ReactNativeStraightTableViewManager());
return Arrays.<ViewManager>asList(new ReactNativeStraightTableViewManager(), new MiniChartViewManager());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.qliktrialreactnativestraighttable;

import android.util.Log;

import com.facebook.react.bridge.ReadableMap;

import org.json.JSONException;
Expand Down Expand Up @@ -44,7 +46,9 @@ public JSONObject toEvent() throws JSONException {
column.put("urlPosition", urlPosition);
column.put("globalMax", globalMax);
column.put("globalMin", globalMin);
column.put("miniChart", miniChart);
if(miniChart != null) {
column.put("miniChart", miniChart.toEvent());
}

return column;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void setData(DataRow dataRow, int rowHeight, CellContentStyle cellContent
} else if(column.representation.type.equals("miniChart")) {
LinearLayout.LayoutParams cellViewLayoutParams = new LinearLayout.LayoutParams(column.width, ViewGroup.LayoutParams.MATCH_PARENT);
cellView.setLayoutParams(cellViewLayoutParams);

cellView.setData(cell, dataRow, column);
cellView.convertCellContentType("miniChart", column);
MiniChartView miniChartView = (MiniChartView) cellView.content;
miniChartView.setData(cell, column);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableType;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -13,7 +17,7 @@ public class qMatrix {
class qMatrixColumn {
public double qElemNumber;
public double qNum = 0.0;
public String qText;
public String qText = null;
public qMatrixColumn(ReadableMap data) {
qElemNumber = data.hasKey("qElemNumber") ? data.getDouble("qElemNumber") : 0.0;
if(data.hasKey("qNum")) {
Expand All @@ -24,6 +28,16 @@ public qMatrixColumn(ReadableMap data) {
}
qText = data.hasKey("qText") ? data.getString("qText") : "";
}

JSONObject toEvent() throws JSONException {
JSONObject object = new JSONObject();
object.put("qElemenNumber", qElemNumber);
object.put("qNum", qNum);
if(qText != null){
object.put("qText", qText);
}
return object;
}
}

class qMatrixRow {
Expand All @@ -33,6 +47,13 @@ public qMatrixRow(ReadableArray dataArray) {
columns.add(new qMatrixColumn(dataArray.getMap(i)));
}
}
JSONArray toEvent() throws JSONException {
JSONArray jsonArray = new JSONArray();
for(qMatrixColumn column : columns) {
jsonArray.put(column.toEvent());
}
return jsonArray;
}
}

public qMatrix(ReadableArray dataArray) {
Expand All @@ -42,4 +63,12 @@ public qMatrix(ReadableArray dataArray) {
}
}

JSONArray toEvent() throws JSONException{
JSONArray jsonArray = new JSONArray();
for(qMatrixRow row : rows) {
jsonArray.put(row.toEvent());
}
return jsonArray;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;

import org.json.JSONException;
import org.json.JSONObject;

public class qMiniChart {
public double qMin;
public double qMax;
Expand All @@ -15,4 +18,16 @@ public qMiniChart(ReadableMap data) {
matrix = new qMatrix(dataArray);
}
}

public JSONObject toEvent() throws JSONException {

JSONObject json = new JSONObject();
json.put("qMin", qMin);
json.put("qMax", qMax);
if(matrix != null) {
String foo = matrix.toEvent().toString();
json.put("qMatrix", matrix.toEvent());
}
return json;
}
}