mirror of https://github.com/apache/superset.git
Doing some refactoring
This commit is contained in:
parent
85963900ae
commit
085430cb53
|
@ -412,7 +412,7 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
|
||||||
"Datetime column not provided as part table configuration")
|
"Datetime column not provided as part table configuration")
|
||||||
dttm_expr = cols[granularity].expression
|
dttm_expr = cols[granularity].expression
|
||||||
if dttm_expr:
|
if dttm_expr:
|
||||||
timestamp = ColumnClause(dttm_expr, is_literal=True).label('timestamp')
|
timestamp = literal_column(dttm_expr).label('timestamp')
|
||||||
else:
|
else:
|
||||||
timestamp = literal_column(granularity).label('timestamp')
|
timestamp = literal_column(granularity).label('timestamp')
|
||||||
metrics_exprs = [
|
metrics_exprs = [
|
||||||
|
@ -437,8 +437,8 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
|
||||||
col = cols[s]
|
col = cols[s]
|
||||||
expr = col.expression
|
expr = col.expression
|
||||||
if expr:
|
if expr:
|
||||||
outer = ColumnClause(expr, is_literal=True).label(s)
|
outer = literal_column(expr).label(s)
|
||||||
inner = ColumnClause(expr, is_literal=True).label('__' + s)
|
inner = literal_column(expr).label('__' + s)
|
||||||
else:
|
else:
|
||||||
outer = column(s).label(s)
|
outer = column(s).label(s)
|
||||||
inner = column(s).label('__' + s)
|
inner = column(s).label('__' + s)
|
||||||
|
@ -462,15 +462,16 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
|
||||||
if not columns:
|
if not columns:
|
||||||
qry = qry.group_by(*groupby_exprs)
|
qry = qry.group_by(*groupby_exprs)
|
||||||
|
|
||||||
|
tf = '%Y-%m-%d %H:%M:%S.%f'
|
||||||
time_filter = [
|
time_filter = [
|
||||||
timestamp >= from_dttm.isoformat(),
|
timestamp >= from_dttm.strftime(tf),
|
||||||
timestamp <= to_dttm.isoformat(),
|
timestamp <= to_dttm.strftime(tf),
|
||||||
]
|
]
|
||||||
inner_time_filter = copy(time_filter)
|
inner_time_filter = copy(time_filter)
|
||||||
if inner_from_dttm:
|
if inner_from_dttm:
|
||||||
inner_time_filter[0] = timestamp >= inner_from_dttm.isoformat()
|
inner_time_filter[0] = timestamp >= inner_from_dttm.strftime(tf)
|
||||||
if inner_to_dttm:
|
if inner_to_dttm:
|
||||||
inner_time_filter[1] = timestamp <= inner_to_dttm.isoformat()
|
inner_time_filter[1] = timestamp <= inner_to_dttm.strftime(tf)
|
||||||
where_clause_and = []
|
where_clause_and = []
|
||||||
having_clause_and = []
|
having_clause_and = []
|
||||||
for col, op, eq in filter:
|
for col, op, eq in filter:
|
||||||
|
|
|
@ -3,6 +3,28 @@ var px = (function() {
|
||||||
var visualizations = {};
|
var visualizations = {};
|
||||||
var dashboard = undefined;
|
var dashboard = undefined;
|
||||||
|
|
||||||
|
function UTC(dttm){
|
||||||
|
return v = new Date(dttm.getUTCFullYear(), dttm.getUTCMonth(), dttm.getUTCDate(), dttm.getUTCHours(), dttm.getUTCMinutes(), dttm.getUTCSeconds());
|
||||||
|
}
|
||||||
|
var tickMultiFormat = d3.time.format.multi([
|
||||||
|
[".%L", function(d) { return d.getMilliseconds(); }], // If there are millisections, show only them
|
||||||
|
[":%S", function(d) { return d.getSeconds(); }], // If there are seconds, show only them
|
||||||
|
["%a %b %d, %I:%M %p", function(d) { return d.getMinutes()!=0; }], // If there are non-zero minutes, show Date, Hour:Minute [AM/PM]
|
||||||
|
["%a %b %d, %I %p", function(d) { return d.getHours() != 0; }], // If there are hours that are multiples of 3, show date and AM/PM
|
||||||
|
["%a %b %d, %Y", function(d) { return d.getDate() != 1; }], // If not the first of the month, do "month day, year."
|
||||||
|
["%B %Y", function(d) { return d.getMonth() != 0 && d.getDate() == 1; }], // If the first of the month, do "month day, year."
|
||||||
|
["%Y", function(d) { return true; }] // fall back on month, year
|
||||||
|
]);
|
||||||
|
function formatDate(dttm) {
|
||||||
|
var d = UTC(new Date(dttm));
|
||||||
|
//d = new Date(d.getTime() - 1 * 60 * 60 * 1000);
|
||||||
|
return tickMultiFormat(d);
|
||||||
|
}
|
||||||
|
colors = [
|
||||||
|
"#FF5A5F", "#007A87", "#7B0051", "#00D1C1", "#8CE071", "#FFB400",
|
||||||
|
"#FFAA91", "#B4A76C", "#9CA299", "#565A5C"
|
||||||
|
];
|
||||||
|
|
||||||
var Slice = function(data, dashboard){
|
var Slice = function(data, dashboard){
|
||||||
var timer;
|
var timer;
|
||||||
var token = $('#' + data.token);
|
var token = $('#' + data.token);
|
||||||
|
@ -119,7 +141,6 @@ var px = (function() {
|
||||||
addFilter: function(slice_id, filters) {
|
addFilter: function(slice_id, filters) {
|
||||||
this.filters[slice_id] = filters;
|
this.filters[slice_id] = filters;
|
||||||
this.refreshExcept(slice_id);
|
this.refreshExcept(slice_id);
|
||||||
console.log(this.filters);
|
|
||||||
},
|
},
|
||||||
readFilters: function() {
|
readFilters: function() {
|
||||||
// Returns a list of human readable active filters
|
// Returns a list of human readable active filters
|
||||||
|
@ -424,5 +445,7 @@ var px = (function() {
|
||||||
druidify: druidify,
|
druidify: druidify,
|
||||||
initExploreView: initExploreView,
|
initExploreView: initExploreView,
|
||||||
initDashboardView: initDashboardView,
|
initDashboardView: initDashboardView,
|
||||||
|
formatDate: formatDate,
|
||||||
|
colors: colors,
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -98,7 +98,8 @@ px.registerViz('big_number', function(slice) {
|
||||||
var x_axis = d3.svg.axis()
|
var x_axis = d3.svg.axis()
|
||||||
.scale(scale_x)
|
.scale(scale_x)
|
||||||
.orient('bottom')
|
.orient('bottom')
|
||||||
.ticks(4);
|
.ticks(4)
|
||||||
|
.tickFormat(px.formatDate);
|
||||||
g.call(x_axis);
|
g.call(x_axis);
|
||||||
g.attr('transform', 'translate(0,' + (height - margin) + ')');
|
g.attr('transform', 'translate(0,' + (height - margin) + ')');
|
||||||
|
|
||||||
|
|
|
@ -2,27 +2,6 @@ function viz_nvd3(slice) {
|
||||||
var chart = undefined;
|
var chart = undefined;
|
||||||
var data = {};
|
var data = {};
|
||||||
|
|
||||||
function UTC(dttm){
|
|
||||||
return v = new Date(dttm.getUTCFullYear(), dttm.getUTCMonth(), dttm.getUTCDate(), dttm.getUTCHours(), dttm.getUTCMinutes(), dttm.getUTCSeconds());
|
|
||||||
}
|
|
||||||
var tickMultiFormat = d3.time.format.multi([
|
|
||||||
[".%L", function(d) { return d.getMilliseconds(); }], // If there are millisections, show only them
|
|
||||||
[":%S", function(d) { return d.getSeconds(); }], // If there are seconds, show only them
|
|
||||||
["%a %b %d, %I:%M %p", function(d) { return d.getMinutes()!=0; }], // If there are non-zero minutes, show Date, Hour:Minute [AM/PM]
|
|
||||||
["%a %b %d, %I %p", function(d) { return d.getHours() != 0; }], // If there are hours that are multiples of 3, show date and AM/PM
|
|
||||||
["%a %b %d, %Y", function(d) { return d.getDate() != 1; }], // If not the first of the month, do "month day, year."
|
|
||||||
["%B %Y", function(d) { return d.getMonth() != 0 && d.getDate() == 1; }], // If the first of the month, do "month day, year."
|
|
||||||
["%Y", function(d) { return true; }] // fall back on month, year
|
|
||||||
]);
|
|
||||||
function formatDate(dttm) {
|
|
||||||
var d = UTC(new Date(dttm));
|
|
||||||
//d = new Date(d.getTime() - 1 * 60 * 60 * 1000);
|
|
||||||
return tickMultiFormat(d);
|
|
||||||
}
|
|
||||||
colors = [
|
|
||||||
"#FF5A5F", "#007A87", "#7B0051", "#00D1C1", "#8CE071", "#FFB400",
|
|
||||||
"#FFAA91", "#B4A76C", "#9CA299", "#565A5C"
|
|
||||||
];
|
|
||||||
var refresh = function() {
|
var refresh = function() {
|
||||||
$.getJSON(slice.jsonEndpoint(), function(payload) {
|
$.getJSON(slice.jsonEndpoint(), function(payload) {
|
||||||
var fd = payload.form_data;
|
var fd = payload.form_data;
|
||||||
|
@ -36,7 +15,7 @@ function viz_nvd3(slice) {
|
||||||
chart.lines2.xScale(d3.time.scale.utc());
|
chart.lines2.xScale(d3.time.scale.utc());
|
||||||
chart.x2Axis
|
chart.x2Axis
|
||||||
.showMaxMin(fd.x_axis_showminmax)
|
.showMaxMin(fd.x_axis_showminmax)
|
||||||
.tickFormat(formatDate)
|
.tickFormat(px.formatDate)
|
||||||
.staggerLabels(true);
|
.staggerLabels(true);
|
||||||
} else {
|
} else {
|
||||||
chart = nv.models.lineChart()
|
chart = nv.models.lineChart()
|
||||||
|
@ -47,7 +26,7 @@ function viz_nvd3(slice) {
|
||||||
chart.interpolate(fd.line_interpolation);
|
chart.interpolate(fd.line_interpolation);
|
||||||
chart.xAxis
|
chart.xAxis
|
||||||
.showMaxMin(fd.x_axis_showminmax)
|
.showMaxMin(fd.x_axis_showminmax)
|
||||||
.tickFormat(formatDate)
|
.tickFormat(px.formatDate)
|
||||||
.staggerLabels(true);
|
.staggerLabels(true);
|
||||||
chart.showLegend(fd.show_legend);
|
chart.showLegend(fd.show_legend);
|
||||||
chart.yAxis.tickFormat(d3.format('.3s'));
|
chart.yAxis.tickFormat(d3.format('.3s'));
|
||||||
|
@ -66,7 +45,7 @@ function viz_nvd3(slice) {
|
||||||
.groupSpacing(0.1);
|
.groupSpacing(0.1);
|
||||||
chart.xAxis
|
chart.xAxis
|
||||||
.showMaxMin(false)
|
.showMaxMin(false)
|
||||||
.tickFormat(formatDate)
|
.tickFormat(px.formatDate)
|
||||||
.staggerLabels(true);
|
.staggerLabels(true);
|
||||||
chart.showLegend(fd.show_legend);
|
chart.showLegend(fd.show_legend);
|
||||||
chart.stacked(fd.bar_stacked);
|
chart.stacked(fd.bar_stacked);
|
||||||
|
@ -104,7 +83,7 @@ function viz_nvd3(slice) {
|
||||||
chart.xScale(d3.time.scale.utc());
|
chart.xScale(d3.time.scale.utc());
|
||||||
chart.xAxis
|
chart.xAxis
|
||||||
.showMaxMin(false)
|
.showMaxMin(false)
|
||||||
.tickFormat(formatDate)
|
.tickFormat(px.formatDate)
|
||||||
.staggerLabels(true);
|
.staggerLabels(true);
|
||||||
chart.showLegend(fd.show_legend);
|
chart.showLegend(fd.show_legend);
|
||||||
chart.yAxis.tickFormat(d3.format('.3p'));
|
chart.yAxis.tickFormat(d3.format('.3p'));
|
||||||
|
@ -137,7 +116,7 @@ function viz_nvd3(slice) {
|
||||||
chart.xScale(d3.time.scale.utc());
|
chart.xScale(d3.time.scale.utc());
|
||||||
chart.xAxis
|
chart.xAxis
|
||||||
.showMaxMin(false)
|
.showMaxMin(false)
|
||||||
.tickFormat(formatDate)
|
.tickFormat(px.formatDate)
|
||||||
.staggerLabels(true);
|
.staggerLabels(true);
|
||||||
chart.showLegend(fd.show_legend);
|
chart.showLegend(fd.show_legend);
|
||||||
chart.yAxis.tickFormat(d3.format('.3s'));
|
chart.yAxis.tickFormat(d3.format('.3s'));
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block tail_js %}
|
{% block tail_js %}
|
||||||
|
<script src="/static/lib/d3.min.js"></script>
|
||||||
<script src="/static/panoramix.js"></script>
|
<script src="/static/panoramix.js"></script>
|
||||||
<script src="/static/lib/jquery-ui/jquery-ui.min.js"></script>
|
<script src="/static/lib/jquery-ui/jquery-ui.min.js"></script>
|
||||||
<script src="/static/lib/select2.sortable.js"></script>
|
<script src="/static/lib/select2.sortable.js"></script>
|
||||||
|
|
|
@ -289,7 +289,6 @@ class TableViz(BaseViz):
|
||||||
]
|
]
|
||||||
is_timeseries = False
|
is_timeseries = False
|
||||||
js_files = [
|
js_files = [
|
||||||
'lib/d3.min.js',
|
|
||||||
'lib/dataTables/jquery.dataTables.min.js',
|
'lib/dataTables/jquery.dataTables.min.js',
|
||||||
'lib/dataTables/dataTables.bootstrap.js',
|
'lib/dataTables/dataTables.bootstrap.js',
|
||||||
'widgets/viz_table.js',
|
'widgets/viz_table.js',
|
||||||
|
@ -437,7 +436,6 @@ class WordCloudViz(BaseViz):
|
||||||
)
|
)
|
||||||
},)
|
},)
|
||||||
js_files = [
|
js_files = [
|
||||||
'lib/d3.min.js',
|
|
||||||
'lib/d3.layout.cloud.js',
|
'lib/d3.layout.cloud.js',
|
||||||
'widgets/viz_wordcloud.js',
|
'widgets/viz_wordcloud.js',
|
||||||
]
|
]
|
||||||
|
@ -463,7 +461,6 @@ class NVD3Viz(BaseViz):
|
||||||
verbose_name = "Base NVD3 Viz"
|
verbose_name = "Base NVD3 Viz"
|
||||||
is_timeseries = False
|
is_timeseries = False
|
||||||
js_files = [
|
js_files = [
|
||||||
'lib/d3.min.js',
|
|
||||||
'lib/nvd3/nv.d3.min.js',
|
'lib/nvd3/nv.d3.min.js',
|
||||||
'widgets/viz_nvd3.js',
|
'widgets/viz_nvd3.js',
|
||||||
]
|
]
|
||||||
|
@ -547,7 +544,6 @@ class BigNumberViz(BaseViz):
|
||||||
verbose_name = "Big Number"
|
verbose_name = "Big Number"
|
||||||
is_timeseries = True
|
is_timeseries = True
|
||||||
js_files = [
|
js_files = [
|
||||||
'lib/d3.min.js',
|
|
||||||
'widgets/viz_bignumber.js',
|
'widgets/viz_bignumber.js',
|
||||||
]
|
]
|
||||||
css_files = [
|
css_files = [
|
||||||
|
@ -562,6 +558,7 @@ class BigNumberViz(BaseViz):
|
||||||
'metric',
|
'metric',
|
||||||
'compare_lag',
|
'compare_lag',
|
||||||
'compare_suffix',
|
'compare_suffix',
|
||||||
|
'y_axis_format',
|
||||||
)
|
)
|
||||||
},)
|
},)
|
||||||
|
|
||||||
|
@ -584,7 +581,6 @@ class BigNumberViz(BaseViz):
|
||||||
form_data = self.form_data
|
form_data = self.form_data
|
||||||
df = self.get_df()
|
df = self.get_df()
|
||||||
df = df.sort(columns=df.columns[0])
|
df = df.sort(columns=df.columns[0])
|
||||||
df['timestamp'] = df[[0]].astype(np.int64) // 10**9
|
|
||||||
compare_lag = form_data.get("compare_lag", "")
|
compare_lag = form_data.get("compare_lag", "")
|
||||||
compare_lag = int(compare_lag) if compare_lag and compare_lag.isdigit() else 0
|
compare_lag = int(compare_lag) if compare_lag and compare_lag.isdigit() else 0
|
||||||
d = {
|
d = {
|
||||||
|
@ -592,7 +588,7 @@ class BigNumberViz(BaseViz):
|
||||||
'compare_lag': compare_lag,
|
'compare_lag': compare_lag,
|
||||||
'compare_suffix': form_data.get('compare_suffix', ''),
|
'compare_suffix': form_data.get('compare_suffix', ''),
|
||||||
}
|
}
|
||||||
return json.dumps(d)
|
return dumps(d)
|
||||||
|
|
||||||
|
|
||||||
class NVD3TimeSeriesViz(NVD3Viz):
|
class NVD3TimeSeriesViz(NVD3Viz):
|
||||||
|
@ -865,7 +861,6 @@ class SunburstViz(BaseViz):
|
||||||
verbose_name = "Sunburst"
|
verbose_name = "Sunburst"
|
||||||
is_timeseries = False
|
is_timeseries = False
|
||||||
js_files = [
|
js_files = [
|
||||||
'lib/d3.min.js',
|
|
||||||
'widgets/viz_sunburst.js']
|
'widgets/viz_sunburst.js']
|
||||||
css_files = ['widgets/viz_sunburst.css']
|
css_files = ['widgets/viz_sunburst.css']
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
|
@ -931,7 +926,6 @@ class SankeyViz(BaseViz):
|
||||||
verbose_name = "Sankey"
|
verbose_name = "Sankey"
|
||||||
is_timeseries = False
|
is_timeseries = False
|
||||||
js_files = [
|
js_files = [
|
||||||
'lib/d3.min.js',
|
|
||||||
'lib/d3-sankey.js',
|
'lib/d3-sankey.js',
|
||||||
'widgets/viz_sankey.js']
|
'widgets/viz_sankey.js']
|
||||||
css_files = ['widgets/viz_sankey.css']
|
css_files = ['widgets/viz_sankey.css']
|
||||||
|
@ -973,7 +967,6 @@ class DirectedForceViz(BaseViz):
|
||||||
verbose_name = "Directed Force Layout"
|
verbose_name = "Directed Force Layout"
|
||||||
is_timeseries = False
|
is_timeseries = False
|
||||||
js_files = [
|
js_files = [
|
||||||
'lib/d3.min.js',
|
|
||||||
'widgets/viz_directed_force.js']
|
'widgets/viz_directed_force.js']
|
||||||
css_files = ['widgets/viz_directed_force.css']
|
css_files = ['widgets/viz_directed_force.css']
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
|
@ -1019,7 +1012,6 @@ class WorldMapViz(BaseViz):
|
||||||
verbose_name = "World Map"
|
verbose_name = "World Map"
|
||||||
is_timeseries = False
|
is_timeseries = False
|
||||||
js_files = [
|
js_files = [
|
||||||
'lib/d3.min.js',
|
|
||||||
'lib/topojson.min.js',
|
'lib/topojson.min.js',
|
||||||
'lib/datamaps.all.js',
|
'lib/datamaps.all.js',
|
||||||
'widgets/viz_world_map.js']
|
'widgets/viz_world_map.js']
|
||||||
|
@ -1098,7 +1090,6 @@ class FilterBoxViz(BaseViz):
|
||||||
verbose_name = "Filters"
|
verbose_name = "Filters"
|
||||||
is_timeseries = False
|
is_timeseries = False
|
||||||
js_files = [
|
js_files = [
|
||||||
'lib/d3.min.js',
|
|
||||||
'widgets/viz_filter_box.js']
|
'widgets/viz_filter_box.js']
|
||||||
css_files = [
|
css_files = [
|
||||||
'widgets/viz_filter_box.css']
|
'widgets/viz_filter_box.css']
|
||||||
|
|
Loading…
Reference in New Issue