diff --git a/cortex/dataset/view2D.py b/cortex/dataset/view2D.py index 6a41792ac..341c7c50a 100644 --- a/cortex/dataset/view2D.py +++ b/cortex/dataset/view2D.py @@ -57,8 +57,10 @@ def to_json(self, simple=False): d1js = self.dim1.to_json() d2js = self.dim2.to_json() sdict.update(dict( - vmin = [[self.vmin or d1js['vmin'][0], self.vmin2 or d2js['vmin'][0]]], - vmax = [[self.vmax or d1js['vmax'][0], self.vmax2 or d2js['vmax'][0]]], + vmin = [[d1js['vmin'][0] if self.vmin is None else self.vmin, + d2js['vmin'][0] if self.vmin2 is None else self.vmin2]], + vmax = [[d1js['vmax'][0] if self.vmax is None else self.vmax, + d2js['vmax'][0] if self.vmax2 is None else self.vmax2]], )) if "xfm" in d1js: diff --git a/cortex/tests/test_dataset.py b/cortex/tests/test_dataset.py index d3224bd4f..0e3d03691 100644 --- a/cortex/tests/test_dataset.py +++ b/cortex/tests/test_dataset.py @@ -154,6 +154,36 @@ def test_2D(): twod.to_json() +def test_2D_to_json_keeps_explicit_zero_limits(): + """to_json must keep an explicitly requested limit of 0 for all four bounds. + + 0 is falsy, so a fallback written with ``or`` silently replaces it with the + data range taken from the underlying dim. + """ + d1 = cortex.Volume.random(subj, xfmname) + d2 = cortex.Volume.random(subj, xfmname) + + # Control: nonzero limits are already passed through untouched. + control = cortex.Volume2D(d1, d2, vmin=1, vmax=3, vmin2=2, vmax2=4) + assert control.to_json()["vmin"] == [[1, 2]] + assert control.to_json()["vmax"] == [[3, 4]] + + view = cortex.Volume2D(d1, d2, vmin=0, vmax=0, vmin2=0, vmax2=0) + assert view.to_json()["vmin"] == [[0, 0]] + assert view.to_json()["vmax"] == [[0, 0]] + + v1 = cortex.Vertex.random(subj) + v2 = cortex.Vertex.random(subj) + + control = cortex.Vertex2D(v1, v2, vmin=1, vmax=3, vmin2=2, vmax2=4) + assert control.to_json()["vmin"] == [[1, 2]] + assert control.to_json()["vmax"] == [[3, 4]] + + view = cortex.Vertex2D(v1, v2, vmin=0, vmax=0, vmin2=0, vmax2=0) + assert view.to_json()["vmin"] == [[0, 0]] + assert view.to_json()["vmax"] == [[0, 0]] + + def test_braindata_hash(): d = cortex.Volume.random(subj, xfmname) hash(d)