/** * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or http://ckeditor.com/license */ /** * @fileOverview Charts for CKEditor using Chart.js. */ /* global alert:false, Chart:false */ 'use strict'; // TODO IE8 fallback to a table maybe? // TODO a11y http://www.w3.org/html/wg/wiki/Correct_Hidden_Attribute_Section_v4 ( function() { CKEDITOR.plugins.add( 'chart', { // Required plugins requires: 'widget,dialog', // Name of the file in the "icons" folder icons: 'chart', // Supported languages lang: 'en,pl', // Load library that renders charts inside CKEditor, if Chart object is not already available. afterInit: function() { var plugin = this; if ( typeof Chart === 'undefined' ) { // Chart library is loaded asynchronously, so we can draw anything only once it's loaded. CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( plugin.path + 'lib/chart.min.js' ), function() { plugin.drawCharts(); } ); } }, // Function called on initialization of every editor instance created in the page. init: function( editor ) { var plugin = this; var chartDefaultHeight = editor.config.chart_height || 300; // Default hardcoded values used if config.chart_colors is not provided. var colors = editor.config.chart_colors || { // Colors for Bar/Line chart: http://www.chartjs.org/docs/#bar-chart-data-structure fillColor: 'rgba(151,187,205,0.5)', strokeColor: 'rgba(151,187,205,0.8)', highlightFill: 'rgba(151,187,205,0.75)', highlightStroke: 'rgba(151,187,205,1)', // Colors for Doughnut/Pie/PolarArea charts: http://www.chartjs.org/docs/#doughnut-pie-chart-data-structure data: [ '#B33131', '#B66F2D', '#00b5b0', '#71B232', '#33B22D', '#31B272', '#2DB5B5', '#3172B6', '#3232B6', '#6E31B2', '#B434AF', '#B53071' ] }; var config = { Bar: editor.config.chart_configBar || { animation: false }, Doughnut: editor.config.chart_configDoughnut || { animateRotate: false }, Line: editor.config.chart_configLine || { animation: false }, Pie: editor.config.chart_configPie || { animateRotate: false }, PolarArea: editor.config.chart_configPolarArea || { animateRotate: false } }; // The number of rows in Edit Chart dialog window. var inputRows = editor.config.chart_maxItems || 8; // Inject required CSS stylesheet to classic editors because the