Added graphs to show workouts & PR's per week on dashboard. However there is no tooltip on hover and I duplicated the svg spark line template (May combine the two)
This commit is contained in:
@@ -2,6 +2,14 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="w-full mb-4 grid grid-cols-1 xl:grid-cols-2 gap-4">
|
||||
{% for graph in dashboard_graphs %}
|
||||
<div class="bg-white shadow rounded-lg p-4 sm:p-6 xl:p-8">
|
||||
{{ render_partial('partials/svg_line_graph.html', **graph) }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="bg-white shadow rounded-lg pt-4 p-3 md:p-4 w-full mb-4">
|
||||
<div class="flex flex-wrap">
|
||||
<div class="w-full lg:w-1/4 sm:w-full px-3 mb-6 md:mb-0">
|
||||
|
||||
88
templates/partials/svg_line_graph.html
Normal file
88
templates/partials/svg_line_graph.html
Normal file
@@ -0,0 +1,88 @@
|
||||
{% set stroke_width = 4 %}
|
||||
{% set margin = 2 %}
|
||||
|
||||
{% macro path(data_points, vb_height) %}
|
||||
{% for value, position in data_points %}
|
||||
{% set x = (position * vb_width)+margin %}
|
||||
{% set y = (vb_height - value)+margin %}
|
||||
{% if loop.first %}M{{ x | int }} {{ y | int }}{% else %} L{{ x | int }} {{ y | int }}{% endif %}
|
||||
{% endfor %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro path_best_fit(best_fit_points, vb_height) %}
|
||||
{% for value, position in best_fit_points %}
|
||||
{% set x = (position * vb_width)+margin %}
|
||||
{% set y = (vb_height - value)+margin %}
|
||||
{% if loop.first %}M{{ x | int }} {{ y | int }}{% else %} L{{ x | int }} {{ y | int }}{% endif %}
|
||||
{% endfor %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro circles(data_points, color) %}
|
||||
{% for i in range(data_points|length) %}
|
||||
{% set current_value, current_position = data_points[i] %}
|
||||
{% set prev_value = data_points[i - 1][0] if i > 0 else None %}
|
||||
{% set next_value = data_points[i + 1][0] if i < data_points|length - 1 else None %}
|
||||
{# Plot the circle only if the current value is different from both previous and next values #}
|
||||
{% if next_value != prev_value or (next_value == prev_value and next_value != current_value) %}
|
||||
{% set x=(current_position * vb_width) + margin %}
|
||||
{% set y=(vb_height - current_value) + margin %}
|
||||
<circle cx="{{ x | int }}" cy="{{ y | int }}" r="1" fill="{{ color }}"></circle>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro plot_line(points, color) %}
|
||||
<path d="{{ path(points, vb_height) }}" stroke="{{ color }}" fill="none" />
|
||||
{{ circles(points, color) }}
|
||||
{% endmacro %}
|
||||
|
||||
<!-- HubSpot doesn't escape whitespace. -->
|
||||
{% macro random_int() %}{% for n in [0,1,2,3,4,5] %}{{ [0,1,2,3,4,5,6,7,8,9]|random }}{% endfor %}{% endmacro %}
|
||||
|
||||
<!-- You have to manually call the macros in a list. -->
|
||||
{% set parts = [random_int()] %}
|
||||
{% set unique_id = parts|join('-') %}
|
||||
|
||||
<div class="relative" id="svg-plot-{{ unique_id }}" _="
|
||||
on mouseover from .pnt-{{ unique_id }}
|
||||
put event.target @data-msg into #popover-{{ unique_id }}
|
||||
then remove .hidden from #popover-{{ unique_id }}
|
||||
on mouseout from .pnt-{{ unique_id }}
|
||||
add .hidden to #popover-{{ unique_id }}">
|
||||
<div id="popover-{{ unique_id }}" class="absolute t-0 r-0 hidden bg-white border border-gray-300 p-2 z-10">
|
||||
<!-- Popover content will be dynamically inserted here -->
|
||||
</div>
|
||||
<h4 class="text-l font-semibold text-blue-400 mb-2 text-center">{{ title }}</h4>
|
||||
<svg viewBox="0 0 {{ (vb_width + 2*margin) | int }} {{ (vb_height + 2*margin) | int }}"
|
||||
preserveAspectRatio="none">
|
||||
{% for plot in plots %}
|
||||
<g class="{{ plot.label }}" style="fill: {{ plot.color }}; stroke: {{ plot.color }};">
|
||||
{{ plot_line(plot.points, plot.color) }}
|
||||
</g>
|
||||
{% endfor %}
|
||||
|
||||
<g style="fill-opacity: 0%">
|
||||
{% for pos, message in plot_labels %}
|
||||
{% set x = (pos * vb_width) - (stroke_width/2) + margin %}
|
||||
{% set y = 0 %}
|
||||
{% set width = stroke_width %}
|
||||
{% set height = vb_height + margin %}
|
||||
<rect x="{{ x | int }}" y="{{ y | int }}" width="{{ width | int }}" height="{{ height | int }}"
|
||||
class="pnt-{{ unique_id }}" data-msg="{{ message }}"></rect>
|
||||
{% endfor %}
|
||||
</g>
|
||||
|
||||
<path d="{{ path_best_fit(best_fit_points, vb_height) }}" stroke="gray" stroke-dasharray="2,1" fill="none"
|
||||
stroke-opacity="60%" />
|
||||
</svg>
|
||||
<div class="flex justify-center pt-2">
|
||||
{% for plot in plots %}
|
||||
<div class="flex items-center px-2 select-none cursor-pointer" _="on load put document.querySelector('#svg-plot-{{ unique_id }} g.{{plot.label}}') into my.plot_line
|
||||
on click toggle .hidden on my.plot_line then toggle .line-through on me">
|
||||
<div class="w-3 h-3 mr-1" style="background-color: {{ plot.color }};"></div>
|
||||
<div class="text-xs">{{ plot.label }}</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user