Skip to content

PedalEfficiencyTextIndicator

roosit edited this page Nov 15, 2026 · 1 revision

PedalEfficiencyTextIndicator

Up | Previous | Next | Русский

Full source with short explanations

Below is the full source of the class in documentation form. The comments inside the block explain the purpose of the parts of the class, but they are not stored in the working file PedalEfficiencyTextIndicator.java: the production code stays clean and the explanations live in the wiki.

package com.velitask.plugin.official;

import com.velitask.sdk.FrameContext;
import com.velitask.sdk.Indicator;
import com.velitask.sdk.IndicatorContext;
import com.velitask.sdk.IndicatorSkin;
import com.velitask.sdk.IndicatorSkinTransfer;
import com.velitask.sdk.data.PedalEfficiencySensorAtom;
import com.velitask.sdk.properties.DisplayConfig;
import com.velitask.sdk.properties.FontColorProperty;
import com.velitask.sdk.properties.IProperty;
import com.velitask.sdk.properties.PedalEfficiencyAtomProperty;
import com.velitask.sdk.properties.PropertyGroup;
import com.velitask.sdk.properties.TextAlignProperty;
import com.velitask.sdk.properties.TextTemplateProperty;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import org.abricos.core.state.maket.HorizontalAlign;
import org.abricos.core.state.maket.Maket;
import org.abricos.core.state.maket.VerticalAlign;

/* Text with the torque effectiveness and the pedal smoothness of one leg. */
public class PedalEfficiencyTextIndicator extends Indicator {

    /* Stable indicator name: it is part of the layer identifier in a project, it must not be changed. */
    public static final String NAME = "pedalEfficiencyText";

    /* Prefix of the localization keys of this indicator. */
    private static final String KEY = _KEY + "." + NAME;

    /* Data source: the pedal efficiency sensor; the leg is determined by the selected sensor (JSON key PedalEfficiency). */
    private final PedalEfficiencyAtomProperty mEfficiency = new PedalEfficiencyAtomProperty();

    /* Font and text color. */
    private final FontColorProperty mText = new FontColorProperty();

    /* Position of the text inside the layer (nine variants, centered by default). */
    private final TextAlignProperty mTextAlign = new TextAlignProperty();

    /* Template of the resulting string with variables in curly braces. */
    private final PedalEfficiencyTextTemplateProperty mTemplate = new PedalEfficiencyTextTemplateProperty();

    @Override
    public String getName() {
        return NAME;
    }

    /* The title, description and tags are taken from the plugin localization. */
    @Override
    public String getTitle() {
        return localized(KEY + ".title");
    }

    @Override
    public String getDescription() {
        return localized(KEY + ".description");
    }

    @Override
    public String getTags() {
        return localized(KEY + ".tags");
    }

    /* Default maket: top left, margins 100 from the top and the right, size 320×120. */
    @Override
    public void defineMaket(Maket maket) {
        maket.setVertical(VerticalAlign.TOP);
        maket.setHorizontal(HorizontalAlign.LEFT);
        maket.setLayerMargin(null, 100d, 100d, null);
        maket.setLayerSize(320d, 120d);
    }

    /* The order of the properties defines the order of the settings and the order of the keys in JSON. */
    @Override
    public IProperty[] defineProperties() {
        return new IProperty[]{
            mEfficiency,
            mText,
            mTextAlign,
            mTemplate
        };
    }

    /* The text alignment is shown in the "Appearance" group. */
    @Override
    public void configureDisplay(DisplayConfig config) {
        config.set(mTextAlign, PropertyGroup.APPEARANCE);
    }

    /* The only skin "compact" changes only the text template. */
    @Override
    public IndicatorSkin[] defineSkins() {
        return new IndicatorSkin[]{
            IndicatorSkin.builder("compact", localized(KEY + ".skin.compact"))
            .set(mTemplate.skinCompact())
            .build()
        };
    }

    /* Draws one frame: reads the sensor data, builds the string by the template and outputs it. */
    @Override
    public void render(IndicatorContext indicatorContext) {
        PedalEfficiencyTextContext ctx = (PedalEfficiencyTextContext) indicatorContext;
        Graphics2D g = ctx.graphics;

        /* The sample for the current frame time; if there is no data, the frame stays empty. */
        PedalEfficiencySensorAtom atom = ctx.efficiency.queryAtom();
        if (atom == null) {
            return;
        }

        /* The torque effectiveness, refined by the frame time and rounded to whole percent. */
        int te = (int) Math.round(atom.calcEffectivenessPercent(ctx.efficiency.rawTime));
        /* The pedal smoothness, refined by the frame time and rounded to whole percent. */
        int ps = (int) Math.round(atom.calcSmoothnessPercent(ctx.efficiency.rawTime));
        /* Argument order: te, ps. */
        String text = ctx.template.makeText(te, ps);

        /* Text smoothing. */
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);

