Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D3fc plugin - Basic OHLC and Candlestick charts #488

Merged
merged 64 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
c831f18
Tooltips for line charts
Mar 8, 2019
b7727fb
remove duplicate withOutOpacity method from seriesColours
Mar 8, 2019
1807f26
Merge pull request #85 from redbearsam/remove_duplicate_method
matt-hooper Mar 11, 2019
daa8234
Refactored tooltips into cartesian-chart component
Mar 11, 2019
3818fd7
Only apply XY colour for category colours
Mar 12, 2019
4d10af7
Default highlight colour
Mar 12, 2019
c31da4e
Merge pull request #86 from redbearsam/feature/tooltip_refactor
matt-hooper Mar 12, 2019
48d092e
Updated d3fc and replaced local cartesianSvgChart
Mar 11, 2019
5958468
Fixed problem with non-rotated labels
Mar 12, 2019
7e520a0
Fix non-category axis bug
Mar 12, 2019
6f17306
Updated test results
Mar 12, 2019
67442a6
Fixed merge error
Mar 12, 2019
c724cae
Merge pull request #87 from redbearsam/feature/d3fc-new-chart
matt-hooper Mar 12, 2019
1d83355
Add tooltips for Area charts
Mar 12, 2019
3b00eec
Removed old SVG X/Y chart and replace with the Canvas one (#88)
Mar 12, 2019
c7c8032
Fixed some MS-Edge issues (#90)
Mar 12, 2019
84eb792
Merge pull request #89 from redbearsam/feature/area_tooltip
matt-hooper Mar 12, 2019
133e0d9
replace colour references with color
Mar 12, 2019
d5709ed
Merge pull request #91 from redbearsam/feature/colorize
matt-hooper Mar 12, 2019
f78c419
Improved and simplified nearby-tooltip code and used on y-scatter
Mar 12, 2019
e83c254
Use extentLinear to pad domain
Ro4052 Mar 12, 2019
4e3402b
Merge pull request #92 from redbearsam/feature/improve-nearby-tip
Mar 13, 2019
4d73fb5
Refactored tooltip html generation
Ro4052 Mar 13, 2019
56acea1
Converted formatNumber to arrow function
Ro4052 Mar 13, 2019
556b2a5
Removed unused filter
Ro4052 Mar 13, 2019
53e308f
Fixed tooltip for line charts
Ro4052 Mar 13, 2019
7ae689e
Slight refactor to generateHtml
Ro4052 Mar 13, 2019
89bedf4
Fixed tooltip for data values
Ro4052 Mar 13, 2019
432ca4f
Fixed tooltip for xy with split
Ro4052 Mar 13, 2019
7345081
Merge pull request #96 from redbearsam/fix/line-bar-tip
matt-hooper Mar 13, 2019
3147906
basic OHLC chart
Mar 13, 2019
710d253
add tooltip for ohlc
Mar 13, 2019
c372d49
Add vertical and horizontal zoom
Mar 13, 2019
aea2174
Added candlestick chart
Ro4052 Mar 14, 2019
aee8d31
Merge pull request #97 from redbearsam/feature/candlestick
matt-hooper Mar 14, 2019
3f949d7
Ohlc/candlestick charts default to 4 values
Ro4052 Mar 14, 2019
3f097f0
basic OHLC chart
Mar 13, 2019
c4f1f86
add tooltip for ohlc
Mar 13, 2019
1813063
Add vertical and horizontal zoom
Mar 13, 2019
073fd92
Added candlestick chart
Ro4052 Mar 14, 2019
bba217b
Ohlc/candlestick charts default to 4 values
Ro4052 Mar 14, 2019
360be4e
refactor less file
Mar 14, 2019
de180aa
add support for just two values (open/close) and infer the high/low f…
Mar 14, 2019
bc31642
ohlc support split-by
Mar 15, 2019
f8cbfd0
rebase and merge
Mar 15, 2019
7e3d29b
Updated d3fc and used its new ordinalAxis
Mar 15, 2019
87f32fc
Merge pull request #99 from redbearsam/feature/d3fc-ordinal
matt-hooper Mar 15, 2019
2a4aa79
replace lowerValueName and upperValueName with valueNames
matt-hooper Mar 15, 2019
8a32668
Add an OHLC example to the simple examples folder
matt-hooper Mar 15, 2019
8084948
Merge pull request #95 from redbearsam/feature/ohlc
matt-hooper Mar 15, 2019
0449c1c
remove unnecessary slice
matt-hooper Mar 18, 2019
9ecef29
Merge pull request #101 from redbearsam/fix/missing_tooltip_value
matt-hooper Mar 18, 2019
615db26
Add upColors and downColors to series
matt-hooper Mar 18, 2019
ef12186
Merge pull request #104 from redbearsam/develop
matt-hooper Mar 18, 2019
c1fc975
update perspective-viewer-d3fc/test/results
matt-hooper Mar 19, 2019
7bd2e35
Merge pull request #105 from redbearsam/fix/screenshots
matt-hooper Mar 19, 2019
7ba7e5e
Merge pull request #106 from redbearsam/develop
matt-hooper Mar 19, 2019
028ac30
use opacity to distinguish up and down on multi-series version
matt-hooper Mar 19, 2019
6f00972
Merge branch 'develop' of https://github.com/redbearsam/perspective i…
matt-hooper Mar 19, 2019
253daec
add legend
matt-hooper Mar 19, 2019
b476aa2
replaced seriesSvgRepeat with seriesSvgMulti to resolve issue where d…
matt-hooper Mar 19, 2019
1130587
update legend to support on-click hide functionality
matt-hooper Mar 19, 2019
bf4ab7c
Merge pull request #102 from redbearsam/feature/color_ohlc
matt-hooper Mar 19, 2019
567dfaf
Merge pull request #107 from redbearsam/develop
matt-hooper Mar 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improved and simplified nearby-tooltip code and used on y-scatter
It turns out we don't actually need to use copies of the scales, and therefore can avoid decorating the chart object to get the "measure" (though this approach does require calling the "toolTip" component after the chart has been rendered. This allows us to simplify the code quite a lot.
Also:
* rebind `settings` and other properties from base tooltip component
* added `size` option for controlling highlight sizing (though the "range" has to be modified because the symbol size behaviour isn't the same as the circle radius behaviour)
* Use nearby-tooltip for the y-scatter chart, since it's a better experience
  • Loading branch information
Andy committed Mar 12, 2019
commit f78c4198142d412de52ae04d3d84f5836e167805
3 changes: 1 addition & 2 deletions packages/perspective-viewer-d3fc/src/js/charts/area.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,15 @@ function areaChart(container, settings) {
.xScale(xScale);

const toolTip = nearbyTip()
.chart(chart)
.settings(settings)
.xScale(xScale)
.yScale(yScale)
.color(color)
.data(data);
container.call(toolTip);

// render
container.datum(data).call(zoomChart);
container.call(toolTip);
container.call(legend);
}
areaChart.plugin = {
Expand Down
3 changes: 1 addition & 2 deletions packages/perspective-viewer-d3fc/src/js/charts/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,15 @@ function lineChart(container, settings) {
.xScale(xScale);

const toolTip = nearbyTip()
.chart(chart)
.settings(settings)
.xScale(xScale)
.yScale(yScale)
.color(color)
.data(data);
container.call(toolTip);

// render
container.datum(data).call(zoomChart);
container.call(toolTip);
container.call(legend);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/perspective-viewer-d3fc/src/js/charts/xy-scatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ function xyScatter(container, settings) {
.canvas(true);

const toolTip = nearbyTip()
.chart(chart)
.settings(settings)
.canvas(true)
.xScale(xScale)
.xValueName("x")
.yValueName("y")
.yScale(yScale)
.color(useGroupColors && color)
.size(size)
.data(data);
container.call(toolTip);

// render
container.datum(data).call(zoomChart);
container.call(toolTip);
if (legend) container.call(legend);
}
xyScatter.plugin = {
Expand Down
12 changes: 11 additions & 1 deletion packages/perspective-viewer-d3fc/src/js/charts/y-scatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {filterData} from "../legend/filter";
import {withGridLines} from "../gridlines/gridlines";
import {hardLimitZeroPadding} from "../d3fc/padding/hardLimitZero";
import zoomableChart from "../zoom/zoomableChart";
import nearbyTip from "../tooltip/nearbyTip";

function yScatter(container, settings) {
const data = groupData(settings, filterData(settings));
Expand All @@ -40,11 +41,12 @@ function yScatter(container, settings) {
const xDomain = crossAxis.domain(settings)(data);
const xScale = crossAxis.scale(settings);
const xAxis = crossAxis.axisFactory(settings).domain(xDomain)();
const yScale = mainAxis.scale(settings);

const chart = fc
.chartSvgCartesian({
xScale,
yScale: mainAxis.scale(settings),
yScale,
xAxis
})
.xDomain(xDomain)
Expand All @@ -65,8 +67,16 @@ function yScatter(container, settings) {
.settings(settings)
.xScale(xScale);

const toolTip = nearbyTip()
.settings(settings)
.xScale(xScale)
.yScale(yScale)
.color(color)
.data(data);

// render
container.datum(data).call(zoomChart);
container.call(toolTip);
if (legend) {
container.call(legend);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function barSeries(settings, color) {
let series = settings.mainValues.length > 1 ? fc.seriesSvgGrouped(fc.seriesSvgBar()) : fc.seriesSvgBar();

series = series.decorate(selection => {
tooltip()(selection, settings);
tooltip().settings(settings)(selection);
if (color) {
selection.style("fill", d => color(d.key));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*
*/
import * as fc from "d3fc";
import {tooltip} from "../tooltip/tooltip";
import {withOpacity, withoutOpacity} from "./seriesColors";
import {fromDomain} from "./seriesSymbols";

Expand All @@ -19,7 +18,6 @@ export function categoryPointSeries(settings, seriesKey, color, symbols) {
}

series.decorate(selection => {
tooltip()(selection, settings);
if (color) {
selection.style("stroke", d => withoutOpacity(color(d.colorValue || seriesKey))).style("fill", d => withOpacity(color(d.colorValue || seriesKey)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export function heatmapSeries(settings, color) {
let series = fc.seriesSvgHeatmap();

series.decorate(selection => {
tooltip().generateHtml(generateHtmlForHeatmap)(selection, settings);
tooltip()
.generateHtml(generateHtmlForHeatmap)
.settings(settings)(selection);
});

return fc
Expand Down
54 changes: 18 additions & 36 deletions packages/perspective-viewer-d3fc/src/js/tooltip/nearbyTip.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,23 @@
*
*/

import * as d3 from "d3";
import * as fc from "d3fc";
import {chainCallback} from "../utils/utils";
import {tooltip} from "./tooltip";
import {withOpacity} from "../series/seriesColors.js";
import {findBestFromData} from "../data/findBest";

export default () => {
let chart = null;
let settings = null;
const base = tooltip().alwaysShow(true);

let xScale = null;
let xCopy = null;
let yScale = null;
let yCopy = null;
let color = null;
let size = null;
let canvas = false;
let data = null;
let xValueName = "crossValue";
let yValueName = "mainValue";

const showTooltip = tooltip().alwaysShow(true);

function nearbyTip(selection) {
const chartPlotArea = `d3fc-${canvas ? "canvas" : "svg"}.plot-area`;
if (xScale || yScale) {
Expand All @@ -38,14 +33,10 @@ export default () => {
renderTip(selection, tooltipData);
});

chainCallback(chart.decorate, sel => {
sel.select(chartPlotArea)
.on("measure.nearby-tip", () => {
if (xCopy) xCopy.range([0, d3.event.detail.width]);
if (yCopy) yCopy.range([0, d3.event.detail.height]);
})
.call(pointer);
});
selection
.select(chartPlotArea)
.on("measure.nearbyTip", () => renderTip(selection, []))
.call(pointer);
}
}

Expand All @@ -59,13 +50,13 @@ export default () => {
tips.enter()
.append("circle")
.attr("class", "nearbyTip")
.attr("r", 10)
.merge(tips)
.attr("r", d => (size ? Math.sqrt(size(d.size)) : 10))
.attr("transform", d => `translate(${xScale(d[xValueName])},${yScale(d[yValueName])})`)
.style("stroke", "none")
.style("fill", d => color && withOpacity(color(d.key)));

showTooltip(tips, settings);
base(tips);
};

const getClosestDataPoint = pos => {
Expand All @@ -80,28 +71,11 @@ export default () => {
);
};

nearbyTip.chart = (...args) => {
if (!args.length) {
return chart;
}
chart = args[0];
return nearbyTip;
};

nearbyTip.settings = (...args) => {
if (!args.length) {
return settings;
}
settings = args[0];
return nearbyTip;
};

nearbyTip.xScale = (...args) => {
if (!args.length) {
return xScale;
}
xScale = args[0];
xCopy = xScale ? xScale.copy() : null;
return nearbyTip;
};

Expand All @@ -110,7 +84,6 @@ export default () => {
return yScale;
}
yScale = args[0];
yCopy = yScale ? yScale.copy() : null;
return nearbyTip;
};

Expand All @@ -122,6 +95,14 @@ export default () => {
return nearbyTip;
};

nearbyTip.size = (...args) => {
if (!args.length) {
return size;
}
size = args[0] ? args[0].copy().range([40, 4000]) : null;
return nearbyTip;
};

nearbyTip.canvas = (...args) => {
if (!args.length) {
return canvas;
Expand Down Expand Up @@ -154,5 +135,6 @@ export default () => {
return nearbyTip;
};

fc.rebindAll(nearbyTip, base);
return nearbyTip;
};
11 changes: 10 additions & 1 deletion packages/perspective-viewer-d3fc/src/js/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ export const tooltip = () => {
let generateHtml = generateHtmlDefault;
let alwaysShow = false;
let tooltipDiv = null;
let settings = null;

const _tooltip = (selection, settings) => {
const _tooltip = selection => {
const node = selection.node();

if (!node || !node.isConnected) {
Expand Down Expand Up @@ -56,6 +57,14 @@ export const tooltip = () => {
return _tooltip;
};

_tooltip.settings = (...args) => {
if (!args.length) {
return settings;
}
settings = args[0];
return _tooltip;
};

return _tooltip;
};

Expand Down
8 changes: 0 additions & 8 deletions packages/perspective-viewer-d3fc/src/js/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,3 @@ export function getOrCreateElement(container, selector, createCallback) {
let element = container.select(selector);
return element.size() > 0 ? element : createCallback();
}

export const chainCallback = (property, fn) => {
const oldFn = property();
property((...args) => {
if (oldFn) oldFn(...args);
fn(...args);
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import * as d3 from "d3";
import {getOrCreateElement} from "../utils/utils";
import template from "../../html/zoom-controls.html";
import {chainCallback} from "../utils/utils";

export default () => {
let chart = null;
Expand Down Expand Up @@ -46,7 +45,7 @@ export default () => {
});
});

chainCallback(chart.decorate, sel => {
chart.decorate(sel => {
if (!bound) {
bound = true;
// add the zoom interaction on the enter selection
Expand Down