Skip to content

Commit eb17cf5

Browse files
committed
Fix the bug with some properties change having no effect in the chart
1 parent 66abcd0 commit eb17cf5

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

piechart/src/androidTest/kotlin/ir/mahozad/android/ScreenshotTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class ScreenshotTest {
8181
@RegisterExtension
8282
val scenarioExtension = ActivityScenarioExtension.launch<ScreenshotTestActivity>()
8383
lateinit var scenario: ActivityScenario<ScreenshotTestActivity>
84-
lateinit var device: UiDevice
84+
lateinit var device: UiDevice // FIXME: This is not used (?)
8585
// See https://stackoverflow.com/a/46183452
8686
val shouldSave = InstrumentationRegistry.getArguments().getString("shouldSave", "false").toBoolean()
8787

piechart/src/main/kotlin/ir/mahozad/android/PieChart.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class PieChart @JvmOverloads constructor(
235235

236236
var slices by Property(defaultSlices) {
237237
onSizeChanged(width, height, width, height)
238+
invalidate()
238239
}
239240

240241
var startAngleResource by IntegerResource(::startAngle)
@@ -302,11 +303,13 @@ class PieChart @JvmOverloads constructor(
302303
var isLegendEnabledResource by BooleanResource(::isLegendEnabled)
303304
var isLegendEnabled by Property(DEFAULT_LEGEND_STATUS) {
304305
onSizeChanged(width, height, width, height)
306+
invalidate()
305307
}
306308

307309
var legendsSizeResource by DimensionResource(::legendsSize)
308310
var legendsSize by Property(DEFAULT_LEGENDS_SIZE) {
309311
onSizeChanged(width, height, width, height)
312+
invalidate()
310313
}
311314

312315
/**
@@ -328,90 +331,107 @@ class PieChart @JvmOverloads constructor(
328331
var legendsTitleAlignment by Property(defaultLegendsTitleAlignment) {
329332
// TODO: No need to recalculate everything; provide a method in legend box for this
330333
onSizeChanged(width, height, width, height)
334+
invalidate()
331335
}
332336

333337
var legendsAlignment by Property(defaultLegendsAlignment) {
334338
// TODO: No need to recalculate everything; provide a method in legend box for this
335339
onSizeChanged(width, height, width, height)
340+
invalidate()
336341
}
337342

338343
var legendBoxAlignment by Property(defaultLegendBoxAlignment) {
339344
// TODO: No need to recalculate everything; provide a method in legend box for this
340345
onSizeChanged(width, height, width, height)
346+
invalidate()
341347
}
342348

343349
var legendsWrapping by Property(defaultLegendsWrapping) {
344350
onSizeChanged(width, height, width, height)
351+
invalidate()
345352
}
346353

347354
var legendsTitleResource by StringResource(::legendsTitle)
348355
var legendsTitle by Property(DEFAULT_LEGENDS_TITLE) {
349356
onSizeChanged(width, height, width, height)
357+
invalidate()
350358
}
351359

352360
var legendPosition by Property(defaultLegendPosition) {
353361
onSizeChanged(width, height, width, height)
362+
invalidate()
354363
}
355364

356365
var legendArrangement by Property(defaultLegendArrangement) {
357366
onSizeChanged(width, height, width, height)
367+
invalidate()
358368
}
359369

360370
var legendsMarginResource by DimensionResource(::legendsMargin)
361371
var legendsMargin by Property(DEFAULT_LEGENDS_MARGIN) {
362372
onSizeChanged(width, height, width, height)
373+
invalidate()
363374
}
364375

365376
var legendsColorResource by ColorResource(::legendsColor)
366377
var legendsColor by Property(DEFAULT_LEGENDS_COLOR) {
367378
// TODO: No need to recalculate everything; provide a method in legend box for this
368379
onSizeChanged(width, height, width, height)
380+
invalidate()
369381
}
370382

371383
var legendBoxBackgroundColorResource by ColorResource(::legendBoxBackgroundColor)
372384
var legendBoxBackgroundColor by Property(DEFAULT_LEGEND_BOX_BACKGROUND_COLOR) {
373385
// TODO: No need to recalculate everything; provide a method in legend box for this
374386
onSizeChanged(width, height, width, height)
387+
invalidate()
375388
}
376389

377390
// FIXME: Changing these properties makes the legend box disappear
378391
var legendBoxMarginResource by DimensionResource(::legendBoxMargin)
379392
var legendBoxMargin by Property(DEFAULT_LEGEND_BOX_MARGIN) {
380393
onSizeChanged(width, height, width, height)
394+
invalidate()
381395
}
382396

383397
var legendBoxPaddingResource by DimensionResource(::legendBoxPadding)
384398
var legendBoxPadding by Property(DEFAULT_LEGEND_BOX_PADDING) {
385399
// TODO: No need to recalculate everything; provide a method in legend box for this
386400
onSizeChanged(width, height, width, height)
401+
invalidate()
387402
}
388403

389404
var legendBoxBorderResource by DimensionResource(::legendBoxBorder)
390405
var legendBoxBorder by Property(DEFAULT_LEGEND_BOX_BORDER) {
391406
onSizeChanged(width, height, width, height)
407+
invalidate()
392408
}
393409

394410
var legendBoxBorderCornerRadiusResource by DimensionResource(::legendBoxBorderCornerRadius)
395411
var legendBoxBorderCornerRadius by Property(DEFAULT_LEGEND_BOX_BORDER_CORNER_RADIUS) {
396412
// TODO: No need to recalculate everything; provide a method in legend box for this
397413
onSizeChanged(width, height, width, height)
414+
invalidate()
398415
}
399416

400417
var legendBoxBorderColorResource by ColorResource(::legendBoxBorderColor)
401418
var legendBoxBorderColor by Property(DEFAULT_LEGEND_BOX_BORDER_COLOR) {
402419
// TODO: No need to recalculate everything; provide a method in legend box for this
403420
onSizeChanged(width, height, width, height)
421+
invalidate()
404422
}
405423

406424
var legendBoxBorderAlphaResource by FractionResource(::legendBoxBorderAlpha)
407425
var legendBoxBorderAlpha by Property(DEFAULT_LEGEND_BOX_BORDER_ALPHA) {
408426
// TODO: No need to recalculate everything; provide a method in legend box for this
409427
onSizeChanged(width, height, width, height)
428+
invalidate()
410429
}
411430

412431
var legendBoxBorderType by Property(defaultLegendBoxBorderType) {
413432
// TODO: No need to recalculate everything; provide a method in legend box for this
414433
onSizeChanged(width, height, width, height)
434+
invalidate()
415435
}
416436

417437
/**
@@ -425,69 +445,82 @@ class PieChart @JvmOverloads constructor(
425445
var legendBoxBorderDashArray by Property(DEFAULT_LEGEND_BOX_BORDER_DASH_ARRAY) {
426446
// TODO: No need to recalculate everything; provide a method in legend box for this
427447
onSizeChanged(width, height, width, height)
448+
invalidate()
428449
}
429450

430451
var legendIconsAlphaResource by FractionResource(::legendIconsAlpha)
431452
var legendIconsAlpha by Property(DEFAULT_LEGEND_ICONS_ALPHA, { it.coerceIn(0f, 1f) }) {
432453
// TODO: No need to recalculate everything; provide a method in legend box for this
433454
onSizeChanged(width, height, width, height)
455+
invalidate()
434456
}
435457

436458
var legendsTitleColorResource by ColorResource(::legendsTitleColor)
437459
var legendsTitleColor by Property(DEFAULT_LEGENDS_TITLE_COLOR) {
438460
// TODO: No need to recalculate everything; provide a method in legend box for this
439461
onSizeChanged(width, height, width, height)
462+
invalidate()
440463
}
441464

442465
var legendsTitleSizeResource by DimensionResource(::legendsTitleSize)
443466
var legendsTitleSize by Property(DEFAULT_LEGENDS_TITLE_SIZE) {
444467
onSizeChanged(width, height, width, height)
468+
invalidate()
445469
}
446470

447471
var legendsPercentageSizeResource by DimensionResource(::legendsPercentageSize)
448472
var legendsPercentageSize by Property(DEFAULT_LEGENDS_PERCENTAGE_SIZE) {
449473
onSizeChanged(width, height, width, height)
474+
invalidate()
450475
}
451476

452477
var isLegendsPercentageEnabledResource by BooleanResource(::isLegendsPercentageEnabled)
453478
var isLegendsPercentageEnabled by Property(DEFAULT_LEGENDS_PERCENTAGE_STATUS) {
454479
onSizeChanged(width, height, width, height)
480+
invalidate()
455481
}
456482

457483
var isLegendBoxBorderEnabledResource by BooleanResource(::isLegendBoxBorderEnabled)
458484
var isLegendBoxBorderEnabled by Property(DEFAULT_LEGEND_BOX_BORDER_STATUS) {
459485
onSizeChanged(width, height, width, height)
486+
invalidate()
460487
}
461488

462489
var legendsPercentageColorResource by ColorResource(::legendsPercentageColor)
463490
var legendsPercentageColor by Property(DEFAULT_LEGENDS_PERCENTAGE_COLOR) {
464491
// TODO: No need to recalculate everything; provide a method in legend box for this
465492
onSizeChanged(width, height, width, height)
493+
invalidate()
466494
}
467495

468496
var legendsPercentageMarginResource by DimensionResource(::legendsPercentageMargin)
469497
var legendsPercentageMargin by Property(DEFAULT_LEGENDS_PERCENTAGE_MARGIN) {
470498
onSizeChanged(width, height, width, height)
499+
invalidate()
471500
}
472501

473502
var legendTitleMarginResource by DimensionResource(::legendTitleMargin)
474503
var legendTitleMargin by Property(DEFAULT_LEGEND_TITLE_MARGIN) {
475504
onSizeChanged(width, height, width, height)
505+
invalidate()
476506
}
477507

478508
var legendLinesMarginResource by DimensionResource(::legendLinesMargin)
479509
var legendLinesMargin by Property(DEFAULT_LEGEND_LINES_MARGIN) {
480510
onSizeChanged(width, height, width, height)
511+
invalidate()
481512
}
482513

483514
var legendIconsHeightResource by DimensionResource(::legendIconsHeight)
484515
var legendIconsHeight by Property(DEFAULT_LEGEND_ICONS_HEIGHT) {
485516
onSizeChanged(width, height, width, height)
517+
invalidate()
486518
}
487519

488520
var legendIconsMarginResource by DimensionResource(::legendIconsMargin)
489521
var legendIconsMargin by Property(DEFAULT_LEGEND_ICONS_MARGIN) {
490522
onSizeChanged(width, height, width, height)
523+
invalidate()
491524
}
492525

493526
/**
@@ -678,6 +711,7 @@ class PieChart @JvmOverloads constructor(
678711
*/
679712
var legendsIcon: Icon by Property(defaultLegendsIcon) {
680713
onSizeChanged(width, height, width, height)
714+
invalidate()
681715
}
682716

683717
var isCenterLabelEnabledResource by BooleanResource(::isCenterLabelEnabled)

0 commit comments

Comments
 (0)