Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/Chart/api/subchart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const subchart = function<T = TDomain[]>(domainValue?: T): T | undefined {

if (Array.isArray(domain)) {
domain = axis.isTimeSeries() ? domain.map(x => parseDate.bind($$)(x)) : domain;
domain = $$.setCanvasSubchartDomain(domain) || state.domain;
domain = $$.setCanvasSubchartDomain?.(domain) || state.domain;
} else {
domain = state.domain ?? x.orgDomain();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Chart/api/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const tooltip = {
const {
$el,
config,
state: {customType, eventReceiver, hasFunnel, hasTreemap, inputType, isCanvasMode}
state: {customType, eventReceiver, hasTreemap, inputType, isCanvasMode}
} = $$;
let index;
let mouse;
Expand All @@ -99,7 +99,7 @@ const tooltip = {
const {data} = args;
const y = $$.getYScaleById(data.id)?.(data.value);

if ((customType || hasFunnel || hasTreemap) && data.id) {
if ((customType || hasTreemap) && data.id) {
// canvas has no shape elements: the tooltip is resolved from the data below
if (!isCanvasMode) {
eventReceiver.rect = $el.main.select(
Expand Down
58 changes: 35 additions & 23 deletions src/ChartInternal/ChartInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Options from "../config/Options/Options";
import Store from "../config/Store/Store";
import {document, window} from "../module/browser";
import Cache from "../module/Cache";
import {checkModuleImport} from "../module/error";
import {checkModuleImport, getTypeMethod} from "../module/error";
import {generateResize} from "../module/generator";
import {
callFn,
Expand Down Expand Up @@ -81,17 +81,23 @@ function getUnsupportedCanvasRenderType($$): string | null {
return "arc charts";
}

if ($$.hasType("funnel")) {
return "funnel chart";
}
if ($$.state.customType) {
// the type tells it by itself when it is drawn by svg only
const unsupported = $$.customTypeHooks?.canvasUnsupported;

if (unsupported) {
return unsupported;
}

// a type of its own module is drawn on canvas by the canvas part of that module:
// there is nothing to draw it when only the svg part was imported
if ($$.state.customType && !$$.drawCustomTypeOnCanvas) {
return `${$$.state.customType} chart without its canvas module`;
// otherwise it is drawn on canvas by the canvas part of its module:
// there is nothing to draw it when only the svg part was imported
if (!$$.getCustomTypeParts()?.canvas) {
return `${$$.state.customType} chart without its canvas module`;
}
}

return null;
// the types drawn by canvas parts, which only the canvas module knows
return $$.getUnsupportedCanvasPart?.() ?? null;
}

/**
Expand Down Expand Up @@ -244,23 +250,33 @@ export default class ChartInternal {
callFn($$.config.onafterinit, $$.api);
}

/**
* The hooks of the module of the custom type of the chart (see registerCustomType()).
* @private
*/
get customTypeHooks() {
const $$ = <any>this;

// (reading it from the prototype, which has no state, is not an error)
return $$.state && $$.getCustomTypeParts()?.hooks;
}

init(): void {
const $$ = <any>this;
const {config, state, $el} = $$;
const {boost_useCssRule, bindto} = config;

// set by the module of a type that is neither axis based nor built in:
// the import check needs it to tell a type whose module is there
state.customType = $$.getCustomType?.() ?? null;
state.customType = $$.getCustomType();

checkModuleImport($$);
fallbackUnsupportedCanvasRenderMode($$);

const hasArcType = $$.hasArcType();
state.hasRadar = !state.hasAxis && $$.hasType("radar");
state.hasFunnel = !state.hasAxis && $$.hasType("funnel");
state.hasTreemap = !state.hasAxis && $$.hasType("treemap");
state.hasAxis = !hasArcType && !state.customType && !state.hasFunnel && !state.hasTreemap;
state.hasAxis = !hasArcType && !state.customType && !state.hasTreemap;

// datetime to be used for uniqueness
state.datetimeId = `bb-${+new Date() * (getRandom() as number)}`;
Expand Down Expand Up @@ -364,7 +380,7 @@ export default class ChartInternal {
}

if (config.render_mode !== "canvas" && ($$.hasPointType() || $$.hasLegendDefsPoint?.())) {
$$.point = $$.generatePoint();
$$.point = getTypeMethod($$, "generatePoint").call($$);
}

if (state.hasAxis) {
Expand Down Expand Up @@ -415,7 +431,7 @@ export default class ChartInternal {
initWithData(data): void {
const $$ = <any>this;
const {config, scale, state, $el, org} = $$;
const {customType, hasAxis, hasFunnel, hasTreemap} = state;
const {customType, hasAxis, hasTreemap} = state;
const hasInteraction = config.interaction_enabled;
const hasPolar = $$.hasType("polar");
const labelsBGColor = config.data_labels_backgroundColors;
Expand Down Expand Up @@ -574,8 +590,7 @@ export default class ChartInternal {
// Define regions
const main = $el.svg.append("g")
.classed($COMMON.main, true)
.attr("transform",
customType || hasFunnel || hasTreemap ? null : $$.getTranslate("main"));
.attr("transform", customType || hasTreemap ? null : $$.getTranslate("main"));

$el.main = main;

Expand Down Expand Up @@ -682,8 +697,6 @@ export default class ChartInternal {
}
} else if (hasTreemap) {
types.push("Treemap");
} else if ($$.hasType("funnel")) {
types.push("Funnel");
} else if ($$.state.customType) {
types.push(capitalize($$.state.customType));
} else {
Expand All @@ -704,7 +717,7 @@ export default class ChartInternal {
}

for (const type of types) {
$$[`init${type}`]();
getTypeMethod($$, `init${type}`).call($$);
}

if (notEmpty($$.config.data_labels) && !$$.hasArcType(null, ["radar"])) {
Expand Down Expand Up @@ -797,9 +810,10 @@ export default class ChartInternal {
*/
updateTargets(targets): void {
const $$ = <any>this;
const {customType, hasAxis, hasFunnel, hasRadar, hasTreemap} = $$.state;
const {customType, hasAxis, hasRadar, hasTreemap} = $$.state;
const helper = type =>
$$[`updateTargetsFor${type}`](
getTypeMethod($$, `updateTargetsFor${type}`).call(
$$,
targets.filter($$[`is${type}Type`].bind($$))
);

Expand Down Expand Up @@ -829,8 +843,6 @@ export default class ChartInternal {
}

helper(type);
} else if (hasFunnel) {
helper("Funnel");
} else if (customType) {
helper(capitalize(customType));
} else if (hasTreemap) {
Expand Down
4 changes: 2 additions & 2 deletions src/ChartInternal/data/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ export default {
// Remove targets
$$.data.targets = $$.data.targets.filter(t => !unloadIds.has(t.id));

// since treemap uses different data types, it needs to be transformed
state.hasFunnel && $$.updateFunnel($$.data.targets);
// a type of its own module can need its data to be transformed
$$.customTypeHooks?.afterUnload?.($$);

// since treemap uses different data types, it needs to be transformed
state.hasTreemap && $$.updateTargetsForTreemap($$.data.targets);
Expand Down
15 changes: 7 additions & 8 deletions src/ChartInternal/interactions/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default {
*/
setOverOut(isOver: boolean, d: number | IArcDataRow): void {
const $$ = this;
const {config, state: {customType, hasFunnel, hasRadar, hasTreemap}, $el: {main}} = $$;
const {config, state: {customType, hasRadar, hasTreemap}, $el: {main}} = $$;
const isArcishData = isObject(d);

// Call event handler
Expand All @@ -74,7 +74,7 @@ export default {

if (isArcishData) {
const suffix = $$.getTargetSelectorSuffix((d as IArcDataRow).id);
const selector = customType || hasFunnel || hasTreemap ?
const selector = customType || hasTreemap ?
`${$COMMON.target + suffix} .${$SHAPE.shape}` :
$ARC.arc + suffix;

Expand Down Expand Up @@ -188,14 +188,13 @@ export default {
eventReceiver,
hasAxis,
customType,
hasFunnel,
hasRadar,
hasTreemap
},
$el: {eventRect, funnel, radar, svg, treemap}
$el: {eventRect, radar, svg, treemap}
} = $$;
let element = (
((customType || hasFunnel || hasTreemap) && eventReceiver.rect) ||
((customType || hasTreemap) && eventReceiver.rect) ||
(hasRadar && radar.axes.select(`.${$AXIS.axis}-${index} text`)) || (
eventRect || $$.getArcElementByIdOrIndex?.(index)
)
Expand Down Expand Up @@ -243,9 +242,9 @@ export default {
bubbles: hasRadar // radar type needs to bubble up event
};

// for custom type, funnel and treemap event bound to <g> node
if (customType || hasFunnel || hasTreemap) {
element = ($$.$el[customType as string] ?? funnel ?? treemap).node();
// for custom type and treemap event bound to <g> node
if (customType || hasTreemap) {
element = ($$.$el[customType as string] ?? treemap).node();
}

emulateEvent[/^(mouse|click)/.test(type) ? "mouse" : "touch"](
Expand Down
5 changes: 3 additions & 2 deletions src/ChartInternal/internals/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ export default {
* Get class string
* @param {string} type Shape type
* @param {boolean} withShape Get with shape prefix
* @param {boolean} useId Use the id of the data as the key of the class, as the types of the group
* @returns {string} Class string
* @private
*/
getClass(type: string, withShape: boolean): Function {
getClass(type: string, withShape: boolean, useId?: boolean): Function {
const isPlural = /s$/.test(type);
const useIdKey = /^(area|arc|line|funnel|treemap)s?$/.test(type);
const useIdKey = useId ?? /^(area|arc|line|treemap)s?$/.test(type);
const key = isPlural ? "id" : "index";

return (d): string => {
Expand Down
3 changes: 0 additions & 3 deletions src/ChartInternal/internals/redraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ export default {
// polar
$el.polar && $$.redrawPolar();

// funnel
$el.funnel && $$.redrawFunnel();

// custom type
state.customType && $$[`redraw${capitalize(state.customType)}`](wth.Transition);

Expand Down
7 changes: 3 additions & 4 deletions src/ChartInternal/internals/size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,7 @@ export default {
const $$ = this;
const {config, state, $el: {legend}} = $$;
const isRotated = config.axis_rotated;
const isNonAxis = $$.hasArcType() || state.customType || state.hasFunnel ||
state.hasTreemap;
const isNonAxis = $$.hasArcType() || state.customType || state.hasTreemap;
const isFitPadding = config.padding?.mode === "fit";

!isInit && $$.setContainerSize();
Expand Down Expand Up @@ -580,8 +579,8 @@ export default {
$$.updateRadius?.();
}

// arc types center their legend by the arc size: a custom type places it beside its own plot
if (state.isLegendRight && isNonAxis && !state.customType) {
// arc types center their legend by the arc size: a custom type can place it beside its own plot
if (state.isLegendRight && isNonAxis && !$$.customTypeHooks?.ownLegendLayout) {
state.margin3.left = state.arcWidth / 2 + state.radiusExpanded * 1.1;
}
}
Expand Down
33 changes: 6 additions & 27 deletions src/ChartInternal/internals/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
capitalize,
getBBox,
getBoundingRect,
getElementPos,
getRandom,
getTranslation,
isFunction,
Expand Down Expand Up @@ -52,7 +51,7 @@ export default {

$el.main.select(`.${$COMMON.chart}`).append("g")
.attr("class", $TEXT.chartTexts)
.style("pointer-events", state.customType || $el.funnel || $el.treemap ? "none" : null);
.style("pointer-events", state.customType || $el.treemap ? "none" : null);
},

/**
Expand Down Expand Up @@ -164,7 +163,7 @@ export default {
const labelColors = config.data_labels_colors;
const defaultColor =
($$.isArcType(d) && !$$.isRadarType(d)) || $$.getCustomTypeHooks(d)?.themeTextColor ||
$$.isFunnelType(d) || $$.isTreemapType(d) ?
$$.isTreemapType(d) ?
null :
$$.color(d);
let color;
Expand Down Expand Up @@ -373,13 +372,12 @@ export default {
generateXYForText(indices,
forX?: boolean): (d, i, labelDimension?: TTextLabelDimension) => number {
const $$ = this;
const {state: {customType, hasRadar, hasFunnel, hasTreemap}} = $$;
const {state: {customType, hasRadar, hasTreemap}} = $$;
const types = Object.keys(indices);
const points = {};
const getter = forX ? $$.getXForText : $$.getYForText;

customType && types.push(customType);
hasFunnel && types.push("funnel");
hasRadar && types.push("radar");
hasTreemap && types.push("treemap");

Expand All @@ -392,7 +390,6 @@ export default {
($$.isBarType(d) && "bar") ||
(customType && $$.isTypeOf(d, customType) && customType) ||
($$.isCandlestickType(d) && "candlestick") ||
($$.isFunnelType(d) && "funnel") ||
($$.isRadarType(d) && "radar") ||
($$.isTreemapType(d) && "treemap") || "line";

Expand Down Expand Up @@ -469,29 +466,20 @@ export default {
const $$ = this;
const {config} = $$;
const isRotated = config.axis_rotated;
const isFunnelType = $$.isFunnelType(d);
const isTreemapType = $$.isTreemapType(d);

let xPos = points ? points[0][0] : 0;

const custom = $$.getCustomTypeHooks(d);

if (custom) {
return custom.textX($$, points, d, textElement);
return custom.textX($$, points, d, textElement, labelDimension);
} else if ($$.isCandlestickType(d)) {
if (isRotated) {
xPos = $$.getCandlestickData(d)?._isUp ? points[2][2] + 4 : points[2][1] - 4;
} else {
xPos += (points[1][0] - xPos) / 2;
}
} else if (isFunnelType) {
// Use pre-calculated center x from points[2]
// Preserve current position when points unavailable (during hide transition)
if (points) {
xPos = points[2]?.[0] ?? xPos;
} else {
return getElementPos(textElement, "x");
}
} else if (isTreemapType) {
xPos += config.data_labels.centered ? 0 : 5;
} else {
Expand All @@ -507,7 +495,7 @@ export default {
}
}

if (isRotated || isTreemapType || isFunnelType) {
if (isRotated || isTreemapType) {
xPos += $$.getCenteredTextPos(d, points, textElement, "x", labelDimension);
}

Expand All @@ -529,7 +517,6 @@ export default {
const isRotated = config.axis_rotated;
const isInverted = config[`axis_${axis?.getId(d.id)}_inverted`];
const isBarType = $$.isBarType(d);
const isFunnelType = $$.isFunnelType(d);
const isTreemapType = $$.isTreemapType(d);
const r = config.point_r;
const rect = labelDimension?.rect || getBoundingRect(textElement);
Expand All @@ -540,7 +527,7 @@ export default {
const custom = $$.getCustomTypeHooks(d);

if (custom) {
return custom.textY($$, points, d, textElement, rect);
return custom.textY($$, points, d, textElement, rect, labelDimension);
} else if ($$.isCandlestickType(d)) {
value = $$.getCandlestickData(d);

Expand All @@ -554,14 +541,6 @@ export default {
yPos += 15 * (value._isUp ? 1 : -1);
}
}
} else if (isFunnelType) {
// Use pre-calculated center y from points[2]
// Preserve current position when points unavailable (during hide transition)
if (points) {
yPos = (points[2]?.[1] ?? points[0][1]) + rect.height / 2 - 3;
} else {
return getElementPos(textElement, "y");
}
} else if (isTreemapType) {
yPos = points[0][1] + (config.data_labels.centered ? 0 : rect.height + 5);
} else {
Expand Down
Loading
Loading