        /* The font size is scaled together with the layer. */
        Font font = ctx.text.toFont(ctx.scale);
        g.setFont(font);
        g.setColor(ctx.text.color.value);

        /* The text is placed inside the layer by the selected alignment. */
        ctx.textAlign.drawText(g, text, ctx.width, ctx.height);
    }

    /* Text template of this indicator: the default value, the list of variables and the skin. */
    static class PedalEfficiencyTextTemplateProperty extends TextTemplateProperty {

        private static final String KEY_PROPERTY = KEY + "." + NAME;
        private static final String KEY_PROPERTY_TEMPLATE = KEY_PROPERTY + ".template";
        private static final String KEY_PROPERTY_VAR = KEY_PROPERTY + ".var";

        /* The default template is taken from localization. */
        @Override
        protected String defineTemplate() {
            return localized(KEY_PROPERTY_TEMPLATE + ".default");
        }

        /* Template variables: the name, the default format and the explanation. The order must match the order of the makeText(...) arguments. */
        @Override
        protected Var[] defineVars() {
            return new Var[]{
                new Var("te", "%d", localized(KEY_PROPERTY_VAR + ".te")),
                new Var("ps", "%d", localized(KEY_PROPERTY_VAR + ".ps"))
            };
        }

        /* The skin changes only the template text, the variable formats stay the same. */
        public IndicatorSkinTransfer skinCompact() {
            return skin(localized(KEY_PROPERTY_TEMPLATE + ".compact"));
        }
    }

    /* Text with the torque effectiveness and the pedal smoothness of one leg. */
    public class PedalEfficiencyTextContext extends IndicatorContext {

        public final PedalEfficiencyAtomProperty.SensorContext efficiency;
        public final FontColorProperty.FontColorContext text;
        public final TextAlignProperty.TextAlignContext textAlign;
        public final TextTemplateProperty.TextTemplateContext template;

        public PedalEfficiencyTextContext(FrameContext frame) {
            super(frame);
            efficiency = mEfficiency.createContext(frame);
            text = mText.createContext(frame);
            textAlign = mTextAlign.createContext(frame);
            template = mTemplate.createContext(frame);
        }
    }

    /* Creates the frame context for the indicator. */
    @Override
    public IndicatorContext createContext(FrameContext frame) {
        return new PedalEfficiencyTextContext(frame);
    }
}

Purpose

PedalEfficiencyTextIndicator shows the pedalling efficiency of one leg: the torque effectiveness and the smoothness in percent. The leg is determined by the selected sensor. The data is available only from power-meter pedals that record these fields (FIT).

How it works

Data. PedalEfficiencyAtomProperty creates ctx.efficiency. queryAtom() returns a PedalEfficiencySensorAtom for the frame time; calcEffectivenessPercent(...) and calcSmoothnessPercent(...) linearly refine the values between the current and the next sample. The indicator knows nothing about leg channels: the leg is selected by selecting the sensor in the property. If there is no sample (a pause or outside the recording), render draws nothing.

Settings. PedalEfficiencyAtomProperty (the sensor), FontColorProperty, TextAlignProperty (default CENTER) and the internal PedalEfficiencyTextTemplateProperty. There is no units property. The compact skin sets the template {te}/{ps}.

Drawing. The values are brought to integers, the string is built with ctx.template.makeText(te, ps), then smoothing, the font (its size multiplied by ctx.scale) and the color are set, and ctx.textAlign.drawText(...) outputs the text.

Features and limitations

  • No sensor data, a pause, or outside the recording means an empty layer.
  • The data is available only from power-meter pedals that record these fields (FIT).
  • One leg is shown, the one whose sensor is selected; a second indicator is needed for the other leg.
  • The %d formats are meant for an integer: floating-point formats (%.1f) give an empty substitution (the formatting error is suppressed).
  • The number of variables in defineVars() (two) must match the number of makeText(...) arguments.

Clone this wiki locally