vvplot 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Selection.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { computed, isRef, reactive, unref, onMounted, nextTick, getCurrentScope, onScopeDispose, getCurrentInstance, shallowRef, watch, toValue, useTemplateRef, createElementBlock, openBlock, mergeProps, renderSlot, createCommentVNode, createTextVNode, toDisplayString, inject, normalizeStyle, createElementVNode, createBlock, Fragment, renderList, createVNode, toHandlers, normalizeProps, resolveDynamicComponent, guardReactiveProps, mergeModels, useModel, createPropsRestProxy, ref, useId, Teleport, useSlots, useAttrs, provide } from "vue";
2
2
  import { theme_base, theme_default, themeBuild, themePreprocess, themeMerge } from "./theme.js";
3
- import { vecutils, intraaction, numutils, intrazip, GEnumLevel, oob_squish_any, dropNull, emitEvent, plus, categorize, obj_merge, interaction, unique, oob_squish_infinite, str_c, serializeSVG } from "./utils.js";
3
+ import { vecutils, intraaction, numutils, intrazip, GEnumLevel, plus, oob_squish_any, dropNull, emitEvent, categorize, obj_merge, interaction, unique, oob_squish_infinite, str_c, serializeSVG } from "./utils.js";
4
4
  import vvscale from "./scale.js";
5
5
  import vvbreak from "./break.js";
6
6
  import vvlabel from "./label.js";
