Browse Source

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

master
phryk 2 months ago
parent
commit
c847630b30

+ 1
- 1
example.py View File

@@ -121,7 +121,7 @@ def list_nonexposed(listing):
121 121
 
122 122
 class NASAApproaches(poobrains.svg.plot.Dataset):
123 123
 
124
-    def fill(self, spkid):
124
+    def fill(self, spkid=2099942): # default spkid for apophis
125 125
 
126 126
         try:
127 127
             spkid = int(spkid)

+ 5
- 1
poobrains/__init__.py View File

@@ -604,13 +604,17 @@ class Poobrain(flask.Flask):
604 604
         return decorator
605 605
 
606 606
 
607
-    def expose(self, rule, mode='full', title=None, force_secure=False):
607
+    def expose(self, rule, mode='full', extra_modes=None, title=None, force_secure=False):
608 608
         def decorator(cls):
609 609
 
610 610
             if issubclass(cls, storage.Storable):
611 611
                 self.site.add_listing(cls, rule, mode='teaser', title=title, force_secure=force_secure)
612 612
                 self.site.add_view(cls, os.path.join(rule, '<handle>/'), mode=mode, force_secure=force_secure)
613 613
 
614
+                if not extra_modes is None:
615
+                    for extra_mode in extra_modes:
616
+                        self.site.add_view(cls, os.path.join(rule, '<handle>/%s' % extra_mode), mode=extra_mode, force_secure=force_secure)
617
+
614 618
                 for related_model, related_fields in cls._meta.model_backrefs.items(): # Add Models that are associated by ForeignKeyField, like /user/foo/userpermissions
615 619
 
616 620
                     if len(related_fields) > 1:

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

@@ -312,6 +312,7 @@ class Plot(base.SVG):
312 312
     description_height = None
313 313
 
314 314
     datasets = None
315
+    length = None
315 316
     min_x = None
316 317
     max_x = None
317 318
     min_y = None
@@ -361,9 +362,14 @@ class Plot(base.SVG):
361 362
                 self.datasets.append(ds)
362 363
 
363 364
         datapoint_count = 0
365
+        self.length = 0
364 366
         #for datapoint in Datapoint.list('read', g.user).where(Datapoint.dataset << self.datasets):
365 367
         for dataset in self.datasets:
366 368
 
369
+            l = len(dataset.authorized_datapoints)
370
+            if l > self.length:
371
+                self.length = l
372
+
367 373
             for datapoint in dataset.authorized_datapoints:
368 374
 
369 375
                 datapoint_count += 1
@@ -491,6 +497,20 @@ class Plot(base.SVG):
491 497
         return coords
492 498
 
493 499
 
500
+@app.expose('/svg/lineplot')
501
+class LinePlot(Plot):
502
+    pass
503
+
504
+
505
+@app.expose('/svg/barchart')
506
+class BarChart(Plot):
507
+    
508
+    @property
509
+    def bar_width(self):
510
+        #return 10
511
+        return (self.plot_width - self.padding) / self.length - 1
512
+
513
+
494 514
 def new_editor_handle():
495 515
 
496 516
     handle = poobrains.helpers.random_string_light()
@@ -500,6 +520,7 @@ def new_editor_handle():
500 520
 
501 521
     return new_editor_handle()
502 522
 
523
+
503 524
 def dataset_choices():
504 525
 
505 526
 

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

@@ -48,6 +48,10 @@ svg {
48 48
     font-family: 'Clear Sans', sans;
49 49
 }
50 50
 
51
+text {
52
+    stroke: $color_font_light;
53
+}
54
+
51 55
 svg#hexascroll {
52 56
 
53 57
 
@@ -377,8 +381,10 @@ svg#checkbox {
377 381
                         
