Skip to content

Commit

Permalink
fix: removed tickColor, updated axis-default-settings and added arc-p…
Browse files Browse the repository at this point in the history
…adding
  • Loading branch information
Moranski25 committed Nov 6, 2024
1 parent 6a245d4 commit 336f4e6
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 15 deletions.
27 changes: 27 additions & 0 deletions docs/scriptappy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,33 @@
"defaultValue": "auto",
"type": "string"
},
"arc": {
"kind": "object",
"entries": {
"endAngle": {
"description": "End of arc line",
"optional": true,
"type": "number"
},
"isRadial": {
"description": "Flag that determines if axis is radial",
"optional": true,
"defaultValue": false,
"type": "boolean"
},
"radius": {
"description": "Radius of arc line",
"optional": true,
"defaultValue": 0.5,
"type": "number"
},
"startAngle": {
"description": "Start of arc line",
"optional": true,
"type": "number"
}
}
},
"labels": {
"kind": "object",
"entries": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function buildArcLabels(tick, buildOpts) {
const centerPoint = { cx: rect.width / 2, cy: rect.height / 2 };
const plotSize = Math.min(rect.height, rect.width) / 2;
const innerRadius = buildOpts.radius !== undefined ? plotSize * buildOpts.radius : plotSize * 0.5;
const outerRadius = innerRadius + 1;
const outerRadius = innerRadius + buildOpts.padding;
const startAngle = buildOpts.startAngle !== undefined ? buildOpts.startAngle : -Math.PI / 2;
const endAngle = buildOpts.endAngle !== undefined ? buildOpts.endAngle : Math.PI / 2;
const tickLength = buildOpts.tickSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default function buildArcLine(buildOpts) {
const centerPoint = { cx: rect.width / 2, cy: rect.height / 2 };
const plotSize = Math.min(rect.height, rect.width) / 2;

const innerRadius = buildOpts.radius !== undefined ? plotSize * buildOpts.radius : plotSize * 0.5;
const outerRadius = innerRadius + 1;
const innerRadius = plotSize * buildOpts.radius;
const outerRadius = innerRadius + buildOpts.style.strokeWidth;

const startAngle = buildOpts.startAngle !== undefined ? buildOpts.startAngle : -Math.PI / 2;
const endAngle = buildOpts.endAngle !== undefined ? buildOpts.endAngle : Math.PI / 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function buildArcTicks(tick, buildOpts) {
const centerPoint = { cx: rect.width / 2, cy: rect.height / 2 };
const plotSize = Math.min(rect.height, rect.width) / 2;
const innerRadius = buildOpts.radius !== undefined ? plotSize * buildOpts.radius : plotSize * 0.5;
const outerRadius = innerRadius + 1;
const outerRadius = innerRadius + buildOpts.padding;
const startAngle = buildOpts.startAngle !== undefined ? buildOpts.startAngle : -Math.PI / 2;
const endAngle = buildOpts.endAngle !== undefined ? buildOpts.endAngle : Math.PI / 2;
const tickLength = buildOpts.tickSize;
Expand All @@ -30,7 +30,6 @@ export default function buildArcTicks(tick, buildOpts) {

const struct = {
type: 'line',
stroke: buildOpts.tickColor,
x1: innerPos.x,
y1: innerPos.y,
x2: outerPos.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,23 @@ const DEFAULT_CONTINUOUS_SETTINGS = {
* @type {boolean=} */
show: true,
},
/**
* @typedef {object}
*/
arc: {
/** Flag that determines if axis is radial
* @type {boolean=} */
isRadial: false,
/** Start of arc line
* @type {number=} */
startAngle: -Math.PI / 2,
/** End of arc line
* @type {number=} */
endAngle: Math.PI / 2,
/** Radius of arc line
* @type {number=} */
radius: 0.5,
},
/** Padding in direction perpendicular to the axis
* @type {number=} */
paddingStart: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ function tickSpacing(settings) {
spacing += settings.ticks.show ? settings.ticks.margin : 0;
return spacing;
}
function arcTickSpacing(settings) {
let spacing = 0;
spacing += settings.line.show ? settings.line.strokeWidth / 2 : 0;
spacing += settings.ticks.show ? settings.ticks.margin : 0;
return spacing;
}

function tickMinorSpacing(settings) {
return settings.line.strokeWidth + settings.minorTicks.margin;
Expand All @@ -27,6 +33,12 @@ function labelsSpacing(settings) {
spacing += tickSpacing(settings) + settings.labels.margin;
return spacing;
}
function arcLabelSpacing(settings) {
let spacing = 0;
spacing += settings.ticks.show ? settings.ticks.tickSize : 0;
spacing += arcTickSpacing(settings) + settings.labels.margin;
return spacing;
}

function calcActualTextRect({ style, measureText, tick }) {
return measureText({
Expand Down Expand Up @@ -230,15 +242,15 @@ export default function nodeBuilder(isDiscrete) {
const layered = state.labels.activeMode === 'layered';
let majorTickNodes;

if (settings.isRadial) {
buildOpts.startAngle = settings.startAngle;
buildOpts.endAngle = settings.endAngle;
buildOpts.radius = settings.radius;
if (settings.arc.isRadial) {

Check failure on line 245 in packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js

View workflow job for this annotation

GitHub Actions / unit-test

Axis › Settings › maxLengthPx › should limit text nodes max width in horizontal mode and docked vertically

TypeError: Cannot read properties of undefined (reading 'isRadial') at Function.isRadial [as build] (packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js:245:22) at Object.build (packages/picasso.js/src/core/chart-components/axis/axis.js:194:41) at Function.call [as render] (packages/picasso.js/src/core/component/component-factory.js:469:26) at Function.render [as simulateRender] (packages/picasso.js/test/helpers/component-factory-fixture.js:148:10) at Object.simulateRender (packages/picasso.js/src/core/chart-components/axis/__tests__/axis.spec.js:70:26)

Check failure on line 245 in packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js

View workflow job for this annotation

GitHub Actions / unit-test

Axis › Settings › maxLengthPx › should limit text nodes max width in horizontal mode and docked horizontally

TypeError: Cannot read properties of undefined (reading 'isRadial') at Function.isRadial [as build] (packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js:245:22) at Object.build (packages/picasso.js/src/core/chart-components/axis/axis.js:194:41) at Function.call [as render] (packages/picasso.js/src/core/component/component-factory.js:469:26) at Function.render [as simulateRender] (packages/picasso.js/test/helpers/component-factory-fixture.js:148:10) at Object.simulateRender (packages/picasso.js/src/core/chart-components/axis/__tests__/axis.spec.js:81:26)

Check failure on line 245 in packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js

View workflow job for this annotation

GitHub Actions / unit-test

Axis › Settings › maxLengthPx › should limit text nodes max width in tilted mode

TypeError: Cannot read properties of undefined (reading 'isRadial') at Function.isRadial [as build] (packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js:245:22) at Object.build (packages/picasso.js/src/core/chart-components/axis/axis.js:194:41) at Function.call [as render] (packages/picasso.js/src/core/component/component-factory.js:469:26) at Function.render [as simulateRender] (packages/picasso.js/test/helpers/component-factory-fixture.js:148:10) at Object.simulateRender (packages/picasso.js/src/core/chart-components/axis/__tests__/axis.spec.js:93:26)

Check failure on line 245 in packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js

View workflow job for this annotation

GitHub Actions / unit-test

Axis › Settings › maxLengthPx › should limit text nodes max width in layered mode

TypeError: Cannot read properties of undefined (reading 'isRadial') at Function.isRadial [as build] (packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js:245:22) at Object.build (packages/picasso.js/src/core/chart-components/axis/axis.js:194:41) at Function.call [as render] (packages/picasso.js/src/core/component/component-factory.js:469:26) at Function.render [as simulateRender] (packages/picasso.js/test/helpers/component-factory-fixture.js:148:10) at Object.simulateRender (packages/picasso.js/src/core/chart-components/axis/__tests__/axis.spec.js:105:26)

Check failure on line 245 in packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js

View workflow job for this annotation

GitHub Actions / unit-test

Axis › Settings › minLengthPx › should limit text nodes min width in horizontal mode and docked vertically

TypeError: Cannot read properties of undefined (reading 'isRadial') at Function.isRadial [as build] (packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js:245:22) at Object.build (packages/picasso.js/src/core/chart-components/axis/axis.js:194:41) at Function.call [as render] (packages/picasso.js/src/core/component/component-factory.js:469:26) at Function.render [as simulateRender] (packages/picasso.js/test/helpers/component-factory-fixture.js:148:10) at Object.simulateRender (packages/picasso.js/src/core/chart-components/axis/__tests__/axis.spec.js:132:26)

Check failure on line 245 in packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js

View workflow job for this annotation

GitHub Actions / unit-test

Axis › Settings › minLengthPx › should limit text nodes min width in horizontal mode and docked horizontally

TypeError: Cannot read properties of undefined (reading 'isRadial') at Function.isRadial [as build] (packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js:245:22) at Object.build (packages/picasso.js/src/core/chart-components/axis/axis.js:194:41) at Function.call [as render] (packages/picasso.js/src/core/component/component-factory.js:469:26) at Function.render [as simulateRender] (packages/picasso.js/test/helpers/component-factory-fixture.js:148:10) at Object.simulateRender (packages/picasso.js/src/core/chart-components/axis/__tests__/axis.spec.js:143:26)

Check failure on line 245 in packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js

View workflow job for this annotation

GitHub Actions / unit-test

Axis › Settings › minLengthPx › should limit text nodes min width in tilted mode

TypeError: Cannot read properties of undefined (reading 'isRadial') at Function.isRadial [as build] (packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js:245:22) at Object.build (packages/picasso.js/src/core/chart-components/axis/axis.js:194:41) at Function.call [as render] (packages/picasso.js/src/core/component/component-factory.js:469:26) at Function.render [as simulateRender] (packages/picasso.js/test/helpers/component-factory-fixture.js:148:10) at Object.simulateRender (packages/picasso.js/src/core/chart-components/axis/__tests__/axis.spec.js:158:26)

Check failure on line 245 in packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js

View workflow job for this annotation

GitHub Actions / unit-test

Axis › Settings › minLengthPx › should limit text nodes min width in layered mode

TypeError: Cannot read properties of undefined (reading 'isRadial') at Function.isRadial [as build] (packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js:245:22) at Object.build (packages/picasso.js/src/core/chart-components/axis/axis.js:194:41) at Function.call [as render] (packages/picasso.js/src/core/component/component-factory.js:469:26) at Function.render [as simulateRender] (packages/picasso.js/test/helpers/component-factory-fixture.js:148:10) at Object.simulateRender (packages/picasso.js/src/core/chart-components/axis/__tests__/axis.spec.js:170:26)

Check failure on line 245 in packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js

View workflow job for this annotation

GitHub Actions / unit-test

Axis › Lifecycle › Update › should handle an update where scale type changes from discrete to continuous

TypeError: Cannot read properties of undefined (reading 'isRadial') at Function.isRadial [as build] (packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js:245:22) at Object.build (packages/picasso.js/src/core/chart-components/axis/axis.js:194:41) at Function.call [as render] (packages/picasso.js/src/core/component/component-factory.js:469:26) at Function.render [as simulateRender] (packages/picasso.js/test/helpers/component-factory-fixture.js:148:10) at Object.simulateRender (packages/picasso.js/src/core/chart-components/axis/__tests__/axis.spec.js:259:26)

Check failure on line 245 in packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js

View workflow job for this annotation

GitHub Actions / unit-test

Axis › Lifecycle › Update › should handle an update where scale type changes from continuous to discrete

TypeError: Cannot read properties of undefined (reading 'isRadial') at Function.isRadial [as build] (packages/picasso.js/src/core/chart-components/axis/axis-node-builder.js:245:22) at Object.build (packages/picasso.js/src/core/chart-components/axis/axis.js:194:41) at Function.call [as update] (packages/picasso.js/src/core/component/component-factory.js:508:26) at Function.update [as simulateUpdate] (packages/picasso.js/test/helpers/component-factory-fixture.js:158:10) at Object.simulateUpdate (packages/picasso.js/src/core/chart-components/axis/__tests__/axis.spec.js:281:26)
buildOpts.startAngle = settings.arc.startAngle;
buildOpts.endAngle = settings.arc.endAngle;
buildOpts.radius = settings.arc.radius;
}
if (settings.line.show) {
buildOpts.style = settings.line;
buildOpts.padding = settings.paddingStart;
if (settings.isRadial) {
if (settings.arc.isRadial) {
nodes.push(buildArcLine(buildOpts));
} else {
nodes.push(buildLine(buildOpts));
Expand All @@ -248,9 +260,9 @@ export default function nodeBuilder(isDiscrete) {
buildOpts.style = settings.ticks;
buildOpts.tickSize = settings.ticks.tickSize;
buildOpts.padding = tickSpacing(settings);
buildOpts.tickColor = settings.ticks.tickColor || '#000';
if (settings.isRadial) {
majorTickNodes = arcTickBuilder(ticks, buildOpts);
if (settings.arc.isRadial) {
buildOpts.padding = arcTickSpacing(settings);
majorTickNodes = arcTickBuilder(major, buildOpts);
} else {
majorTickNodes = tickBuilder(major, buildOpts);
}
Expand Down Expand Up @@ -288,9 +300,9 @@ export default function nodeBuilder(isDiscrete) {
tick,
});
};

let labelNodes = [];
if (settings.isRadial) {
if (settings.arc.isRadial) {
buildOpts.padding = arcLabelSpacing(settings);
labelNodes = arcLabelBuilder(major, buildOpts, resolveTickOpts);
} else if (layered && (settings.align === 'top' || settings.align === 'bottom')) {
labelNodes = layeredLabelBuilder(major, buildOpts, settings, resolveTickOpts);
Expand Down
6 changes: 6 additions & 0 deletions packages/picasso.js/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,12 @@ declare namespace picassojs {
namespace ComponentAxis {
type ContinuousSettings = {
align?: string;
arc: {
endAngle?: number;
isRadial?: boolean;
radius?: number;
startAngle?: number;
};
labels: {
align?: number;
filterOverlapping?: boolean;
Expand Down

0 comments on commit 336f4e6

Please sign in to comment.