dashboard_chart.html 2.01 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{% extends "base.html" %}

{% block title %}{{ chart.title }}{% endblock %}

{% block extra_head %}
{{ super() }}
<link href="{{ urls.static_plugins('datasette_dashboards', 'dashboards.css') }}" rel="stylesheet"/>
{% endblock %}

{% block nav %}
    <p class="crumbs">
        <a href="{{ urls.instance() }}">home</a> /
        <a href="{{ urls.path('-/dashboards') }}">dashboards</a> /
        <a href="{{ urls.path('-/dashboards') }}/{{ slug }}">{{ dashboard.title }}</a>
    </p>
    {{ super() }}
{% endblock %}

{% block body_class %}index{% endblock %}

{% block content %}
22
    <div class="chart-header">
23
24
25
26
27
28
29
30
31
      <div class="page-header" style="border-color: black">
        <h1>{{ dashboard.title }}</h1>
      </div>
      {% if chart.title %}
      <p>{{ chart.title }}</p>
      {% endif %}
    </div>

    {% if chart.db and chart.query %}
32
33
34
35
36
    <p>
      <a class="not-underlined" title="{{ chart.query }}" href="{{ urls.database(chart.db) }}?{{ {'sql': chart.query}|urlencode|safe }}{% if query_string|length > 0 %}&{{ query_string|safe }}{% endif %}">
        &#x270e; <span class="underlined">View and edit SQL</span>
      </a>
    </p>
37
38
    {% endif %}

39
40
41
42
43
44
    <div class="dashboard-card">
      <div id="chart" class="chart-container">
        {% if chart.library == 'markdown' %}
        {{ render_markdown(chart.display) }}
        {% endif %}
      </div>
45
46
47
48
49
50
51
52
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vega@5.20.2"></script>
    <script src="https://cdn.jsdelivr.net/npm/vega-lite@5.1.0"></script>
    <script src="https://cdn.jsdelivr.net/npm/vega-embed@6.17.0"></script>
    <script src="{{ urls.static_plugins('datasette_dashboards', 'dashboards.js') }}"></script>
    <script type="text/javascript">
      {% if chart.library == 'vega' %}
53
      renderVegaChart('#chart', JSON.parse('{{ chart|tojson }}'), '{{ query_string|safe }}', 'container')
54
      {% elif chart.library == 'metric' %}
55
      renderMetricChart('#chart', JSON.parse('{{ chart|tojson }}'), '{{ query_string|safe }}')
56
57
58
      {% endif %}
    </script>
{% endblock %}