Browse Source

added scatterplot and barchart. didn't i already do this?

master
phryk 1 year ago
parent
commit
c847630b30
9 changed files with 80 additions and 19 deletions
  1. +1
    -1
      example.py
  2. +5
    -1
      poobrains/__init__.py
  3. +21
    -0
      poobrains/svg/plot.py
  4. +10
    -3
      poobrains/themes/default/svg.scss
  5. +9
    -0
      poobrains/themes/default/svg/barchart-raw.jinja
  6. +1
    -0
      poobrains/themes/default/svg/boxplot-raw.jinja
  7. +17
    -0
      poobrains/themes/default/svg/lineplot-raw.jinja
  8. +11
    -13
      poobrains/themes/default/svg/plot-raw.jinja
  9. +5
    -1
      poobrains/themes/default/svg/svg.jinja

+ 1
- 1
example.py View File

@@ -121,7 +121,7 @@ def list_nonexposed(listing):

class NASAApproaches(poobrains.svg.plot.Dataset):

def fill(self, spkid):
def fill(self, spkid=2099942): # default spkid for apophis

try:
spkid = int(spkid)


+ 5
- 1
poobrains/__init__.py View File

@@ -604,13 +604,17 @@ class Poobrain(flask.Flask):
return decorator


def expose(self, rule, mode='full', title=None, force_secure=False):
def expose(self, rule, mode='full', extra_modes=None, title=None, force_secure=False):
def decorator(cls):

if issubclass(cls, storage.Storable):
self.site.add_listing(cls, rule, mode='teaser', title=title, force_secure=force_secure)
self.site.add_view(cls, os.path.join(rule, '<handle>/'), mode=mode, force_secure=force_secure)

if not extra_modes is None:
for extra_mode in extra_modes:
self.site.add_view(cls, os.path.join(rule, '<handle>/%s' % extra_mode), mode=extra_mode, force_secure=force_secure)

for related_model, related_fields in cls._meta.model_backrefs.items(): # Add Models that are associated by ForeignKeyField, like /user/foo/userpermissions

if len(related_fields) > 1:


+ 21
- 0
poobrains/svg/plot.py View File

@@ -312,6 +312,7 @@ class Plot(base.SVG):
description_height = None

datasets = None
length = None
min_x = None
max_x = None
min_y = None
@@ -361,9 +362,14 @@ class Plot(base.SVG):
self.datasets.append(ds)

datapoint_count = 0
self.length = 0
#for datapoint in Datapoint.list('read', g.user).where(Datapoint.dataset << self.datasets):
for dataset in self.datasets:

l = len(dataset.authorized_datapoints)
if l > self.length:
self.length = l

for datapoint in dataset.authorized_datapoints:

datapoint_count += 1
@@ -491,6 +497,20 @@ class Plot(base.SVG):
return coords


@app.expose('/svg/lineplot')
class LinePlot(Plot):
pass


@app.expose('/svg/barchart')
class BarChart(Plot):
@property
def bar_width(self):
#return 10
return (self.plot_width - self.padding) / self.length - 1


def new_editor_handle():

handle = poobrains.helpers.random_string_light()
@@ -500,6 +520,7 @@ def new_editor_handle():

return new_editor_handle()


def dataset_choices():




+ 10
- 3
poobrains/themes/default/svg.scss View File

@@ -48,6 +48,10 @@ svg {
font-family: 'Clear Sans', sans;
}

text {
stroke: $color_font_light;
}

svg#hexascroll {


