Skip to content

Commit

Permalink
fix: serialize data for mini charts
Browse files Browse the repository at this point in the history
  • Loading branch information
vcellu committed Nov 28, 2022
1 parent 592104f commit d36ee76
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public JSONObject toEvent() throws JSONException {
cell.put("rawColIdx", rawColIdx);
cell.put("isNumber", isNumber);
if(miniChart != null) {
cell.put("miniChart", miniChart.toEvent());
cell.put("qMiniChart", miniChart.toEvent());
}
if(indicator != null) {
cell.put("indicator", indicator.toEvent());
Expand Down
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
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 @@ -20,10 +20,14 @@ public qMiniChart(ReadableMap data) {
}

public JSONObject toEvent() throws JSONException {

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

0 comments on commit d36ee76

Please sign in to comment.