Add line of best fit (adding dependency on numpy)

This commit is contained in:
Peter Stockings
2023-12-08 23:51:10 +11:00
parent ded5154acf
commit dd093e3819
3 changed files with 29 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
{% set fill = "#dcfce7" %}
{% set stroke = "#bbf7d0" %}
{% set fill = "#2ca02c" %}
{% set stroke = "#2ca02c" %}
{% set stroke_width = 4 %}
{% set margin = 2 %}
@@ -11,6 +11,14 @@
{% 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 }} {{ y }}{% else %} L{{ x }} {{ y }}{% endif %}
{% endfor %}
{% endmacro %}
{% macro circles(data_points, vb_height) %}
{% for value, position, message in data_points %}
{% set x = (position * vb_width)+margin %}
@@ -22,7 +30,7 @@
on mouseout
add .hidden to #popover-{{ unique_id }}">
</circle>
<circle cx="{{ x }}" cy="{{ y }}" r="1" stroke="blue" fill="blue"></circle>
<circle cx="{{ x }}" cy="{{ y }}" r="1" stroke="{{ stroke }}" fill="{{ fill }}"></circle>
{% endfor %}
{% endmacro %}
@@ -38,7 +46,8 @@
<!-- Popover content will be dynamically inserted here -->
</div>
<svg viewBox="0 0 {{ vb_width + 4 }} {{ vb_height + 4 }}" preserveAspectRatio="none">
<path d="{{ path(data_points, vb_height) }}" stroke="blue" fill="none" />
<path d="{{ path_best_fit(best_fit_points, vb_height) }}" stroke="gray" stroke-dasharray="2,1" fill="none" stroke-opacity="40%"/>
<path d="{{ path(data_points, vb_height) }}" stroke="{{ stroke }}" fill="none" />
{{ circles(data_points, vb_height) }}
</svg>
</div>