Skip to content

Commit

Permalink
Fix cannot apply both size and shape to points in a plot-by series (#…
Browse files Browse the repository at this point in the history
…3402)

-Fixed issue where multi_series_key would be removed too early and not applied to every argument
-Verified by running the code below from issue #3402:
```python
from deephaven import empty_table
from deephaven.plot import Figure
import math

math_funcs = ["sin", "cos"]
shapes = ["SQUARE", "CIRCLE", "UP_TRIANGLE", "DOWN_TRIANGLE", "RIGHT_TRIANGLE", "LEFT_TRIANGLE", "DIAMOND"]
size = 50
# Unsupported shapes: ["ELLIPSE", "HORIZONTAL_RECTANGLE", "VERTICAL_RECTANGLE"]

# Create a generic table that has enough columns to display all the shapes
# Re-uses some of the funcs
t = empty_table(size).update([f"name=`` + shapes[(int)Math.floor(i / Math.ceil(size / {len(shapes)}))]", "x=i*0.1"])
for i in range(len(shapes)):
    t = t.update([f"y{i}=Math.{math_funcs[i % len(math_funcs)]}(x+{math.floor(i / len(math_funcs))})"])

# Create a plot by figure
p2 = Figure().plot_xy(series_name="Multi", t=t, by=["name"], x="x", y="y1").line(visible=True)
for i in range(len(shapes)):
    # apply both shapes and sizes to points
    p2 = p2.point(shape=shapes[i], multi_series_key=[shapes[i]], size=len(shapes) - i, visible=True)
p2 = p2.show()```

---------

Co-authored-by: Mike Bender <mikebender@deephaven.io>
  • Loading branch information
jnumainville and mofojed authored Feb 10, 2023
1 parent d15687d commit 227eb5e
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ private void generatePyFuncCallSequential(final StringBuilder sb,
.append(INDENT)
.append("j_figure = self.j_figure\n\n");

boolean needsMskCheck = false;

final Set<Set<String>> alreadyGenerated = new HashSet<>();

Expand All @@ -890,22 +891,36 @@ private void generatePyFuncCallSequential(final StringBuilder sb,
final List<String[]> argNames = pyArgNames(sigs, pyArgMap);

for (String[] argName : argNames) {
needsMskCheck = needsMskCheck || Arrays.stream(argName).anyMatch("multi_series_key"::equals);
final Pair<Key, String[]> e = new Pair<>(key, argName);
items.add(e);
}
}

if (needsMskCheck) {
sb.append(INDENT)
.append(INDENT)
.append("multi_series_key_used = False\n\n");
}

// sort from largest number of args to smallest number of args so that the most specific method is called
items.sort((a, b) -> b.second.length - a.second.length);

for (Pair<Key, String[]> item : items) {
final Key key = item.first;
final String[] an = item.second;

final boolean mskUsed = Arrays.stream(an).anyMatch("multi_series_key"::equals);

validateArgNames(an, alreadyGenerated, signatures, pyArgMap);
final String[] quoted_an = Arrays.stream(an).map(s -> "\"" + s + "\"").toArray(String[]::new);
final String[] quotedAn = Arrays.stream(an).map(s -> "\"" + s + "\"").toArray(String[]::new);

if (quoted_an.length == 0) {
// prevent removal of multi_series_key until after it's been fully used
final String[] filteredQuotedAn = Arrays.stream(quotedAn)
.filter(s -> !s.equals("\"multi_series_key\""))
.toArray(String[]::new);

if (quotedAn.length == 0) {
sb.append(INDENT)
.append(INDENT)
.append("if set()")
Expand All @@ -914,7 +929,7 @@ private void generatePyFuncCallSequential(final StringBuilder sb,
sb.append(INDENT)
.append(INDENT)
.append("if {")
.append(String.join(", ", quoted_an))
.append(String.join(", ", quotedAn))
.append("}.issubset(non_null_args):\n");
}
sb.append(INDENT)
Expand All @@ -929,12 +944,31 @@ private void generatePyFuncCallSequential(final StringBuilder sb,
.append(INDENT)
.append(INDENT)
.append("non_null_args = non_null_args.difference({")
.append(String.join(", ", quoted_an))
.append(String.join(", ", filteredQuotedAn))
.append("})\n")
.append(INDENT)
.append(INDENT)
.append(INDENT)
.append("f_called = True\n\n");
.append("f_called = True\n");

if (mskUsed) {
sb.append(INDENT)
.append(INDENT)
.append(INDENT)
.append("multi_series_key_used = True\n");
}

sb.append("\n");
}

if (needsMskCheck) {
sb.append(INDENT)
.append(INDENT)
.append("if multi_series_key_used:\n")
.append(INDENT)
.append(INDENT)
.append(INDENT)
.append("non_null_args = non_null_args.difference({\"multi_series_key\"})\n\n");
}

sb.append(INDENT)
Expand Down
Loading

0 comments on commit 227eb5e

Please sign in to comment.