This repository was archived by the owner on Nov 3, 2023. It is now read-only.
forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Visualization for multiple line charts (apache#4819)
* Initial test * Save * Working version * Use since/until from payload * Option to prefix metric name * Rename LineMultiLayer to MultiLineViz * Add more styles * Explicit nulls * Add more x controls * Refactor to reuse nvd3_vis * Fix x ticks * Fix spacing * Fix for druid datasource * Rename file * Small fixes and cleanup * Fix margins * Add proper thumbnails * Align yaxis1 and yaxis2 ticks * Improve code * Trigger tests * Move file * Small fixes plus example * Fix unit test * Remove SQL and Filter sections
- Loading branch information
1 parent
a746fce
commit 459cb70
Showing
13 changed files
with
342 additions
and
18 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import nvd3Vis from './nvd3_vis'; | ||
import { getExploreLongUrl } from '../explore/exploreUtils'; | ||
|
||
|
||
export default function lineMulti(slice, payload) { | ||
/* | ||
* Show multiple line charts | ||
* | ||
* This visualization works by fetching the data from each of the saved | ||
* charts, building the payload data and passing it along to nvd3Vis. | ||
*/ | ||
const fd = slice.formData; | ||
|
||
// fetch data from all the charts | ||
const promises = []; | ||
const subslices = [ | ||
...payload.data.slices.axis1.map(subslice => [1, subslice]), | ||
...payload.data.slices.axis2.map(subslice => [2, subslice]), | ||
]; | ||
subslices.forEach(([yAxis, subslice]) => { | ||
let filters = subslice.form_data.filters || []; | ||
filters.concat(fd.filters); | ||
if (fd.extra_filters) { | ||
filters = filters.concat(fd.extra_filters); | ||
} | ||
const fdCopy = { | ||
...subslice.form_data, | ||
filters, | ||
since: fd.since, | ||
until: fd.until, | ||
}; | ||
const url = getExploreLongUrl(fdCopy, 'json'); | ||
promises.push(new Promise((resolve, reject) => { | ||
d3.json(url, (error, response) => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
const data = []; | ||
response.data.forEach((datum) => { | ||
let key = datum.key; | ||
if (fd.prefix_metric_with_slice_name) { | ||
key = subslice.slice_name + ': ' + key; | ||
} | ||
data.push({ key, values: datum.values, type: fdCopy.viz_type, yAxis }); | ||
}); | ||
resolve(data); | ||
} | ||
}); | ||
})); | ||
}); | ||
|
||
Promise.all(promises).then((data) => { | ||
const payloadCopy = { ...payload }; | ||
payloadCopy.data = [].concat(...data); | ||
|
||
// add null values at the edges to fix multiChart bug when series with | ||
// different x values use different y axes | ||
if (fd.line_charts.length && fd.line_charts_2.length) { | ||
let minx = Infinity; | ||
let maxx = -Infinity; | ||
payloadCopy.data.forEach((datum) => { | ||
minx = Math.min(minx, ...datum.values.map(v => v.x)); | ||
maxx = Math.max(maxx, ...datum.values.map(v => v.x)); | ||
}); | ||
// add null values at the edges | ||
payloadCopy.data.forEach((datum) => { | ||
datum.values.push({ x: minx, y: null }); | ||
datum.values.push({ x: maxx, y: null }); | ||
}); | ||
} | ||
|
||
nvd3Vis(slice, payloadCopy); | ||
}); | ||
} |
Oops, something went wrong.