Add line of best fit (adding dependency on numpy)
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user