Repository: bbonnin/vue-morris Branch: master Commit: a03d8bc41cf6 Files: 15 Total size: 20.2 KB Directory structure: gitextract_1gpywlcm/ ├── .babelrc ├── .gitignore ├── LICENSE ├── README.md ├── build/ │ ├── webpack.base.conf.js │ ├── webpack.build.conf.js │ └── webpack.dev.conf.js ├── package.json └── src/ ├── components/ │ ├── area-chart.vue │ ├── bar-chart.vue │ ├── chart-mixins.js │ ├── donut-chart.vue │ └── line-chart.vue ├── index.js └── util/ └── converter.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .babelrc ================================================ { "presets": ["es2015"], "plugins": ["transform-runtime"], "comments": false } ================================================ FILE: .gitignore ================================================ node_modules *.log ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2016 Bruno Bonnin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # vue-morris > Vue.js components wrapping Morris.js lib > > See http://morrisjs.github.io/morris.js/ for documentation > Depends on Vue.js v2.1.0+ ## Install Use npm ```bash npm install vue-morris --save ``` Do not forget to declare jQuery in your `package.json` and, if you are using Webpack, you should have something like that in your `webpack.config.js` ```javascript resolve: { alias: { 'vue$': 'vue/dist/vue.common.js', 'jquery': 'jquery/src/jquery.js' } }, ``` ## Examples For a complete example, see files in `examples` directory or the project: https://github.com/bbonnin/vue-morris-example. * Import the component ```javascript // Do not forget to import raphael import Raphael from 'raphael/raphael' global.Raphael = Raphael import Vue from 'vue' import { DonutChart } from 'vue-morris' new Vue({ el: '#app', data: { donutData: [ { label: 'Red', value: 300 }, { label: 'Blue', value: 50 }, { label: 'Yellow', value: 100 } ], components: { DonutChart, BarChart, LineChart, AreaChart } }) ``` * Use the component in html ```html ``` * Bar chart ![bar chart](img/barchart.png) * Line chart ![line chart](img/linechart.png) * Area chart ![area chart](img/areachart.png) * Donut chart ![donut chart](img/donutchart.png) ## Build Setup ``` bash # install dependencies npm install # serve with hot reload at localhost:8080 npm run dev # build for production with minification npm run build ``` ================================================ FILE: build/webpack.base.conf.js ================================================ var path = require('path') module.exports = { entry: { 'vue-morris': './src/index.js' }, output: { path: path.resolve(__dirname, '../dist'), publicPath: '/dist/', //library: 'VueMorris', //libraryTarget: 'amd', filename: process.env.NODE_ENV === 'production' ? '[name].min.js' : '[name].js' }, module: { rules: [ { test: /\.vue$/, loader: 'vue-loader', options: { // vue-loader options go here } }, { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ }, { test: /\.(png|jpg|gif|svg)$/, loader: 'file-loader', options: { name: '[name].[ext]?[hash]' } }, { test: /\.css$/, loader: 'vue-style-loader!css-loader' } ] } } ================================================ FILE: build/webpack.build.conf.js ================================================ var webpack = require('webpack') var merge = require('webpack-merge') var baseWebpackConfig = require('./webpack.base.conf') baseWebpackConfig.output.library = 'VueMorris' baseWebpackConfig.output.libraryTarget = 'amd' module.exports = merge(baseWebpackConfig, { devtool: '#source-map', plugins: [ new webpack.DefinePlugin({ 'process.env': { NODE_ENV: '"production"' } }), new webpack.optimize.UglifyJsPlugin({ sourceMap: true, compress: { warnings: false } }), new webpack.LoaderOptionsPlugin({ minimize: true }) ] }) ================================================ FILE: build/webpack.dev.conf.js ================================================ var webpack = require('webpack') var merge = require('webpack-merge') var baseWebpackConfig = require('./webpack.base.conf') var HtmlWebpackPlugin = require('html-webpack-plugin') baseWebpackConfig.entry.examples = './examples/main.js' module.exports = merge(baseWebpackConfig, { devServer: { historyApiFallback: true, noInfo: true }, devtool: '#eval-source-map', resolve: { alias: { 'vue$': 'vue/dist/vue.common.js', 'jquery': 'jquery/src/jquery.js'/*, 'raphael': 'raphael/raphael.js'*/ } }, plugins: [ new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery'/*, Raphael: 'raphael'*/ }), new webpack.DefinePlugin({ 'process.env': { NODE_ENV: '"development"' } }), new HtmlWebpackPlugin({ filename: './examples/index.html', inject: false }) ] }) ================================================ FILE: package.json ================================================ { "name": "vue-morris", "description": "Vue.js component wrapping Morris.js lib", "version": "1.1.0", "author": "Bruno Bonnin ", "private": false, "keywords": [ "vue", "vuejs", "morris.js" ], "main": "dist/vue-morris.min.js", "repository": { "type": "git", "url": "https://github.com/bbonnin/vue-morris.git" }, "bugs": "https://github.com/bbonnin/vue-morris/issues", "scripts": { "dev": "cross-env NODE_ENV=development webpack-dev-server --content-base ./examples --open --inline --hot --colors --config build/webpack.dev.conf.js", "build": "cross-env NODE_ENV=production webpack --progress --hide-modules --colors --config build/webpack.build.conf.js" }, "dependencies": { "babel-runtime": "^6.0.0", "morris.js": "github:morrisjs/morris.js", "raphael": "^2.2.7", "vue": "^2.1.0" }, "devDependencies": { "babel-core": "^6.0.0", "babel-loader": "^6.0.0", "babel-plugin-transform-runtime": "^6.0.0", "babel-preset-es2015": "^6.0.0", "cross-env": "^3.0.0", "css-loader": "^0.25.0", "file-loader": "^0.9.0", "html-webpack-plugin": "^2.24.1", "vue-loader": "^10.0.0", "vue-style-loader": "^1.0.0", "vue-template-compiler": "^2.1.0", "webpack": "^2.1.0-beta.25", "webpack-dev-server": "^2.11.5", "webpack-merge": "^2.3.1" }, "peerDependencies": { "jquery": "^3.0.0" }, "license": "MIT" } ================================================ FILE: src/components/area-chart.vue ================================================ ================================================ FILE: src/components/bar-chart.vue ================================================ ================================================ FILE: src/components/chart-mixins.js ================================================ import Converter from '../util/converter' /** * All properties used by the charts with their constraints. */ const Props = { id: { type: String, required: true }, data: { type: [ String, Array ], required: true }, barColors: { type: [ String, Array, Function ], required: false }, xkey: { type: String, required: false, default: 'key' }, ykeys: { type: [ String, Array ], required: false, default: function _default() { return ['value']; }}, labels: { type: [ String, Array ], required: false, default: function _default() { return ['Value']; }}, hoverCallback: { type: Function, required: false }, axes: { type: [ Boolean, String ], required: false, default: true }, hideHover: { type: String, required: false }, stacked: { type: [ Boolean, String ], required: false }, resize: { type: [ Boolean, String ], required: false }, horizontal: { type: [ Boolean, String ], required: false, default: false }, grid: { type: [ Boolean, String ], required: false, default: true }, gridTextColor: { type: String, required: false, default: '#888' }, gridTextSize: { type: [ Number, String ], required: false, default: 12 }, gridTextFamily: { type: String, required: false, default: 'sans-serif' }, gridTextWeight: { type: String, required: false, default: 'normal' }, colors: { type: [ String, Array ], required: false }, formatter: { type: Function, required: false }, lineColors: { type: [ String, Array, Function ], required: false }, xLabels: { type: String, required: false }, lineWidth: { type: [ Number, String ], required: false }, pointSize: { type: [ Number, String ], required: false }, pointFillColors: { type: [ String, Array ], required: false }, pointStrokeColors: { type: [ String, Array ], required: false }, ymax: { type: String, required: false }, ymin: { type: String, required: false }, smooth: { type: [ Boolean, String ], required: false, default: true }, parseTime: { type: [ Boolean, String ], required: false, default: true }, postUnits: { type: String, required: false }, preUnits: { type: String, required: false }, dateFormat: { type: Function, required: false }, xLabelFormat: { type: Function, required: false }, yLabelFormat: { type: Function, required: false }, xLabelAngle: { type: String, required: false }, goals: { type: [ String, Array ], required: false }, goalStrokeWidth: { type: [ Number, String ], required: false }, goalLineColors: { type: [ String, Array ], required: false }, events: { type: [ String, Array ], required: false }, eventStrokeWidth: { type: String, required: false }, eventLineColors: { type: [ String, Array ], required: false }, fillOpacity: { type: String, required: false }, behaveLikeLine: { type: [ Boolean, String ], required: false, default: false } } /** * Properties of a bar chart. */ const BarProps = { id: Props.id, data: Props.data, barColors: Props.barColors, xkey: Props.xkey, ykeys: Props.ykeys, labels: Props.labels, xLabelFormat: Props.xLabelFormat, yLabelFormat: Props.yLabelFormat, xLabelAngle: Props.xLabelAngle, hoverCallback: Props.hoverCallback, grid: Props.grid, horizontal: Props.horizontal, axes: Props.axes, hideHover: Props.hideHover, stacked: Props.stacked, resize: Props.resize, ymax: Props.ymax, ymin: Props.ymin, gridTextColor: Props.gridTextColor, gridTextSize: Props.gridTextSize, gridTextFamily: Props.gridTextFamily, gridTextWeight: Props.gridTextWeight } /** * Properties of a donut chart. */ const DonutProps = { id: Props.id, data: Props.data, colors: Props.colors, formatter: Props.formatter, resize: Props.resize } /** * Properties of a line chart. */ const LineProps = { id: Props.id, data: Props.data, resize: Props.resize, lineColors: Props.lineColors, xkey: Props.xkey, ykeys: Props.ykeys, labels: Props.labels, xLabels: Props.xLabels, grid: Props.grid, gridTextColor: Props.gridTextColor, gridTextSize: Props.gridTextSize, gridTextFamily: Props.gridTextFamily, gridTextWeight: Props.gridTextWeight, lineWidth: Props.lineWidth, pointSize: Props.pointSize, pointFillColors: Props.pointFillColors, pointStrokeColors: Props.pointStrokeColors, ymax: Props.ymax, ymin: Props.ymin, smooth: Props.smooth, hideHover: Props.hideHover, parseTime: Props.parseTime, postUnits: Props.postUnits, preUnits: Props.preUnits, dateFormat: Props.dateFormat, xLabelFormat: Props.xLabelFormat, yLabelFormat: Props.yLabelFormat, xLabelAngle: Props.xLabelAngle, goals: Props.goals, goalStrokeWidth: Props.goalStrokeWidth, goalLineColors: Props.goalLineColors, events: Props.events, eventStrokeWidth: Props.eventStrokeWidth, eventLineColors: Props.eventLineColors, fillOpacity: Props.fillOpacity, hoverCallback: Props.hoverCallback } /** * Properties of an area chart. */ const AreaProps = { behaveLikeLine: Props.behaveLikeLine } for (var prop in LineProps) { if (LineProps.hasOwnProperty(prop)) { AreaProps[prop] = LineProps[prop]; } } /** * Common methods for all the charts. */ const ChartMethods = { addOption (name, options) { if (this[name]) { options[name] = this[name] } }, addOptionAsObject (name, options) { if (this[name]) { options[name] = Converter.toObject(this[name]) } } } export default { bar: { props: BarProps, methods: ChartMethods }, donut: { props: DonutProps, methods: ChartMethods }, line: { props: LineProps, methods: ChartMethods }, area: { props: AreaProps, methods: ChartMethods } } ================================================ FILE: src/components/donut-chart.vue ================================================ ================================================ FILE: src/components/line-chart.vue ================================================ ================================================ FILE: src/index.js ================================================ import DonutChart from './components/donut-chart.vue' import BarChart from './components/bar-chart.vue' import LineChart from './components/line-chart.vue' import AreaChart from './components/area-chart.vue' const VueMorris = { DonutChart, BarChart, LineChart, AreaChart } module.exports = VueMorris ================================================ FILE: src/util/converter.js ================================================ const Converter = { toObject: function (data) { if (typeof data === 'string') { return JSON.parse(data) } return data }, toBoolean: function (data) { if (typeof data === 'string') { return data === 'true' } return data }, toInt: function(data) { if (typeof data === 'string') { return parseInt(data) } return data }, } module.exports = Converter