Skip to content
This repository was archived by the owner on Jun 8, 2020. It is now read-only.
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
2 changes: 1 addition & 1 deletion public/build/static/application.css

Large diffs are not rendered by default.

137 changes: 134 additions & 3 deletions public/build/static/application.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions public/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ require([
return that.reports.loadAll();
})
.then(function() {
if (that.reports.size() > 0) {
that.setReport(that.reports.first());
}
that.update();
})
.fail(dialogs.error);
Expand Down
2 changes: 1 addition & 1 deletion public/src/models/visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ define([
});

return Visualization;
});
});
34 changes: 33 additions & 1 deletion public/src/resources/langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,38 @@
}
}
},
"plot": {
"title": "Plot Chart",
"config": {
"sample": {
"label": "Sampling Points",
"help": "X-Axis of this plot"
},
"fields": {
"label": "Fields",
"help": "Separated by commas"
},
"limit": {
"label": "Limit",
"help": "Max number of events"
},
"name": {
"label": "Name",
"help": "Template for the hover series name, see documentation for more infos about templates."
},
"interpolation": {
"label": "Interpolation",
"linear": "Linear - straight lines between points",
"step-after": "Step After - square steps from point to point",
"cardinal": "Cardinal - smooth curves via cardinal splines (default)",
"basis": "Basis - smooth curves via B-splines"
},
"fillEmpty": {
"label": "Fill Empty",
"help": "Fill when there is no events with zero values."
}
}
},
"value": {
"title": "Last Value",
"config": {
Expand All @@ -230,4 +262,4 @@
"label": "Language"
}
}
}
}
1 change: 1 addition & 0 deletions public/src/resources/stylesheets/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

@import "visualization.less";
@import "visualizations/time.less";
@import "visualizations/plot.less";
@import "visualizations/bar.less";
@import "visualizations/value.less";
@import "visualizations/map.less";
Expand Down
8 changes: 8 additions & 0 deletions public/src/resources/stylesheets/visualizations/plot.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.visualization.visualization-plot{
width: 100%;

.graph {
width: 100%;
height: 100%;
}
}
2 changes: 1 addition & 1 deletion public/src/utils/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ define([
});

return template;
});
});
6 changes: 4 additions & 2 deletions public/src/views/visualizations/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ define([
"views/visualizations/table",
"views/visualizations/value",
"views/visualizations/time",
"views/visualizations/plot",
"views/visualizations/map"
], function(resources, bar, table, value, time, map) {
], function(resources, bar, table, value, time, plot, map) {

return {
'time': time,
'plot': plot,
'table': table,
'bar': bar,
'value': value,
'map': map
};
});
});
122 changes: 122 additions & 0 deletions public/src/views/visualizations/plot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
define([
"hr/utils",
"hr/dom",
"hr/hr",
"d3",
"rickshaw",
"core/api",
"utils/i18n",
"utils/template",
"views/visualizations/base",
"text!resources/templates/visualizations/time.html"
], function(_, $, hr, d3, Rickshaw, api, i18n, template, BaseVisualization, templateFile) {
window.d3 = d3;

var INTERPOLATIONS = ['linear', 'step-after', 'cardinal', 'basis'];

var PlotVisualization = BaseVisualization.extend({
className: "visualization visualization-plot",
defaults: {},
events: {},
template: templateFile,

finish: function() {
try {
var that = this;
var tplMessage = that.model.getConf("name") || "<%- (field? field : 'Count') %>";

// Build series from data
var fieldNames = _.map(this.model.getConf("fields", "").split(","),
function (str) { return str.trim() }
);
var sampleName = this.model.getConf("sample", "").trim();
var series = _.chain(fieldNames).compact().concat([""])
.map(function(field, i, list) {
if (list.length > 1 && !field) return null;

return {
name: template(tplMessage, {
'field': field
}),
color: '#a6d87a',
data: _.map(
_.sortBy(
_.filter(
that.data,
function(n) { return n['properties'][field]; }
),
function(n) { return n['properties'][sampleName]; }
),
function(d) {
return {
x: d.properties[sampleName],
y: field? d.properties[field] : d.n
};
})
}
})
.compact()
.value();

// Build graph
var graph = new Rickshaw.Graph( {
element: this.$('.graph').get(0),
renderer: 'line',
series: series,
interpolation: that.model.getConf("interpolation", "cardinal")
});
graph.render();

// Build hover details
var hoverDetail = new Rickshaw.Graph.HoverDetail( {
graph: graph,
xFormatter: function(x) {
return template("<%- x %>", {'x': x});
}
});
} catch(e) {
console.error(e);
}

return PlotVisualization.__super__.finish.apply(this, arguments);
},

pull: function() {
return api.execute("get:events", {
limit: this.model.getConf("limit"),
type: this.model.get("eventName"),
});
}
});

return {
title: i18n.t("visualizations.plot.title"),
View: PlotVisualization,
config: {
'sample': {
'type': "text",
'label': i18n.t("visualizations.plot.config.sample.label"),
'help': i18n.t("visualizations.plot.config.sample.help")
},
'fields': {
'type': "text",
'label': i18n.t("visualizations.plot.config.fields.label"),
'help': i18n.t("visualizations.plot.config.fields.help")
},
'limit': {
'type': "number",
'label': i18n.t("visualizations.plot.config.limit.label"),
'help': i18n.t("visualizations.plot.config.limit.help"),
'default': 1000,
'min': 100,
'max': 1000000
},
'interpolation': {
'type': "select",
'label': i18n.t("visualizations.plot.config.interpolation.label"),
'default': "cardinal",
'options': _.chain(INTERPOLATIONS). map(function(i) { return [i, i18n.t("visualizations.plot.config.interpolation."+i)] }).object().value()
},
}
};
});