Skip to content

Channel label option #1733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Fil opened this issue Jul 4, 2023 · 1 comment · Fixed by #1823
Closed

Channel label option #1733

Fil opened this issue Jul 4, 2023 · 1 comment · Fixed by #1823
Labels
enhancement New feature or request

Comments

@Fil
Copy link
Contributor

Fil commented Jul 4, 2023

In this discussion we realize that to specify a channel label (for the interactive tips #1612), we need either a {transform, label} value, or an arcane combination of an accessor function with a label property:

channels: {year: Object.assign((d) => d.year, {label: "My custom year label"})} 

This is because labelof only reads the value.

It would be nice to be allowed to write instead:

channels: {year: {value: "year", label: "My custom year label"}}

Note that this is not strictly necessary for the given use case, since we can also name the channel as we want (although not with a string which has precedence over the channel’s key name):

channels: {["My custom year label"]: d => d.year}

(maybe related to #1364)

@Fil Fil added the enhancement New feature or request label Jul 4, 2023
@Fil
Copy link
Contributor Author

Fil commented Jul 4, 2023

potential patch (not yet tested):

diff --git a/src/channel.js b/src/channel.js
index 38edcc3e..019efc26 100644
--- a/src/channel.js
+++ b/src/channel.js
@@ -5,13 +5,13 @@ import {registry} from "./scales/index.js";
 import {isSymbol, maybeSymbol} from "./symbol.js";
 import {maybeReduce} from "./transforms/group.js";

-export function createChannel(data, {scale, type, value, filter, hint}, name) {
+export function createChannel(data, {scale, type, value, filter, hint, label}, name) {
   if (hint === undefined && typeof value?.transform === "function") hint = value.hint;
   return inferChannelScale(name, {
     scale,
     type,
     value: valueof(data, value),
-    label: labelof(value),
+    label: label === undefined ? labelof(value) : label,
     filter,
     hint
   });

Fil added a commit that referenced this issue Jul 5, 2023
@Fil Fil mentioned this issue Jul 5, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant