Skip to content

Commit

Permalink
Add zero values to field chart widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Edmundo Alvarez committed Mar 24, 2015
1 parent db8b777 commit 2fe7faf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/dashboards/widgets/field_chart.js
Expand Up @@ -48,7 +48,7 @@ function updateWidget_field_chart(widget, data) {
for (var key in data.result) { for (var key in data.result) {
var point = { var point = {
x: parseInt(key), x: parseInt(key),
y: data.result[key][graphElem.attr("data-config-valuetype")] y: data.result[key]
}; };


series.push(point); series.push(point);
Expand Down
15 changes: 10 additions & 5 deletions app/controllers/api/DashboardsApiController.java
Expand Up @@ -177,7 +177,7 @@ public Result widgetValue(String dashboardId, String widgetId, int resolution) {
DashboardWidgetValueResponse widgetValue = widget.getValue(api()); DashboardWidgetValueResponse widgetValue = widget.getValue(api());


Object resultValue; Object resultValue;
if (widget instanceof SearchResultChartWidget) { if (widget instanceof SearchResultChartWidget || widget instanceof FieldChartWidget) {
resultValue = formatWidgetValueResults(resolution, widget, widgetValue); resultValue = formatWidgetValueResults(resolution, widget, widgetValue);
} else { } else {
resultValue = widgetValue.result; resultValue = widgetValue.result;
Expand All @@ -198,7 +198,7 @@ public Result widgetValue(String dashboardId, String widgetId, int resolution) {
} }
} }


protected Map<String, Long> formatWidgetValueResults(final int maxDataPoints, protected Map<String, Object> formatWidgetValueResults(final int maxDataPoints,
final DashboardWidget widget, final DashboardWidget widget,
final DashboardWidgetValueResponse widgetValue) { final DashboardWidgetValueResponse widgetValue) {
final Map<String, Object> widgetConfig = widget.getConfig(); final Map<String, Object> widgetConfig = widget.getConfig();
Expand All @@ -207,18 +207,20 @@ protected Map<String, Long> formatWidgetValueResults(final int maxDataPoints,


return formatWidgetValueResults(maxDataPoints, return formatWidgetValueResults(maxDataPoints,
widgetValue.result, widgetValue.result,
(String)widgetConfig.get("valuetype"),
interval, interval,
widgetValue.computationTimeRange, widgetValue.computationTimeRange,
allQuery); allQuery);
} }


// TODO: Extract common parts of this and the similar method on SearchApiController // TODO: Extract common parts of this and the similar method on SearchApiController
protected Map<String, Long> formatWidgetValueResults(final int maxDataPoints, protected Map<String, Object> formatWidgetValueResults(final int maxDataPoints,
final Object resultValue, final Object resultValue,
final String functionType,
final String interval, final String interval,
final Map<String, Object> timeRange, final Map<String, Object> timeRange,
final boolean allQuery) { final boolean allQuery) {
final Map<String, Long> points = Maps.newHashMap(); final Map<String, Object> points = Maps.newHashMap();


if (resultValue instanceof Map) { if (resultValue instanceof Map) {
final Map<?, ?> resultMap = (Map) resultValue; final Map<?, ?> resultMap = (Map) resultValue;
Expand All @@ -245,7 +247,10 @@ protected Map<String, Long> formatWidgetValueResults(final int maxDataPoints,
if (index % factor == 0) { if (index % factor == 0) {
String timestamp = Long.toString(currentTime.getMillis() / 1000); String timestamp = Long.toString(currentTime.getMillis() / 1000);
Object value = resultMap.get(timestamp); Object value = resultMap.get(timestamp);
Long result = value == null ? 0L : Long.parseLong(String.valueOf(value)); if (functionType != null && value != null) {
value = ((Map)value).get(functionType);
}
Object result = value == null ? 0 : value;
points.put(timestamp, result); points.put(timestamp, result);
} }
index++; index++;
Expand Down
Expand Up @@ -139,7 +139,7 @@ var GraphVisualization = React.createClass({
var formattedData = []; var formattedData = [];
for(var key in data) { for(var key in data) {
if (data.hasOwnProperty(key)) { if (data.hasOwnProperty(key)) {
var normalizedValue = NumberUtils.normalizeNumber(data[key][this.props.config.valuetype]); var normalizedValue = NumberUtils.normalizeNumber(data[key]);
formattedData.push({ formattedData.push({
x: Number(key), x: Number(key),
y: isNaN(normalizedValue) ? 0 : normalizedValue y: isNaN(normalizedValue) ? 0 : normalizedValue
Expand Down

0 comments on commit 2fe7faf

Please sign in to comment.