@@ -2845,46 +2845,47 @@ class GPlot {
2845
2845
  let result = {};
2846
2846
  this._range = range;
2847
2847
  if (this.levels.x) {
2848
- let min = +(range?.xmin ?? -0.5) - (add.x?.min ?? 0), max = +(range?.xmax ?? this.levels.x.length - 0.5) + (add.x?.max ?? 0);
2848
+ let min = +(range?.xmin ?? -0.5) - (+add.x?.min || 0), max = +(range?.xmax ?? this.levels.x.length - 0.5) + (+add.x?.max || 0);
2849
2849
  result.x = new DiscreteCoordScale(this.levels.x, { min, max });
2850
2850
  } else {
2851
2851
  let $min = range?.xmin ?? this.extents.x?.min ?? 0, $max = range?.xmax ?? this.extents.x?.max ?? 0;
2852
- let min = +$min - (add.x?.min ?? 0), max = +$max + (add.x?.max ?? 0);
2852
+ let min = plus($min, -add.x?.min || 0), max = plus($max, +add.x?.max || 0);
2853
2853
  let dmin = minRange?.x ?? 1;
2854
2854
  if (max - min < dmin) {
2855
2855
  if (range?.xmax == null && range?.xmin != null) {
2856
- max = min + dmin;
2856
+ max = plus(min, +dmin);
2857
2857
  } else if (range?.xmax != null && range?.xmin == null) {
2858
- min = max - dmin;
2858
+ min = plus(max, -dmin);
2859
2859
  } else {
2860
- max = (max + min) / 2 + dmin / 2;
2861
- min = max - dmin;
2860
+ let interval2 = max - min;
2861
+ max = plus(max, -interval2 / 2 + dmin / 2);
2862
+ min = plus(max, -dmin);
2862
2863
  }
2863
2864
  }
2864
- if ($min instanceof Date || $max instanceof Date) {
2865
+ if (min instanceof Date || max instanceof Date) {
2865
2866
  result.x = new DatetimeCoordScale({ min, max });
2866
2867
  } else {
2867
2868
  result.x = new ContinuousCoordScale({ min, max });
2868
2869
  }
2869
2870
  }
2870
2871
  if (this.levels.y) {
2871
- let min = +(range?.ymin ?? -0.5) - (add.y?.min ?? 0), max = +(range?.ymax ?? this.levels.y.length - 0.5) + (add.y?.max ?? 0);
2872
+ let min = +(range?.ymin ?? -0.5) - (+add.y?.min || 0), max = +(range?.ymax ?? this.levels.y.length - 0.5) + (+add.y?.max || 0);
2872
2873
  result.y = new DiscreteCoordScale(this.levels.y, { min, max });
2873
2874
  } else {
2874
2875
  let $min = range?.ymin ?? this.extents.y?.min ?? 0, $max = range?.ymax ?? this.extents.y?.max ?? 0;
2875
- let min = +$min - (add.y?.min ?? 0), max = +$max + (add.y?.max ?? 0);
2876
+ let min = plus($min, -add.y?.min), max = plus($max, +add.y?.max || 0);
2876
2877
  let dmin = minRange?.y ?? 1;
2877
2878
  if (max - min < dmin) {
2878
2879
  if (range?.ymax == null && range?.ymin != null) {
2879
- max = min + dmin;
2880
+ max = plus(min, +dmin);
2880
2881
  } else if (range?.ymax != null && range?.ymin == null) {
2881
- min = max - dmin;
2882
+ min = plus(max, -dmin);
2882
2883
  } else {
2883
- max = (max + min) / 2 + dmin / 2;
2884
- min = max - dmin;
2884
+ max = plus(max, -interval / 2 + dmin / 2);
2885
+ min = plus(max, -dmin);
2885
2886
  }
2886
2887
  }
2887
- if ($min instanceof Date || $max instanceof Date) {
2888
+ if (min instanceof Date || max instanceof Date) {
2888
2889
  result.y = new DatetimeCoordScale({ min, max });
2889
2890
  } else {
2890
2891
  result.y = new ContinuousCoordScale({ min, max });
@@ -2934,23 +2935,13 @@ class DiscreteCoordScale extends Function {
2934
2935
  constructor(level, { min, max } = {}) {
2935
2936
  const scale = min == max ? (x2) => 0 : (x2) => (+x2 - min) / (max - min);
2936
2937
  scale.range = { min, max };
2937
- scale.limits = { min, max };
2938
2938
  scale.level = level;
2939
- scale.invert = (w) => w * (max - min) + min;
2940
2939
  Object.setPrototypeOf(scale, DiscreteCoordScale.prototype);
2941
2940
  return scale;
2942
2941
  }
2943
- expand({ min: mmin = 0, max: mmax = 0 } = {}) {
2944
- let $min = 0, $max = this.level.length, $interval = $max;
2945
- let min = $min - mmin * $interval, max = $max + mmax * $interval;
2946
- const scale = min == max ? (x2) => 0 : (x2) => (+x2 - min) / (max - min);
2947
- scale.invert = (w) => w * (max - min) + min;
2948
- scale.range = this.range;
2949
- scale.level = this.level;
2950
- scale.title = this.title;
2951
- scale.limits = { min, max };
2952
- Object.setPrototypeOf(scale, DiscreteCoordScale.prototype);
2953
- return scale;
2942
+ invert(w) {
2943
+ let { min, max } = this.range;
2944
+ return w * (max - min) + min;
2954
2945
  }
2955
2946
  get breaks() {
2956
2947
  return Array.from(this.level);
@@ -2961,35 +2952,19 @@ class DiscreteCoordScale extends Function {
2961
2952
  }
2962
2953
  class ContinuousCoordScale extends Function {
2963
2954
  constructor(domain) {
2964
- let min = +domain.min, max = +domain.max;
2965
- const scale = min == max ? (x2) => 0.5 : (x2) => (+x2 - min) / (max - min);
2955
+ let { min, max } = domain;
2956
+ const scale = min == max ? (x2) => isFinite(x2) ? 0.5 : x2 : (x2) => (+x2 - min) / (max - min);
2966
2957
  scale.range = { min, max };
2967
- scale.limits = { min, max };
2968
- Object.setPrototypeOf(scale, ContinuousCoordScale.prototype);
2969
- return scale;
2970
- }
2971
- expand({ min: mmin = 0, max: mmax = 0 } = {}) {
2972
- let { min: $min, max: $max } = this.limits;
2973
- let $interval = $max - $min;
2974
- let min = $min - mmin * $interval, max = $max + mmax * $interval;
2975
- const scale = min == max ? (x2) => 0.5 : (x2) => (+x2 - min) / (max - min);
2976
- scale.range = this.range;
2977
- scale.level = this.level;
2978
- scale.title = this.title;
2979
- scale.limits = { min, max };
2980
2958
  Object.setPrototypeOf(scale, ContinuousCoordScale.prototype);
2981
2959
  return scale;
2982
2960
  }
2983
2961
  invert(w) {
2984
- let { min, max } = this.limits;
2985
- return w * (max - min) + min;
2962
+ let { min, max } = this.range;
2963
+ return plus(min, w * (max - min));
2986
2964
  }
2987
2965
  get breaks() {
2988
2966
  return vvbreak.number();
2989
2967
  }
2990
- get minorBreaks() {
2991
- return vvbreak.number({ minor: true });
2992
- }
2993
2968
  }
2994
2969
  class DatetimeCoordScale extends ContinuousCoordScale {
2995
2970
  constructor(domain) {
@@ -2997,15 +2972,6 @@ class DatetimeCoordScale extends ContinuousCoordScale {
2997
2972
  Object.setPrototypeOf(scale, DatetimeCoordScale.prototype);
2998
2973
  return scale;
2999
2974
  }
3000
- expand({ min: mmin = 0, max: mmax = 0 } = {}) {
3001
- let scale = super.expand({ min: mmin, max: mmax });
3002
- Object.setPrototypeOf(scale, DatetimeCoordScale.prototype);
3003
- return scale;
3004
- }
3005
- invert(w) {
3006
- let { min, max } = this.limits;
3007
- return new Date(w * (max - min) + min);
3008
- }
3009
2975
  get breaks() {
3010
2976
  return vvbreak.datetime();
3011
2977
  }
@@ -3014,25 +2980,28 @@ class DatetimeCoordScale extends ContinuousCoordScale {
3014
2980
  }
3015
2981
  }
3016
2982
  class GAxis {
3017
- constructor(scale, { extend: extend2, breaks, labels, minorBreaks, titles } = {}) {
2983
+ constructor(scale, { breaks, labels, minorBreaks, titles } = {}) {
3018
2984
  this.scale = scale;
3019
- this.limits = scale?.limits;
3020
- this.extend = extend2 ?? 0;
2985
+ this.range = scale?.range;
3021
2986
  this.breaks = breaks ?? scale.breaks;
3022
2987
  this.labels = labels ?? vvlabel.auto();
3023
2988
  this.titles = titles ?? vvlabel.asis();
3024
- this.minorBreaks = minorBreaks ?? scale.minorBreaks;
3025
- }
3026
- getBindings({ limits = this.limits, extend: extend2 = this.extend } = {}) {
3027
- let breaks = this.breaks, minorBreaks = this.minorBreaks;
3028
- let { min, max } = limits, interval = max - min || 0;
3029
- min = min == null ? min : min - extend2 * interval;
3030
- max = max == null ? max : max + extend2 * interval;
3031
- if (typeof breaks == "function") breaks = breaks(limits);
3032
- breaks = Array.isArray(breaks) ? breaks.sort((a, b) => a - b) : [];
3033
- if (typeof minorBreaks == "function") minorBreaks = minorBreaks(limits);
3034
- minorBreaks = Array.isArray(minorBreaks) ? minorBreaks.sort((a, b) => a - b) : [];
3035
- let labels = this.labels, titles = this.titles;
2989
+ this.minorBreaks = minorBreaks ?? breaks ?? scale.minorBreaks ?? scale.breaks;
2990
+ }
2991
+ getBindings({ range = this.range, expandMult = { min: 0, max: 0 } } = {}) {
2992
+ let majorBreaks = this.breaks, minorBreaks = this.minorBreaks, labels = this.labels, titles = this.titles;
2993
+ let { min, max } = range, interval2 = max - min || 0;
2994
+ min = min == null ? min : plus(min, -expandMult.min * interval2);
2995
+ max = max == null ? max : plus(max, +expandMult.max * interval2);
2996
+ function normalizeBreaks(val) {
2997
+ if (val.position != null) return val;
2998
+ return { position: val };
2999
+ }
3000
+ if (typeof majorBreaks == "function") majorBreaks = majorBreaks({ min, max });
3001
+ majorBreaks = Array.isArray(majorBreaks) ? majorBreaks.map(normalizeBreaks) : [];
3002
+ let breaks = majorBreaks.map((x2) => x2.position);
3003
+ if (typeof minorBreaks == "function") minorBreaks = minorBreaks({ min, max, minor: true });
3004
+ minorBreaks = Array.isArray(minorBreaks) ? minorBreaks.map(normalizeBreaks) : [];
3036
3005
  if (typeof labels === "function") labels = breaks.map(labels);
3037
3006
  if (!Array.isArray(labels)) {
3038
3007
  labels = [];
@@ -3042,11 +3011,11 @@ class GAxis {
3042
3011
  if (typeof titles === "function") titles = breaks.map(titles);
3043
3012
  if (!Array.isArray(titles)) {
3044
3013
  titles = [];
3045
- } else if (titles.length != titles.length) {
3014
+ } else if (titles.length != breaks.length) {
3046
3015
  throw new Error("Length of titles must be the same as breaks");
3047
3016
  }
3048
3017
  return {
3049
- majorBreaks: breaks,
3018
+ majorBreaks,
3050
3019
  minorBreaks,
3051
3020
  ticks: breaks.map((position, i) => ({ position, label: labels[i], title: titles[i] }))
3052
3021
  };
@@ -3155,7 +3124,7 @@ const _hoisted_3$4 = {
3155
3124
  class: "vvplot-interactive",
3156
3125
  fill: "transparent"
3157
3126
  };
3158
- const _hoisted_4$3 = ["width"];
3127
+ const _hoisted_4$3 = ["width", "cursor"];
3159
3128
  const _hoisted_5$2 = {
3160
3129
  key: 0,
3161
3130
  class: "vvplot-interactive",
@@ -3522,7 +3491,7 @@ const _sfc_main$S = {
3522
3491
  height: 10,
3523
3492
  y: -5
3524
3493
  }, toHandlers(axisVOn, true), {
3525
- class: { "vvplot-cursor-grab": __props.action.some?.((a) => a.action == "move") }
3494
+ cursor: __props.action.some?.((a) => a.action == "move") ? "grab" : null
3526
3495
  }), null, 16, _hoisted_4$3)
3527
3496
  ]),
3528
3497
  __props.action.some?.((a) => a.action == "rescale") ? (openBlock(), createElementBlock("g", _hoisted_5$2, [
@@ -3553,7 +3522,7 @@ const _hoisted_3$3 = {
3553
3522
  class: "vvplot-interactive",
3554
3523
  fill: "transparent"
3555
3524
  };
3556
- const _hoisted_4$2 = ["height"];
3525
+ const _hoisted_4$2 = ["height", "cursor"];
3557
3526
  const _hoisted_5$1 = {
3558
3527
  key: 0,
3559
3528
  class: "vvplot-interactive",
@@ -3920,7 +3889,7 @@ const _sfc_main$R = {
3920
3889
  height: height.value,
3921
3890
  x: -5
3922
3891
  }, toHandlers(axisVOn, true), {
3923
- class: { "vvplot-cursor-grab": __props.action.some?.((a) => a.action == "move") }
3892
+ cursor: __props.action.some?.((a) => a.action == "move") ? "grab" : null
3924
3893
  }), null, 16, _hoisted_4$2)
3925
3894
  ]),
3926
3895
  __props.action.some?.((a) => a.action == "rescale") ? (openBlock(), createElementBlock("g", _hoisted_5$1, [
@@ -3985,8 +3954,8 @@ const _sfc_main$P = {
3985
3954
  const majorLines = computed(() => {
3986
3955
  let result = [];
3987
3956
  for (let line2 of __props.majorBreaks) {
3988
- if (line2?.position == null) line2 = { position: +line2 };
3989
3957
  let pos = __props.coord2pos({ v: line2.position }).v;
3958
+ if (isNaN(pos)) continue;
3990
3959
  let tsl = pos * (__props.activeTransform.scaleV - 1) + __props.activeTransform.translateV;
3991
3960
  let position = pos + __props.layout.t;
3992
3961
  if (position + tsl < 0 || position + tsl > height.value) continue;
@@ -4007,8 +3976,9 @@ const _sfc_main$P = {
4007
3976
  const minorLines = computed(() => {
4008
3977
  let result = [];
4009
3978
  for (let line2 of __props.minorBreaks) {
4010
- if (line2?.position == null) line2 = { position: +line2 };
3979
+ if (__props.majorBreaks.some((ml) => ml.position == line2.position)) continue;
4011
3980
  let pos = __props.coord2pos({ v: line2.position }).v;
3981
+ if (isNaN(pos)) continue;
4012
3982
  let tsl = pos * (__props.activeTransform.scaleV - 1) + __props.activeTransform.translateV;
4013
3983
  let position = pos + __props.layout.t;
4014
3984
  if (position + tsl < 0 || position + tsl > height.value) continue;
@@ -4024,16 +3994,12 @@ const _sfc_main$P = {
4024
3994
  style: { transition: __props.transition }
4025
3995
  });
4026
3996
  }
4027
- return result.filter((l) => l.stroke !== null && majorLines.value.every((ml) => ml.y1 !== l.y1));
3997
+ return result.filter((l) => l.stroke !== null);
4028
3998
  });
3999
+ const lines = computed(() => minorLines.value.concat(majorLines.value).sort((a, b) => a.y1 - b.y1));
4029
4000
  return (_ctx, _cache) => {
4030
4001
  return openBlock(), createElementBlock("g", null, [
4031
- (openBlock(true), createElementBlock(Fragment, null, renderList(minorLines.value, (line2) => {
4032
- return openBlock(), createElementBlock("line", mergeProps({ ref_for: true }, line2, {
4033
- style: { transition: __props.transition }
4034
- }), null, 16);
4035
- }), 256)),
4036
- (openBlock(true), createElementBlock(Fragment, null, renderList(majorLines.value, (line2) => {
4002
+ (openBlock(true), createElementBlock(Fragment, null, renderList(lines.value, (line2) => {
4037
4003
  return openBlock(), createElementBlock("line", mergeProps({ ref_for: true }, line2, {
4038
4004
  style: { transition: __props.transition }
4039
4005
  }), null, 16);
@@ -4061,8 +4027,8 @@ const _sfc_main$O = {
4061
4027
  const majorLines = computed(() => {
4062
4028
  let result = [];
4063
4029
  for (let line2 of __props.majorBreaks) {
4064
- if (line2?.position == null) line2 = { position: +line2 };
4065
4030
  let pos = __props.coord2pos({ h: line2.position }).h;
4031
+ if (isNaN(pos)) continue;
4066
4032
  let tsl = pos * (__props.activeTransform.scaleH - 1) + __props.activeTransform.translateH;
4067
4033
  let position = pos + __props.layout.l;
4068
4034
  if (position + tsl < 0 || position + tsl > width.value) continue;
@@ -4083,8 +4049,9 @@ const _sfc_main$O = {
4083
4049
  const minorLines = computed(() => {
4084
4050
  let result = [];
4085
4051
  for (let line2 of __props.minorBreaks) {
4086
- if (line2?.position == null) line2 = { position: +line2 };
4052
+ if (__props.majorBreaks.some((ml) => ml.position == line2.position)) continue;
4087
4053
  let pos = __props.coord2pos({ h: line2.position }).h;
4054
+ if (isNaN(pos)) continue;
4088
4055
  let tsl = pos * (__props.activeTransform.scaleH - 1) + __props.activeTransform.translateH;
4089
4056
  let position = pos + __props.layout.l;
4090
4057
  if (position + tsl < 0 || position + tsl > width.value) continue;
@@ -4100,15 +4067,15 @@ const _sfc_main$O = {
4100
4067
  style: { transition: __props.transition }
4101
4068
  });
4102
4069
  }
4103
- return result.filter((l) => l.stroke !== null && majorLines.value.every((ml) => ml.x1 !== l.x1));
4070
+ return result.filter((l) => l.stroke !== null);
4104
4071
  });
4072
+ const lines = computed(() => minorLines.value.concat(majorLines.value).sort((a, b) => a.x1 - b.x1));
4105
4073
  return (_ctx, _cache) => {
4106
4074
  return openBlock(), createElementBlock("g", null, [
4107
- (openBlock(true), createElementBlock(Fragment, null, renderList(minorLines.value, (line2) => {
4108
- return openBlock(), createElementBlock("line", mergeProps({ ref_for: true }, line2), null, 16);
4109
- }), 256)),
4110
- (openBlock(true), createElementBlock(Fragment, null, renderList(majorLines.value, (line2) => {
4111
- return openBlock(), createElementBlock("line", mergeProps({ ref_for: true }, line2), null, 16);
4075
+ (openBlock(true), createElementBlock(Fragment, null, renderList(lines.value, (line2) => {
4076
+ return openBlock(), createElementBlock("line", mergeProps({ ref_for: true }, line2, {
4077
+ style: { transition: __props.transition }
4078
+ }), null, 16);
4112
4079
  }), 256))
4113
4080
  ]);
4114
4081
  };
@@ -5767,7 +5734,7 @@ const _sfc_main$s = {
5767
5734
  stroke: __props.theme?.line_color ?? "transparent",
5768
5735
  "stroke-width": __props.theme?.line_width,
5769
5736
  "stroke-opacity": __props.theme?.opacity,
5770
- style: config.move ? "cursor:move;" : "pointer:events-none;"
5737
+ style: config.move ? "cursor:move;" : "pointer-events:none;"
5771
5738
  };
5772
5739
  if (config.resize) {
5773
5740
  if (pos.hmin != null)
@@ -6324,15 +6291,15 @@ const _sfc_main$n = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
6324
6291
  function _coord2pos({ value, min, max } = {}, { oob = oob_squish_infinite } = {}, scale, rev, length, boundary) {
6325
6292
  let result = {};
6326
6293
  if (value != null) {
6327
- result.value = oob(length * (rev ? 1 - scale(value) : scale(value)), boundary);
6294
+ result.value = length ? oob(length * (rev ? 1 - scale(value) : scale(value)), boundary) : 0;
6328
6295
  }
6329
6296
  if (min == null && max == null) return result;
6330
6297
  if (rev) {
6331
- if (max != null) result.min = oob(length * (1 - scale(max)), boundary);
6332
- if (min != null) result.max = oob(length * (1 - scale(min)), boundary);
6298
+ if (max != null) result.min = length ? oob(length * (1 - scale(max)), boundary) : 0;
6299
+ if (min != null) result.max = length ? oob(length * (1 - scale(min)), boundary) : 0;
6333
6300
  } else {
6334
- if (min != null) result.min = oob(length * scale(min), boundary);
6335
- if (max != null) result.max = oob(length * scale(max), boundary);
6301
+ if (min != null) result.min = length ? oob(length * scale(min), boundary) : 0;
6302
+ if (max != null) result.max = length ? oob(length * scale(max), boundary) : 0;
6336
6303
  }
6337
6304
  return result;
6338
6305
  }
@@ -6400,10 +6367,10 @@ const _sfc_main$n = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
6400
6367
  }
6401
6368
  function getPadding({ min: $min, max: $max } = {}, { min: mmin = 0, max: mmax = 0 } = {}) {
6402
6369
  let $interval = $max - $min;
6403
- let min = $min - mmin * $interval, max = $max + mmax * $interval, interval = max - min;
6370
+ let min = +$min - mmin * $interval, max = +$max + mmax * $interval, interval2 = max - min;
6404
6371
  return {
6405
- min: interval == 0 ? 0 : ($min - min) / interval,
6406
- max: interval == 0 ? 0 : (max - $max) / interval
6372
+ min: interval2 == 0 ? 0 : ($min - min) / interval2,
6373
+ max: interval2 == 0 ? 0 : (max - $max) / interval2
6407
6374
  };
6408
6375
  }
6409
6376
  function getCoord(event) {
@@ -6676,14 +6643,14 @@ const _sfc_main$n = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
6676
6643
  function changerange(coord) {
6677
6644
  let { xmin, xmax, ymin, ymax } = coord;
6678
6645
  let { xmin: $xmin, xmax: $xmax, ymin: $ymin, ymax: $ymax } = range;
6679
- xmin = xmin != null ? plus(xmin, __props.expandAdd.x.min) : $xmin;
6646
+ xmin = xmin != null ? plus(xmin, +__props.expandAdd.x.min) : $xmin;
6680
6647
  xmax = xmax != null ? plus(xmax, -__props.expandAdd.x.max) : $xmax;
6681
- ymin = ymin != null ? plus(ymin, __props.expandAdd.y.min) : $ymin;
6648
+ ymin = ymin != null ? plus(ymin, +__props.expandAdd.y.min) : $ymin;
6682
6649
  ymax = ymax != null ? plus(ymax, -__props.expandAdd.y.max) : $ymax;
6683
6650
  if (xmin == $xmin && xmax == $xmax && ymin == $ymin && ymax == $ymax) return;
6684
6651
  Object.assign(range, { xmin, xmax, ymin, ymax });
6685
6652
  }
6686
- const axisLimits = reactiveComputed(() => {
6653
+ const axisRange = reactiveComputed(() => {
6687
6654
  let xmin = rangePreview?.xmin ?? range?.xmin, xmax = rangePreview?.xmax ?? range?.xmax, ymin = rangePreview?.ymin ?? range?.ymin, ymax = rangePreview?.ymax ?? range?.ymax;
6688
6655
  return {
6689
6656
  x: xmin || xmax ? { min: xmin, max: xmax } : void 0,
@@ -6692,24 +6659,26 @@ const _sfc_main$n = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
6692
6659
  });
6693
6660
  const gaxes = computed(() => {
6694
6661
  let coordScales = {
6695
- x: vplot.value.coordScales.x.expand(__props.expandMult?.x),
6696
- y: vplot.value.coordScales.y.expand(__props.expandMult?.y)
6662
+ x: vplot.value.coordScales.x,
6663
+ y: vplot.value.coordScales.y
6697
6664
  };
6698
6665
  return props.axes.filter((a) => a.coord in coordScales).filter((a) => ["h", "v"].includes(a.orientation)).map(({
6699
6666
  coord,
6700
6667
  breaks,
6701
- extend: extend2,
6702
6668
  labels,
6703
6669
  minorBreaks,
6704
6670
  ...etc
6705
6671
  }) => ({
6706
6672
  coord,
6707
- axis: new GAxis(coordScales[coord], { breaks, extend: extend2, labels, minorBreaks }),
6673
+ axis: new GAxis(coordScales[coord], { breaks, labels, minorBreaks }),
6708
6674
  etc
6709
6675
  }));
6710
6676
  });
6711
6677
  const vaxes = computed(() => gaxes.value.map(({ coord, axis, etc }) => {
6712
- let { majorBreaks, minorBreaks, ticks } = axis.getBindings({ limits: axisLimits[coord] });
6678
+ let { majorBreaks, minorBreaks, ticks } = axis.getBindings({
6679
+ range: axisRange[coord],
6680
+ expandMult: __props.expandMult[coord]
6681
+ });
6713
6682
  let { showGrid, orientation, ...bind } = etc;
6714
6683
  return {
6715
6684
  majorBreaks,
@@ -6725,12 +6694,12 @@ const _sfc_main$n = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
6725
6694
  let hAxes = vaxes.value.filter((a) => a.showGrid && a.orientation == "v"), vAxes = vaxes.value.filter((a) => a.showGrid && a.orientation == "h");
6726
6695
  return {
6727
6696
  h: {
6728
- majorBreaks: unique(hAxes.flatMap((a) => a.majorBreaks)),
6729
- minorBreaks: unique(hAxes.flatMap((a) => a.minorBreaks))
6697
+ majorBreaks: unique(hAxes.flatMap((a) => a.majorBreaks), (x2) => x2.position),
6698
+ minorBreaks: unique(hAxes.flatMap((a) => a.minorBreaks), (x2) => x2.position)
6730
6699
  },
6731
6700
  v: {
6732
- majorBreaks: unique(vAxes.flatMap((a) => a.majorBreaks)),
6733
- minorBreaks: unique(vAxes.flatMap((a) => a.minorBreaks))
6701
+ majorBreaks: unique(vAxes.flatMap((a) => a.majorBreaks), (x2) => x2.position),
6702
+ minorBreaks: unique(vAxes.flatMap((a) => a.minorBreaks), (x2) => x2.position)
6734
6703
  }
6735
6704
  };
6736
6705
  });
@@ -7036,7 +7005,10 @@ const axis_components = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.def
7036
7005
  VVAxisX: _sfc_main$3,
7037
7006
  VVAxisY: _sfc_main$2
7038
7007
  }, Symbol.toStringTag, { value: "Module" }));
7039
- const _hoisted_1 = { class: "vvplot-panel" };
7008
+ const _hoisted_1 = {
7009
+ key: 0,
7010
+ class: "vvplot-panel"
7011
+ };
7040
7012
  const _sfc_main$1 = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
7041
7013
  __name: "Plot",
7042
7014
  props: /* @__PURE__ */ mergeModels({
@@ -7543,6 +7515,7 @@ const _sfc_main$1 = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
7543
7515
  });
7544
7516
  const panelStyle = computed(() => {
7545
7517
  return {
7518
+ position: "absolute",
7546
7519
  left: str_c(plotRef.value?.panel?.left, "px"),
7547
7520
  top: str_c(plotRef.value?.panel?.top, "px"),
7548
7521
  width: str_c(plotRef.value?.panel?.width, "px"),
@@ -7599,17 +7572,16 @@ const _sfc_main$1 = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
7599
7572
  legendTeleport: __props.legendTeleport,
7600
7573
  onSelect: _cache[3] || (_cache[3] = (d, e) => emit("select", d, e))
7601
7574
  }), null, 16, ["paddings", "schema", "layers", "min-range", "expand-add", "expand-mult", "reverse", "flip", "coord-levels", "levels", "scales", "axes", "theme", "selections", "transition", "selectionPreview", "selectionPreviewTheme", "action", "clip", "legendTeleport"]),
7602
- vnodes.dom.panel?.length ? (openBlock(), createElementBlock("div", {
7603
- key: 0,
7575
+ createElementVNode("div", {
7604
7576
  class: "vvplot-panel-container",
7605
7577
  style: normalizeStyle(panelStyle.value)
7606
7578
  }, [
7607
- createElementVNode("div", _hoisted_1, [
7579
+ vnodes.dom.panel?.length ? (openBlock(), createElementBlock("div", _hoisted_1, [
7608
7580
  (openBlock(true), createElementBlock(Fragment, null, renderList(vnodes.dom.panel, (c) => {
7609
7581
  return openBlock(), createBlock(resolveDynamicComponent(c));
7610
7582
  }), 256))
7611
- ])
7612
- ], 4)) : createCommentVNode("", true),
7583
+ ])) : createCommentVNode("", true)
7584
+ ], 4),
7613
7585
  (openBlock(true), createElementBlock(Fragment, null, renderList(vdom.value, (c) => {
7614
7586
  return openBlock(), createBlock(resolveDynamicComponent(c));
7615
7587
  }), 256))
package/dist/break.js CHANGED
@@ -1,5 +1,5 @@
1
- function break_number({ step: $step, minor = false } = {}) {
2
- return function({ min, max } = {}) {
1
+ function break_number({ step: $step, minor: $minor = false } = {}) {
2
+ return function({ min, max, minor = $minor } = {}) {
3
3
  let interval = max - min, step = $step;
4
4
  if (isNaN(interval) || interval < 0) return [];
5
5
  if (interval == 0) return [min];
package/dist/scale.js CHANGED
@@ -2691,6 +2691,11 @@ const oob = {
2691
2691
  return value;
2692
2692
  }
2693
2693
  };
2694
+ function custom_scale(func, { title, ...etc } = {}) {
2695
+ return Object.assign(function(arr) {
2696
+ return arr.map(func);
2697
+ }, { title }, etc);
2698
+ }
2694
2699
  function manual_scale({
2695
2700
  values = {},
2696
2701
  na_value = null,
@@ -2886,6 +2891,7 @@ const palette_scales = {
2886
2891
  gradientn: palette_scale_gradientn,
2887
2892
  dynamic: palette_scale_dynamic,
2888
2893
  auto: palette_scale_auto,
2894
+ custom: custom_scale,
2889
2895
  default: palette_scale_auto
2890
2896
  };
2891
2897
  function scale_identity_number({ title, ...etc } = {}) {
@@ -2932,33 +2938,33 @@ const vvscale = {
2932
2938
  fill: palette_scales,
2933
2939
  alpha: {
2934
2940
  continuous: continuous_scale,
2941
+ custom: custom_scale,
2935
2942
  default: ({ title, ...etc } = {}) => continuous_scale({ range: [0.1, 1], title, ...etc })
2936
2943
  },
2937
2944
  size: {
2938
2945
  identity: scale_identity_number,
2939
2946
  continuous: continuous_scale,
2947
+ custom: custom_scale,
2940
2948
  default: ({ title, ...etc } = {}) => continuous_scale({ range: [1, 6], title, ...etc })
2941
2949
  },
2942
2950
  linewidth: {
2943
2951
  identity: scale_identity_number,
2944
2952
  continuous: continuous_scale,
2945
2953
  manual: manual_scale,
2954
+ custom: custom_scale,
2946
2955
  default: ({ title, ...etc } = {}) => continuous_scale({ range: [1, 6], title, ...etc })
2947
2956
  },
2948
2957
  linetype: {
2949
2958
  identity: scale_identity_string,
2950
2959
  discrete: linetype_scale_discrete,
2951
- default: linetype_scale_discrete
2960
+ default: linetype_scale_discrete,
2961
+ custom: custom_scale
2952
2962
  },
2953
2963
  shape: {
2954
2964
  identity: scale_identity_string,
2955
2965
  discrete: shape_scale_discrete,
2956
- default: shape_scale_discrete
2957
- },
2958
- custom(func, { title, ...etc } = {}) {
2959
- return Object.assign(function(arr) {
2960
- return arr.map(func);
2961
- }, { title }, etc);
2966
+ default: shape_scale_discrete,
2967
+ custom: custom_scale
2962
2968
  }
2963
2969
  };
2964
2970
  export {
package/dist/style.css CHANGED
@@ -3,7 +3,6 @@
3
3
  }
4
4
 
5
5
  .vvplot-panel-container {
6
- position: absolute;
7
6
  pointer-events: none;
8
7
  }
9
8
 
@@ -16,7 +15,3 @@
16
15
  display: flex;
17
16
  flex-direction: column;
18
17
  }
19
-
20
- .vvplot-cursor-grab {
21
- cursor: grab;
22
- }
package/dist/utils.js CHANGED
@@ -111,11 +111,11 @@ const numutils = {
111
111
  return arr[lo] * (hi - idx) + arr[hi] * (idx - lo);
112
112
  },
113
113
  extent(arr, { na_rm = true, infinity_rm = true } = {}) {
114
- if (arr.length == 0) return [];
115
114
  if (na_rm) arr = arr.filter(isContinuous);
116
115
  if (infinity_rm) arr = arr.filter((x) => isFinite(x));
116
+ if (arr.length == 0) return new Array(2);
117
117
  let min = Array.from(arr).reduce((a, b) => a < b ? a : b, Infinity), max = Array.from(arr).reduce((a, b) => a > b ? a : b, -Infinity);
118
- return { 0: min, 1: max, length: 2, min, max };
118
+ return Object.assign([min, max], { min, max });
119
119
  }
120
120
  };
121
121
  const vecutils = {
@@ -148,9 +148,13 @@ function str_c(...args) {
148
148
  if (args.some((x) => x === null)) return null;
149
149
  return args.join("");
150
150
  }
151
- function unique(arr) {
152
- if (arr == null) return [];
153
- return Array.from(new Set(arr));
151
+ function unique(arr, mapper = null) {
152
+ let map = /* @__PURE__ */ new Map();
153
+ for (let i in arr) {
154
+ let key = mapper ? mapper(arr[i]) : arr[i];
155
+ if (!map.has(key)) map.set(key, arr[i]);
156
+ }
157
+ return Array.from(map.values());
154
158
  }
155
159
  function compare(a, b, { numeric = false } = {}) {
156
160
  if (typeof a != "number" || typeof b != "number")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vvplot",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist"
@@ -15,8 +15,6 @@
15
15
  "imports": {
16
16
  "#base/*": "./src/*"
17
17
  },
18
- "homepage": "https://fan-ix.github.io/vvplot/",
19
- "repository": "https://github.com/Fan-iX/vvplot/",
20
18
  "exports": {
21
19
  ".": "./dist/index.js",
22
20
  "./components": "./dist/components.js",
@@ -26,6 +24,11 @@
26
24
  "./label": "./dist/label.js",
27
25
  "./style.css": "./dist/style.css"
28
26
  },
27
+ "homepage": "https://fan-ix.github.io/vvplot/",
28
+ "repository": "https://github.com/Fan-iX/vvplot/",
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
29
32
  "dependencies": {
30
33
  "@vueuse/core": "^13.7.0",
31
34
  "d3": "^7.9.0",