def widthratio(value, maxvalue, max_width):
try:<EOL><INDENT>max_width = int(max_width)<EOL><DEDENT>except ValueError:<EOL><INDENT>raise TemplateSyntaxError("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>value = float(value)<EOL>maxvalue = float(maxvalue)<EOL>ratio = (value / maxvalue) * max_width<EOL><DEDENT>except (ValueError, ZeroDivisionError):<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>return str(int(round(ratio)))<EOL>
For creating bar charts and such, this tag calculates the ratio of a given
value to a maximum value, and then applies that ratio to a constant.

For example::

    <img src='bar.gif' height='10' width='{% widthratio this_value max_value 100 %}' />

Above, if ``this_value`` is 175 and ``max_value`` is 200, the image in
the above example will be 88 pixels wide (because 175/200 = .875;
.875 * 100 = 87.5 which is rounded up to 88).