378 382
                     g.datapoint {
379 383
 
380
-                        .marker {
381
-                            fill: desaturate($color, 20%);
384
+                        .marker,
385
+                        .bar {
386
+                            fill: desaturate($color, 60%);
387
+                            transition: fill 0.3s linear;
382 388
                         }
383 389
 
384 390
                         g.error {
@@ -396,7 +402,8 @@ svg#checkbox {
396 402
                         &:focus,
397 403
                         &:target {
398 404
 
399
-                            .marker {
405
+                            .marker,
406
+                            .bar {
400 407
                                 fill: $color;
401 408
                             }
402 409
                         }

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

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

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

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

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

@@ -0,0 +1,17 @@
1
+{% extends 'svg/plot-raw.jinja' %}
2
+{% block dataset %}
3
+
4
+    {% if dataset.authorized_datapoints|length %} 
5
+    <a class="dataset-link" href="#{{ dataset.ref_id }}">
6
+        <path class="dataset-line" d="
7
+            {% for datapoint in dataset.authorized_datapoints %}
8
+                {% if loop.first %}M{% else %}L{% endif %} {# first loop Moves the "pen", others create Lines from last coord #}
9
+                {{ content.normalize_x(datapoint.x) }} {{ content.normalize_y(datapoint.y) }}
10
+            {% endfor %}
11
+        " />
12
+    </a>
13
+    {% endif %}
14
+
15
+    {{ super() }}
16
+
17
+{% endblock %}

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

@@ -7,7 +7,7 @@
7 7
     height="{{ content.height }}"
8 8
     viewBox="0 0 {{ content.width }} {{ content.height }}"
9 9
     preserveAspectRatio="xMinYMin meet"
10
-    class="plot"
10
+    class="plot {{ content.__class__.__name__.lower()}}"
11 11
    >
12 12
 
13 13
     <!-- 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 @@
24 24
 
25 25
     <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">
26 26
         <g class="grid">
27
+            {% block grid %}
27 28
             {% for i in range(0, content.grid_x|length) %}
28 29
 
29 30
                 {% set x = content.grid_x[i] %}
@@ -56,31 +57,25 @@
56 57
                 <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>
57 58
                 {% endif %}
58 59
             {% endfor %}
60
+            {% endblock %}
59 61
         </g>
60 62
 
61 63
         <g class="datasets">
64
+        {% block datasets scoped %}
62 65
         {% for idx in range(0, content.datasets|length) %}
63 66
 
64 67
             {% set dataset = content.datasets[idx] %}
65 68
 
66 69
             <g id="{{ dataset.ref_id }}" class="dataset">
67 70
 
68
-                {% if dataset.authorized_datapoints|length %} 
69
-                <a class="dataset-link" href="#{{ dataset.ref_id }}">
70
-                    <path class="dataset-line" d="
71
-                        {% for datapoint in dataset.authorized_datapoints %}
72
-                            {% if loop.first %}M{% else %}L{% endif %} {# first loop Moves the "pen", others create Lines from last coord #}
73
-                            {{ content.normalize_x(datapoint.x) }} {{ content.normalize_y(datapoint.y) }}
74
-                        {% endfor %}
75
-                    " />
76
-                </a>
77
-                {% endif %}
71
+                {% block dataset scoped %}
78 72
 
79 73
                 {% for datapoint in dataset.authorized_datapoints %}
80 74
 
81 75
 
82 76
                     <a href="#{{ dataset.datapoint_id(datapoint) }}">
83 77
                         <g id="{{ dataset.datapoint_id(datapoint) }}" class="datapoint">
78
+                        {% block datapoint scoped %}
84 79
 
85 80
                             <g class="error">
86 81
 
@@ -104,6 +99,7 @@
104 99
 
105 100
                             <text class="datapoint-value" x="{{ content.normalize_x(datapoint.x) + 5 }}" y="{{ content.normalize_y(datapoint.y) - 20 }}">{{ "%.5f"|format(datapoint.y) }}</text>
106 101
 
102
+                        {% endblock %}
107 103
                         </g>
108 104
                     </a>
109 105
 
@@ -141,8 +137,10 @@
141 137
                     </switch>
142 138
                 </g>
143 139
 
144
-            </g>
145
-        {% endfor %}i
140
+            {% endblock dataset %}
141
+            </g> <!-- / .dataset -->
142
+        {% endfor %}
143
+        {% endblock %}
146 144
         </g> <!-- /datasets -->
147 145
     </svg>
148 146
 </svg>

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

@@ -1,5 +1,9 @@
1 1
 {% extends 'renderable.jinja' %}
2 2
 
3 3
 {% block content %}
4
-    <object class="svg-wrapper" data="{{ content.url('raw') }}" ></object>
4
+    {# <object class="svg-wrapper" data="{{ content.url('raw') }}" ></object> #}
5
+
6
+    {{ content.render('raw') }}
7
+    <a href="{{ content.url('raw') }}">Save</a>
8
+
5 9
 {% endblock %}

Loading…
Cancel
Save