Skip to content

Commit 00637b4

Browse files
committed
Merge branch 'main' into demo
2 parents 7965b04 + 11633ac commit 00637b4

9 files changed

Lines changed: 302 additions & 204 deletions

File tree

src/components/Plot.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,12 @@ const panelStyle = computed(() => {
409409

410410
const wrapperStyle = computed(() => {
411411
let style = { overflow: 'hidden', boxSizing: 'border-box' }
412-
if (resize == "x") {
412+
if (resize === "both" || resize === true || resize === "") {
413+
Object.assign(style, { resize: "both" })
414+
} else if (resize === "horizontal" || resize === "x" && !flip || resize === "y" && flip) {
413415
Object.assign(style, { resize: "horizontal" })
414-
} else if (resize == "y") {
416+
} else if (resize === "vertical" || resize === "y" && !flip || resize === "x" && flip) {
415417
Object.assign(style, { resize: "vertical" })
416-
} else if (resize == true || resize == "both" || resize == "") {
417-
Object.assign(style, { resize: "both" })
418418
}
419419
return style
420420
})

src/components/core/CorePlot.vue

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup>
22
defineOptions({ inheritAttrs: false })
3-
import { reactive, ref, computed, watch, useTemplateRef, useId } from 'vue'
3+
import { reactive, computed, watch, useTemplateRef, useId } from 'vue'
44
import { GPlot } from '#base/js/plot'
55
import { unique, oob_squish_any, oob_squish_infinite, dropNull, emitEvent } from '#base/js/utils'
66
import { reactiveComputed, useElementSize } from '@vueuse/core'
@@ -193,19 +193,19 @@ function pos2coord({
193193
function _coord2pos(
194194
{ value, min, max } = {},
195195
{ oob = oob_squish_infinite } = {},
196-
scale, rev, length, range
196+
scale, rev, length, boundary
197197
) {
198198
let result = {}
199199
if (value != null) {
200-
result.value = oob(length * (rev ? 1 - scale(value) : scale(value)), range)
200+
result.value = oob(length * (rev ? 1 - scale(value) : scale(value)), boundary)
201201
}
202202
if (min == null && max == null) return result
203203
if (rev) {
204-
if (max != null) result.min = oob(length * (1 - scale(max)), range)
205-
if (min != null) result.max = oob(length * (1 - scale(min)), range)
204+
if (max != null) result.min = oob(length * (1 - scale(max)), boundary)
205+
if (min != null) result.max = oob(length * (1 - scale(min)), boundary)
206206
} else {
207-
if (min != null) result.min = oob(length * scale(min), range)
208-
if (max != null) result.max = oob(length * scale(max), range)
207+
if (min != null) result.min = oob(length * scale(min), boundary)
208+
if (max != null) result.max = oob(length * scale(max), boundary)
209209
}
210210
return result
211211
}
@@ -218,8 +218,8 @@ function coord2pos({
218218
let { width, height, l, r, t, b } = innerRect
219219
let result = {}
220220
let scales = vplot.value.coordScales
221-
let rangeH = { min: -l, max: width + r },
222-
rangeV = { min: -t, max: height + b }
221+
let boundaryH = { min: -l, max: width + r },
222+
boundaryV = { min: -t, max: height + b }
223223
if (x != null || xmin != null || xmax != null) {
224224
if (flip) {
225225
[v, vmin, vmax] = [x, xmin, xmax]
@@ -240,7 +240,7 @@ function coord2pos({
240240
{ oob },
241241
scales[flip ? 'y' : 'x'],
242242
reverse[flip ? 'y' : 'x'],
243-
width, rangeH
243+
width, boundaryH
244244
)
245245
Object.assign(result, dropNull({ h: value, hmin: min, hmax: max }))
246246
}
@@ -250,15 +250,15 @@ function coord2pos({
250250
{ oob },
251251
scales[flip ? 'x' : 'y'],
252252
!reverse[flip ? 'x' : 'y'],
253-
height, rangeV
253+
height, boundaryV
254254
)
255255
Object.assign(result, dropNull({ v: value, vmin: min, vmax: max }))
256256
}
257257
if (limited) {
258-
if (result.hmin == null) result.hmin = rangeH.min
259-
if (result.hmax == null) result.hmax = rangeH.max
260-
if (result.vmin == null) result.vmin = rangeV.min
261-
if (result.vmax == null) result.vmax = rangeV.max
258+
if (result.hmin == null) result.hmin = boundaryH.min
259+
if (result.hmax == null) result.hmax = boundaryH.max
260+
if (result.vmin == null) result.vmin = boundaryV.min
261+
if (result.vmax == null) result.vmax = boundaryV.max
262262
}
263263
return result
264264
}
@@ -411,19 +411,19 @@ function svgPointerdown(e) {
411411
svg.style.userSelect = 'none'
412412
moveTimer = clearTimeout(moveTimer)
413413
let boundary = coord2pos(act, { unlimited: true })
414-
let rangeH = {
414+
let boundaryH = {
415415
min: boundary.hmax == null ? -Infinity : innerRect.width - boundary.hmax,
416416
max: boundary.hmin == null ? Infinity : - boundary.hmin,
417417
},
418-
rangeV = {
418+
boundaryV = {
419419
min: boundary.vmax == null ? -Infinity : innerRect.height - boundary.vmax,
420420
max: boundary.vmin == null ? Infinity : - boundary.vmin,
421421
}
422422
e.target.onpointermove = (ev) => {
423423
let { x = false, y = false } = act
424424
let [h, v] = flip ? [y, x] : [x, y]
425-
if (h) translateH.value = oob_squish_any(translateH.value + ev.movementX, rangeH)
426-
if (v) translateV.value = oob_squish_any(translateV.value + ev.movementY, rangeV)
425+
if (h) translateH.value = oob_squish_any(translateH.value + ev.movementX, boundaryH)
426+
if (v) translateV.value = oob_squish_any(translateV.value + ev.movementY, boundaryV)
427427
}
428428
e.target.onpointerup = (ev) => {
429429
ev.currentTarget.onpointerup = null
@@ -546,19 +546,19 @@ function wheel(act, pos, delta) {
546546
let boundary = coord2pos(act, { unlimited: true })
547547
if (h) {
548548
let movement = sensitivity * innerRect.width * (-delta / 120)
549-
let range = {
549+
let boundaryH = {
550550
min: boundary.hmax == null ? -Infinity : innerRect.width - boundary.hmax,
551551
max: boundary.hmin == null ? Infinity : - boundary.hmin,
552552
}
553-
translateH.value = oob_squish_any(movement, range)
553+
translateH.value = oob_squish_any(movement, boundaryH)
554554
}
555555
if (v) {
556556
let movement = sensitivity * innerRect.height * (-delta / 120)
557-
let range = {
557+
let boundaryV = {
558558
min: boundary.vmax == null ? -Infinity : innerRect.height - boundary.vmax,
559559
max: boundary.vmin == null ? Infinity : - boundary.vmin,
560560
}
561-
translateV.value = oob_squish_any(movement, range)
561+
translateV.value = oob_squish_any(movement, boundaryV)
562562
}
563563
}
564564
}
@@ -579,10 +579,10 @@ const svgVOn = {
579579
function changerange(coord) {
580580
let { xmin, xmax, ymin, ymax } = coord
581581
let { xmin: $xmin, xmax: $xmax, ymin: $ymin, ymax: $ymax } = range
582-
xmin = xmin != null ? xmin + expandAdd.x.min : $xmin
583-
xmax = xmax != null ? xmax - expandAdd.x.max : $xmax
584-
ymin = ymin != null ? ymin + expandAdd.y.min : $ymin
585-
ymax = ymax != null ? ymax - expandAdd.y.max : $ymax
582+
xmin = xmin != null ? typeof xmin == "number" ? xmin + expandAdd.x.min : new xmin.constructor(+xmin + expandAdd.x.min) : $xmin
583+
xmax = xmax != null ? typeof xmin == "number" ? xmax - expandAdd.x.max : new xmax.constructor(+xmax - expandAdd.x.max) : $xmax
584+
ymin = ymin != null ? typeof xmin == "number" ? ymin + expandAdd.y.min : new ymin.constructor(+ymin + expandAdd.y.min) : $ymin
585+
ymax = ymax != null ? typeof xmin == "number" ? ymax - expandAdd.y.max : new ymax.constructor(+ymax - expandAdd.y.max) : $ymax
586586
if (xmin == $xmin && xmax == $xmax && ymin == $ymin && ymax == $ymax) return
587587
if (xmin != $xmin) emit('update:xmin', xmin)
588588
if (xmax != $xmax) emit('update:xmax', xmax)

src/components/core/axis/CoreAxisH.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ function axisMovePointerdown(e) {
147147
e.stopPropagation()
148148
e.target.style.cursor = 'grabbing'
149149
let boundary = coord2pos(act, { unlimited: true })
150-
let range = {
150+
let boundaryH = {
151151
min: boundary.hmax == null ? -Infinity : layout.width - boundary.hmax,
152152
max: boundary.hmin == null ? Infinity : - boundary.hmin
153153
}
154154
e.target.setPointerCapture(e.pointerId)
155155
e.target.onpointermove = (ev) => {
156-
translateH.value = oob_squish_any(translateH.value + ev.movementX, range)
156+
translateH.value = oob_squish_any(translateH.value + ev.movementX, boundaryH)
157157
}
158158
e.target.onpointerup = (ev) => {
159159
e.target.onpointermove = null
@@ -256,11 +256,11 @@ function wheel(act, pos, delta) {
256256
let { sensitivity = 0.1 } = act
257257
let movement = sensitivity * layout.width * (-delta / 120)
258258
let boundary = coord2pos(act, { unlimited: true })
259-
let range = {
259+
let boundaryH = {
260260
min: boundary.hmax == null ? -Infinity : layout.width - boundary.hmax,
261261
max: boundary.hmin == null ? Infinity : - boundary.hmin,
262262
}
263-
translateH.value = oob_squish_any(movement, range)
263+
translateH.value = oob_squish_any(movement, boundaryH)
264264
}
265265
}
266266
function applyTransform(act, event) {

src/components/core/axis/CoreAxisV.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ function axisMovePointerdown(e) {
147147
e.stopPropagation()
148148
e.target.style.cursor = 'grabbing'
149149
let boundary = coord2pos(act, { unlimited: true })
150-
let range = {
150+
let boundaryV = {
151151
min: boundary.vmax == null ? -Infinity : layout.height - boundary.vmax,
152152
max: boundary.vmin == null ? Infinity : - boundary.vmin
153153
}
154154
e.target.setPointerCapture(e.pointerId)
155155
e.target.onpointermove = (ev) => {
156-
translateV.value = oob_squish_any(translateV.value + ev.movementY, range)
156+
translateV.value = oob_squish_any(translateV.value + ev.movementY, boundaryV)
157157
}
158158
e.target.onpointerup = (ev) => {
159159
e.target.onpointermove = null
@@ -256,11 +256,11 @@ function wheel(act, pos, delta) {
256256
let { sensitivity = 0.1 } = act
257257
let movement = sensitivity * layout.height * (-delta / 120)
258258
let boundary = coord2pos(act, { unlimited: true })
259-
let range = {
259+
let boundaryV = {
260260
min: boundary.vmax == null ? -Infinity : layout.height - boundary.vmax,
261261
max: boundary.vmin == null ? Infinity : - boundary.vmin,
262262
}
263-
translateV.value = oob_squish_any(movement, range)
263+
translateV.value = oob_squish_any(movement, boundaryV)
264264
}
265265
}
266266
function applyTransform(act, event) {

src/js/geom.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ export default {
120120
},
121121
get_range(ds, orientation) {
122122
if (orientation == 'x') {
123-
let xmin = (ds.x ?? []).map((v, i) => +v - ds.width[i] / 2),
124-
xmax = (ds.x ?? []).map((v, i) => +v + ds.width[i] / 2)
123+
let xmin = (ds.x ?? []).map((v, i) => +v - (ds.width?.[i] ?? 0) / 2),
124+
xmax = (ds.x ?? []).map((v, i) => +v + (ds.width?.[i] ?? 0) / 2)
125125
return xmin.concat(xmax)
126126
}
127127
if (orientation == 'y') {
128-
let ymin = (ds.y ?? []).map((v, i) => +v - ds.height[i] / 2),
129-
ymax = (ds.y ?? []).map((v, i) => +v + ds.height[i] / 2)
128+
let ymin = (ds.y ?? []).map((v, i) => +v - (ds.height?.[i] ?? 0) / 2),
129+
ymax = (ds.y ?? []).map((v, i) => +v + (ds.height?.[i] ?? 0) / 2)
130130
return ymin.concat(ymax)
131131
}
132132
},

web-docs/docs/gallery.vue

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -125,46 +125,46 @@ const vBind = {
125125
</div>
126126
<hr>
127127
<pre><code class="html">{{templates[9] = `<VVPlot :data="economics" :theme="{ plot: { margin_right: 50 } }">
128-
<VVAxisY :labels="v => \`\${v * 100}%\`" :expand-mult="{ min: 0.2, max: 0.1 }" title="unemployment rate"
129-
:theme="{ title_color: 'gray' }">
130-
<VVAction move rescale zoom />
131-
</VVAxisY>
132-
<VVAxisX position="10%"
133-
:theme="{ tick_length: 3, title_position: 'right', title_size: 16, text_angle: 45, tick_anchor_x: 0 }"
134-
:show-grid="false" title="date" :extend="0.5">
135-
<VVAction move rescale zoom />
136-
</VVAxisX>
137-
<VVGeomLine :x="d => new Date(d.date)" :y="d => d.unemploy / d.pop" />
138-
</VVPlot>`}}</code></pre>
128+
<VVAxisY :labels="v => \`\${v * 100}%\`" :expand-mult="{ min: 0.2, max: 0.1 }" title="unemployment rate"
129+
:theme="{ title_color: 'gray' }">
130+
<VVAction move rescale zoom />
131+
</VVAxisY>
132+
<VVAxisX position="10%"
133+
:theme="{ tick_length: 3, title_position: 'right', title_size: 16, text_angle: 45, tick_anchor_x: 0 }"
134+
:show-grid="false" title="date" :extend="0.5">
135+
<VVAction move rescale zoom />
136+
</VVAxisX>
137+
<VVGeomLine :x="d => new Date(d.date)" :y="d => d.unemploy / d.pop" />
138+
</VVPlot>`}}</code></pre>
139139
<component :is="{ template: templates[9], props: Object.keys(vBind) }" v-bind="vBind" />
140140
<hr>
141141
<pre><code class="html">{{templates[10] = `<VVPlot :data="economics">
142-
<VVAxisX :labels="vvlabel.timestamp({ format: 'yyyy/MM' })" position="top" />
143-
<VVAxisY position="left" primary />
144-
<VVAxisY position="right" />
145-
<VVAxisX position="bottom" secondary />
146-
<VVGeomLine :x="d => new Date(d.date)" :y="d => d.pop" />
147-
</VVPlot>`}}</code></pre>
142+
<VVAxisX :labels="vvlabel.timestamp({ format: 'yyyy/MM' })" position="top" />
143+
<VVAxisY position="left" primary />
144+
<VVAxisY position="right" />
145+
<VVAxisX position="bottom" secondary />
146+
<VVGeomLine :x="d => new Date(d.date)" :y="d => d.pop" />
147+
</VVPlot>`}}</code></pre>
148148
<component :is="{ template: templates[10], props: Object.keys(vBind) }" v-bind="vBind" />
149149
<hr>
150150
<pre><code class="html">{{templates[11] = `<VVPlot :data="[{ x: 2, y: -1 }, { x: -1, y: 2 }]">
151-
<VVAxisX :position="0" :expand-mult="1" :breaks="vvbreak.number({ step: 1 })" title="x"
152-
:theme="{ title_position: 'right', title_size: 16 }">
153-
<VVAction move rescale zoom />
154-
</VVAxisX>
155-
<VVAxisY :position="0" :expand-mult="1" :extend="1" title="y"
156-
:theme="{ title_position: 'top', title_dock_x: 0, title_size: 16, title_angle: 0 }">
157-
<VVAction move rescale zoom />
158-
</VVAxisY>
159-
<VVGeomPoint :x="d => d.x" :y="d => d.y" />
160-
</VVPlot>`}}</code></pre>
151+
<VVAxisX :position="0" :expand-mult="1" :breaks="vvbreak.number({ step: 1 })" title="x"
152+
:theme="{ title_position: 'right', title_size: 16 }">
153+
<VVAction move rescale zoom />
154+
</VVAxisX>
155+
<VVAxisY :position="0" :expand-mult="1" :extend="1" title="y"
156+
:theme="{ title_position: 'top', title_dock_x: 0, title_size: 16, title_angle: 0 }">
157+
<VVAction move rescale zoom />
158+
</VVAxisY>
159+
<VVGeomPoint :x="d => d.x" :y="d => d.y" />
160+
</VVPlot>`}}</code></pre>
161161
<component :is="{ template: templates[11], props: Object.keys(vBind) }" v-bind="vBind" />
162162
<hr>
163163
<pre><code class="html">{{templates[12] = `<VVPlot :data="letters">
164-
<VVAxisX :expand-add="1" :expand-mult="0" :levels="['x', 'y', 'z', '', 'a', 'b', 'c']" :position="0" />
165-
<VVAxisY position="center" :theme="{ tick_anchor_y: 1 }" />
166-
<VVGeomBar :x="d => d" />
167-
</VVPlot>`}}</code></pre>
164+
<VVAxisX :expand-add="1" :expand-mult="0" :levels="['x', 'y', 'z', '', 'a', 'b', 'c']" :position="0" />
165+
<VVAxisY position="center" :theme="{ tick_anchor_y: 1 }" />
166+
<VVGeomBar :x="d => d" />
167+
</VVPlot>`}}</code></pre>
168168
<component :is="{ template: templates[12], props: Object.keys(vBind) }" v-bind="vBind" />
169169
</section>
170170
</article>

web-docs/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ window.addEventListener('hashchange', () => {
3434
})
3535
</script>
3636
<template>
37-
<div class="content">
37+
<div class="content" :class="{ 'h-screen': page == 'playground' }">
3838
<nav class="flex flex-row gap-4 p-4 sticky top-0 bg-white border-b border-gray-200 z-20">
3939
<a :href="'#' + k" :key="k" v-for="(v, k) in pages">{{ k.replace(/_/g, " ") }}</a>
4040
</nav>

0 commit comments

Comments
 (0)