-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Register all ChartJS registerables
- Loading branch information
Showing
10 changed files
with
1,889 additions
and
2,628 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
module.exports = { | ||
verbose: true, | ||
clearMocks: true, | ||
transform: { | ||
'^.+\\.vue$': 'vue-jest', | ||
'^.+\\.vue$': 'vue3-jest', | ||
'^.+\\js$': 'babel-jest' | ||
}, | ||
testEnvironment: 'jsdom', | ||
setupFiles: ['jest-canvas-mock'], | ||
collectCoverage: true, | ||
coverageReporters: ['lcov', 'text-summary'] | ||
coverageReporters: ['lcov', 'text-summary'], | ||
moduleFileExtensions: ['vue', 'js', 'json', 'jsx', 'ts', 'tsx', 'node'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,150 +1,135 @@ | ||
<template> | ||
<div style="width: 100%;height:20%;display: block;"> | ||
<vue3-chart-js v-bind="{...barChart}" @after-update="afterUpdate"/> | ||
</div> | ||
<div style="display: block;"> | ||
<vue3-chart-js ref="chartRef" v-bind="{...localDoughnutChartOptions}" @after-update="afterUpdate"/> | ||
</div> | ||
<button type="submit" @click="updateChart">Update Doughnut Data</button> | ||
<button type="submit" @click="exportChart">Export Chart as PNG</button> | ||
<div style="width: 100%;height:20%;display: block;"> | ||
<vue3-chart-js v-bind="{...barChart}" @after-update="afterUpdate"/> | ||
</div> | ||
<div style="display: block;"> | ||
<vue3-chart-js ref="chartRef" v-bind="{...localDoughnutChartOptions}" @after-render="afterRender"/> | ||
</div> | ||
<button type="submit" @click="updateChart">Update Doughnut Data</button> | ||
<button type="submit" @click="exportChart">Export Chart as PNG</button> | ||
</template> | ||
|
||
<script> | ||
<script setup> | ||
import { ref } from 'vue' | ||
import Vue3ChartJs from '../lib/main' | ||
export default { | ||
name: 'App', | ||
components: { | ||
Vue3ChartJs | ||
import Vue3ChartJs from '../' | ||
const barChart = { | ||
type: 'line', | ||
data: { | ||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], | ||
datasets: [{ | ||
label: 'My First Dataset', | ||
data: [65, 59, 80, 81, 56, 55, 40], | ||
fill: false, | ||
borderColor: 'rgb(75, 192, 192)', | ||
tension: 0.1 | ||
}] | ||
}, | ||
setup () { | ||
const barChart = { | ||
type: 'line', | ||
data: { | ||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], | ||
datasets: [{ | ||
label: 'My First Dataset', | ||
data: [65, 59, 80, 81, 56, 55, 40], | ||
fill: false, | ||
borderColor: 'rgb(75, 192, 192)', | ||
tension: 0.1 | ||
}] | ||
}, | ||
options: { | ||
maintainAspectRatio: false, | ||
plugins: { | ||
zoom: { | ||
zoom: { | ||
wheel: { | ||
enabled: true, | ||
mode: 'xy', | ||
}, | ||
pinch: { | ||
enabled: true, | ||
mode: 'xy', | ||
} | ||
} | ||
options: { | ||
maintainAspectRatio: false, | ||
plugins: { | ||
zoom: { | ||
zoom: { | ||
wheel: { | ||
enabled: true, | ||
mode: 'xy', | ||
}, | ||
pinch: { | ||
enabled: true, | ||
mode: 'xy', | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
const doughnutChart = { | ||
id: 'doughnut', | ||
type: 'doughnut', | ||
height: 800, | ||
width: 800, | ||
data: { | ||
labels: ['VueJs', 'EmberJs', 'ReactJs', 'AngularJs'], | ||
datasets: [ | ||
{ | ||
backgroundColor: [ | ||
'#41B883', | ||
'#E46651', | ||
'#00D8FF', | ||
'#DD1B16' | ||
], | ||
data: [40, 20, 80, 10] | ||
} | ||
] | ||
}, | ||
options: { | ||
responsive: false, | ||
cutout: '10%', | ||
plugins: {} | ||
const doughnutChart = { | ||
id: 'doughnut', | ||
type: 'doughnut', | ||
height: 800, | ||
width: 800, | ||
data: { | ||
labels: ['VueJs', 'EmberJs', 'ReactJs', 'AngularJs'], | ||
datasets: [ | ||
{ | ||
backgroundColor: [ | ||
'#41B883', | ||
'#E46651', | ||
'#00D8FF', | ||
'#DD1B16' | ||
], | ||
data: [40, 20, 80, 10] | ||
} | ||
} | ||
const beforeInit = (e) => { | ||
console.log('chart is before init', e) | ||
} | ||
const beforeUpdate = (e) => { | ||
console.log('beforeUpdate', e) | ||
} | ||
const afterUpdate = (e) => { | ||
console.log('afterUpdate', e) | ||
} | ||
] | ||
}, | ||
options: { | ||
responsive: false, | ||
cutout: '10%', | ||
plugins: {} | ||
} | ||
} | ||
const testFunc = () => { | ||
console.log('test func called') | ||
} | ||
const beforeInit = (e) => { | ||
console.log('chart is before init', e) | ||
} | ||
const chartRef = ref(null) | ||
const beforeUpdate = (e) => { | ||
console.log('beforeUpdate', e) | ||
} | ||
const localDoughnutChartOptions = { ...doughnutChart } | ||
const afterUpdate = (e) => { | ||
console.log('afterUpdate', e) | ||
} | ||
let counter = 1 | ||
const afterRender = (e) => { | ||
console.log('afterRender', e) | ||
} | ||
const updateChart = () => { | ||
localDoughnutChartOptions.options.plugins.title = { | ||
display: true, | ||
text: 'Loaded: ' + (counter++) | ||
} | ||
const testFunc = () => { | ||
console.log('test func called') | ||
} | ||
localDoughnutChartOptions.data.labels.reverse() | ||
localDoughnutChartOptions.data.datasets = [ | ||
{ | ||
backgroundColor: [ | ||
'#' + Math.floor(Math.random() * 16777215).toString(16), | ||
'#' + Math.floor(Math.random() * 16777215).toString(16), | ||
'#' + Math.floor(Math.random() * 16777215).toString(16), | ||
'#' + Math.floor(Math.random() * 16777215).toString(16), | ||
], | ||
data: [ | ||
Math.floor(Math.random() * 500), | ||
Math.floor(Math.random() * 500), | ||
Math.floor(Math.random() * 500), | ||
Math.floor(Math.random() * 500), | ||
] | ||
} | ||
const chartRef = ref(null) | ||
const localDoughnutChartOptions = { ...doughnutChart } | ||
let counter = 1 | ||
const updateChart = () => { | ||
localDoughnutChartOptions.options.plugins.title = { | ||
display: true, | ||
text: 'Loaded: ' + (counter++) | ||
} | ||
localDoughnutChartOptions.data.labels.reverse() | ||
localDoughnutChartOptions.data.datasets = [ | ||
{ | ||
backgroundColor: [ | ||
'#' + Math.floor(Math.random() * 16777215).toString(16), | ||
'#' + Math.floor(Math.random() * 16777215).toString(16), | ||
'#' + Math.floor(Math.random() * 16777215).toString(16), | ||
'#' + Math.floor(Math.random() * 16777215).toString(16), | ||
], | ||
data: [ | ||
Math.floor(Math.random() * 500), | ||
Math.floor(Math.random() * 500), | ||
Math.floor(Math.random() * 500), | ||
Math.floor(Math.random() * 500), | ||
] | ||
chartRef.value.update(750) | ||
} | ||
] | ||
const exportChart = () => { | ||
let a = document.createElement('a') | ||
a.href = chartRef.value.chartJSState.chart.toBase64Image('image/png', 1) | ||
a.download = 'image-export.png' | ||
a.click() | ||
a = null | ||
} | ||
chartRef.value.update(750) | ||
} | ||
return { | ||
barChart, | ||
localDoughnutChartOptions, | ||
updateChart, | ||
exportChart, | ||
beforeInit, | ||
beforeUpdate, | ||
afterUpdate, | ||
testFunc, | ||
chartRef | ||
} | ||
}, | ||
const exportChart = () => { | ||
let a = document.createElement('a') | ||
a.href = chartRef.value.chartJSState.chart.toBase64Image('image/png', 1) | ||
a.download = 'image-export.png' | ||
a.click() | ||
a = null | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.