Skip to content

Commit 20fa476

Browse files
Plotly set responsive to false
1 parent 3854132 commit 20fa476

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

src/components/Plotly.vue

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<template>
2-
<div :id="id" v-resize:debounce.100="onResize" />
2+
<div
3+
:id="id"
4+
v-resize:debounce.100="onResize"
5+
/>
36
</template>
47
<script>
58
import Plotly from "plotly.js";
@@ -62,10 +65,12 @@ export default {
6265
},
6366
computed: {
6467
options() {
65-
return Object.keys(this.$attrs).reduce((acc, key) => {
68+
const optionsFromAttrs = Object.keys(this.$attrs).reduce((acc, key) => {
6669
acc[camelize(key)] = this.$attrs[key];
6770
return acc;
6871
}, {});
72+
73+
return Object.assign(optionsFromAttrs, {responsive: false});
6974
}
7075
},
7176
beforeDestroy() {

tests/unit/plotly.spec.js

+32-13
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,30 @@ let wrapper;
66
let vm;
77
let layout;
88
let data;
9+
let attrs;
910
const id = "id";
1011

12+
function shallowMountPlotty() {
13+
jest.clearAllMocks();
14+
return shallowMount(Plotly, {
15+
propsData: {
16+
layout,
17+
data,
18+
id
19+
},
20+
attrs,
21+
attachToDocument: true
22+
});
23+
}
24+
1125
describe("Plotly.vue", () => {
1226
beforeEach(() => {
13-
jest.clearAllMocks();
1427
layout = {};
1528
data = [];
16-
wrapper = shallowMount(Plotly, {
17-
propsData: {
18-
layout,
19-
data,
20-
id
21-
},
22-
attrs: {
23-
"display-mode-bar": true
24-
},
25-
attachToDocument: true
26-
});
29+
attrs = {
30+
"display-mode-bar": true
31+
}
32+
wrapper = shallowMountPlotty();
2733
vm = wrapper.vm;
2834
});
2935

@@ -41,7 +47,20 @@ describe("Plotly.vue", () => {
4147

4248
it("calls plotly newPlot", () => {
4349
expect(plotlyjs.newPlot).toHaveBeenCalledWith(vm.$el, data, layout, {
44-
displayModeBar: true
50+
displayModeBar: true,
51+
responsive: false
52+
});
53+
expect(plotlyjs.newPlot.mock.calls.length).toBe(1);
54+
});
55+
56+
it("overrides responsive attribute", () => {
57+
attrs = {
58+
responsive: true
59+
};
60+
wrapper = shallowMountPlotty();
61+
62+
expect(plotlyjs.newPlot).toHaveBeenCalledWith(vm.$el, data, layout, {
63+
responsive: false
4564
});
4665
expect(plotlyjs.newPlot.mock.calls.length).toBe(1);
4766
});

0 commit comments

Comments
 (0)