﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20419	Support a limited set of filter to ease writing SVG template	Sylvain Leroux	nobody	"The Django template system is able to process any kind of text document, including SVG.

But the standard filter provided by Django are mostly ""text"" oriented, and does not provide basic ""mathematical"" operations often required by SVG template authors.

Specifically, it appears that when producing SVG chart for example, one require often to scale from model data range to chart axis. With the added complexity that SVG y-axis grows downward -- whereas many charts y-axis grow upward. For now, the only solution is (a) to perform the scaling in the view, which throws out the separation of concern or (b) preferably, provide a custom filter.

Since I think this is a common pattern while producing SVG, it could be interesting to provide a standard ""scaling"" filter. Here is what I propose (a patch is attached):

{{{#!python
@register.filter(""map"")
def map_filter(value, src_min, src_max, dst_min, dst_max):
    """"""map the value from [src_min,src_max] range to [dst_min, dst_max]
    range.

    Modeled after the corresponding map() function available (for
    example) in Processing http://processing.org/reference/map_.html
    """"""
    return dst_min + ( value - src_min ) * ( dst_max - dst_min) / ( src_max - src_min)
}}}

As stated in the comment, this is modeled after the corresponding Processing map() function, since our designer was more familiar with that language. Maybe, ""scale()"" could be less confusing for Python-aware people."	New feature	closed	Template system	dev	Normal	wontfix			Unreviewed	1	0	0	0	1	0
