Skip to content
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

Can't make grouped bar work #16

Open
translunar opened this issue Apr 18, 2014 · 0 comments
Open

Can't make grouped bar work #16

translunar opened this issue Apr 18, 2014 · 0 comments

Comments

@translunar
Copy link
Member

I think there are still some problems with the group mark.

In particular, to get things to the right height in grouped_bar, I have to include a mult in several that shouldn't need it.

Another big problem is that it prints exactly the same data in each group — and the data appears to be incorrect.

The text is also wrong, and I can't see why that would be.

require 'plotrb'

data = pdata.name('table').values(
    [
      {category: :A, position: 0, value: 0.1},
      {category: :A, position: 1, value: 0.6},
      {category: :A, position: 2, value: 0.9},
      {category: :A, position: 3, value: 0.4},
      {category: :B, position: 0, value: 0.7},
      {category: :B, position: 1, value: 0.2},
      {category: :B, position: 2, value: 1.1},
      {category: :B, position: 3, value: 0.8},
      {category: :C, position: 0, value: 0.6},
      {category: :C, position: 1, value: 0.1},
      {category: :C, position: 2, value: 0.2},
      {category: :C, position: 3, value: 0.7}
    ]
)

category = pdata.name('category').source('table').transform [facet_transform.keys(:category)]

xs = linear_scale.name('val').from('table.value').nicely.to_width
gs = ordinal_scale.name('cat').from('category.key').padding(0.2).to_height
cs = ordinal_scale.name('color').to_colors
ys = ordinal_scale.name('pos').from('table.position').to_height

rm = rect_mark.from(data) do
  enter do
    y_start { scale(ys).mult(0.25).field(:position) }
    height  { scale(ys).mult(0.25).use_band }
    x_start { scale(xs).field(:value) }
    x_end   { scale(xs).value(0) }
    fill    { scale(cs).field(:position) }
  end
end

tm = text_mark.from(data) do
  enter do
    y       { scale(ys).mult(0.25).field(:position) }
    dy      { scale(ys).mult(0.25).use_band }
    x       { scale(xs).field(:value).offset(-4) }
    text    { scale(xs).field(:value) }
    fill :white
    align :right
    baseline :middle
  end
end

mark = group_mark.from(category) do
  scales gs
  axes y_axis.scale(gs).tick_size(0).tick_padding(8)
  marks rm, tm
  enter do
    y      { scale(gs).field(:key) }
    height { scale(gs).use_band }
  end
end

vis = visualization.width(300).height(240) do
  data data, category
  scales gs, cs, xs, ys
  marks mark
  axes x_axis.scale(xs), y_axis.scale(ys)
end

puts vis.generate_spec(:pretty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant