-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: barchart * feat: dot chart * feat: pos/neg chart * fix: send events from proper context Co-authored-by: Vittorio Cellucci <[email protected]>
- Loading branch information
Showing
21 changed files
with
535 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
android/src/main/java/com/qliktrialreactnativestraighttable/MiniBarChartRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.qliktrialreactnativestraighttable; | ||
|
||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.graphics.Rect; | ||
|
||
public class MiniBarChartRenderer extends MiniChartRenderer { | ||
|
||
Rect bar = new Rect(); | ||
|
||
public MiniBarChartRenderer(qMiniChart chartData, Representation representation) { | ||
super(chartData, representation); | ||
} | ||
|
||
@Override | ||
public void render(Canvas canvas) { | ||
float x = padding + (horizontalPadding / 2.0f); | ||
paint.setColor(miniChartInfo.colors.main.color); | ||
for(int i = 0; i < miniChartData.matrix.rows.size(); i++) { | ||
float value = (float) miniChartData.matrix.rows.get(i).columns.get(1).qNum; | ||
float height = value * scale; | ||
float y = xAxis - height ; | ||
float b = xAxis; | ||
setColor(i, value, miniChartData.matrix.rows.size()); | ||
canvas.drawRect(x, y, x + bandwidth, b, paint); | ||
x += padding * 2.0f + bandwidth; | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.qliktrialreactnativestraighttable; | ||
|
||
import android.graphics.Color; | ||
|
||
import com.facebook.react.bridge.ReadableMap; | ||
|
||
public class MiniChartInfo { | ||
public String type; | ||
public Boolean showDots; | ||
public YAxis yAxis; | ||
public ChartColors colors; | ||
|
||
class YAxis { | ||
public String position; | ||
public String scale; | ||
public YAxis(ReadableMap data) { | ||
position = data.hasKey("position") ? data.getString("position") : ""; | ||
scale = data.hasKey("scale") ? data.getString("scale") : ""; | ||
} | ||
} | ||
|
||
class MiniChartColor { | ||
public String colorValue; | ||
public int index; | ||
int color; | ||
boolean valid = false; | ||
public MiniChartColor(ReadableMap data) { | ||
colorValue = data.hasKey("color") ? data.getString("color") : "none"; | ||
index = data.hasKey("index") ? data.getInt("index") : 0; | ||
if(!colorValue.equals("none")) { | ||
color = Color.parseColor(colorValue); | ||
valid = true; | ||
} | ||
} | ||
} | ||
|
||
class ChartColors { | ||
public MiniChartColor first; | ||
public MiniChartColor last; | ||
public MiniChartColor min; | ||
public MiniChartColor max; | ||
public MiniChartColor negative; | ||
public MiniChartColor positive; | ||
public MiniChartColor main; | ||
public ChartColors(ReadableMap data) { | ||
first = getMiniChartColor("first", data); | ||
last = getMiniChartColor("last", data); | ||
min = getMiniChartColor("min", data); | ||
max = getMiniChartColor("max", data); | ||
negative = getMiniChartColor("negative", data); | ||
positive = getMiniChartColor("positive", data); | ||
main = getMiniChartColor("main", data); | ||
} | ||
|
||
MiniChartColor getMiniChartColor(String name, ReadableMap data) { | ||
return data.hasKey(name) ? new MiniChartColor(data.getMap(name)) : null; | ||
} | ||
} | ||
|
||
MiniChartInfo(ReadableMap data) { | ||
type = data.hasKey("type") ? data.getString("type") : ""; | ||
showDots = data.hasKey("showDots") ? data.getBoolean("showDots") : false; | ||
yAxis = data.hasKey("yAxis") ? new YAxis(data.getMap("yAxis")) : null; | ||
colors = data.hasKey("colors") ? new ChartColors(data.getMap("colors")) : null; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.qliktrialreactnativestraighttable; | ||
|
||
import android.graphics.Canvas; | ||
import android.graphics.Color; | ||
import android.graphics.Paint; | ||
import android.graphics.Rect; | ||
|
||
public class MiniChartRenderer { | ||
qMiniChart miniChartData = null; | ||
MiniChartInfo miniChartInfo = null; | ||
Representation representation = null; | ||
Rect bounds = new Rect(); | ||
Paint paint = new Paint(); | ||
float horizontalPadding = 20.0f; | ||
float verticalPadding = 8.0f; | ||
float bandwidth = 0.0f; | ||
float padding = 0.0f; | ||
float scale = 0.0f; | ||
float yScale = 1.0f; | ||
float xAxis = 0.0f; | ||
|
||
public MiniChartRenderer(qMiniChart chartData, Representation representation ) { | ||
this.representation = representation; | ||
miniChartData = chartData; | ||
miniChartInfo = representation.miniChart; | ||
paint.setColor(Color.RED); | ||
|
||
|
||
} | ||
|
||
public void updateData(qMiniChart chartData, Representation representation) { | ||
miniChartData = chartData; | ||
this.representation = representation; | ||
} | ||
|
||
public void resetScales(Rect bounds) { | ||
this.bounds = bounds; | ||
if(miniChartData != null) { | ||
if(miniChartInfo.yAxis != null && miniChartInfo.yAxis.scale.equals("global")) { | ||
float min = Math.min((float) representation.globalMin, 0.0f); | ||
yScale = (float) representation.globalMax - min; | ||
} else { | ||
float min = Math.min((float) miniChartData.qMin, 0.0f); | ||
yScale = (float) (miniChartData.qMax - min); | ||
} | ||
setBandwidth(); | ||
setScales(); | ||
} | ||
} | ||
|
||
protected void setBandwidth() { | ||
float width = bounds.width() - horizontalPadding; | ||
float totalBandWidth = width / miniChartData.matrix.rows.size(); | ||
bandwidth = totalBandWidth * 0.8f; | ||
padding = totalBandWidth * 0.1f; | ||
} | ||
|
||
protected void setScales() { | ||
float height = bounds.height() - (verticalPadding * 2.0f); | ||
scale = height / yScale; | ||
xAxis = miniChartData.qMin < 0.0 ? (float)bounds.height() + ((float)miniChartData.qMin * scale) : bounds.height(); | ||
} | ||
|
||
protected void setColor(int index, float value, int count) { | ||
if(miniChartInfo.colors.max.valid && value == (float) miniChartData.qMax) { | ||
paint.setColor(miniChartInfo.colors.max.color); | ||
} else if(miniChartInfo.colors.min.valid && value == (float) miniChartData.qMin) { | ||
paint.setColor(miniChartInfo.colors.min.color); | ||
} else if(miniChartInfo.colors.first.valid && index == 0) { | ||
paint.setColor(miniChartInfo.colors.first.color); | ||
} else if(miniChartInfo.colors.last.valid && index == count - 1) { | ||
paint.setColor(miniChartInfo.colors.last.color); | ||
} else { | ||
paint.setColor(miniChartInfo.colors.main.color); | ||
} | ||
} | ||
|
||
public void render(Canvas canvas) {} | ||
} |
Oops, something went wrong.