Skip to content

Commit f7f7acf

Browse files
author
Ben Lerner
committed
feature request: make image scatter plots draw images at native size
I've added a new method to scatter- and line-plots (which support image-labels), `.use-image-sizes(use-size :: Boolean)`, to toggle whether the charts should show the images at full size (true) or scaled to the point-size (false)
1 parent 551ded0 commit f7f7acf

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/arr/trove/charts.arr

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,8 @@ type LinePlotSeries = {
11501150
trendlineDegree :: NumInteger,
11511151
dashedLine :: Boolean,
11521152
dashlineStyle :: RawArray<NumInteger>,
1153-
point-size :: Number,
1153+
point-size :: Number,
1154+
useImageSizes :: Boolean,
11541155
pointshapeType :: String,
11551156
pointshapeSides :: NumInteger,
11561157
pointshapeDent :: Number,
@@ -1170,7 +1171,8 @@ default-line-plot-series = {
11701171
trendlineDegree: 3,
11711172
dashedLine: false,
11721173
dashlineStyle: [raw-array: 2, 2],
1173-
point-size: 0,
1174+
point-size: 0,
1175+
useImageSizes: true,
11741176
pointshapeType: 'circle',
11751177
pointshapeSides: 5,
11761178
pointshapeDent: 0.5,
@@ -1190,6 +1192,7 @@ type ScatterPlotSeries = {
11901192
color :: Option<I.Color>,
11911193
legend :: String,
11921194
point-size :: Number,
1195+
useImageSizes :: Boolean,
11931196
trendlineType :: Option<String>,
11941197
trendlineColor :: Option<I.Color>,
11951198
trendlineWidth :: Number,
@@ -1206,6 +1209,7 @@ default-scatter-plot-series = {
12061209
color: none,
12071210
legend: '',
12081211
point-size: 7,
1212+
useImageSizes: true,
12091213
pointshapeType: 'circle',
12101214
pointshapeSides: 5,
12111215
pointshapeDent: 0.5,
@@ -1510,6 +1514,9 @@ data DataSeries:
15101514
end
15111515
self.constr()(self.obj.{point-size: point-size})
15121516
end,
1517+
method use-image-sizes(self, use-image-sizes :: Boolean):
1518+
self.constr()(self.obj.{useImageSizes: use-image-sizes})
1519+
end,
15131520
horizontal: horizontal-method,
15141521
| scatter-plot-series(obj :: ScatterPlotSeries) with:
15151522
trendline-type: trendline-type-method,
@@ -1524,11 +1531,14 @@ data DataSeries:
15241531
image-labels: image-labels-method,
15251532
point-shape: pointshape-method,
15261533
method point-size(self, point-size :: Number) block:
1527-
when point-size < 0:
1528-
raise("point-size: Point Size must be non-negative")
1534+
when point-size <= 0:
1535+
raise("point-size: Point Size must be positive")
15291536
end
15301537
self.constr()(self.obj.{point-size: point-size})
15311538
end,
1539+
method use-image-sizes(self, use-image-sizes :: Boolean):
1540+
self.constr()(self.obj.{useImageSizes: use-image-sizes})
1541+
end,
15321542
horizontal: horizontal-method,
15331543
| dot-plot-series(obj :: DotPlotSeries) with:
15341544
is-single: true,

src/js/trove/charts-lib.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,6 +1962,7 @@
19621962
const color = getColorOrDefault(get(rawData, 'color'), defaultColor);
19631963
const legend = get(rawData, 'legend') || config.legend;
19641964
const pointSize = toFixnum(get(rawData, 'point-size'));
1965+
const autosizeImage = isTrue(get(rawData, 'useImageSizes'));
19651966
const pointshapeType = get(rawData, 'pointshapeType');
19661967
const pointshapeSides = toFixnum(get(rawData, 'pointshapeSides'));
19671968
const pointshapeDent = toFixnum(get(rawData, 'pointshapeDent'));
@@ -2137,8 +2138,8 @@
21372138
name: `${prefix}ImageMarks`,
21382139
encode: {
21392140
enter: {
2140-
width: { value: pointSize },
2141-
height: { value: pointSize },
2141+
width: autosizeImage ? undefined : { value: pointSize },
2142+
height: autosizeImage ? undefined : { value: pointSize },
21422143
image: { field: 'image' },
21432144
tooltip: tooltips
21442145
},

0 commit comments

Comments
 (0)