Coder Social home page Coder Social logo

Comments (3)

pvictor avatar pvictor commented on June 30, 2024 1

Hi!
So there is no option to place the labels at different position, but you can use a JavaScript callback (warning you cannot select an axis by names, e.g. "Speed", only by position, see the arrow in JS function) :

library("billboarder")
library("dplyr")
data("avengers")

avengersSub <- avengers %>%
  filter(group == 'Thor') %>%
  filter(axis %in% c('Durability','Speed','Energy'))

bb <- billboarder() %>%
  bb_radarchart(
    data = avengersSub,
    mapping = bbaes(x = axis, y = value, group = group)
  ) %>%
  bb_radar(level = list(show = FALSE)) %>%
  bb_data(
    labels = TRUE # list(position = list(x = 10))
  )
bb$x$bb_opts$onrendered <- htmlwidgets::JS(
  "function() {

    // Durability
    d3.selectAll('.bb-texts .bb-text-1').each(function() { //  <<<<<-------- Durability is 'bb-text-1' (only for this chart)
	      var text = d3.select(this);
  
        text.attr('x', (+text.attr('x') - 10)).attr('y', (+text.attr('y') + 20))
    });

    // Energy
    d3.selectAll('.bb-texts .bb-text-2').each(function() { // <<<<<-------- Energy is 'bb-text-2' (only for this chart)
  	      var text = d3.select(this);
          text.attr('x', (+text.attr('x') + 10)).attr('y', (+text.attr('y') + 20))
    });
   }"
)
bb

Victor

from billboarder.

andrefsferreira avatar andrefsferreira commented on June 30, 2024

Victor,

Thank you for your help. The provided code serves the purpose perfectly.

Regards,
André

from billboarder.

pvictor avatar pvictor commented on June 30, 2024

I added a function to use callbacks, so with dev version you can add the onrendered func in the pipe workflow :

billboarder() %>%
  bb_radarchart(
    data = avengersSub,
    mapping = bbaes(x = axis, y = value, group = group)
  ) %>%
  bb_radar(level = list(show = FALSE)) %>%
  bb_data(
    labels = TRUE # list(position = list(x = 10))
  ) %>% 
  bb_callbacks(
    onrendered = "function() {
  
    // Durability
    d3.selectAll('.bb-texts .bb-text-1').each(function() { //  <<<<<-------- Durability is 'bb-text-1' (only for this chart)
    var text = d3.select(this);
    
    text.attr('x', (+text.attr('x') - 10)).attr('y', (+text.attr('y') + 20))
    });
    
    // Energy
    d3.selectAll('.bb-texts .bb-text-2').each(function() { // <<<<<-------- Energy is 'bb-text-2' (only for this chart)
    var text = d3.select(this);
    text.attr('x', (+text.attr('x') + 10)).attr('y', (+text.attr('y') + 20))
    });
    }"
  )

Victor

from billboarder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.