11<script >
22import { DOWNLOAD_PATH } from ' ./../icons.js' ;
3- import { create as d3_create } from ' d3' ;
3+ import { create as d3_create , event as d3_event } from ' d3' ;
4+ import { select as d3_select } from ' d3-selection' ;
5+ import { drag as d3_drag } from ' d3-drag' ;
46
57
68/**
@@ -153,47 +155,137 @@ export default {
153155 ' downloadName' : {
154156 type: String ,
155157 default: " plot"
156- }
158+ },
159+ ' showResizeButton' : {
160+ type: Boolean ,
161+ default: false
162+ },
163+ ' resizeButtonSize' : {
164+ type: Number ,
165+ default: 16
166+ },
167+ ' resizeButtonColor' : {
168+ type: String ,
169+ default: " gray"
170+ },
157171 },
158172 data () {
159173 return {
160174 initialKey: 1 ,
175+ initialY: 0 ,
176+ offsetY: 0 ,
161177 };
162178 },
179+ mounted () {
180+ this .initResizeButton ();
181+ },
163182 render (h ) {
164- this .$slots .axisTop = addProp (this .$slots .axisTop , this .$props );
165- this .$slots .axisLeft = addProp (this .$slots .axisLeft , this .$props );
166- this .$slots .plot = addProp (this .$slots .plot , this .$props );
167- this .$slots .axisRight = addProp (this .$slots .axisRight , this .$props );
168- this .$slots .axisBottom = addProp (this .$slots .axisBottom , this .$props );
183+ const props = Object .assign ({}, this .$props );
184+ props[" pHeight" ] = this .pHeight + this .offsetY ;
185+
186+ this .$slots .axisTop = addProp (this .$slots .axisTop , props);
187+ this .$slots .axisLeft = addProp (this .$slots .axisLeft , props);
188+ this .$slots .plot = addProp (this .$slots .plot , props);
189+ this .$slots .axisRight = addProp (this .$slots .axisRight , props);
190+ this .$slots .axisBottom = addProp (this .$slots .axisBottom , props);
169191
170- const downloadChildren = [];
192+ const buttonChildren = [];
171193 if (this .showDownloadButton ) {
172- downloadChildren .push (h (' svg' , { class: ' vdp-plot-container-dl-btn' , attrs: {' width' : this .downloadButtonSize , ' height' : this .downloadButtonSize , ' viewBox' : ' 0 0 24 24' }, style: {' top' : (this .downloadButtonOffsetY + ' px' ), ' left' : (this .downloadButtonOffsetX + ' px' )}, on: { click : ()=> {this .downloadViaButton ();} } }, [h (' path' , {attrs: {' d' : DOWNLOAD_PATH , ' fill' : this .downloadButtonFill }})]));
194+ buttonChildren .push (h (' svg' ,
195+ {
196+ key: ` dl-btn-${ this .initialKey } ` ,
197+ class: ' vdp-plot-container-dl-btn' ,
198+ attrs: {
199+ ' width' : this .downloadButtonSize ,
200+ ' height' : this .downloadButtonSize ,
201+ ' viewBox' : ' 0 0 24 24'
202+ },
203+ style: {
204+ ' top' : (this .downloadButtonOffsetY + ' px' ),
205+ ' left' : (this .downloadButtonOffsetX + ' px' )
206+ },
207+ on: { click : ()=> {this .downloadViaButton ();} }
208+ },
209+ [h (' path' , {attrs: {' d' : DOWNLOAD_PATH , ' fill' : this .downloadButtonFill }})]
210+ ));
211+ }
212+ if (this .showResizeButton ) {
213+ buttonChildren .push (h (' svg' ,
214+ {
215+ ref: ' resizeButton' ,
216+ class: ' vdp-plot-container-rs-btn' ,
217+ attrs: {
218+ ' width' : this .resizeButtonSize ,
219+ ' height' : this .resizeButtonSize ,
220+ ' viewBox' : ' 0 0 24 24'
221+ },
222+ style: {
223+ ' left' : ((this .pMarginLeft + this .pWidth + this .pMarginRight - this .resizeButtonSize ) + ' px' ),
224+ ' top' : ((this .pMarginTop + props[" pHeight" ] + this .pMarginBottom - this .resizeButtonSize ) + ' px' ),
225+ }
226+ },
227+ [
228+ h (' line' , {attrs: {
229+ ' x1' : 0 ,
230+ ' y1' : 26 ,
231+ ' x2' : 26 ,
232+ ' y2' : 0 ,
233+ ' stroke' : this .resizeButtonColor ,
234+ ' stroke-width' : 1
235+ }}),
236+ h (' line' , {attrs: {
237+ ' x1' : 0 ,
238+ ' y1' : 32 ,
239+ ' x2' : 32 ,
240+ ' y2' : 0 ,
241+ ' stroke' : this .resizeButtonColor ,
242+ ' stroke-width' : 1
243+ }}),
244+ h (' line' , {attrs: {
245+ ' x1' : 0 ,
246+ ' y1' : 38 ,
247+ ' x2' : 38 ,
248+ ' y2' : 0 ,
249+ ' stroke' : this .resizeButtonColor ,
250+ ' stroke-width' : 1
251+ }}),
252+ h (' line' , {attrs: {
253+ ' x1' : 0 ,
254+ ' y1' : 44 ,
255+ ' x2' : 44 ,
256+ ' y2' : 0 ,
257+ ' stroke' : this .resizeButtonColor ,
258+ ' stroke-width' : 1
259+ }})
260+ ]
261+ ));
173262 }
174263
175264 const children = ([]).concat (
176- this .$slots .axisTop ,
177- this .$slots .axisLeft ,
178- this .$slots .plot ,
179- this .$slots .axisRight ,
180- this .$slots .axisBottom ,
181- h (' div' , { key: this .initialKey }, downloadChildren )
265+ h ( ' div ' , { key : ` axisTop- ${ this .initialKey } ` }, [ this . $slots .axisTop ]) ,
266+ h ( ' div ' , { key : ` axisLeft- ${ this .initialKey } ` }, [ this . $slots .axisLeft ]) ,
267+ h ( ' div ' , { key : ` plot- ${ this .initialKey } ` }, [ this . $slots .plot ]) ,
268+ h ( ' div ' , { key : ` axisRight- ${ this .initialKey } ` }, [ this . $slots .axisRight ]) ,
269+ h ( ' div ' , { key : ` axisBottom- ${ this .initialKey } ` }, [ this . $slots .axisBottom ]) ,
270+ h (' div' , { key: ` buttons- ${ this .initialKey } ` }, buttonChildren )
182271 );
183272
184273 let classes = [' vdp-plot-container' ];
185274 let styles = {
186275 width: this .fullWidth + ' px' ,
187276 height: this .fullHeight + ' px'
188277 };
278+
279+ this .$nextTick (this .initResizeButton );
280+
189281 return h (' div' , { class: classes, style: styles }, children);
190282 },
191283 computed: {
192284 fullWidth () {
193285 return this .pMarginLeft + this .pWidth + this .pMarginRight ;
194286 },
195287 fullHeight () {
196- return this .pMarginTop + this .pHeight + this .pMarginBottom ;
288+ return this .pMarginTop + this .pHeight + this .offsetY + this . pMarginBottom ;
197289 }
198290 },
199291 watch: {
@@ -227,7 +319,42 @@ export default {
227319 downloadAnchorNode .click ();
228320 downloadAnchorNode .remove ();
229321 },
322+ initResizeButton () {
323+ if (this .showResizeButton ) {
324+ if (this .$refs .resizeButton ) {
325+ const resizeDiv = d3_select (this .$refs .resizeButton );
326+ resizeDiv .call (
327+ d3_drag ()
328+ .on (" start" , () => {
329+ this .dragState = 0 ;
330+ this .initialY = d3_event .sourceEvent .pageY - this .offsetY ;
331+ this .initialKey ++ ;
332+ })
333+ .on (" drag" , () => {
334+ this .offsetY = Math .max (- this .pHeight , d3_event .sourceEvent .pageY - this .initialY );
335+ this .initialKey ++ ;
336+ })
337+ .on (" end" , () => {
338+ this .initialY = d3_event .sourceEvent .pageY ;
339+ this .initialKey ++ ;
340+ })
341+ );
342+ }
343+ }
344+ },
230345 download () {
346+ const pHeight = this .pHeight + this .offsetY ;
347+
348+ try {
349+ this .$slots .axisTop [0 ].componentInstance .pHeight = pHeight;
350+ this .$slots .axisLeft [0 ].componentInstance .pHeight = pHeight;
351+ this .$slots .plot [0 ].componentInstance .pHeight = pHeight;
352+ this .$slots .axisRight [0 ].componentInstance .pHeight = pHeight;
353+ this .$slots .axisBottom [0 ].componentInstance .pHeight = pHeight;
354+ } catch (e) {
355+ console .log (e);
356+ }
357+
231358 const svg = d3_create (" svg" )
232359 .attr (" width" , this .fullWidth )
233360 .attr (" height" , this .fullHeight );
@@ -238,9 +365,16 @@ export default {
238365 const renderAxisToContext = (axisType ) => {
239366 if (this .$slots [axisType].length > 0 ) {
240367 const x = this .$slots [axisType][0 ].componentInstance .computedLeft ;
241- const y = this .$slots [axisType][0 ].componentInstance .computedTop ;
368+ let y = this .$slots [axisType][0 ].componentInstance .computedTop ;
242369 const width = this .$slots [axisType][0 ].componentInstance .computedWidth ;
243- const height = this .$slots [axisType][0 ].componentInstance .computedHeight ;
370+ let height = this .$slots [axisType][0 ].componentInstance .computedHeight
371+
372+ if (axisType === " axisLeft" || axisType === " axisRight" ) {
373+ height += this .offsetY ;
374+ }
375+ if (axisType === " axisBottom" ) {
376+ y += this .offsetY ;
377+ }
244378
245379 defs
246380 .append (" clipPath" )
@@ -273,7 +407,7 @@ export default {
273407 const x = this .pMarginLeft ;
274408 const y = this .pMarginTop ;
275409 const width = this .pWidth ;
276- const height = this . pHeight ;
410+ const height = pHeight;
277411
278412 defs
279413 .append (" clipPath" )
@@ -322,7 +456,12 @@ export default {
322456
323457}
324458.vdp-plot-container .vdp-plot-container-dl-btn {
325- position : relative ;
459+ position : absolute ;
326460 cursor : pointer ;
327461}
462+
463+ .vdp-plot-container .vdp-plot-container-rs-btn {
464+ position : absolute ;
465+ cursor : ns-resize ;
466+ }
328467 </style >
0 commit comments