vvplot 0.1.0 → 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";
@@ -182,18 +182,8 @@ function useElementSize(target, initialSize = { width: 0, height: 0 }, options =
182
182
  stop
183
183
  };
184
184
  }
185
- /**
186
- * @vue/shared v3.5.20
187
- * (c) 2018-present Yuxi (Evan) You and Vue contributors
188
- * @license MIT
189
- **/
190
185
  const NO = () => false;
191
186
  const extend = Object.assign;
192
- /**
193
- * @vue/compiler-core v3.5.20
194
- * (c) 2018-present Yuxi (Evan) You and Vue contributors
195
- * @license MIT
196
- **/
197
187
  const TELEPORT = Symbol(``);
198
188
  const SUSPENSE = Symbol(``);
199
189
  const KEEP_ALIVE = Symbol(``);
@@ -1055,6 +1045,14 @@ function isVPre(p) {
1055
1045
  return p.type === 7 && p.name === "pre";
1056
1046
  }
1057
1047
  const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
1048
+ function isAllWhitespace(str) {
1049
+ for (let i = 0; i < str.length; i++) {
1050
+ if (!isWhitespace(str.charCodeAt(i))) {
1051
+ return false;
1052
+ }
1053
+ }
1054
+ return true;
1055
+ }
1058
1056
  const defaultParserOptions = {
1059
1057
  parseMode: "base",
1060
1058
  ns: 0,
@@ -1609,14 +1607,6 @@ function condenseWhitespace(nodes) {
1609
1607
  }
1610
1608
  return removedWhitespace ? nodes.filter(Boolean) : nodes;
1611
1609
  }
