Skip to content

Commit

Permalink
Vega chart responsive height only for chart view
Browse files Browse the repository at this point in the history
  • Loading branch information
rclement committed Mar 12, 2023
1 parent 8b03183 commit 8ce9bc0
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions datasette_dashboards/static/dashboards.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
function renderVegaChart(el, chart, query_string, full_height) {
const query = encodeURIComponent(chart.query)
let defaultSignals = [
{
'name': 'width',
'init': 'containerSize()[0]',
'on': [
{
'events': {
'source': 'window',
'type': 'resize'
},
'update': 'containerSize()[0]',
}
]
}
]
if (full_height) {
defaultSignals.push({
'name': 'height',
'init': 'containerSize()[1]',
'on': [
{
'events': {
'source': 'window',
'type': 'resize'
},
'update': 'containerSize()[1]'
}
]
})
}

const spec = {
$schema: 'https://vega.github.io/schema/vega/v5.json',
description: chart.title,
Expand All @@ -11,34 +42,7 @@ function renderVegaChart(el, chart, query_string, full_height) {
format: { 'type': 'csv', 'parse': 'auto' }
}
],
signals: [
{
'name': 'width',
'init': 'containerSize()[0]',
'on': [
{
'events': {
'source': 'window',
'type': 'resize'
},
'update': 'containerSize()[0]',
}
]
},
{
'name': 'height',
'init': 'containerSize()[1]',
'on': [
{
'events': {
'source': 'window',
'type': 'resize'
},
'update': 'containerSize()[1]'
}
]
}
],
signals: defaultSignals,
...chart.display
};

Expand Down

0 comments on commit 8ce9bc0

Please sign in to comment.