diff --git a/docs/dev/notebooks/crossbar_errorbar.ipynb b/docs/dev/notebooks/crossbar_errorbar.ipynb index 9fbb1f8c6db..ca7e0b01476 100644 --- a/docs/dev/notebooks/crossbar_errorbar.ipynb +++ b/docs/dev/notebooks/crossbar_errorbar.ipynb @@ -12,7 +12,7 @@ " \n", " \n", @@ -26,7 +26,8 @@ "source": [ "from lets_plot import *\n", "\n", - "LetsPlot.setup_html()" + "LetsPlot.setup_html()\n", + "LetsPlot.set_theme(theme_grey())" ] }, { @@ -51,7 +52,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 3, @@ -110,7 +114,7 @@ "ggplot(data) + \\\n", " geom_crossbar(aes(x='drink', middle='mean', ymin='lower', ymax='upper', color='mean'),\n", " tooltips=layer_tooltips().disable_splitting()) + \\\n", - " scale_color_discrete()" + " scale_color_discrete() + theme_grey()" ] }, { @@ -121,7 +125,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 4, @@ -179,7 +186,7 @@ ], "source": [ "ggplot(data) + \\\n", - " geom_crossbar(aes(x='drink', middle='mean', ymin='lower', ymax='upper', color='mean'), \n", + " geom_crossbar(aes(x='drink', middle='mean', ymin='lower', ymax='upper', color='mean'),\n", " fill_by='color',\n", " tooltips=layer_tooltips().disable_splitting()) + \\\n", " scale_color_discrete()" @@ -195,7 +202,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 5, @@ -255,7 +265,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 6, @@ -309,7 +321,7 @@ ], "source": [ "ggplot(data) + \\\n", - " geom_errorbar(aes(x='drink', y='mean', ymin='lower', ymax='upper', color='mean'), alpha=0.5) + \\\n", + " geom_errorbar(aes(x='drink', y='mean', ymin='lower', ymax='upper', color='mean')) + \\\n", " scale_color_discrete()" ] }, @@ -321,7 +333,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " - ], - "text/plain": [ - "" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ggplot(data) + \\\n", - " geom_errorbar(aes(x='drink', y='mean', ymin='lower', ymax='upper', color='mean')) + \\\n", - " scale_color_discrete()" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - " " ], "text/plain": [ - "" + "" ] }, - "execution_count": 8, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -450,13 +400,13 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, - "execution_count": 9, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } diff --git a/docs/dev/notebooks/geoms_and_flavors.ipynb b/docs/dev/notebooks/geoms_and_flavors.ipynb index 66f482a2a87..16a238da433 100644 --- a/docs/dev/notebooks/geoms_and_flavors.ipynb +++ b/docs/dev/notebooks/geoms_and_flavors.ipynb @@ -13,7 +13,7 @@ " \n", " \n", @@ -165,7 +165,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "a7e28c9a5f99425fa8605af1ca3a5059", + "model_id": "f218e67ad01c46f39ab95017d7371eb2", "version_major": 2, "version_minor": 0 }, @@ -179,7 +179,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "bc26e92f049048e38a5ee4a18a90caf3", + "model_id": "db2f47b1c6c449429b681d1827d7e532", "version_major": 2, "version_minor": 0 }, @@ -213,7 +213,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 9, @@ -267,7 +266,7 @@ "# POINT\n", "\n", "show(\n", - " ggplot(mpg_df, aes('cty', 'hwy')) + geom_point(size=4)\n", + " ggplot(mpg_df, aes('cty', 'hwy')) + geom_point()\n", ")" ] }, @@ -280,7 +279,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 10, @@ -335,7 +333,7 @@ "# POINT + shape\n", "\n", "show(\n", - " ggplot(mpg_df, aes('cty', 'hwy')) + geom_point(size=4, shape=22)\n", + " ggplot(mpg_df, aes('cty', 'hwy')) + geom_point(shape=22)\n", ")" ] }, @@ -348,7 +346,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 11, @@ -401,7 +398,7 @@ "source": [ "# JITTER\n", "\n", - "show( ggplot(mpg_df, aes('fl', 'drv')) + geom_jitter(size=4) )" + "show( ggplot(mpg_df, aes('fl', 'drv')) + geom_jitter() )" ] }, { @@ -413,13 +410,13 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 12, @@ -480,13 +477,13 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 13, @@ -547,7 +544,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 14, @@ -600,7 +597,7 @@ "source": [ "# SEGMENT\n", "\n", - "show(ggplot() + geom_segment(x=0, y=0, xend=1, yend=1, arrow=arrow()) )" + "show( ggplot() + geom_segment(x=0, y=0, xend=1, yend=1, arrow=arrow()) )" ] }, { @@ -612,7 +609,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 15, @@ -658,7 +655,8 @@ ], "source": [ "# ABLINE\n", - "show(ggplot() + geom_abline(slope=.5))" + "\n", + "show( ggplot() + geom_abline(slope=.5))" ] }, { @@ -670,7 +668,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 16, @@ -716,7 +714,8 @@ ], "source": [ "# HLINE\n", - "show(ggplot() + geom_hline(yintercept=0) )" + "\n", + "show( ggplot() + geom_hline(yintercept=0) )" ] }, { @@ -728,7 +727,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 17, @@ -774,7 +773,8 @@ ], "source": [ "# VLINE \n", - "show(ggplot() + geom_vline(xintercept=0))" + "\n", + "show( ggplot() + geom_vline(xintercept=0) )" ] }, { @@ -786,7 +786,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 18, @@ -839,7 +839,8 @@ ], "source": [ "# CONTOUR\n", - "show(ggplot(random_df, aes('x', 'y')) + geom_contour(aes(z='z')) )" + "\n", + "show( ggplot(random_df, aes('x', 'y')) + geom_contour(aes(z='z')) )" ] }, { @@ -851,7 +852,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 19, @@ -916,7 +917,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 20, @@ -979,7 +980,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 21, @@ -1044,7 +1045,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 22, @@ -1108,7 +1109,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 23, @@ -1180,7 +1181,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 24, @@ -1233,10 +1234,10 @@ "# LOLLIPOP\n", "\n", "show(\n", - "ggplot({\n", - " 'x': [-3, -2, -1, 0, 1, 2, 3],\n", - " 'y': [2, 3, -2, 3, -1, 0, 4],\n", - "}, aes('x', 'y')) + geom_lollipop()\n", + " ggplot({\n", + " 'x': [-3, -2, -1, 0, 1, 2, 3],\n", + " 'y': [2, 3, -2, 3, -1, 0, 4],\n", + " }, aes('x', 'y')) + geom_lollipop()\n", ") " ] }, @@ -1249,7 +1250,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 25, @@ -1313,7 +1314,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 26, @@ -1366,8 +1367,9 @@ ], "source": [ "# Y_DOT_PLOT\n", + "\n", "show(\n", - " ggplot(mpg_df, aes('class', 'hwy')) + geom_ydotplot()\n", + " ggplot(mpg_df, aes('class', 'hwy')) + geom_ydotplot()\n", ")" ] }, @@ -1380,7 +1382,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 27, @@ -1430,9 +1432,8 @@ ], "source": [ "# BAR\n", - "# color is transparent by default\n", "\n", - "show(ggplot(mpg_df, aes('hwy')) + geom_bar())" + "show( ggplot(mpg_df, aes('hwy')) + geom_bar() )" ] }, { @@ -1444,7 +1445,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 28, @@ -1493,7 +1494,7 @@ } ], "source": [ - "#HISTOGRAM\n", + "# HISTOGRAM\n", "\n", "show( ggplot(mpg_df, aes(x='hwy')) + geom_histogram() )" ] @@ -1507,7 +1508,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 29, @@ -1573,7 +1574,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 30, @@ -1638,7 +1639,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 31, @@ -1702,7 +1703,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 32, @@ -1766,7 +1767,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 33, @@ -1818,6 +1819,8 @@ } ], "source": [ + "# ERROR_BAR\n", + "\n", "show(\n", " ggplot(class_df, aes(x='class')) + geom_errorbar(aes(ymin='min', ymax='max'))\n", ")" @@ -1832,7 +1835,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 34, @@ -1887,8 +1890,9 @@ ], "source": [ "# CROSSBAR\n", + "\n", "show(\n", - " ggplot(class_df, aes(x='class')) + geom_crossbar(aes(ymin='min', middle='median', ymax='max'))\n", + " ggplot(class_df, aes(x='class')) + geom_crossbar(aes(ymin='min', middle='median', ymax='max'))\n", ")" ] }, @@ -1901,7 +1905,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 35, @@ -1967,7 +1971,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 36, @@ -2037,7 +2041,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 37, @@ -2093,6 +2112,7 @@ ], "source": [ "# BOXPLOT\n", + "\n", "show( ggplot(mpg_df, aes('class', 'hwy')) + geom_boxplot() )" ] }, @@ -2105,7 +2125,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 38, @@ -2158,6 +2178,7 @@ ], "source": [ "# VIOLIN \n", + "\n", "show( ggplot(mpg_df, aes('class', 'hwy')) + geom_violin() )" ] }, @@ -2170,7 +2191,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 39, @@ -2236,7 +2257,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 40, @@ -2300,7 +2321,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 41, @@ -2366,7 +2387,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 42, @@ -2416,7 +2437,7 @@ "source": [ "# POLYGON\n", "\n", - "show(ggplot() + geom_polygon(data=states_df) )" + "show( ggplot() + geom_polygon(data=states_df) )" ] }, { @@ -2428,7 +2449,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 43, @@ -2490,7 +2511,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 44, @@ -2549,8 +2570,9 @@ "x = np.arange(n)\n", "ymin = np.random.randint(-5, 0, size=n)\n", "ymax = np.random.randint(1, 6, size=n)\n", - "show(ggplot({'x': x, 'ymin': ymin, 'ymax': ymax}, aes(x='x')) + \\\n", - " geom_ribbon(aes(ymin='ymin', ymax='ymax')) )" + "show(\n", + " ggplot({'x': x, 'ymin': ymin, 'ymax': ymax}, aes(x='x')) + geom_ribbon(aes(ymin='ymin', ymax='ymax'))\n", + ")" ] }, { @@ -2562,7 +2584,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 45, @@ -2627,7 +2649,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 46, @@ -2676,7 +2698,8 @@ ], "source": [ "# MAP\n", - "show(ggplot() + geom_map(data=states_df) )" + "\n", + "show( ggplot() + geom_map(data=states_df) )" ] }, { @@ -2688,7 +2711,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 47, @@ -2737,7 +2759,8 @@ ], "source": [ "# TEXT\n", - "show( ggplot() + geom_text(x=0, y=0, label='Lorem ipsum', size=14))\n", + "\n", + "show( ggplot() + geom_text(x=0, y=0, label='Lorem ipsum'))\n", "#ggplot(mpg_df, aes('cty', 'hwy')) + geom_text(aes(label='fl'))" ] }, @@ -2750,7 +2773,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 48, @@ -2799,7 +2821,8 @@ ], "source": [ "# LABEL\n", - "show( ggplot() + geom_label(x=0, y=0, label='Lorem ipsum', size=14) )\n", + "\n", + "show( ggplot() + geom_label(x=0, y=0, label='Lorem ipsum') )\n", "#ggplot(mpg_df, aes('cty', 'hwy')) + geom_label(aes(label='fl'))" ] }, @@ -2812,7 +2835,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 49, @@ -2864,7 +2886,8 @@ ], "source": [ "# QQ\n", - "show( ggplot(mpg_df, aes(sample='hwy')) + geom_qq(size=5) )" + "\n", + "show( ggplot(mpg_df, aes(sample='hwy')) + geom_qq() )" ] }, { @@ -2876,7 +2899,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 50, @@ -2928,7 +2950,8 @@ ], "source": [ "# QQ2\n", - "show( ggplot(mpg_df, aes(x='cty', y='hwy')) + geom_qq2(size=5) )" + "\n", + "show( ggplot(mpg_df, aes(x='cty', y='hwy')) + geom_qq2() )" ] }, { @@ -2942,7 +2965,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 51, @@ -2994,7 +3016,8 @@ ], "source": [ "# QQ_LINE\n", - "show( ggplot(mpg_df, aes(sample='hwy')) + geom_qq_line(size=1) )" + "\n", + "show( ggplot(mpg_df, aes(sample='hwy')) + geom_qq_line() )" ] }, { @@ -3006,7 +3029,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 52, @@ -3058,13 +3080,14 @@ ], "source": [ "# QQ2_LINE\n", - "show( ggplot(mpg_df, aes(x='cty', y='hwy')) + geom_qq2_line(size=1) )" + "\n", + "show( ggplot(mpg_df, aes(x='cty', y='hwy')) + geom_qq2_line() )" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -3078,7 +3101,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.10.11" }, "widgets": { "application/vnd.jupyter.widget-state+json": { diff --git a/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/aes/AesScaling.kt b/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/aes/AesScaling.kt index cc446422a4c..ee0423dc44d 100644 --- a/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/aes/AesScaling.kt +++ b/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/aes/AesScaling.kt @@ -27,7 +27,7 @@ object AesScaling { fun lineWidth(p: DataPointAesthetics): Double { // aes Units -> px - return p.linewidth()!! * 2.0 + return p.linewidth()!! * UNIT_SHAPE_SIZE / 2.0 } fun circleDiameter(p: DataPointAesthetics): Double { diff --git a/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/aes/AestheticsDefaults.kt b/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/aes/AestheticsDefaults.kt index 3e16f0c5d1b..88e7a352f49 100644 --- a/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/aes/AestheticsDefaults.kt +++ b/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/aes/AestheticsDefaults.kt @@ -25,6 +25,7 @@ open class AestheticsDefaults(geomTheme: GeomTheme) { put(Aes.ALPHA, geomTheme.alpha()) put(Aes.SIZE, geomTheme.size()) put(Aes.LINEWIDTH, geomTheme.lineWidth()) + put(Aes.STROKE, geomTheme.lineWidth()) } private val myDefaultsInLegend = TypedKeyHashMap() @@ -96,7 +97,6 @@ open class AestheticsDefaults(geomTheme: GeomTheme) { private fun lollipop(geomTheme: GeomTheme): AestheticsDefaults { return point(geomTheme) .update(Aes.SHAPE, NamedShape.STICK_CIRCLE) - .update(Aes.STROKE, 1.0) } private fun base(geomTheme: GeomTheme): AestheticsDefaults { diff --git a/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/aes/AestheticsUtil.kt b/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/aes/AestheticsUtil.kt index 0d0997e8308..7a83723ed32 100644 --- a/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/aes/AestheticsUtil.kt +++ b/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/aes/AestheticsUtil.kt @@ -50,35 +50,11 @@ object AestheticsUtil { // else, override with color's alpha } - fun strokeWidth(p: DataPointAesthetics): Double { - // aes Units -> px - return p.size()!! * 2.0 - } + fun strokeWidth(p: DataPointAesthetics) = AesScaling.strokeWidth(p) - fun pointStrokeWidth(p: DataPointAesthetics): Double { - // aes Units -> px - return p.stroke()!! * AesScaling.UNIT_SHAPE_SIZE / 2.0 - } -// -// fun circleDiameter(p: DataPointAesthetics): Double { -// // aes Units -> px -// return p.size()!! * 2.2 -// } -// -// fun circleDiameterSmaller(p: DataPointAesthetics): Double { -// // aes Units -> px -// return p.size()!! * 1.5 -// } -// -// fun sizeFromCircleDiameter(diameter: Double): Double { -// // px -> aes Units -// return diameter / 2.2 -// } -// - fun textSize(p: DataPointAesthetics): Double { - // aes Units -> px - return p.size()!! * 2 - } + fun pointStrokeWidth(p: DataPointAesthetics) = AesScaling.pointStrokeWidth(p) + + fun textSize(p: DataPointAesthetics) = AesScaling.textSize(p) fun updateStroke(shape: SvgShape, p: DataPointAesthetics, applyAlpha: Boolean) { shape.strokeColor().set(p.color()) diff --git a/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/geom/SmoothGeom.kt b/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/geom/SmoothGeom.kt index 86e2482d5d3..084e1a45a82 100644 --- a/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/geom/SmoothGeom.kt +++ b/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/geom/SmoothGeom.kt @@ -31,17 +31,16 @@ class SmoothGeom : GeomBase() { val dataPoints = ordered_X(with_X_Y(aesthetics.dataPoints())) val helper = LinesHelper(pos, coord, ctx) - // Regression line helper.setAlphaEnabled(false) - val regressionLines = helper.createLines(dataPoints, GeomUtil.TO_LOCATION_X_Y) - appendNodes(regressionLines, root) // Confidence interval - helper.setAlphaFilter(PROPORTION) - helper.setWidthFilter(ZERO) val bands = helper.createBands(dataPoints, GeomUtil.TO_LOCATION_X_YMAX, GeomUtil.TO_LOCATION_X_YMIN) appendNodes(bands, root) + // Regression line + val regressionLines = helper.createLines(dataPoints, GeomUtil.TO_LOCATION_X_Y) + appendNodes(regressionLines, root) + buildHints(dataPoints, pos, coord, ctx) } @@ -66,7 +65,7 @@ class SmoothGeom : GeomBase() { ) .defaultColor( p.fill()!!, - PROPORTION(p.alpha()) + p.alpha() ) val hintsCollection = HintsCollection(p, helper) @@ -87,8 +86,5 @@ class SmoothGeom : GeomBase() { companion object { const val HANDLES_GROUPS = true - - private val PROPORTION = { v: Double? -> if (v == null) null else v / 10 } - private val ZERO = { _: Double? -> 0.0 } } } diff --git a/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/geom/util/LinesHelper.kt b/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/geom/util/LinesHelper.kt index 4a7978ead31..71362b28d3d 100644 --- a/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/geom/util/LinesHelper.kt +++ b/plot-base-portable/src/commonMain/kotlin/jetbrains/datalore/plot/base/geom/util/LinesHelper.kt @@ -24,8 +24,6 @@ import jetbrains.datalore.plot.common.geometry.PolylineSimplifier open class LinesHelper(pos: PositionAdjustment, coord: CoordinateSystem, ctx: GeomContext) : GeomHelper(pos, coord, ctx) { - private var myAlphaFilter = { v: Double? -> v } - private var myWidthFilter = { v: Double? -> v } private var myAlphaEnabled = true private fun insertPathSeparators(rings: Iterable>): List { @@ -139,7 +137,8 @@ open class LinesHelper(pos: PositionAdjustment, coord: CoordinateSystem, ctx: Ge if (!points.isEmpty()) { val path = LinePath.polygon(points) - //decorate(path, groupDataPoints.get(0), true); + // to retain the side edges of area: + // decorate(path, groupDataPoints.get(0), true); decorateFillingPart(path, groupDataPoints[0]) lines.add(path) } @@ -159,7 +158,7 @@ open class LinesHelper(pos: PositionAdjustment, coord: CoordinateSystem, ctx: Ge strokeScaler: (DataPointAesthetics) -> Double = AesScaling::strokeWidth ) { val stroke = p.color() - val strokeAlpha = myAlphaFilter(AestheticsUtil.alpha(stroke!!, p))!! + val strokeAlpha = AestheticsUtil.alpha(stroke!!, p) path.color().set(withOpacity(stroke, strokeAlpha)) if (!AestheticsUtil.ALPHA_CONTROLS_BOTH && (filled || !myAlphaEnabled)) { path.color().set(stroke) @@ -169,7 +168,7 @@ open class LinesHelper(pos: PositionAdjustment, coord: CoordinateSystem, ctx: Ge decorateFillingPart(path, p) } - val size = myWidthFilter(strokeScaler(p))!! + val size = strokeScaler(p) path.width().set(size) val lineType = p.lineType() @@ -180,18 +179,10 @@ open class LinesHelper(pos: PositionAdjustment, coord: CoordinateSystem, ctx: Ge private fun decorateFillingPart(path: LinePath, p: DataPointAesthetics) { val fill = p.fill() - val fillAlpha = myAlphaFilter(AestheticsUtil.alpha(fill!!, p))!! + val fillAlpha = AestheticsUtil.alpha(fill!!, p) path.fill().set(withOpacity(fill, fillAlpha)) } - fun setAlphaFilter(alphaFilter: (Double?) -> Double?) { - myAlphaFilter = alphaFilter - } - - fun setWidthFilter(widthFilter: (Double?) -> Double?) { - myWidthFilter = widthFilter - } - // ToDo: get rid of PathInfo class class PathInfo internal constructor(val path: LinePath) diff --git a/plot-builder-portable/src/commonMain/kotlin/jetbrains/datalore/plot/builder/assemble/GeomLayerBuilder.kt b/plot-builder-portable/src/commonMain/kotlin/jetbrains/datalore/plot/builder/assemble/GeomLayerBuilder.kt index c02bc25d5e7..6a60fbd2614 100644 --- a/plot-builder-portable/src/commonMain/kotlin/jetbrains/datalore/plot/builder/assemble/GeomLayerBuilder.kt +++ b/plot-builder-portable/src/commonMain/kotlin/jetbrains/datalore/plot/builder/assemble/GeomLayerBuilder.kt @@ -36,7 +36,6 @@ import jetbrains.datalore.plot.builder.assemble.geom.PointDataAccess import jetbrains.datalore.plot.builder.data.DataProcessing import jetbrains.datalore.plot.builder.data.GroupingContext import jetbrains.datalore.plot.builder.data.StatInput -import jetbrains.datalore.plot.builder.defaultTheme.DefaultGeomTheme import jetbrains.datalore.plot.builder.interact.ContextualMappingProvider import jetbrains.datalore.plot.builder.presentation.DefaultFontFamilyRegistry import jetbrains.datalore.plot.builder.presentation.FontFamilyRegistry @@ -72,7 +71,7 @@ class GeomLayerBuilder( private var myAnnotationsProvider: ((MappedDataAccess, DataFrame) -> Annotations?)? = null - private var myGeomTheme: GeomTheme = DefaultGeomTheme.BASE + private lateinit var myGeomTheme: GeomTheme fun addBinding(v: VarBinding): GeomLayerBuilder { myBindings.add(v) diff --git a/plot-builder-portable/src/commonMain/kotlin/jetbrains/datalore/plot/builder/defaultTheme/DefaultGeomTheme.kt b/plot-builder-portable/src/commonMain/kotlin/jetbrains/datalore/plot/builder/defaultTheme/DefaultGeomTheme.kt index a5265c3562d..77c332c803d 100644 --- a/plot-builder-portable/src/commonMain/kotlin/jetbrains/datalore/plot/builder/defaultTheme/DefaultGeomTheme.kt +++ b/plot-builder-portable/src/commonMain/kotlin/jetbrains/datalore/plot/builder/defaultTheme/DefaultGeomTheme.kt @@ -6,7 +6,6 @@ package jetbrains.datalore.plot.builder.defaultTheme import jetbrains.datalore.base.values.Color -import jetbrains.datalore.base.values.Colors import jetbrains.datalore.plot.base.GeomKind import jetbrains.datalore.plot.builder.defaultTheme.values.ThemeOption import jetbrains.datalore.plot.builder.defaultTheme.values.ThemeOption.AXIS @@ -35,14 +34,6 @@ internal class DefaultGeomTheme private constructor( override fun lineWidth() = lineWidth companion object { - val BASE = DefaultGeomTheme( - color = Color.PACIFIC_BLUE, - fill = Color.PACIFIC_BLUE, - alpha = 1.0, - size = 0.5, - lineWidth = 0.5 - ) - internal class InheritedColors( options: Map, fontFamilyRegistry: FontFamilyRegistry @@ -61,13 +52,24 @@ internal class DefaultGeomTheme private constructor( } } + private class FixedColors(geomKind: GeomKind) { + val color = if (geomKind == GeomKind.SMOOTH) { + Color.MAGENTA + } else { + Color.PACIFIC_BLUE + } + val fill = Color.PACIFIC_BLUE + } + // defaults for geomKind fun forGeomKind(geomKind: GeomKind, inheritedColors: InheritedColors): GeomTheme { - var color = BASE.color - var fill = BASE.fill - var alpha = BASE.alpha - var size = BASE.size - val lineWidth = BASE.lineWidth + val fixedColors = FixedColors(geomKind) + + var color = fixedColors.color + var fill = fixedColors.fill + var alpha = 1.0 + var size = 0.5 + var lineWidth = 0.5 when (geomKind) { GeomKind.PATH, @@ -88,12 +90,8 @@ internal class DefaultGeomTheme private constructor( } GeomKind.HISTOGRAM, - GeomKind.CROSS_BAR, - GeomKind.BOX_PLOT, GeomKind.AREA_RIDGES, - GeomKind.VIOLIN, GeomKind.AREA, - GeomKind.DENSITY, GeomKind.RECT, GeomKind.RIBBON -> { color = inheritedColors.lineColor() @@ -108,25 +106,40 @@ internal class DefaultGeomTheme private constructor( size = 0.2 } - GeomKind.POINT_RANGE -> { + GeomKind.DENSITY, + GeomKind.VIOLIN, + GeomKind.CROSS_BAR, + GeomKind.BOX_PLOT -> { color = inheritedColors.lineColor() - fill = Colors.withOpacity(inheritedColors.lineColor(), 0.1) + fill = inheritedColors.backgroundFill() + alpha = 0.1 } GeomKind.POINT, GeomKind.JITTER, GeomKind.Q_Q, - GeomKind.Q_Q_2, + GeomKind.Q_Q_2 -> { + color = inheritedColors.lineColor() + fill = inheritedColors.backgroundFill() + size = 2.0 + } + + GeomKind.POINT_RANGE -> { + color = inheritedColors.lineColor() + fill = inheritedColors.backgroundFill() + lineWidth = 1.0 // line width and stroke for point + } + GeomKind.LOLLIPOP -> { color = inheritedColors.lineColor() - fill = Colors.withOpacity(inheritedColors.lineColor(), 0.1) + fill = inheritedColors.backgroundFill() size = 2.0 + lineWidth = 1.0 // line width and stroke for point } GeomKind.SMOOTH -> { - color = Color.MAGENTA fill = inheritedColors.lineColor() - alpha = 1.5 // Geometry uses (value / 10) for alpha: SmoothGeom.kt:91 (PROPORTION) + alpha = 0.15 } GeomKind.DOT_PLOT, @@ -161,7 +174,9 @@ internal class DefaultGeomTheme private constructor( } } - return DefaultGeomTheme(color, fill, alpha, size, lineWidth) + val sizeMultiplier = 1.5 + + return DefaultGeomTheme(color, fill, alpha, size * sizeMultiplier, lineWidth * sizeMultiplier) } } } \ No newline at end of file diff --git a/plot-builder/src/jvmTest/kotlin/plot/builder/assemble/GeomLayerBuilderTest.kt b/plot-builder/src/jvmTest/kotlin/plot/builder/assemble/GeomLayerBuilderTest.kt index 61537c58073..7bd2b8d7778 100644 --- a/plot-builder/src/jvmTest/kotlin/plot/builder/assemble/GeomLayerBuilderTest.kt +++ b/plot-builder/src/jvmTest/kotlin/plot/builder/assemble/GeomLayerBuilderTest.kt @@ -5,7 +5,9 @@ package jetbrains.datalore.plot.builder.assemble +import jetbrains.datalore.base.values.Color import jetbrains.datalore.plot.base.* +import jetbrains.datalore.plot.base.aes.GeomTheme import jetbrains.datalore.plot.base.scale.Scales import jetbrains.datalore.plot.base.stat.Stats import jetbrains.datalore.plot.builder.VarBinding @@ -73,6 +75,13 @@ class GeomLayerBuilderTest { // .geom(geomProvider) // .pos(posProvider) // .addConstantAes(Aes.ALPHA, 0.5) + .geomTheme(object : GeomTheme { + override fun color(): Color = Color.PACIFIC_BLUE + override fun fill(): Color = Color.PACIFIC_BLUE + override fun alpha() = 1.0 + override fun size() = 0.5 + override fun lineWidth() = 0.5 + }) .addBinding(bindings[0]) .addBinding(bindings[1]) .build(data, scaleByAes, scaleMappersNP) @@ -94,4 +103,5 @@ class GeomLayerBuilderTest { // checkNotOriginalVar(layerData, histogramLayer.getBinding(Aes.Y)) checkNotOriginalVar(layerData, histogramLayer.getBinding(Aes.FILL)) } + } \ No newline at end of file