[Python-modules-commits] [python-chartkick] 01/11: New upstream version 0.5.0
ChangZhuo Chen
czchen at moszumanska.debian.org
Fri Sep 2 10:12:30 UTC 2016
This is an automated email from the git hooks/post-receive script.
czchen pushed a commit to branch master
in repository python-chartkick.
commit c15d4fc57c135036ce80e6e70efec0c8aeb0fbe8
Author: ChangZhuo Chen (陳昌倬) <czchen at debian.org>
Date: Fri Sep 2 14:41:26 2016 +0800
New upstream version 0.5.0
---
MANIFEST.in | 3 +
PKG-INFO | 141 ++++
README.rst | 120 +++
chartkick.egg-info/PKG-INFO | 141 ++++
chartkick.egg-info/SOURCES.txt | 14 +
chartkick.egg-info/dependency_links.txt | 1 +
chartkick.egg-info/top_level.txt | 1 +
chartkick/__init__.py | 10 +
chartkick/ext.py | 102 +++
chartkick/js/chartkick.js | 1352 +++++++++++++++++++++++++++++++
chartkick/options.py | 20 +
chartkick/template.py | 16 +
chartkick/templatetags/__init__.py | 0
chartkick/templatetags/chartkick.py | 109 +++
setup.cfg | 5 +
setup.py | 50 ++
16 files changed, 2085 insertions(+)
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..861293a
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,3 @@
+include MANIFEST.in
+include README.rst
+recursive-include chartkick/js *
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..ee7820a
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,141 @@
+Metadata-Version: 1.1
+Name: chartkick
+Version: 0.5.0
+Summary: Create beautiful Javascript charts with minimal code
+Home-page: https://github.com/mher/chartkick.py
+Author: Mher Movsisyan
+Author-email: mher.movsisyan at gmail.com
+License: MIT
+Description: Chartkick.py
+ ============
+
+ .. image:: https://img.shields.io/pypi/v/chartkick.svg
+ :target: https://pypi.python.org/pypi/chartkick
+
+ .. image:: https://img.shields.io/pypi/dm/chartkick.svg
+ :target: https://pypi.python.org/pypi/chartkick
+
+ .. image:: https://travis-ci.org/mher/chartkick.py.svg?branch=master
+ :target: https://travis-ci.org/mher/chartkick.py
+
+ Create beautiful Javascript charts with minimal code. Demo_!
+
+ Supports `Chart.js`_, `Google Charts`_, and Highcharts_
+
+ Works with Django, Flask/Jinja2 and most browsers (including IE 6).
+ Also available in Ruby_ and pure JavaScript_
+
+ .. _Chartkick: http://chartkick.com
+ .. _Chart.js: http://www.chartjs.org
+ .. _Google Charts: https://developers.google.com/chart/
+ .. _Highcharts: http://highcharts.com
+ .. _Demo: http://mher.github.io/chartkick.py/
+ .. _Ruby: http://chartkick.com
+ .. _Javascript: https://github.com/ankane/chartkick.js
+
+ Usage
+ -----
+
+ Line chart: ::
+
+ {% line_chart data %}
+
+ Pie chart: ::
+
+ {% pie_chart data with id='chart-1' height='400px' %}
+
+ Column chart: ::
+
+ {% column_chart data with min=400 max=1000 %}
+
+ Bar chart: ::
+
+ {% bar_chart data %}
+
+ Area chart: ::
+
+ {% area_chart data %}
+
+ Data
+ ----
+
+ Data can be a dictionary or a list: ::
+
+ {'Chrome': 52.9, 'Opera': 1.6, 'Firefox': 27.7}
+
+ [['Chrome', 52.9], ['Firefox', 27.7], ['Opera', 1.6]]
+
+ For multiple series: ::
+
+ [{'data': [['2013-04-01 00:00:00 UTC', 52.9], ['2013-05-01 00:00:00 UTC', 50.7]], 'name': 'Chrome'},
+ {'data': [['2013-04-01 00:00:00 UTC', 27.7], ['2013-05-01 00:00:00 UTC', 25.9]], 'name': 'Firefox'}]
+
+ Options
+ -------
+
+ Charting library options can be passed through the *library* variable: ::
+
+ {% column_chart data with library={"title":"Super chart","width":"400px"} %}
+
+ .. Note:: Google Charts and Highcharts have different APIs. You may need
+ to change the value of `library` when you switch from one
+ library to another.
+
+ Or using *chartkick.json* file. Chartkick tries to locate *chartkick.json*
+ file in template path and match options by id.
+
+ Installation
+ ------------
+
+ Install chartkick: ::
+
+ $ pip install chartkick
+
+ - Django: Add chartkick to *INSTALLED_APPS* and *STATICFILES_DIRS*: ::
+
+ INSTALLED_APPS = (
+ 'chartkick',
+ )
+
+ import chartkick
+ STATICFILES_DIRS = (
+ chartkick.js(),
+ )
+
+ - Flask: Add chartkick to *jinja_env* and *static_folder*: ::
+
+ ck = Blueprint('ck_page', __name__, static_folder=chartkick.js(), static_url_path='/static')
+ app.register_blueprint(ck, url_prefix='/ck')
+ app.jinja_env.add_extension("chartkick.ext.charts")
+
+ Load JS scripts:
+
+ - Chart.js ::
+
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.4/Chart.bundle.min.js"></script>
+ <script src="ck/static/chartkick.js"></script>
+
+ - Google Charts ::
+
+ <script src="http://www.google.com/jsapi"></script>
+ <script src="ck/static/chartkick.js"></script>
+
+ - Highcharts ::
+
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
+ <script src="http://code.highcharts.com/highcharts.js"></script>
+ <script src="ck/static/chartkick.js"></script>
+
+
+Platform: UNKNOWN
+Classifier: Development Status :: 3 - Alpha
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Topic :: Software Development :: Libraries
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: Implementation :: CPython
+Classifier: Operating System :: OS Independent
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..b4b3bf9
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,120 @@
+Chartkick.py
+============
+
+.. image:: https://img.shields.io/pypi/v/chartkick.svg
+ :target: https://pypi.python.org/pypi/chartkick
+
+.. image:: https://img.shields.io/pypi/dm/chartkick.svg
+ :target: https://pypi.python.org/pypi/chartkick
+
+.. image:: https://travis-ci.org/mher/chartkick.py.svg?branch=master
+ :target: https://travis-ci.org/mher/chartkick.py
+
+Create beautiful Javascript charts with minimal code. Demo_!
+
+Supports `Chart.js`_, `Google Charts`_, and Highcharts_
+
+Works with Django, Flask/Jinja2 and most browsers (including IE 6).
+Also available in Ruby_ and pure JavaScript_
+
+.. _Chartkick: http://chartkick.com
+.. _Chart.js: http://www.chartjs.org
+.. _Google Charts: https://developers.google.com/chart/
+.. _Highcharts: http://highcharts.com
+.. _Demo: http://mher.github.io/chartkick.py/
+.. _Ruby: http://chartkick.com
+.. _Javascript: https://github.com/ankane/chartkick.js
+
+Usage
+-----
+
+Line chart: ::
+
+ {% line_chart data %}
+
+Pie chart: ::
+
+ {% pie_chart data with id='chart-1' height='400px' %}
+
+Column chart: ::
+
+ {% column_chart data with min=400 max=1000 %}
+
+Bar chart: ::
+
+ {% bar_chart data %}
+
+Area chart: ::
+
+ {% area_chart data %}
+
+Data
+----
+
+Data can be a dictionary or a list: ::
+
+ {'Chrome': 52.9, 'Opera': 1.6, 'Firefox': 27.7}
+
+ [['Chrome', 52.9], ['Firefox', 27.7], ['Opera', 1.6]]
+
+For multiple series: ::
+
+ [{'data': [['2013-04-01 00:00:00 UTC', 52.9], ['2013-05-01 00:00:00 UTC', 50.7]], 'name': 'Chrome'},
+ {'data': [['2013-04-01 00:00:00 UTC', 27.7], ['2013-05-01 00:00:00 UTC', 25.9]], 'name': 'Firefox'}]
+
+Options
+-------
+
+Charting library options can be passed through the *library* variable: ::
+
+ {% column_chart data with library={"title":"Super chart","width":"400px"} %}
+
+.. Note:: Google Charts and Highcharts have different APIs. You may need
+ to change the value of `library` when you switch from one
+ library to another.
+
+Or using *chartkick.json* file. Chartkick tries to locate *chartkick.json*
+file in template path and match options by id.
+
+Installation
+------------
+
+Install chartkick: ::
+
+ $ pip install chartkick
+
+- Django: Add chartkick to *INSTALLED_APPS* and *STATICFILES_DIRS*: ::
+
+ INSTALLED_APPS = (
+ 'chartkick',
+ )
+
+ import chartkick
+ STATICFILES_DIRS = (
+ chartkick.js(),
+ )
+
+- Flask: Add chartkick to *jinja_env* and *static_folder*: ::
+
+ ck = Blueprint('ck_page', __name__, static_folder=chartkick.js(), static_url_path='/static')
+ app.register_blueprint(ck, url_prefix='/ck')
+ app.jinja_env.add_extension("chartkick.ext.charts")
+
+Load JS scripts:
+
+- Chart.js ::
+
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.4/Chart.bundle.min.js"></script>
+ <script src="ck/static/chartkick.js"></script>
+
+- Google Charts ::
+
+ <script src="http://www.google.com/jsapi"></script>
+ <script src="ck/static/chartkick.js"></script>
+
+- Highcharts ::
+
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
+ <script src="http://code.highcharts.com/highcharts.js"></script>
+ <script src="ck/static/chartkick.js"></script>
+
diff --git a/chartkick.egg-info/PKG-INFO b/chartkick.egg-info/PKG-INFO
new file mode 100644
index 0000000..ee7820a
--- /dev/null
+++ b/chartkick.egg-info/PKG-INFO
@@ -0,0 +1,141 @@
+Metadata-Version: 1.1
+Name: chartkick
+Version: 0.5.0
+Summary: Create beautiful Javascript charts with minimal code
+Home-page: https://github.com/mher/chartkick.py
+Author: Mher Movsisyan
+Author-email: mher.movsisyan at gmail.com
+License: MIT
+Description: Chartkick.py
+ ============
+
+ .. image:: https://img.shields.io/pypi/v/chartkick.svg
+ :target: https://pypi.python.org/pypi/chartkick
+
+ .. image:: https://img.shields.io/pypi/dm/chartkick.svg
+ :target: https://pypi.python.org/pypi/chartkick
+
+ .. image:: https://travis-ci.org/mher/chartkick.py.svg?branch=master
+ :target: https://travis-ci.org/mher/chartkick.py
+
+ Create beautiful Javascript charts with minimal code. Demo_!
+
+ Supports `Chart.js`_, `Google Charts`_, and Highcharts_
+
+ Works with Django, Flask/Jinja2 and most browsers (including IE 6).
+ Also available in Ruby_ and pure JavaScript_
+
+ .. _Chartkick: http://chartkick.com
+ .. _Chart.js: http://www.chartjs.org
+ .. _Google Charts: https://developers.google.com/chart/
+ .. _Highcharts: http://highcharts.com
+ .. _Demo: http://mher.github.io/chartkick.py/
+ .. _Ruby: http://chartkick.com
+ .. _Javascript: https://github.com/ankane/chartkick.js
+
+ Usage
+ -----
+
+ Line chart: ::
+
+ {% line_chart data %}
+
+ Pie chart: ::
+
+ {% pie_chart data with id='chart-1' height='400px' %}
+
+ Column chart: ::
+
+ {% column_chart data with min=400 max=1000 %}
+
+ Bar chart: ::
+
+ {% bar_chart data %}
+
+ Area chart: ::
+
+ {% area_chart data %}
+
+ Data
+ ----
+
+ Data can be a dictionary or a list: ::
+
+ {'Chrome': 52.9, 'Opera': 1.6, 'Firefox': 27.7}
+
+ [['Chrome', 52.9], ['Firefox', 27.7], ['Opera', 1.6]]
+
+ For multiple series: ::
+
+ [{'data': [['2013-04-01 00:00:00 UTC', 52.9], ['2013-05-01 00:00:00 UTC', 50.7]], 'name': 'Chrome'},
+ {'data': [['2013-04-01 00:00:00 UTC', 27.7], ['2013-05-01 00:00:00 UTC', 25.9]], 'name': 'Firefox'}]
+
+ Options
+ -------
+
+ Charting library options can be passed through the *library* variable: ::
+
+ {% column_chart data with library={"title":"Super chart","width":"400px"} %}
+
+ .. Note:: Google Charts and Highcharts have different APIs. You may need
+ to change the value of `library` when you switch from one
+ library to another.
+
+ Or using *chartkick.json* file. Chartkick tries to locate *chartkick.json*
+ file in template path and match options by id.
+
+ Installation
+ ------------
+
+ Install chartkick: ::
+
+ $ pip install chartkick
+
+ - Django: Add chartkick to *INSTALLED_APPS* and *STATICFILES_DIRS*: ::
+
+ INSTALLED_APPS = (
+ 'chartkick',
+ )
+
+ import chartkick
+ STATICFILES_DIRS = (
+ chartkick.js(),
+ )
+
+ - Flask: Add chartkick to *jinja_env* and *static_folder*: ::
+
+ ck = Blueprint('ck_page', __name__, static_folder=chartkick.js(), static_url_path='/static')
+ app.register_blueprint(ck, url_prefix='/ck')
+ app.jinja_env.add_extension("chartkick.ext.charts")
+
+ Load JS scripts:
+
+ - Chart.js ::
+
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.4/Chart.bundle.min.js"></script>
+ <script src="ck/static/chartkick.js"></script>
+
+ - Google Charts ::
+
+ <script src="http://www.google.com/jsapi"></script>
+ <script src="ck/static/chartkick.js"></script>
+
+ - Highcharts ::
+
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
+ <script src="http://code.highcharts.com/highcharts.js"></script>
+ <script src="ck/static/chartkick.js"></script>
+
+
+Platform: UNKNOWN
+Classifier: Development Status :: 3 - Alpha
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Topic :: Software Development :: Libraries
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: Implementation :: CPython
+Classifier: Operating System :: OS Independent
diff --git a/chartkick.egg-info/SOURCES.txt b/chartkick.egg-info/SOURCES.txt
new file mode 100644
index 0000000..abc38b8
--- /dev/null
+++ b/chartkick.egg-info/SOURCES.txt
@@ -0,0 +1,14 @@
+MANIFEST.in
+README.rst
+setup.py
+chartkick/__init__.py
+chartkick/ext.py
+chartkick/options.py
+chartkick/template.py
+chartkick.egg-info/PKG-INFO
+chartkick.egg-info/SOURCES.txt
+chartkick.egg-info/dependency_links.txt
+chartkick.egg-info/top_level.txt
+chartkick/js/chartkick.js
+chartkick/templatetags/__init__.py
+chartkick/templatetags/chartkick.py
\ No newline at end of file
diff --git a/chartkick.egg-info/dependency_links.txt b/chartkick.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/chartkick.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/chartkick.egg-info/top_level.txt b/chartkick.egg-info/top_level.txt
new file mode 100644
index 0000000..ca7f5aa
--- /dev/null
+++ b/chartkick.egg-info/top_level.txt
@@ -0,0 +1 @@
+chartkick
diff --git a/chartkick/__init__.py b/chartkick/__init__.py
new file mode 100644
index 0000000..c8e00cb
--- /dev/null
+++ b/chartkick/__init__.py
@@ -0,0 +1,10 @@
+from __future__ import absolute_import
+import os
+
+VERSION = (0, 5, 0)
+__version__ = '.'.join(map(str, VERSION))
+
+
+def js():
+ "returns home directory of js"
+ return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'js')
diff --git a/chartkick/ext.py b/chartkick/ext.py
new file mode 100644
index 0000000..7d00eef
--- /dev/null
+++ b/chartkick/ext.py
@@ -0,0 +1,102 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import
+
+import json
+import itertools
+import functools
+
+from jinja2 import nodes
+from jinja2.ext import Extension
+from jinja2.exceptions import TemplateNotFound
+
+from .template import CHART_HTML
+from .options import Options
+
+
+class ChartExtension(Extension):
+ tags = set(['line_chart', 'pie_chart', 'column_chart',
+ 'bar_chart', 'area_chart'])
+
+ id = itertools.count()
+ _library = None
+
+ def __init__(self, environment):
+ super(ChartExtension, self).__init__(environment)
+
+ environment.extend(
+ options=dict(height='300px'),
+ )
+
+ for tag in self.tags:
+ setattr(self, tag + '_support',
+ functools.partial(self._chart_support, tag))
+
+ def parse(self, parser):
+ # parse chart name
+ chart_tag = next(parser.stream)
+
+ args = [parser.parse_expression()]
+
+ # parse 'with' statement
+ if parser.stream.current.type != 'block_end':
+ token = next(parser.stream)
+ if token.value != 'with':
+ parser.fail("expected 'with' statement", token.lineno)
+
+ # parse options
+ while parser.stream.current.type != 'block_end':
+ lineno = parser.stream.current.lineno
+
+ target = parser.parse_assign_target()
+ parser.stream.expect('assign')
+ expr = parser.parse_expression()
+
+ args.append(nodes.Assign(target, expr, lineno=lineno))
+
+ support_func = chart_tag.value + '_support'
+
+ return nodes.CallBlock(self.call_method(support_func, args),
+ [], [], []).set_lineno(chart_tag.lineno)
+
+ def _chart_support(self, name, data, caller, **kwargs):
+ "template chart support function"
+ id = 'chart-%s' % next(self.id)
+ name = self._chart_class_name(name)
+ options = dict(self.environment.options)
+ options.update(name=name, id=id)
+
+ # jinja2 prepends 'l_' to keys
+ kwargs = dict((k[2:], v) for (k, v) in kwargs.items())
+
+ if self._library is None:
+ self._library = self.load_library()
+ id = kwargs.get('id', '')
+ library = self._library.get(id, {})
+
+ # apply options from a tag
+ library.update(kwargs.get('library', {}))
+ # apply options from chartkick.json
+ kwargs.update(library=library)
+
+ options.update(kwargs)
+ return CHART_HTML.format(data=data, options=json.dumps(kwargs),
+ **options)
+
+ def _chart_class_name(self, tag_name):
+ "converts chart tag name to javascript class name"
+ return ''.join(map(str.title, tag_name.split('_')))
+
+ def load_library(self):
+ "loads configuration options"
+ try:
+ filename = self.environment.get_template('chartkick.json').filename
+ except TemplateNotFound:
+ return {}
+ else:
+ options = Options()
+ options.load(filename)
+ return options
+
+
+charts = ChartExtension
diff --git a/chartkick/js/chartkick.js b/chartkick/js/chartkick.js
new file mode 100644
index 0000000..f531248
--- /dev/null
+++ b/chartkick/js/chartkick.js
@@ -0,0 +1,1352 @@
+/*
+ * Chartkick.js
+ * Create beautiful JavaScript charts with minimal code
+ * https://github.com/ankane/chartkick.js
+ * v2.0.0
+ * MIT License
+ */
+
+/*jslint browser: true, indent: 2, plusplus: true, vars: true */
+
+(function (window) {
+ 'use strict';
+
+ var config = window.Chartkick || {};
+ var Chartkick, ISO8601_PATTERN, DECIMAL_SEPARATOR, adapters = [];
+ var DATE_PATTERN = /^(\d\d\d\d)(\-)?(\d\d)(\-)?(\d\d)$/i;
+ var GoogleChartsAdapter, HighchartsAdapter, ChartjsAdapter;
+
+ // helpers
+
+ function isArray(variable) {
+ return Object.prototype.toString.call(variable) === "[object Array]";
+ }
+
+ function isFunction(variable) {
+ return variable instanceof Function;
+ }
+
+ function isPlainObject(variable) {
+ return !isFunction(variable) && variable instanceof Object;
+ }
+
+ // https://github.com/madrobby/zepto/blob/master/src/zepto.js
+ function extend(target, source) {
+ var key;
+ for (key in source) {
+ if (isPlainObject(source[key]) || isArray(source[key])) {
+ if (isPlainObject(source[key]) && !isPlainObject(target[key])) {
+ target[key] = {};
+ }
+ if (isArray(source[key]) && !isArray(target[key])) {
+ target[key] = [];
+ }
+ extend(target[key], source[key]);
+ } else if (source[key] !== undefined) {
+ target[key] = source[key];
+ }
+ }
+ }
+
+ function merge(obj1, obj2) {
+ var target = {};
+ extend(target, obj1);
+ extend(target, obj2);
+ return target;
+ }
+
+ // https://github.com/Do/iso8601.js
+ ISO8601_PATTERN = /(\d\d\d\d)(\-)?(\d\d)(\-)?(\d\d)(T)?(\d\d)(:)?(\d\d)?(:)?(\d\d)?([\.,]\d+)?($|Z|([\+\-])(\d\d)(:)?(\d\d)?)/i;
+ DECIMAL_SEPARATOR = String(1.5).charAt(1);
+
+ function parseISO8601(input) {
+ var day, hour, matches, milliseconds, minutes, month, offset, result, seconds, type, year;
+ type = Object.prototype.toString.call(input);
+ if (type === '[object Date]') {
+ return input;
+ }
+ if (type !== '[object String]') {
+ return;
+ }
+ matches = input.match(ISO8601_PATTERN);
+ if (matches) {
+ year = parseInt(matches[1], 10);
+ month = parseInt(matches[3], 10) - 1;
+ day = parseInt(matches[5], 10);
+ hour = parseInt(matches[7], 10);
+ minutes = matches[9] ? parseInt(matches[9], 10) : 0;
+ seconds = matches[11] ? parseInt(matches[11], 10) : 0;
+ milliseconds = matches[12] ? parseFloat(DECIMAL_SEPARATOR + matches[12].slice(1)) * 1000 : 0;
+ result = Date.UTC(year, month, day, hour, minutes, seconds, milliseconds);
+ if (matches[13] && matches[14]) {
+ offset = matches[15] * 60;
+ if (matches[17]) {
+ offset += parseInt(matches[17], 10);
+ }
+ offset *= matches[14] === '-' ? -1 : 1;
+ result -= offset * 60 * 1000;
+ }
+ return new Date(result);
+ }
+ }
+ // end iso8601.js
+
+ function negativeValues(series) {
+ var i, j, data;
+ for (i = 0; i < series.length; i++) {
+ data = series[i].data;
+ for (j = 0; j < data.length; j++) {
+ if (data[j][1] < 0) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ function jsOptionsFunc(defaultOptions, hideLegend, setMin, setMax, setStacked, setXtitle, setYtitle) {
+ return function (series, opts, chartOptions) {
+ var options = merge({}, defaultOptions);
+ options = merge(options, chartOptions || {});
+
+ // hide legend
+ // this is *not* an external option!
+ if (opts.hideLegend) {
+ hideLegend(options);
+ }
+
+ // min
+ if ("min" in opts) {
+ setMin(options, opts.min);
+ } else if (!negativeValues(series)) {
+ setMin(options, 0);
+ }
+
+ // max
+ if (opts.max) {
+ setMax(options, opts.max);
+ }
+
+ if ("stacked" in opts) {
+ setStacked(options, opts.stacked);
+ }
+
+ if (opts.colors) {
+ options.colors = opts.colors;
+ }
+
+ if (opts.xtitle) {
+ setXtitle(options, opts.xtitle);
+ }
+
+ if (opts.ytitle) {
+ setYtitle(options, opts.ytitle);
+ }
+
+ // merge library last
+ options = merge(options, opts.library || {});
+
+ return options;
+ };
+ }
+
+ function setText(element, text) {
+ if (document.body.innerText) {
+ element.innerText = text;
+ } else {
+ element.textContent = text;
+ }
+ }
+
+ function chartError(element, message) {
+ setText(element, "Error Loading Chart: " + message);
+ element.style.color = "#ff0000";
+ }
+
+ function getJSON(element, url, success) {
+ var $ = window.jQuery || window.Zepto || window.$;
+ $.ajax({
+ dataType: "json",
+ url: url,
+ success: success,
+ error: function (jqXHR, textStatus, errorThrown) {
+ var message = (typeof errorThrown === "string") ? errorThrown : errorThrown.message;
+ chartError(element, message);
+ }
+ });
+ }
+
+ function errorCatcher(chart, callback) {
+ try {
+ callback(chart);
+ } catch (err) {
+ chartError(chart.element, err.message);
+ throw err;
+ }
+ }
+
+ function fetchDataSource(chart, callback) {
+ if (typeof chart.dataSource === "string") {
+ getJSON(chart.element, chart.dataSource, function (data, textStatus, jqXHR) {
+ chart.data = data;
+ errorCatcher(chart, callback);
+ });
+ } else {
+ chart.data = chart.dataSource;
+ errorCatcher(chart, callback);
+ }
+ }
+
+ // type conversions
+
+ function toStr(n) {
+ return "" + n;
+ }
+
+ function toFloat(n) {
+ return parseFloat(n);
+ }
+
+ function toDate(n) {
+ var matches, year, month, day;
+ if (typeof n !== "object") {
+ if (typeof n === "number") {
+ n = new Date(n * 1000); // ms
+ } else if ((matches = n.match(DATE_PATTERN))) {
+ year = parseInt(matches[1], 10);
+ month = parseInt(matches[3], 10) - 1;
+ day = parseInt(matches[5], 10);
+ return new Date(year, month, day);
+ } else { // str
+ // try our best to get the str into iso8601
+ // TODO be smarter about this
+ var str = n.replace(/ /, "T").replace(" ", "").replace("UTC", "Z");
+ n = parseISO8601(str) || new Date(n);
+ }
+ }
+ return n;
+ }
+
+ function toArr(n) {
+ if (!isArray(n)) {
+ var arr = [], i;
+ for (i in n) {
+ if (n.hasOwnProperty(i)) {
+ arr.push([i, n[i]]);
+ }
+ }
+ n = arr;
+ }
+ return n;
+ }
+
+ function sortByTime(a, b) {
+ return a[0].getTime() - b[0].getTime();
+ }
+
+ function sortByNumber(a, b) {
+ return a - b;
+ }
+
+ function loadAdapters() {
+ if (!HighchartsAdapter && "Highcharts" in window) {
+ HighchartsAdapter = new function () {
+ var Highcharts = window.Highcharts;
+
+ this.name = "highcharts";
+
+ var defaultOptions = {
+ chart: {},
+ xAxis: {
+ title: {
+ text: null
+ },
+ labels: {
+ style: {
+ fontSize: "12px"
+ }
+ }
+ },
+ yAxis: {
+ title: {
+ text: null
+ },
+ labels: {
+ style: {
+ fontSize: "12px"
+ }
+ }
+ },
+ title: {
+ text: null
+ },
+ credits: {
+ enabled: false
+ },
+ legend: {
+ borderWidth: 0
+ },
+ tooltip: {
+ style: {
+ fontSize: "12px"
+ }
+ },
+ plotOptions: {
+ areaspline: {},
+ series: {
+ marker: {}
+ }
+ }
+ };
+
+ var hideLegend = function (options) {
+ options.legend.enabled = false;
+ };
+
+ var setMin = function (options, min) {
+ options.yAxis.min = min;
+ };
+
+ var setMax = function (options, max) {
+ options.yAxis.max = max;
+ };
+
+ var setStacked = function (options, stacked) {
+ options.plotOptions.series.stacking = stacked ? "normal" : null;
+ };
+
+ var setXtitle = function (options, title) {
+ options.xAxis.title.text = title;
+ };
+
+ var setYtitle = function (options, title) {
+ options.yAxis.title.text = title;
+ };
+
+ var jsOptions = jsOptionsFunc(defaultOptions, hideLegend, setMin, setMax, setStacked, setXtitle, setYtitle);
+
+ this.renderLineChart = function (chart, chartType) {
+ chartType = chartType || "spline";
+ var chartOptions = {};
+ if (chartType === "areaspline") {
+ chartOptions = {
+ plotOptions: {
+ areaspline: {
+ stacking: "normal"
+ },
+ series: {
+ marker: {
+ enabled: false
+ }
+ }
+ }
+ };
+ }
+ var options = jsOptions(chart.data, chart.options, chartOptions), data, i, j;
+ options.xAxis.type = chart.options.discrete ? "category" : "datetime";
+ options.chart.type = chartType;
+ options.chart.renderTo = chart.element.id;
+
+ var series = chart.data;
+ for (i = 0; i < series.length; i++) {
+ data = series[i].data;
+ if (!chart.options.discrete) {
+ for (j = 0; j < data.length; j++) {
+ data[j][0] = data[j][0].getTime();
+ }
+ }
+ series[i].marker = {symbol: "circle"};
+ }
+ options.series = series;
+ new Highcharts.Chart(options);
+ };
+
+ this.renderScatterChart = function (chart) {
+ var chartOptions = {};
+ var options = jsOptions(chart.data, chart.options, chartOptions);
+ options.chart.type = 'scatter';
+ options.chart.renderTo = chart.element.id;
+ options.series = chart.data;
+ new Highcharts.Chart(options);
+ };
+
+ this.renderPieChart = function (chart) {
+ var chartOptions = {};
+ if (chart.options.colors) {
+ chartOptions.colors = chart.options.colors;
+ }
+ var options = merge(merge(defaultOptions, chartOptions), chart.options.library || {});
+ options.chart.renderTo = chart.element.id;
+ options.series = [{
+ type: "pie",
+ name: chart.options.label || "Value",
... 1203 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-chartkick.git
More information about the Python-modules-commits
mailing list