-
-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from apertureless/feature/scatter_chart
Feature/scatter chart
- Loading branch information
Showing
14 changed files
with
265 additions
and
19 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import Vue from 'vue' | ||
import Chart from 'chart.js' | ||
import { mergeOptions } from '../helpers/options' | ||
|
||
export default Vue.extend({ | ||
render: function (createElement) { | ||
return createElement( | ||
'div', | ||
[ | ||
createElement( | ||
'canvas', { | ||
attrs: { | ||
id: this.chartId, | ||
width: this.width, | ||
height: this.height | ||
}, | ||
ref: 'canvas' | ||
} | ||
) | ||
] | ||
) | ||
}, | ||
|
||
props: { | ||
chartId: { | ||
default: 'scatter-chart', | ||
type: String | ||
}, | ||
width: { | ||
default: 400, | ||
type: Number | ||
}, | ||
height: { | ||
default: 400, | ||
type: Number | ||
} | ||
}, | ||
|
||
data () { | ||
return { | ||
defaultOptions: { | ||
scales: { | ||
xAxes: [{ | ||
type: 'linear', | ||
position: 'bottom' | ||
}] | ||
} | ||
} | ||
} | ||
}, | ||
|
||
methods: { | ||
renderChart (data, options) { | ||
let chartOptions = mergeOptions(this.defaultOptions, options) | ||
|
||
this._chart = new Chart( | ||
this.$refs.canvas.getContext('2d'), { | ||
type: 'scatter', | ||
data: data, | ||
options: chartOptions | ||
} | ||
) | ||
this._chart.generateLegend() | ||
} | ||
}, | ||
beforeDestroy () { | ||
this._chart.destroy() | ||
} | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import Scatter from '../BaseCharts/Scatter' | ||
|
||
export default Scatter.extend({ | ||
mounted () { | ||
this.renderChart({ | ||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], | ||
datasets: [{ | ||
label: 'Scatter Dataset 1', | ||
fill: false, | ||
borderColor: '#f87979', | ||
backgroundColor: '#f87979', | ||
data: [{ | ||
x: -2, | ||
y: 4 | ||
}, { | ||
x: -1, | ||
y: 1 | ||
}, { | ||
x: 0, | ||
y: 0 | ||
}, { | ||
x: 1, | ||
y: 1 | ||
}, { | ||
x: 2, | ||
y: 4 | ||
}] | ||
}, | ||
{ | ||
label: 'Scatter Dataset 2', | ||
fill: false, | ||
borderColor: '#7acbf9', | ||
backgroundColor: '#7acbf9', | ||
data: [{ | ||
x: -2, | ||
y: -4 | ||
}, { | ||
x: -1, | ||
y: -1 | ||
}, { | ||
x: 0, | ||
y: 1 | ||
}, { | ||
x: 1, | ||
y: -1 | ||
}, { | ||
x: 2, | ||
y: -4 | ||
}] | ||
}] | ||
}, {responsive: true, maintainAspectRatio: false}) | ||
} | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import Vue from 'vue' | ||
import ScatterChart from 'src/examples/ScatterExample' | ||
|
||
describe('ScatterChart', () => { | ||
let el | ||
|
||
beforeEach(() => { | ||
el = document.createElement('div') | ||
}) | ||
|
||
it('should render a canvas', () => { | ||
const vm = new Vue({ | ||
render: function (createElement) { | ||
return createElement( | ||
ScatterChart | ||
) | ||
}, | ||
components: { ScatterChart } | ||
}).$mount(el) | ||
|
||
expect(vm.$el.querySelector('#scatter-chart')).not.to.be.an('undefined') | ||
expect(vm.$el.querySelector('canvas')).not.to.be.an('undefined') | ||
expect(vm.$el.querySelector('canvas')).not.to.be.an('null') | ||
expect(vm.$el.querySelector('canvas')).to.exist | ||
}) | ||
|
||
it('should change id based on prop', () => { | ||
const vm = new Vue({ | ||
render: function (createElement) { | ||
return createElement( | ||
ScatterChart, { | ||
props: { | ||
chartId: 'linechartprop' | ||
} | ||
} | ||
) | ||
}, | ||
components: { ScatterChart } | ||
}).$mount(el) | ||
|
||
expect(vm.$el.querySelector('#linechartprop')).not.to.be.an('undefined') | ||
}) | ||
|
||
it('should destroy chart instance', (done) => { | ||
const vm = new Vue({ | ||
render: function (createElement) { | ||
return createElement( | ||
ScatterChart | ||
) | ||
}, | ||
components: { ScatterChart } | ||
}).$mount(el) | ||
|
||
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null | ||
|
||
vm.$destroy() | ||
|
||
vm.$nextTick(() => { | ||
vm.$forceUpdate() | ||
expect(vm.$children[0]._chart.chart.ctx).to.be.null | ||
done() | ||
}) | ||
}) | ||
}) |