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

feat(polar): Intent to ship polar type #2462

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8a8de95
feat(polar): implement basicpolar area feature (#12)
Nov 21, 2021
d911cc3
feat(polar): support max size of polar chart
Justin-Moon Dec 6, 2021
855d215
feat(polar): implement mouse hover events and show level line behind …
HanungLee Dec 7, 2021
b5da68d
feat(polar): support options for polar chart level (#24)
cmpark0126 Dec 7, 2021
b97dab0
Feat(polar): add demo for polar chert options (#25)
cmpark0126 Dec 7, 2021
e478e79
docs(polar): fix doc for polar chart option (#26)
cmpark0126 Dec 7, 2021
7ac656c
feat(polar): add multiple options related to angle, padding (#27)
cmpark0126 Dec 7, 2021
8d46289
refactor(polar): refactor polar padding logic (#28)
cmpark0126 Dec 7, 2021
3a2b4e2
test(polar): add tests for default polar chart (#29)
cmpark0126 Dec 8, 2021
5c243c9
refactor(polar): refactor redraw method for polar chart (#33)
cmpark0126 Dec 8, 2021
9313931
skip: add new demo link (#34)
cmpark0126 Dec 8, 2021
7510b67
skip: convert indentation to space
cmpark0126 Dec 14, 2021
73f5726
test(polar): pass unpassed test cases
cmpark0126 Dec 21, 2021
c07fa2e
feat(polar): type definition for polar options
cmpark0126 Dec 21, 2021
fdedda9
skip: follow lint
cmpark0126 Dec 21, 2021
8a44e10
skip: fix typo
cmpark0126 Dec 21, 2021
a6be8b0
feat(polar): updating level text dynamically
cmpark0126 Dec 21, 2021
92fd1d0
skip: follow lint
cmpark0126 Dec 21, 2021
bb48be3
skip: fix typo
cmpark0126 Dec 21, 2021
3207aee
skip: fix logic
cmpark0126 Dec 21, 2021
26eae0c
skip: follow lint
cmpark0126 Dec 21, 2021
1034fbb
feat(polar): update data dynamically
cmpark0126 Dec 22, 2021
dd77faf
feat(polar): update polar chart dynamically
cmpark0126 Dec 22, 2021
22fd77d
skip: follow lint
cmpark0126 Dec 22, 2021
85b5b3f
skip: roll-back
cmpark0126 Dec 22, 2021
665ff3a
skip: follow lint
cmpark0126 Dec 22, 2021
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 demo/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ var billboardDemo = {

// UMD
code.data = code.data.join("")
.replace(/"(area|area-line-range|area-spline|area-spline-range|area-step|bar|bubble|candlestick|donut|gauge|line|pie|radar|scatter|spline|step|selection|subchart|zoom)(\(\))?",?/g, function(match, p1, p2, p3, offset, string) {
.replace(/"(area|area-line-range|area-spline|area-spline-range|area-step|bar|bubble|candlestick|donut|gauge|line|pie|polar|radar|scatter|spline|step|selection|subchart|zoom)(\(\))?",?/g, function(match, p1, p2, p3, offset, string) {
var module = camelize(p1);

code.esm.indexOf(module) === -1 &&
Expand Down
103 changes: 103 additions & 0 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,23 @@ var demos = {
]
}
},
PolarChart: {
options: {
data: {
columns: [
["data1", 60],
["data2", 120],
["data3", 75]
],
type: "polar",
},
polar: {
level:{
depth: 4,
},
}
}
},
RadarChart: {
options: {
data: {
Expand Down Expand Up @@ -4947,6 +4964,92 @@ d3.select(".chart_area")
}
}
},
PolarChartOptions: {
PolarLevel: {
options: {
data: {
columns: [
["data1", 60],
["data2", 120],
["data3", 75]
],
type: "polar",
},
polar: {
level: {
depth: 4,
max: 150,
show: false,
text: {
format: function(x) { return x + "%"; }
}
},
}
}
},
PolarSize: {
options: {
data: {
columns: [
["data1", 60],
["data2", 120],
["data3", 75]
],
type: "polar",
},
polar: {
size: {
ratio: 0.7
}
}
}
},
Padding: {
options: {
data: {
columns: [
["data1", 60],
["data2", 120],
["data3", 75]
],
type: "polar",
},
polar: {
padding: 5
}
}
},
PadAngle: {
options: {
data: {
columns: [
["data1", 60],
["data2", 120],
["data3", 75]
],
type: "polar",
},
polar: {
padAngle: 0.1
}
}
},
StartingAngle: {
options: {
data: {
columns: [
["data1", 60],
["data2", 120],
["data3", 75]
],
type: "polar",
},
polar: {
startingAngle: 1
}
}
},
},
API: {
AxisLabel: {
options: {
Expand Down
1 change: 1 addition & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ <h4>Supported chart types</h4>
<li><a href="#Chart.GaugeChart">Gauge</a></li>
<li><a href="#Chart.LineChart">Line</a></li>
<li><a href="#Chart.PieChart">Pie</a></li>
<li><a href="#Chart.PolarChart">Polar</a></li>
<li><a href="#Chart.RadarChart">Radar</a></li>
<li><a href="#Chart.ScatterPlot">Scatter</a></li>
<li><a href="#Chart.SplineChart">Spline</a></li>
Expand Down
1 change: 1 addition & 0 deletions demo/types/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Types = {
"spline",
"step",
"candlestick",
"polar",
"radar",
"gauge",
"gauge-multi",
Expand Down
7 changes: 5 additions & 2 deletions src/Chart/api/focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default {
candidates.classed(CLASS.focused, false).classed(CLASS.defocused, true);

if ($$.hasArcType()) {
$$.unexpandArc(targetIds);
state.hasPolar ? $$.unexpandPolar(targetIds) : $$.unexpandArc(targetIds);

$$.hasType("gauge") &&
$$.undoMarkOverlapped($$, `.${CLASS.gaugeValue}`);
Expand Down Expand Up @@ -115,7 +115,10 @@ export default {
const candidates = $el.svg.selectAll($$.selectorTargets(targetIds)); // should be for all targets

candidates.classed(CLASS.focused, false).classed(CLASS.defocused, false);
$$.hasArcType() && $$.unexpandArc(targetIds);

if ($$.hasArcType()) {
state.hasPolar ? $$.unexpandPolar(targetIds) : $$.unexpandArc(targetIds);
}

if (config.legend_show) {
$$.showLegend(targetIds.filter($$.isLegendToShow.bind($$)));
Expand Down
15 changes: 10 additions & 5 deletions src/ChartInternal/ChartInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export default class ChartInternal {

state.hasAxis = !$$.hasArcType();
state.hasRadar = !state.hasAxis && $$.hasType("radar");
state.hasPolar = !state.hasAxis && $$.hasType("polar");

// when 'padding=false' is set, disable axes and subchart. Because they are useless.
if (config.padding === false) {
Expand Down Expand Up @@ -499,7 +500,7 @@ export default class ChartInternal {
*/
initChartElements(): void {
const $$ = <any> this;
const {hasAxis, hasRadar} = $$.state;
const {hasAxis, hasRadar, hasPolar} = $$.state;
const types: string[] = [];

if (hasAxis) {
Expand All @@ -511,14 +512,16 @@ export default class ChartInternal {
}
});
} else {
if (!hasRadar) {
if (!hasRadar && !hasPolar) {
types.push("Arc", "Pie");
}

if ($$.hasType("gauge")) {
types.push("Gauge");
} else if (hasRadar) {
types.push("Radar");
} else if (hasPolar) {
types.push("Polar");
}
}

Expand Down Expand Up @@ -598,7 +601,7 @@ export default class ChartInternal {
*/
updateTargets(targets): void {
const $$ = <any> this;
const {hasAxis, hasRadar} = $$.state;
const {hasAxis, hasRadar, hasPolar} = $$.state;

// Text
$$.updateTargetsForText(targets);
Expand All @@ -618,11 +621,13 @@ export default class ChartInternal {
$$.updateTargetsForSubchart &&
$$.updateTargetsForSubchart(targets);
} else {
// Arc & Radar
// Arc & Radar & Polar
$$.hasArcType(targets) && (
hasRadar ?
$$.updateTargetsForRadar(targets.filter($$.isRadarType.bind($$))) :
$$.updateTargetsForArc(targets.filter($$.isArcType.bind($$)))
hasPolar ?
$$.updateTargetsForPolarArc(targets.filter($$.isPolarType.bind($$))) :
$$.updateTargetsForArc(targets.filter($$.isArcType.bind($$)))
);
}

Expand Down
13 changes: 10 additions & 3 deletions src/ChartInternal/internals/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ export default {
getDefaultValueFormat(): Function {
const $$ = this;
const hasArc = $$.hasArcType();
const {hasPolar} = $$.state;

return hasArc && !$$.hasType("gauge") ?
$$.defaultArcValueFormat :
$$.defaultValueFormat;
return hasPolar ?
$$.defaultPolarValueFormat :
hasArc && !$$.hasType("gauge") ?
$$.defaultArcValueFormat :
$$.defaultValueFormat;
},

defaultValueFormat(v): number|string {
Expand All @@ -53,6 +56,10 @@ export default {
return `${(ratio * 100).toFixed(1)}%`;
},

defaultPolarValueFormat(v): string {
return `${v}`;
},

dataLabelFormat(targetId: string): Function {
const $$ = this;
const dataLabels = $$.config.data_labels;
Expand Down
3 changes: 3 additions & 0 deletions src/ChartInternal/internals/redraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ export default {

// radar
$el.radar && $$.redrawRadar();

// polar
$el.polar && $$.redrawPolar();
}

// @TODO: Axis & Radar type
Expand Down
5 changes: 4 additions & 1 deletion src/ChartInternal/internals/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import CLASS from "../../config/classes";
import {asHalfPixel} from "../../module/util";

type TranslateParam = "main" | "context" | "legend" | "x" | "y" | "y2" | "subX" | "arc" | "radar";
type TranslateParam = "main" | "context" | "legend" | "x" | "y" | "y2" | "subX" | "arc" | "radar" | "polar";

export default {
getTranslate(target: TranslateParam, index = 0): string {
Expand Down Expand Up @@ -44,6 +44,9 @@ export default {
} else if (target === "arc") {
x = state.arcWidth / 2;
y = state.arcHeight / 2;
} else if (target === "polar") {
x = state.arcWidth / 2;
y = state.arcHeight / 2;
} else if (target === "radar") {
const [width] = $$.getRadarSize();

Expand Down
5 changes: 5 additions & 0 deletions src/ChartInternal/internals/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ export default {
return this.isTypeOf(d, "donut");
},

isPolarType(d): boolean {
return this.isTypeOf(d, "polar");
},

isRadarType(d): boolean {
return this.isTypeOf(d, "radar");
},
Expand All @@ -195,6 +199,7 @@ export default {
return this.isPieType(d) ||
this.isDonutType(d) ||
this.isGaugeType(d) ||
this.isPolarType(d) ||
this.isRadarType(d);
},

Expand Down
Loading