Skip to content

Commit

Permalink
fix bar plots
Browse files Browse the repository at this point in the history
  • Loading branch information
iamlemec committed Nov 28, 2023
1 parent b562147 commit a8531ca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 4 additions & 1 deletion dist/js/gum.js
Original file line number Diff line number Diff line change
Expand Up @@ -2740,6 +2740,9 @@ class BarPlot extends Plot {
aspect = aspect ?? phi;
shrink = shrink ?? 0.2;
color = color ?? 'lightgray';

// wrangle data
data = is_object(data) ? Object.entries(data) : data;
let n = data.length;

// standardize direction
Expand All @@ -2752,7 +2755,7 @@ class BarPlot extends Plot {

// generate actual bars
let [labs, bars] = zip(...data);
let bars1 = new Bars(direc, bars, {shrink, ...bars_attr});
let bars1 = new Bars(direc, bars, {shrink, bar_fill: color, ...bars_attr});
let ticks = zip(bars1.vals, labs);

// send to general plot
Expand Down
5 changes: 4 additions & 1 deletion js/gum.js
Original file line number Diff line number Diff line change
Expand Up @@ -2772,6 +2772,9 @@ class BarPlot extends Plot {
aspect = aspect ?? phi;
shrink = shrink ?? 0.2;
color = color ?? 'lightgray';

// wrangle data
data = is_object(data) ? Object.entries(data) : data;
let n = data.length;

// standardize direction
Expand All @@ -2784,7 +2787,7 @@ class BarPlot extends Plot {

// generate actual bars
let [labs, bars] = zip(...data);
let bars1 = new Bars(direc, bars, {shrink, ...bars_attr});
let bars1 = new Bars(direc, bars, {shrink, bar_fill: color, ...bars_attr});
let ticks = zip(bars1.vals, labs);

// send to general plot
Expand Down
9 changes: 4 additions & 5 deletions test/golf.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,10 @@ return Interactive({

// bar plot
return Interactive({
x: Slider(10, {min: 0, max: 20, title: 'b'})
}, ({x}) => {
d = {'a': 2, 'b': x, 'c':20, 'd': 13};
b = BarPlot(d, {color:[[17, 100, 45],[78, 80, 45]]});
return Frame(b, {padding: [0.15, 0.05, 0.05, 0.15]});
b: Slider(10, {min: 0, max: 20, title: 'b'})
}, ({b}) => {
let bars = BarPlot({'a': 2, 'b': b, 'c':20, 'd': 13});
return Frame(bars, {padding: 0.15});
});

// stacked bar
Expand Down

0 comments on commit a8531ca

Please sign in to comment.