|
1 | | -/****************************************************************************** |
2 | | - * |
3 | | - * Copyright (c) 2017, the Perspective Authors. |
4 | | - * |
5 | | - * This file is part of the Perspective library, distributed under the terms of |
6 | | - * the Apache License 2.0. The full license can be found in the LICENSE file. |
7 | | - * |
8 | | - */ |
9 | | -import * as fc from "d3fc"; |
10 | | -import * as mainAxis from "../axis/mainAxis"; |
11 | | -import {pointSeries, symbolTypeFromGroups} from "../series/pointSeries"; |
12 | | -import {pointData} from "../data/pointData"; |
13 | | -import {seriesColoursFromGroups} from "../series/seriesColours"; |
14 | | -import {seriesLinearRange, seriesColourRange} from "../series/seriesRange"; |
15 | | -import {symbolLegend} from "../legend/legend"; |
16 | | -import {colourRangeLegend} from "../legend/colourRangeLegend"; |
17 | | -import {filterDataByGroup} from "../legend/filter"; |
18 | | -import {withGridLines} from "../gridlines/gridlines"; |
19 | | -import {hardLimitZeroPadding} from "../d3fc/padding/hardLimitZero"; |
20 | | -import zoomableChart from "../zoom/zoomableChart"; |
21 | | - |
22 | | -function xyScatter(container, settings) { |
23 | | - const data = pointData(settings, filterDataByGroup(settings)); |
24 | | - const symbols = symbolTypeFromGroups(settings); |
25 | | - const useGroupColours = settings.mainValues.length <= 2; |
26 | | - let colour = null; |
27 | | - let legend = null; |
28 | | - |
29 | | - if (useGroupColours) { |
30 | | - colour = seriesColoursFromGroups(settings); |
31 | | - |
32 | | - legend = symbolLegend() |
33 | | - .settings(settings) |
34 | | - .scale(symbols) |
35 | | - .colour(useGroupColours ? colour : null); |
36 | | - } else { |
37 | | - colour = seriesColourRange(settings, data, "colorValue"); |
38 | | - legend = colourRangeLegend().scale(colour); |
39 | | - } |
40 | | - |
41 | | - const size = settings.mainValues.length > 3 ? seriesLinearRange(settings, data, "size").range([10, 10000]) : null; |
42 | | - |
43 | | - const series = fc |
44 | | - .seriesSvgMulti() |
45 | | - .mapping((data, index) => data[index]) |
46 | | - .series(data.map(series => pointSeries(settings, series.key, size, colour, symbols))); |
47 | | - |
48 | | - const domainDefault = () => mainAxis.domain(settings).paddingStrategy(hardLimitZeroPadding().pad([0.1, 0.1])); |
49 | | - |
50 | | - const xScale = mainAxis.scale(settings); |
51 | | - const yScale = mainAxis.scale(settings); |
52 | | - |
53 | | - const chart = fc |
54 | | - .chartSvgCartesian(xScale, yScale) |
55 | | - .xDomain(domainDefault().valueName("x")(data)) |
56 | | - .xLabel(settings.mainValues[0].name) |
57 | | - .yDomain(domainDefault().valueName("y")(data)) |
58 | | - .yLabel(settings.mainValues[1].name) |
59 | | - .yOrient("left") |
60 | | - .yNice() |
61 | | - .xNice() |
62 | | - .plotArea(withGridLines(series)); |
63 | | - |
64 | | - const zoomChart = zoomableChart() |
65 | | - .chart(chart) |
66 | | - .settings(settings) |
67 | | - .xScale(xScale) |
68 | | - .yScale(yScale); |
69 | | - |
70 | | - // render |
71 | | - container.datum(data).call(zoomChart); |
72 | | - if (legend) container.call(legend); |
73 | | -} |
74 | | -xyScatter.plugin = { |
75 | | - type: "d3_xy_scatter", |
76 | | - name: "[d3fc] X/Y Scatter", |
77 | | - max_size: 25000, |
78 | | - initial: { |
79 | | - type: "number", |
80 | | - count: 2 |
81 | | - } |
82 | | -}; |
83 | | - |
84 | | -export default xyScatter; |
| 1 | +/****************************************************************************** |
| 2 | + * |
| 3 | + * Copyright (c) 2017, the Perspective Authors. |
| 4 | + * |
| 5 | + * This file is part of the Perspective library, distributed under the terms of |
| 6 | + * the Apache License 2.0. The full license can be found in the LICENSE file. |
| 7 | + * |
| 8 | + */ |
| 9 | +import * as fc from "d3fc"; |
| 10 | +import * as mainAxis from "../axis/mainAxis"; |
| 11 | +import {pointSeriesCanvas, symbolTypeFromGroups} from "../series/pointSeriesCanvas"; |
| 12 | +import {pointData} from "../data/pointData"; |
| 13 | +import {seriesColoursFromGroups} from "../series/seriesColours"; |
| 14 | +import {seriesLinearRange, seriesColourRange} from "../series/seriesRange"; |
| 15 | +import {symbolLegend} from "../legend/legend"; |
| 16 | +import {colourRangeLegend} from "../legend/colourRangeLegend"; |
| 17 | +import {filterDataByGroup} from "../legend/filter"; |
| 18 | +import {withCanvasGridLines} from "../gridlines/gridlines"; |
| 19 | +import {hardLimitZeroPadding} from "../d3fc/padding/hardLimitZero"; |
| 20 | +import zoomableChart from "../zoom/zoomableChart"; |
| 21 | +import nearbyTip from "../tooltip/nearbyTip"; |
| 22 | + |
| 23 | +function xyScatter(container, settings) { |
| 24 | + const data = pointData(settings, filterDataByGroup(settings)); |
| 25 | + const symbols = symbolTypeFromGroups(settings); |
| 26 | + const useGroupColours = settings.mainValues.length <= 2; |
| 27 | + let colour = null; |
| 28 | + let legend = null; |
| 29 | + |
| 30 | + if (useGroupColours) { |
| 31 | + colour = seriesColoursFromGroups(settings); |
| 32 | + |
| 33 | + legend = symbolLegend() |
| 34 | + .settings(settings) |
| 35 | + .scale(symbols) |
| 36 | + .colour(useGroupColours ? colour : null); |
| 37 | + } else { |
| 38 | + colour = seriesColourRange(settings, data, "colorValue"); |
| 39 | + legend = colourRangeLegend().scale(colour); |
| 40 | + } |
| 41 | + |
| 42 | + const size = settings.mainValues.length > 3 ? seriesLinearRange(settings, data, "size").range([10, 10000]) : null; |
| 43 | + |
| 44 | + const series = fc |
| 45 | + .seriesCanvasMulti() |
| 46 | + .mapping((data, index) => data[index]) |
| 47 | + .series(data.map(series => pointSeriesCanvas(settings, series.key, size, colour, symbols))); |
| 48 | + |
| 49 | + const domainDefault = () => mainAxis.domain(settings).paddingStrategy(hardLimitZeroPadding().pad([0.1, 0.1])); |
| 50 | + |
| 51 | + const xScale = mainAxis.scale(settings); |
| 52 | + const yScale = mainAxis.scale(settings); |
| 53 | + |
| 54 | + const chart = fc |
| 55 | + .chartCanvasCartesian(xScale, yScale) |
| 56 | + .xDomain(domainDefault().valueName("x")(data)) |
| 57 | + .xLabel(settings.mainValues[0].name) |
| 58 | + .yDomain(domainDefault().valueName("y")(data)) |
| 59 | + .yLabel(settings.mainValues[1].name) |
| 60 | + .yOrient("left") |
| 61 | + .yNice() |
| 62 | + .xNice() |
| 63 | + .plotArea(withCanvasGridLines(series)); |
| 64 | + |
| 65 | + const zoomChart = zoomableChart() |
| 66 | + .chart(chart) |
| 67 | + .settings(settings) |
| 68 | + .xScale(xScale) |
| 69 | + .yScale(yScale) |
| 70 | + .canvas(true); |
| 71 | + |
| 72 | + const toolTip = nearbyTip() |
| 73 | + .chart(chart) |
| 74 | + .settings(settings) |
| 75 | + .canvas(true) |
| 76 | + .xScale(xScale) |
| 77 | + .xValueName("x") |
| 78 | + .yValueName("y") |
| 79 | + .yScale(yScale) |
| 80 | + .colour(useGroupColours && colour) |
| 81 | + .data(data); |
| 82 | + container.call(toolTip); |
| 83 | + |
| 84 | + // render |
| 85 | + container.datum(data).call(zoomChart); |
| 86 | + if (legend) container.call(legend); |
| 87 | +} |
| 88 | +xyScatter.plugin = { |
| 89 | + type: "d3_xy_scatter", |
| 90 | + name: "[d3fc] X/Y Scatter", |
| 91 | + max_size: 25000, |
| 92 | + initial: { |
| 93 | + type: "number", |
| 94 | + count: 2 |
| 95 | + } |
| 96 | +}; |
| 97 | + |
| 98 | +export default xyScatter; |
0 commit comments