Skip to content

Commit 672f18e

Browse files
committed
change scale.custom to scale.*.custom
1 parent d03f1ab commit 672f18e

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

src/js/scale.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export const oob = {
1717
},
1818
}
1919

20+
function custom_scale(func, { title, ...etc } = {}) {
21+
return Object.assign(function (arr) { return arr.map(func) }, { title }, etc)
22+
}
23+
2024
function manual_scale({
2125
values = {},
2226
na_value = null,
@@ -214,6 +218,7 @@ const palette_scales = {
214218

215219
dynamic: palette_scale_dynamic,
216220
auto: palette_scale_auto,
221+
custom: custom_scale,
217222

218223
default: palette_scale_auto,
219224
}
@@ -258,30 +263,32 @@ export default {
258263
fill: palette_scales,
259264
alpha: {
260265
continuous: continuous_scale,
266+
custom: custom_scale,
261267
default: ({ title, ...etc } = {}) => continuous_scale({ range: [0.1, 1], title, ...etc }),
262268
},
263269
size: {
264270
identity: scale_identity_number,
265271
continuous: continuous_scale,
272+
custom: custom_scale,
266273
default: ({ title, ...etc } = {}) => continuous_scale({ range: [1, 6], title, ...etc }),
267274
},
268275
linewidth: {
269276
identity: scale_identity_number,
270277
continuous: continuous_scale,
271278
manual: manual_scale,
279+
custom: custom_scale,
272280
default: ({ title, ...etc } = {}) => continuous_scale({ range: [1, 6], title, ...etc }),
273281
},
274282
linetype: {
275283
identity: scale_identity_string,
276284
discrete: linetype_scale_discrete,
277285
default: linetype_scale_discrete,
286+
custom: custom_scale,
278287
},
279288
shape: {
280289
identity: scale_identity_string,
281290
discrete: shape_scale_discrete,
282291
default: shape_scale_discrete,
283-
},
284-
custom(func, { title, ...etc } = {}) {
285-
return Object.assign(function (arr) { return arr.map(func) }, { title }, etc)
292+
custom: custom_scale,
286293
},
287294
}

web-docs/docs/gallery.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const vBind = {
6565
<hr>
6666
<pre><code class="html">{{templates[4] = `<VVPlot :data="letters" legend-teleport="#legend-4">
6767
<VVAxisY :min="0" :expand-mult="0" />
68-
<VVGeomBar :x="d => d" :fill="d => d" :scales="{ fill: vvscale.custom((v) => ['blue', 'gold'][v % 2]) }" />
68+
<VVGeomBar :x="d => d" :fill="d => d" :scales="{ fill: vvscale.fill.custom((v) => ['blue', 'gold'][v % 2]) }" />
6969
</VVPlot>`}}</code></pre>
7070
<div class="flex flex-row">
7171
<component :is="{ template: templates[4], props: Object.keys(vBind) }" v-bind="vBind" />

web-docs/docs/scale.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,11 @@ const size_limits_max = ref(600)
358358
that is not covered by the built-in scale functions.
359359
</p>
360360
<p>
361-
The <code>vvscale.custom</code> wrapper function can be used to create custom scale functions easily.
361+
The <code>vvscale.*.custom</code> wrapper function can be used to create custom scale functions easily.
362362
</p>
363363
<div class="grid grid-cols-[3fr_2fr] gap-4">
364364
<pre><code class="html">{{templates[9] = `<VVPlot :data="letters" :scales="{
365-
fill: vvscale.custom(v => ['blue', 'gold'][v % 2]),
365+
fill: vvscale.fill.custom(v => ['blue', 'gold'][v % 2]),
366366
// same as \`arr => arr.map(v => ['blue','gold'][v % 2])\`
367367
// the function will be applied to an array of categorical values,
368368
// \`v % 2\` works because \`v.valueOf()\` will return its ordinal number

web-docs/playground.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const templates = {
7373
<VVGeomSegment :x="d => d.x1" :y="d => d.y1" :xend="d => d.x2" :yend="d => d.y2"
7474
:data="[{ x1: 2.62, x2: 3.57, y1: 21, y2: 15 }]" color="red" linetype="dashed" />`,
7575
letters: `<VVAxisY :min="0" :expand-mult="0" />
76-
<VVGeomBar :x="d => d" :fill="d => d" :scales="{ fill: vvscale.custom((v) => ['blue', 'gold'][v % 2]) }" />
76+
<VVGeomBar :x="d => d" :fill="d => d" :scales="{ fill: vvscale.fill.custom((v) => ['blue', 'gold'][v % 2]) }" />
7777
<VVAction zoom move />`,
7878
pigments: `<VVGeomLine :x="d => d.wave_length" :y="d => d.molar_extinction" :color="d => d.pigment" :group="d => d.pigment"
7979
:scales="{ color: vvscale.color.manual({ values: { beta_carotene: 'orangered', chlorophyll_a: 'limegreen', chlorophyll_b: 'royalblue' } }) }" />

0 commit comments

Comments
 (0)