1612
- function isAllWhitespace(str) {
1613
- for (let i = 0; i < str.length; i++) {
1614
- if (!isWhitespace(str.charCodeAt(i))) {
1615
- return false;
1616
- }
1617
- }
1618
- return true;
1619
- }
1620
1610
  function hasNewlineChar(str) {
1621
1611
  for (let i = 0; i < str.length; i++) {
1622
1612
  const c = str.charCodeAt(i);
@@ -2855,46 +2845,47 @@ class GPlot {
2855
2845
  let result = {};
2856
2846
  this._range = range;
2857
2847
  if (this.levels.x) {
2858
- 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);
2859
2849
  result.x = new DiscreteCoordScale(this.levels.x, { min, max });
2860
2850
  } else {
2861
2851
  let $min = range?.xmin ?? this.extents.x?.min ?? 0, $max = range?.xmax ?? this.extents.x?.max ?? 0;
2862
- 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);
2863
2853
  let dmin = minRange?.x ?? 1;
2864
2854
  if (max - min < dmin) {
2865
2855
  if (range?.xmax == null && range?.xmin != null) {
2866
- max = min + dmin;
2856
+ max = plus(min, +dmin);
2867
2857
  } else if (range?.xmax != null && range?.xmin == null) {
2868
- min = max - dmin;
2858
+ min = plus(max, -dmin);
2869
2859
  } else {
2870
- max = (max + min) / 2 + dmin / 2;
2871
- min = max - dmin;
2860
+ let interval2 = max - min;
2861
+ max = plus(max, -interval2 / 2 + dmin / 2);
2862
+ min = plus(max, -dmin);
2872
2863
  }
2873
2864
  }
2874
- if ($min instanceof Date || $max instanceof Date) {
2865
+ if (min instanceof Date || max instanceof Date) {
2875
2866
  result.x = new DatetimeCoordScale({ min, max });
2876
2867
  } else {
2877
2868
  result.x = new ContinuousCoordScale({ min, max });
2878
2869
  }
2879
2870
  }
2880
2871
  if (this.levels.y) {
2881
- 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);
2882
2873
  result.y = new DiscreteCoordScale(this.levels.y, { min, max });
2883
2874
  } else {
2884
2875
  let $min = range?.ymin ?? this.extents.y?.min ?? 0, $max = range?.ymax ?? this.extents.y?.max ?? 0;
2885
- 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);
2886
2877
  let dmin = minRange?.y ?? 1;
2887
2878
  if (max - min < dmin) {
2888
2879
  if (range?.ymax == null && range?.ymin != null) {
2889
- max = min + dmin;
2880
+ max = plus(min, +dmin);
2890
2881
  } else if (range?.ymax != null && range?.ymin == null) {
2891
- min = max - dmin;
2882
+ min = plus(max, -dmin);
2892
2883
  } else {
2893
- max = (max + min) / 2 + dmin / 2;
2894
- min = max - dmin;
2884
+ max = plus(max, -interval / 2 + dmin / 2);
2885
+ min = plus(max, -dmin);
2895
2886
  }
2896
2887
  }
2897
- if ($min instanceof Date || $max instanceof Date) {
2888
+ if (min instanceof Date || max instanceof Date) {
2898
2889
  result.y = new DatetimeCoordScale({ min, max });
2899
2890
  } else {
2900
2891
  result.y = new ContinuousCoordScale({ min, max });
@@ -2944,23 +2935,13 @@ class DiscreteCoordScale extends Function {
2944
2935
  constructor(level, { min, max } = {}) {
2945
2936
  const scale = min == max ? (x2) => 0 : (x2) => (+x2 - min) / (max - min);
2946
2937
  scale.range = { min, max };
2947
- scale.limits = { min, max };
2948
2938
  scale.level = level;
2949
- scale.invert = (w) => w * (max - min) + min;
2950
2939
  Object.setPrototypeOf(scale, DiscreteCoordScale.prototype);
2951
2940
  return scale;
2952
2941
  }
2953
- expand({ min: mmin = 0, max: mmax = 0 } = {}) {
2954
- let $min = 0, $max = this.level.length, $interval = $max;
2955
- let min = $min - mmin * $interval, max = $max + mmax * $interval;
2956
- const scale = min == max ? (x2) => 0 : (x2) => (+x2 - min) / (max - min);
2957
- scale.invert = (w) => w * (max - min) + min;
2958
- scale.range = this.range;
2959
- scale.level = this.level;
2960
- scale.title = this.title;
2961
- scale.limits = { min, max };
2962
- Object.setPrototypeOf(scale, DiscreteCoordScale.prototype);
2963
- return scale;
2942
+ invert(w) {
2943
+ let { min, max } = this.range;
2944
+ return w * (max - min) + min;
2964
2945
  }
2965
2946
  get breaks() {
2966
2947
  return Array.from(this.level);
@@ -2971,35 +2952,19 @@ class DiscreteCoordScale extends Function {
2971
2952
  }
2972
2953
  class ContinuousCoordScale extends Function {
2973
2954
  constructor(domain) {
2974
- let min = +domain.min, max = +domain.max;
2975
- 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);
2976
2957
  scale.range = { min, max };
2977
- scale.limits = { min, max };
2978
- Object.setPrototypeOf(scale, ContinuousCoordScale.prototype);
2979
- return scale;
2980
- }
2981
- expand({ min: mmin = 0, max: mmax = 0 } = {}) {
2982
- let { min: $min, max: $max } = this.limits;
2983
- let $interval = $max - $min;
2984
- let min = $min - mmin * $interval, max = $max + mmax * $interval;
2985
- const scale = min == max ? (x2) => 0.5 : (x2) => (+x2 - min) / (max - min);
2986
- scale.range = this.range;
2987
- scale.level = this.level;
2988
- scale.title = this.title;
2989
- scale.limits = { min, max };
2990
2958
  Object.setPrototypeOf(scale, ContinuousCoordScale.prototype);
2991
2959
  return scale;
2992
2960
  }
2993
2961
  invert(w) {
2994
- let { min, max } = this.limits;
2995
- return w * (max - min) + min;
2962
+ let { min, max } = this.range;
2963
+ return plus(min, w * (max - min));
2996
2964
  }
2997
2965
  get breaks() {
2998
2966
  return vvbreak.number();
2999
2967
  }
3000
- get minorBreaks() {
3001
- return vvbreak.number({ minor: true });
3002
- }
3003
2968
  }
3004
2969
  class DatetimeCoordScale extends ContinuousCoordScale {
3005
2970
  constructor(domain) {
@@ -3007,15 +2972,6 @@ class DatetimeCoordScale extends ContinuousCoordScale {
3007
2972
  Object.setPrototypeOf(scale, DatetimeCoordScale.prototype);
3008
2973
  return scale;
3009
2974
  }
3010
- expand({ min: mmin = 0, max: mmax = 0 } = {}) {
3011
- let scale = super.expand({ min: mmin, max: mmax });
3012
- Object.setPrototypeOf(scale, DatetimeCoordScale.prototype);
3013
- return scale;
3014
- }
3015
- invert(w) {
3016
- let { min, max } = this.limits;
3017
- return new Date(w * (max - min) + min);
3018
- }
3019
2975
  get breaks() {
3020
2976
  return vvbreak.datetime();
3021
2977
  }
@@ -3024,25 +2980,28 @@ class DatetimeCoordScale extends ContinuousCoordScale {
3024
2980
  }
3025
2981
  }
3026
2982
  class GAxis {
3027
- constructor(scale, { extend: extend2, breaks, labels, minorBreaks, titles } = {}) {
2983
+ constructor(scale, { breaks, labels, minorBreaks, titles } = {}) {
3028
2984
  this.scale = scale;
3029
- this.limits = scale?.limits;
3030
- this.extend = extend2 ?? 0;
2985
+ this.range = scale?.range;
3031
2986
  this.breaks = breaks ?? scale.breaks;
3032
2987
  this.labels = labels ?? vvlabel.auto();
3033
2988
  this.titles = titles ?? vvlabel.asis();
3034
- this.minorBreaks = minorBreaks ?? scale.minorBreaks;
3035
- }
3036
- getBindings({ limits = this.limits, extend: extend2 = this.extend } = {}) {
3037
- let breaks = this.breaks, minorBreaks = this.minorBreaks;
3038
- let { min, max } = limits, interval = max - min || 0;
3039
- min = min == null ? min : min - extend2 * interval;
3040
- max = max == null ? max : max + extend2 * interval;
3041
- if (typeof breaks == "function") breaks = breaks(limits);
3042
- breaks = Array.isArray(breaks) ? breaks.sort((a, b) => a - b) : [];
3043
- if (typeof minorBreaks == "function") minorBreaks = minorBreaks(limits);
3044
- minorBreaks = Array.isArray(minorBreaks) ? minorBreaks.sort((a, b) => a - b) : [];
3045
- 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) : [];
3046
3005
  if (typeof labels === "function") labels = breaks.map(labels);
3047
3006
  if (!Array.isArray(labels)) {
3048
3007
  labels = [];
@@ -3052,11 +3011,11 @@ class GAxis {
3052
3011
  if (typeof titles === "function") titles = breaks.map(titles);
3053
3012
  if (!Array.isArray(titles)) {
3054
3013
  titles = [];
3055
- } else if (titles.length != titles.length) {
3014
+ } else if (titles.length != breaks.length) {
3056
3015
  throw new Error("Length of titles must be the same as breaks");
3057
3016
  }
3058
3017
  return {
3059
- majorBreaks: breaks,
3018
+ majorBreaks,
3060
3019
  minorBreaks,
3061
3020
  ticks: breaks.map((position, i) => ({ position, label: labels[i], title: titles[i] }))
3062
3021
  };
@@ -3165,7 +3124,7 @@ const _hoisted_3$4 = {
3165
3124
  class: "vvplot-interactive",
3166
3125
  fill: "transparent"
3167
3126
  };
3168
- const _hoisted_4$3 = ["width"];
3127
+ const _hoisted_4$3 = ["width", "cursor"];
3169
3128
  const _hoisted_5$2 = {
3170
3129
  key: 0,
3171
3130
  class: "vvplot-interactive",
@@ -3532,7 +3491,7 @@ const _sfc_main$S = {
3532
3491
  height: 10,
3533
3492
  y: -5
3534
3493
  }, toHandlers(axisVOn, true), {
3535
- class: { "vvplot-cursor-grab": __props.action.some?.((a) => a.action == "move") }
3494
+ cursor: __props.action.some?.((a) => a.action == "move") ? "grab" : null
3536
3495
  }), null, 16, _hoisted_4$3)
3537
3496
  ]),
3538
3497
  __props.action.some?.((a) => a.action == "rescale") ? (openBlock(), createElementBlock("g", _hoisted_5$2, [
@@ -3563,7 +3522,7 @@ const _hoisted_3$3 = {
3563
3522
  class: "vvplot-interactive",
3564
3523
  fill: "transparent"
3565
3524
  };
3566
- const _hoisted_4$2 = ["height"];
3525
+ const _hoisted_4$2 = ["height", "cursor"];
3567
3526
  const _hoisted_5$1 = {
3568
3527
  key: 0,
3569
3528
  class: "vvplot-interactive",
@@ -3930,7 +3889,7 @@ const _sfc_main$R = {
3930
3889
  height: height.value,
3931
3890
  x: -5
3932
3891
  }, toHandlers(axisVOn, true), {
3933
- class: { "vvplot-cursor-grab": __props.action.some?.((a) => a.action == "move") }
3892
+ cursor: __props.action.some?.((a) => a.action == "move") ? "grab" : null
3934
3893
  }), null, 16, _hoisted_4$2)
3935
3894
  ]),
3936
3895
  __props.action.some?.((a) => a.action == "rescale") ? (openBlock(), createElementBlock("g", _hoisted_5$1, [
@@ -3995,8 +3954,8 @@ const _sfc_main$P = {
3995
3954
  const majorLines = computed(() => {
3996
3955
  let result = [];
3997
3956
  for (let line2 of __props.majorBreaks) {
3998
- if (line2?.position == null) line2 = { position: +line2 };
3999
3957
  let pos = __props.coord2pos({ v: line2.position }).v;
3958
+ if (isNaN(pos)) continue;
4000
3959
  let tsl = pos * (__props.activeTransform.scaleV - 1) + __props.activeTransform.translateV;
4001
3960
  let position = pos + __props.layout.t;
4002
3961
  if (position + tsl < 0 || position + tsl > height.value) continue;
@@ -4017,8 +3976,9 @@ const _sfc_main$P = {
4017
3976
  const minorLines = computed(() => {
4018
3977
  let result = [];
4019
3978
  for (let line2 of __props.minorBreaks) {
4020
- if (line2?.position == null) line2 = { position: +line2 };
3979
+ if (__props.majorBreaks.some((ml) => ml.position == line2.position)) continue;
4021
3980
  let pos = __props.coord2pos({ v: line2.position }).v;
3981
+ if (isNaN(pos)) continue;
4022
3982
  let tsl = pos * (__props.activeTransform.scaleV - 1) + __props.activeTransform.translateV;
4023
3983
  let position = pos + __props.layout.t;
4024
3984
  if (position + tsl < 0 || position + tsl > height.value) continue;
@@ -4034,16 +3994,12 @@ const _sfc_main$P = {
4034
3994
  style: { transition: __props.transition }
4035
3995
  });
4036
3996
  }
4037
- return result.filter((l) => l.stroke !== null && majorLines.value.every((ml) => ml.y1 !== l.y1));
3997
+ return result.filter((l) => l.stroke !== null);
4038
3998
  });
3999
+ const lines = computed(() => minorLines.value.concat(majorLines.value).sort((a, b) => a.y1 - b.y1));
4039
4000
  return (_ctx, _cache) => {
4040
4001
  return openBlock(), createElementBlock("g", null, [
4041
- (openBlock(true), createElementBlock(Fragment, null, renderList(minorLines.value, (line2) => {
4042
- return openBlock(), createElementBlock("line", mergeProps({ ref_for: true }, line2, {
4043
- style: { transition: __props.transition }
4044
- }), null, 16);
4045
- }), 256)),
4046
- (openBlock(true), createElementBlock(Fragment, null, renderList(majorLines.value, (line2) => {
4002
+ (openBlock(true), createElementBlock(Fragment, null, renderList(lines.value, (line2) => {
4047
4003
  return openBlock(), createElementBlock("line", mergeProps({ ref_for: true }, line2, {
4048
4004
  style: { transition: __props.transition }
4049
4005
  }), null, 16);
@@ -4071,8 +4027,8 @@ const _sfc_main$O = {
4071
4027
  const majorLines = computed(() => {
4072
4028
  let result = [];
4073
4029
  for (let line2 of __props.majorBreaks) {
4074
- if (line2?.position == null) line2 = { position: +line2 };
4075
4030
  let pos = __props.coord2pos({ h: line2.position }).h;
4031
+ if (isNaN(pos)) continue;
4076
4032
  let tsl = pos * (__props.activeTransform.scaleH - 1) + __props.activeTransform.translateH;
4077
4033
  let position = pos + __props.layout.l;
4078
4034
  if (position + tsl < 0 || position + tsl > width.value) continue;
@@ -4093,8 +4049,9 @@ const _sfc_main$O = {
4093
4049
  const minorLines = computed(() => {
4094
4050
  let result = [];
4095
4051
  for (let line2 of __props.minorBreaks) {
4096
- if (line2?.position == null) line2 = { position: +line2 };
4052
+ if (__props.majorBreaks.some((ml) => ml.position == line2.position)) continue;
4097
4053
  let pos = __props.coord2pos({ h: line2.position }).h;
4054
+ if (isNaN(pos)) continue;
4098
4055
  let tsl = pos * (__props.activeTransform.scaleH - 1) + __props.activeTransform.translateH;
4099
4056
  let position = pos + __props.layout.l;
4100
4057
  if (position + tsl < 0 || position + tsl > width.value) continue;
@@ -4110,15 +4067,15 @@ const _sfc_main$O = {
4110
4067
  style: { transition: __props.transition }
4111
4068
  });
4112
4069
  }
4113
- return result.filter((l) => l.stroke !== null && majorLines.value.every((ml) => ml.x1 !== l.x1));
4070
+ return result.filter((l) => l.stroke !== null);
4114
4071
  });
4072
+ const lines = computed(() => minorLines.value.concat(majorLines.value).sort((a, b) => a.x1 - b.x1));
4115
4073
  return (_ctx, _cache) => {
4116
4074
  return openBlock(), createElementBlock("g", null, [
4117
- (openBlock(true), createElementBlock(Fragment, null, renderList(minorLines.value, (line2) => {
4118
- return openBlock(), createElementBlock("line", mergeProps({ ref_for: true }, line2), null, 16);
4119
- }), 256)),
4120
- (openBlock(true), createElementBlock(Fragment, null, renderList(majorLines.value, (line2) => {
4121
- 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);
4122
4079
  }), 256))
4123
4080
  ]);
4124
4081
  };
@@ -5777,7 +5734,7 @@ const _sfc_main$s = {
5777
5734
  stroke: __props.theme?.line_color ?? "transparent",
5778
5735
  "stroke-width": __props.theme?.line_width,
5779
5736
  "stroke-opacity": __props.theme?.opacity,
5780
- style: config.move ? "cursor:move;" : "pointer:events-none;"
5737
+ style: config.move ? "cursor:move;" : "pointer-events:none;"
5781
5738
  };
5782
5739
  if (config.resize) {
5783
5740
  if (pos.hmin != null)
@@ -6334,15 +6291,15 @@ const _sfc_main$n = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
6334
6291
  function _coord2pos({ value, min, max } = {}, { oob = oob_squish_infinite } = {}, scale, rev, length, boundary) {
6335
6292
  let result = {};
6336
6293
  if (value != null) {
6337
- 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;
6338
6295
  }
6339
6296
  if (min == null && max == null) return result;
6340
6297
  if (rev) {
6341
- if (max != null) result.min = oob(length * (1 - scale(max)), boundary);
6342
- 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;
6343
6300
  } else {
6344
- if (min != null) result.min = oob(length * scale(min), boundary);
6345
- 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;
6346
6303
  }
6347
6304
  return result;
6348
6305
  }
@@ -6410,10 +6367,10 @@ const _sfc_main$n = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
6410
6367
  }
6411
6368
  function getPadding({ min: $min, max: $max } = {}, { min: mmin = 0, max: mmax = 0 } = {}) {
6412
6369
  let $interval = $max - $min;
6413
- 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;
6414
6371
  return {
6415
- min: interval == 0 ? 0 : ($min - min) / interval,
6416
- max: interval == 0 ? 0 : (max - $max) / interval
6372
+ min: interval2 == 0 ? 0 : ($min - min) / interval2,
6373
+ max: interval2 == 0 ? 0 : (max - $max) / interval2
6417
6374
  };
6418
6375
  }
6419
6376
  function getCoord(event) {
@@ -6686,14 +6643,14 @@ const _sfc_main$n = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
6686
6643
  function changerange(coord) {
6687
6644
  let { xmin, xmax, ymin, ymax } = coord;
6688
6645
  let { xmin: $xmin, xmax: $xmax, ymin: $ymin, ymax: $ymax } = range;
6689
- xmin = xmin != null ? plus(xmin, __props.expandAdd.x.min) : $xmin;
6646
+ xmin = xmin != null ? plus(xmin, +__props.expandAdd.x.min) : $xmin;
6690
6647
  xmax = xmax != null ? plus(xmax, -__props.expandAdd.x.max) : $xmax;
6691
- ymin = ymin != null ? plus(ymin, __props.expandAdd.y.min) : $ymin;
6648
+ ymin = ymin != null ? plus(ymin, +__props.expandAdd.y.min) : $ymin;
6692
6649
  ymax = ymax != null ? plus(ymax, -__props.expandAdd.y.max) : $ymax;
6693
6650
  if (xmin == $xmin && xmax == $xmax && ymin == $ymin && ymax == $ymax) return;
6694
6651
  Object.assign(range, { xmin, xmax, ymin, ymax });
6695
6652
  }
6696
- const axisLimits = reactiveComputed(() => {
6653
+ const axisRange = reactiveComputed(() => {
6697
6654
  let xmin = rangePreview?.xmin ?? range?.xmin, xmax = rangePreview?.xmax ?? range?.xmax, ymin = rangePreview?.ymin ?? range?.ymin, ymax = rangePreview?.ymax ?? range?.ymax;
6698
6655
  return {
6699
6656
  x: xmin || xmax ? { min: xmin, max: xmax } : void 0,
@@ -6702,24 +6659,26 @@ const _sfc_main$n = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
6702
6659
  });
6703
6660
  const gaxes = computed(() => {
6704
6661
  let coordScales = {
6705
- x: vplot.value.coordScales.x.expand(__props.expandMult?.x),
6706
- y: vplot.value.coordScales.y.expand(__props.expandMult?.y)
6662
+ x: vplot.value.coordScales.x,
6663
+ y: vplot.value.coordScales.y
6707
6664
  };
6708
6665
  return props.axes.filter((a) => a.coord in coordScales).filter((a) => ["h", "v"].includes(a.orientation)).map(({
6709
6666
  coord,
6710
6667
  breaks,
6711
- extend: extend2,
6712
6668
  labels,
6713
6669
  minorBreaks,
6714
6670
  ...etc
6715
6671
  }) => ({
6716
6672
  coord,
6717
- axis: new GAxis(coordScales[coord], { breaks, extend: extend2, labels, minorBreaks }),
6673
+ axis: new GAxis(coordScales[coord], { breaks, labels, minorBreaks }),
6718
6674
  etc
6719
6675
  }));
6720
6676
  });
6721
6677
  const vaxes = computed(() => gaxes.value.map(({ coord, axis, etc }) => {
6722
- 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
+ });
6723
6682
  let { showGrid, orientation, ...bind } = etc;
6724
6683
  return {
6725
6684
  majorBreaks,
@@ -6735,12 +6694,12 @@ const _sfc_main$n = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
6735
6694
  let hAxes = vaxes.value.filter((a) => a.showGrid && a.orientation == "v"), vAxes = vaxes.value.filter((a) => a.showGrid && a.orientation == "h");
6736
6695
  return {
6737
6696
  h: {
6738
- majorBreaks: unique(hAxes.flatMap((a) => a.majorBreaks)),
6739
- 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)
6740
6699
  },
6741
6700
  v: {
6742
- majorBreaks: unique(vAxes.flatMap((a) => a.majorBreaks)),
6743
- 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)
6744
6703
  }
6745
6704
  };
6746
6705
  });
@@ -7046,7 +7005,10 @@ const axis_components = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.def
7046
7005
  VVAxisX: _sfc_main$3,
7047
7006
  VVAxisY: _sfc_main$2
7048
7007
  }, Symbol.toStringTag, { value: "Module" }));
7049
- const _hoisted_1 = { class: "vvplot-panel" };
7008
+ const _hoisted_1 = {
7009
+ key: 0,
7010
+ class: "vvplot-panel"
7011
+ };
7050
7012
  const _sfc_main$1 = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
7051
7013
  __name: "Plot",
7052
7014
  props: /* @__PURE__ */ mergeModels({
@@ -7553,6 +7515,7 @@ const _sfc_main$1 = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
7553
7515
  });
7554
7516
  const panelStyle = computed(() => {
7555
7517
  return {
7518
+ position: "absolute",
7556
7519
  left: str_c(plotRef.value?.panel?.left, "px"),
7557
7520
  top: str_c(plotRef.value?.panel?.top, "px"),
7558
7521
  width: str_c(plotRef.value?.panel?.width, "px"),
@@ -7609,17 +7572,16 @@ const _sfc_main$1 = /* @__PURE__ */ Object.assign({ inheritAttrs: false }, {
7609
7572
  legendTeleport: __props.legendTeleport,
7610
7573
  onSelect: _cache[3] || (_cache[3] = (d, e) => emit("select", d, e))
7611
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"]),
7612
- vnodes.dom.panel?.length ? (openBlock(), createElementBlock("div", {
7613
- key: 0,
7575
+ createElementVNode("div", {
7614
7576
  class: "vvplot-panel-container",
7615
7577
  style: normalizeStyle(panelStyle.value)
7616
7578
  }, [
7617
- createElementVNode("div", _hoisted_1, [
7579
+ vnodes.dom.panel?.length ? (openBlock(), createElementBlock("div", _hoisted_1, [
7618
7580
  (openBlock(true), createElementBlock(Fragment, null, renderList(vnodes.dom.panel, (c) => {
7619
7581
  return openBlock(), createBlock(resolveDynamicComponent(c));
7620
7582
  }), 256))
7621
- ])
7622
- ], 4)) : createCommentVNode("", true),
7583
+ ])) : createCommentVNode("", true)
7584
+ ], 4),
7623
7585
  (openBlock(true), createElementBlock(Fragment, null, renderList(vdom.value, (c) => {
7624
7586
  return openBlock(), createBlock(resolveDynamicComponent(c));
7625
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.0",
3
+ "version": "0.1.2",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist"
@@ -24,6 +24,11 @@
24
24
  "./label": "./dist/label.js",
25
25
  "./style.css": "./dist/style.css"
26
26
  },
27
+ "homepage": "https://fan-ix.github.io/vvplot/",
28
+ "repository": "https://github.com/Fan-iX/vvplot/",
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
27
32
  "dependencies": {
28
33
  "@vueuse/core": "^13.7.0",
29
34
  "d3": "^7.9.0",