|
11 | 11 | values: { |
12 | 12 | 'pie-chart': "tany", |
13 | 13 | 'dot-chart': "tany", |
| 14 | + 'categorical-dot-chart': "tany", |
14 | 15 | 'bar-chart': "tany", |
15 | 16 | 'multi-bar-chart': "tany", |
16 | 17 | 'histogram': "tany", |
|
1865 | 1866 | fill: { value: color }, |
1866 | 1867 | stroke: { value: 'white' }, |
1867 | 1868 | strokeWidth: { value: 0.25 }, |
1868 | | - tooltip: '{ title: datum.Label, Value: datum.value, BinNum: datum.binNum, Bin0: datum.bin0, Bin1: datum.bin1 }' |
| 1869 | + tooltip: { signal: '{ title: datum.label, Value: datum.value }' } |
1869 | 1870 | }, |
1870 | 1871 | update: { |
1871 | 1872 | xc: { scale: 'binScale', field: 'value' }, |
|
1882 | 1883 | width: autosizeImage ? undefined : { value: pointSize }, |
1883 | 1884 | height: autosizeImage ? undefined : { value: pointSize }, |
1884 | 1885 | image: { field: 'image' }, |
1885 | | - tooltip: '{ title: datum.Label, Value: datum.value, BinNum: datum.binNum, Bin0: datum.bin0, Bin1: datum.bin1 }' |
| 1886 | + tooltip: { signal: '{ title: datum.label, Value: datum.value }' } |
1886 | 1887 | }, |
1887 | 1888 | update: { |
1888 | 1889 | xc: { scale: 'binScale', field: 'value' }, |
|
1910 | 1911 | marks, |
1911 | 1912 | onExit: defaultImageReturn, |
1912 | 1913 | }; |
1913 | | - } |
| 1914 | + } |
| 1915 | + |
| 1916 | + function categoricalDotChart(globalOptions, rawData) { |
| 1917 | + const defaultColor = default_colors[0]; |
| 1918 | + const color = getColorOrDefault(get(rawData, 'color'), defaultColor); |
| 1919 | + const legend = get(rawData, 'legend') || ''; |
| 1920 | + |
| 1921 | + const points = RUNTIME.ffi.toArray(get(rawData, 'ps')); |
| 1922 | + |
| 1923 | + const title = globalOptions['title']; |
| 1924 | + const width = globalOptions['width']; |
| 1925 | + const height = globalOptions['height']; |
| 1926 | + const xAxisLabel = globalOptions['x-axis']; |
| 1927 | + const yAxisLabel = globalOptions['y-axis']; |
| 1928 | + const background = getColorOrDefault(globalOptions['backgroundColor'], 'transparent'); |
| 1929 | + |
| 1930 | + |
| 1931 | + |
| 1932 | + console.log(points); |
| 1933 | + const fixedPoints = points.map((p) => ({ |
| 1934 | + label: get(p, 'label'), |
| 1935 | + count: toFixnum(get(p, 'count')) |
| 1936 | + })); |
| 1937 | + const data = [ |
| 1938 | + { |
| 1939 | + name: 'bars', |
| 1940 | + values: fixedPoints |
| 1941 | + }, |
| 1942 | + { |
| 1943 | + name: 'dotsData', |
| 1944 | + values: fixedPoints.flatMap((p) => |
| 1945 | + Array.from({length: p.count}).map((_, i) => ({ label: p.label, value: i })) |
| 1946 | + ) |
| 1947 | + }, |
| 1948 | + ]; |
| 1949 | + console.log(data) |
| 1950 | + const signals = [ |
| 1951 | + { name: 'dotSize', update: "scale('secondary', 1) - scale('secondary', 0)" }, |
| 1952 | + ]; |
| 1953 | + const scales = [ |
| 1954 | + { |
| 1955 | + name: 'primary', |
| 1956 | + type: 'band', |
| 1957 | + range: 'width', |
| 1958 | + domain: { data: 'bars', field: 'label' } |
| 1959 | + }, |
| 1960 | + { |
| 1961 | + name: 'secondary', |
| 1962 | + type: 'linear', |
| 1963 | + range: 'height', |
| 1964 | + nice: true, zero: true, |
| 1965 | + domain: { data: 'bars', field: 'count' } |
| 1966 | + } |
| 1967 | + ]; |
| 1968 | + const axes = [ |
| 1969 | + { orient: 'bottom', scale: 'primary', zindex: 1, title: xAxisLabel }, |
| 1970 | + { orient: 'bottom', scale: 'primary', zindex: 0, grid: true, ticks: false, labels: false }, |
| 1971 | + { orient: 'left', scale: 'secondary', grid: true, ticks: true, labels: true, title: yAxisLabel, zindex: 1 } |
| 1972 | + ]; |
| 1973 | + const marks = [ |
| 1974 | + { |
| 1975 | + type: 'symbol', |
| 1976 | + name: 'dots', |
| 1977 | + from: { data: 'dotsData' }, |
| 1978 | + encode: { |
| 1979 | + enter: { |
| 1980 | + shape: { value: 'circle' }, |
| 1981 | + fillOpacity: { value: 0.5 }, |
| 1982 | + fill: { value: color }, |
| 1983 | + stroke: { value: 'white' }, |
| 1984 | + strokeWidth: { value: 0.25 }, |
| 1985 | + tooltip: { signal: '{ title: datum.label, Value: datum.value }' }, |
| 1986 | + xc: { scale: 'primary', field: 'label', offset: { scale: 'primary', band: 0.5 } }, |
| 1987 | + yc: { scale: 'secondary', field: 'value', offset: { signal: '0.5 * dotSize' } }, |
| 1988 | + size: { signal: '0.8 * 0.8 * dotSize * dotSize' }, |
| 1989 | + } |
| 1990 | + } |
| 1991 | + }, |
| 1992 | + { |
| 1993 | + type: 'rect', |
| 1994 | + name: 'blocks', |
| 1995 | + from: { data: 'bars' }, |
| 1996 | + encode: { |
| 1997 | + enter: { |
| 1998 | + x: { scale: 'primary', field: 'label', offset: { scale: 'primary', band: 0.25 } }, |
| 1999 | + x2: { scale: 'primary', field: 'label', offset: { scale: 'primary', band: 0.75 } }, |
| 2000 | + y: { scale: 'secondary', value: 0 }, |
| 2001 | + y2: { scale: 'secondary', field: 'count' }, |
| 2002 | + tooltip: { signal: `{ title: datum.label, Count: datum.count }`}, |
| 2003 | + stroke: { value: 'gray' }, |
| 2004 | + strokeWidth: { value: 2 }, |
| 2005 | + fill: { value: 'transparent' }, |
| 2006 | + }, |
| 2007 | + update: { |
| 2008 | + opacity: { value: 0 }, |
| 2009 | + }, |
| 2010 | + hover: { |
| 2011 | + opacity: { value: 1 } |
| 2012 | + } |
| 2013 | + } |
| 2014 | + }, |
| 2015 | + ]; |
| 2016 | + |
| 2017 | + const ans = { |
| 2018 | + "$schema": "https://vega.github.io/schema/vega/v6.json", |
| 2019 | + description: title, |
| 2020 | + title: title ? { text: title } : '', |
| 2021 | + width, |
| 2022 | + height, |
| 2023 | + padding: 0, |
| 2024 | + autosize: 'fit', |
| 2025 | + background, |
| 2026 | + data, |
| 2027 | + signals, |
| 2028 | + scales, |
| 2029 | + axes, |
| 2030 | + marks, |
| 2031 | + onExit: defaultImageReturn, |
| 2032 | + }; |
| 2033 | + console.log(ans); |
| 2034 | + return ans; |
| 2035 | + } |
1914 | 2036 |
|
1915 | 2037 | function computeDomain(domainValues) { |
1916 | 2038 | const domainMin = Math.min(...domainValues); |
|
3153 | 3275 | 'histogram': makeFunction(histogram), |
3154 | 3276 | 'box-plot': makeFunction(boxPlot), |
3155 | 3277 | 'dot-chart': makeFunction(dotChart), |
| 3278 | + 'categorical-dot-chart': makeFunction(categoricalDotChart), |
3156 | 3279 | 'plot': makeFunction(plot), |
3157 | 3280 | }, |
3158 | 3281 | { |
|
0 commit comments