@@ -377,8 +381,10 @@ svg#checkbox {
g.datapoint {

.marker {
fill: desaturate($color, 20%);
.marker,
.bar {
fill: desaturate($color, 60%);
transition: fill 0.3s linear;
}

g.error {
@@ -396,7 +402,8 @@ svg#checkbox {
&:focus,
&:target {

.marker {
.marker,
.bar {
fill: $color;
}
}


+ 9
- 0
poobrains/themes/default/svg/barchart-raw.jinja View File

@@ -0,0 +1,9 @@
{% extends 'svg/plot-raw.jinja' %}
{% block datapoint %}
<rect class="bar"
x="{{ content.normalize_x(datapoint.x) - content.bar_width / 2 }}"
y="{{ content.normalize_y(datapoint.y) }}"
height="{{ content.plot_height - content.normalize_y(datapoint.y) }}"
width="{{ content.bar_width }}"
/>
{% endblock %}

+ 1
- 0
poobrains/themes/default/svg/boxplot-raw.jinja View File

@@ -0,0 +1 @@
{% extends 'svg/plot-raw.jinja' %}

+ 17
- 0
poobrains/themes/default/svg/lineplot-raw.jinja View File

@@ -0,0 +1,17 @@
{% extends 'svg/plot-raw.jinja' %}
{% block dataset %}

{% if dataset.authorized_datapoints|length %}
<a class="dataset-link" href="#{{ dataset.ref_id }}">
<path class="dataset-line" d="
{% for datapoint in dataset.authorized_datapoints %}
{% if loop.first %}M{% else %}L{% endif %} {# first loop Moves the "pen", others create Lines from last coord #}
{{ content.normalize_x(datapoint.x) }} {{ content.normalize_y(datapoint.y) }}
{% endfor %}
" />
</a>
{% endif %}

{{ super() }}

{% endblock %}

+ 11
- 13
poobrains/themes/default/svg/plot-raw.jinja View File

@@ -7,7 +7,7 @@
height="{{ content.height }}"
viewBox="0 0 {{ content.width }} {{ content.height }}"
preserveAspectRatio="xMinYMin meet"
class="plot"
class="plot {{ content.__class__.__name__.lower()}}"
>

<!-- a json representation of all visualized data, not used since there's a strict nojs policy, but included for your convenience -->
@@ -24,6 +24,7 @@

<svg class="plot-inner" x="{{ content.padding }}" y="{{ content.padding }}" width="{{ content.inner_width }}" height="{{ content.inner_height }}" viewBox="0 0 {{ content.inner_width }} {{ content.inner_height }}" preserveAspectRatio="xMinYMin meet">
<g class="grid">
{% block grid %}
{% for i in range(0, content.grid_x|length) %}

{% set x = content.grid_x[i] %}
@@ -56,31 +57,25 @@
<text class="grid-label axis-y" transform="rotate(-90 0 {{ content.normalize_y(y) }}) translate(5 -15)" x="0" y="{{ content.normalize_y(y) }}" dominant-baseline="hanging">{{ "%.3f"|format(y) }}</text>
{% endif %}
{% endfor %}
{% endblock %}
</g>

<g class="datasets">
{% block datasets scoped %}
{% for idx in range(0, content.datasets|length) %}

{% set dataset = content.datasets[idx] %}

<g id="{{ dataset.ref_id }}" class="dataset">

{% if dataset.authorized_datapoints|length %}
<a class="dataset-link" href="#{{ dataset.ref_id }}">
<path class="dataset-line" d="
{% for datapoint in dataset.authorized_datapoints %}
{% if loop.first %}M{% else %}L{% endif %} {# first loop Moves the "pen", others create Lines from last coord #}
{{ content.normalize_x(datapoint.x) }} {{ content.normalize_y(datapoint.y) }}
{% endfor %}
" />
</a>
{% endif %}
{% block dataset scoped %}

{% for datapoint in dataset.authorized_datapoints %}


<a href="#{{ dataset.datapoint_id(datapoint) }}">
<g id="{{ dataset.datapoint_id(datapoint) }}" class="datapoint">
{% block datapoint scoped %}

<g class="error">

@@ -104,6 +99,7 @@

<text class="datapoint-value" x="{{ content.normalize_x(datapoint.x) + 5 }}" y="{{ content.normalize_y(datapoint.y) - 20 }}">{{ "%.5f"|format(datapoint.y) }}</text>

{% endblock %}
</g>
</a>

@@ -141,8 +137,10 @@
</switch>
</g>

</g>
{% endfor %}i
{% endblock dataset %}
</g> <!-- / .dataset -->
{% endfor %}
{% endblock %}
</g> <!-- /datasets -->
</svg>
</svg>

+ 5
- 1
poobrains/themes/default/svg/svg.jinja View File

@@ -1,5 +1,9 @@
{% extends 'renderable.jinja' %}

{% block content %}
<object class="svg-wrapper" data="{{ content.url('raw') }}" ></object>
{# <object class="svg-wrapper" data="{{ content.url('raw') }}" ></object> #}

{{ content.render('raw') }}
<a href="{{ content.url('raw') }}">Save</a>

{% endblock %}

Loading…
Cancel
Save