Skip to content

Commit

Permalink
Fixing time table viz for adhoc metrics (apache#5117)
Browse files Browse the repository at this point in the history
  • Loading branch information
michellethomas authored and Grace Guo committed May 31, 2018
1 parent 4ecd95a commit ff4b103
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion superset/assets/src/components/MetricOption.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const defaultProps = {
};

export default function MetricOption({ metric, openInNewWindow, showFormula, showType, url }) {
const verbose = metric.verbose_name || metric.metric_name;
const verbose = metric.verbose_name || metric.metric_name || metric.label;
const link = url ? <a href={url} target={openInNewWindow ? '_blank' : null}>{verbose}</a> : verbose;
return (
<div>
Expand Down
20 changes: 11 additions & 9 deletions superset/assets/src/visualizations/time_table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,28 @@ function viz(slice, payload) {
let leftCell;
const context = { ...fd, metric };
const url = fd.url ? Mustache.render(fd.url, context) : null;
const metricLabel = metric.label || metric;
const metricData = typeof metric === 'object' ? metric : metricMap[metric];
if (!payload.data.is_group_by) {
leftCell = (
<MetricOption metric={metricMap[metric]} url={url} showFormula={false} openInNewWindow />
<MetricOption metric={metricData} url={url} showFormula={false} openInNewWindow />
);
} else {
leftCell = url ? <a href={url} target="_blank">{metric}</a> : metric;
leftCell = url ? <a href={url} target="_blank">{metricLabel}</a> : metric;
}
const row = { metric: leftCell };
fd.column_collection.forEach((column) => {
if (column.colType === 'spark') {
let sparkData;
if (!column.timeRatio) {
sparkData = data.map(d => d[metric]);
sparkData = data.map(d => d[metricLabel]);
} else {
// Period ratio sparkline
sparkData = [];
for (let i = column.timeRatio; i < data.length; i++) {
const prevData = data[i - column.timeRatio][metric];
const prevData = data[i - column.timeRatio][metricLabel];
if (prevData && prevData !== 0) {
sparkData.push(data[i][metric] / prevData);
sparkData.push(data[i][metricLabel] / prevData);
} else {
sparkData.push(null);
}
Expand All @@ -105,7 +107,7 @@ function viz(slice, payload) {
>
{({ onMouseLeave, onMouseMove, tooltipData }) => (
<Sparkline
ariaLabel={`spark-${metric}`}
ariaLabel={`spark-${metricLabel}`}
width={parseInt(column.width, 10) || 300}
height={parseInt(column.height, 10) || 50}
margin={SPARKLINE_MARGIN}
Expand Down Expand Up @@ -135,7 +137,7 @@ function viz(slice, payload) {
),
};
} else {
const recent = reversedData[0][metric];
const recent = reversedData[0][metricLabel];
let v;
let errorMsg;
if (column.colType === 'time') {
Expand All @@ -145,7 +147,7 @@ function viz(slice, payload) {
if (timeLag > totalLag) {
errorMsg = `The time lag set at ${timeLag} exceeds the length of data at ${reversedData.length}. No data available.`;
} else {
v = reversedData[timeLag][metric];
v = reversedData[timeLag][metricLabel];
}
if (column.comparisonType === 'diff') {
v = recent - v;
Expand All @@ -162,7 +164,7 @@ function viz(slice, payload) {
} else if (column.colType === 'avg') {
// Average over the last {timeLag}
v = reversedData
.map((k, i) => i < column.timeLag ? k[metric] : 0)
.map((k, i) => i < column.timeLag ? k[metricLabel] : 0)
.reduce((a, b) => a + b) / column.timeLag;
}
let color;
Expand Down

0 comments on commit ff4b103

Please sign in to comment.