-
Notifications
You must be signed in to change notification settings - Fork 91
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
This change allows the user to change the size of the label text. #113
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,6 @@ import accessorFn from 'accessor-fn'; | |
import Tooltip from 'float-tooltip'; | ||
import { measureTextWidth } from './text'; | ||
|
||
const TEXT_FONTSIZE = 12; | ||
const TEXT_STROKE_WIDTH = 5; | ||
|
||
export default Kapsule({ | ||
|
||
props: { | ||
|
@@ -23,6 +20,8 @@ export default Kapsule({ | |
sort: { onChange(_, state) { state.needsReparse = true }}, | ||
label: { default: d => d.name }, | ||
labelOrientation: { default: 'auto' }, // angular, radial, auto | ||
textSize: {default: 12}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though this is already an improvement, we could go a step further and turn these props into accessor functions, just like most of the other props. That way you could set different font sizes / stroke widths per individual element. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, would you mind adding docs and types for these new attributes? |
||
textStrokeWidth: {default: 5}, | ||
size: { default: 'value', onChange(_, state) { state.needsReparse = true }}, | ||
color: { default: d => 'lightgrey' }, | ||
strokeColor: { default: d => 'white' }, | ||
|
@@ -115,7 +114,7 @@ export default Kapsule({ | |
state.svg = el.append('svg'); | ||
state.canvas = state.svg.append('g') | ||
.style('font-family', 'sans-serif') | ||
.style('font-size', `${TEXT_FONTSIZE}px`); | ||
.style('font-size', `${state.textSize}px`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be moved to the |
||
|
||
state.tooltip = Tooltip()(el); | ||
|
||
|
@@ -242,7 +241,7 @@ export default Kapsule({ | |
|
||
// white contour | ||
newSlice.selectAll('.text-contour') | ||
.style('stroke-width', `${TEXT_STROKE_WIDTH}px`); | ||
.style('stroke-width', `${state.textStrokeWidth}px`); | ||
|
||
// Entering + Updating | ||
const allSlices = slice.merge(newSlice); | ||
|
@@ -365,14 +364,14 @@ export default Kapsule({ | |
} | ||
|
||
function angularTextFits(d) { | ||
return measureTextWidth(nameOf(d.data).toString(), TEXT_FONTSIZE, { strokeWidth: TEXT_STROKE_WIDTH }) < getAvailableLabelAngularSpace(d); | ||
return measureTextWidth(nameOf(d.data).toString(), state.textSize, { strokeWidth: state.textStrokeWidth }) < getAvailableLabelAngularSpace(d); | ||
} | ||
|
||
function radialTextFits(d) { | ||
const availableHeight = state.radiusScale(d.y0) * (state.angleScale(d.x1) - state.angleScale(d.x0)); | ||
if (availableHeight < TEXT_FONTSIZE + TEXT_STROKE_WIDTH) return false; // not enough angular space | ||
if (availableHeight < state.textSize + state.textStrokeWidth) return false; // not enough angular space | ||
|
||
return measureTextWidth(nameOf(d.data).toString(), TEXT_FONTSIZE, { strokeWidth: TEXT_STROKE_WIDTH }) < getAvailableLabelRadialSpace(d); | ||
return measureTextWidth(nameOf(d.data).toString(), state.textSize, { strokeWidth: state.textStrokeWidth }) < getAvailableLabelRadialSpace(d); | ||
} | ||
|
||
function autoPickLabelOrientation(d) { | ||
|
@@ -386,7 +385,7 @@ export default Kapsule({ | |
|
||
if (!orientation) { | ||
const availableArcWidth = state.radiusScale(d.y0) * (state.angleScale(d.x1) - state.angleScale(d.x0)); | ||
if (availableArcWidth < TEXT_FONTSIZE + TEXT_STROKE_WIDTH) { | ||
if (availableArcWidth < state.textSize + state.textStrokeWidth) { | ||
// not enough space for radial text, choose angular | ||
orientation = 'angular'; | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be more fitting to call these two props
labelFontSize
andlabelStrokeWidth
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have a look later, and follow your suggestions. Thank you for having a look!