| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,12 @@ | |||
| 13 | 13 | * See the License for the specific language governing permissions and | |
| 14 | 14 | * limitations under the License. | |
| 15 | 15 | */ | |
| 16 | + | ||
| 17 | + // Base class for J2CL JsInterop base class | ||
| 18 | + class ChartElement extends HTMLElement { | ||
| 19 | + } | ||
| 20 | + window.ChartElement = ChartElement; | ||
| 21 | + | ||
| 16 | 22 | import './components/pfj-chart-donut.js'; | |
| 17 | 23 | import './components/pfj-chart-donut-utilization.js'; | |
| 18 | 24 | import './components/pfj-chart-donut-threshold.js'; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,10 +95,10 @@ export class ReactWrapperElement extends LitElement { | |||
| 95 | 95 | this._height = undefined; // number | |
| 96 | 96 | this._labels = undefined; // (data: any) => string | |
| 97 | 97 | this._legendAllowWrap = undefined; // boolean | |
| 98 | - this._legendData = undefined; // string[] | ||
| 98 | + this._legendData = undefined; // { name?: string; symbol?: { fill?: string; type?: string; }; }[] | ||
| 99 | 99 | this._legendOrientation = undefined; // string | |
| 100 | 100 | this._legendPosition = undefined; // string | |
| 101 | - this._padding = undefined; // { top?: number, bottom?: number, left?: number, right?: number } | ||
| 101 | + this._padding = undefined; // { top?: number; bottom?: number; left?: number; right?: number } | ||
| 102 | 102 | this._subTitle = undefined; // string | |
| 103 | 103 | this._subTitlePosition = undefined; // string | |
| 104 | 104 | this._themeColor = undefined; // string | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,8 @@ | |||
| 15 | 15 | */ | |
| 16 | 16 | package org.patternfly.chart; | |
| 17 | 17 | ||
| 18 | + import java.util.function.Function; | ||
| 19 | + | ||
| 18 | 20 | import org.jboss.elemento.ElementAttributeMethods; | |
| 19 | 21 | import org.jboss.elemento.ElementClassListMethods; | |
| 20 | 22 | import org.jboss.elemento.ElementConsumerMethods; | |
@@ -27,12 +29,12 @@ | |||
| 27 | 29 | import org.jboss.elemento.HTMLElementStyleMethods; | |
| 28 | 30 | import org.jboss.elemento.HTMLElementVisibilityMethods; | |
| 29 | 31 | import org.jboss.elemento.TypedBuilder; | |
| 30 | - | ||
| 31 | - import elemental2.dom.HTMLElement; | ||
| 32 | + import elemental2.core.JsArray; | ||
| 33 | + import jsinterop.base.Js; | ||
| 32 | 34 | ||
| 33 | 35 | import static java.util.Objects.requireNonNull; | |
| 34 | 36 | ||
| 35 | - public abstract class BaseChart<E extends HTMLElement, B extends TypedBuilder<E, B>> implements | ||
| 37 | + public abstract class BaseChart<E extends ChartElement, B extends TypedBuilder<E, B>> implements | ||
| 36 | 38 | Chart, | |
| 37 | 39 | ElementAttributeMethods<E, B>, | |
| 38 | 40 | ElementClassListMethods<E, B>, | |
@@ -46,12 +48,14 @@ public abstract class BaseChart<E extends HTMLElement, B extends TypedBuilder<E, | |||
| 46 | 48 | HTMLElementStyleMethods<E, B>, | |
| 47 | 49 | HTMLElementVisibilityMethods<E, B> { | |
| 48 | 50 | ||
| 51 | + // ------------------------------------------------------ instance | ||
| 52 | + | ||
| 49 | 53 | private final ChartType chartType; | |
| 50 | 54 | private final E element; | |
| 51 | 55 | ||
| 52 | 56 | protected BaseChart(ChartType chartType, E element) { | |
| 53 | 57 | this.chartType = requireNonNull(chartType, "chart type required"); | |
| 54 | - this.element = requireNonNull(element, "element required"); | ||
| 58 | + this.element = Js.uncheckedCast(requireNonNull(element, "element required")); | ||
| 55 | 59 | Ouia.component(element, chartType); | |
| 56 | 60 | } | |
| 57 | 61 | ||
@@ -64,4 +68,93 @@ public ChartType chartType() { | |||
| 64 | 68 | public E element() { | |
| 65 | 69 | return element; | |
| 66 | 70 | } | |
| 71 | + | ||
| 72 | + // ------------------------------------------------------ builder | ||
| 73 | + | ||
| 74 | + public B height(int height) { | ||
| 75 | + element().height = height; | ||
| 76 | + return that(); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public B labels(Function<Data, String> labels) { | ||
| 80 | + // There's a lot more in 'data', but we just want the 'datum' property | ||
| 81 | + element().labels = (data -> labels.apply(Js.cast(data.asPropertyMap().get("datum")))); | ||
| 82 | + return that(); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + public B legend(String legend, String... moreLegends) { | ||
| 86 | + JsArray<LegendData> array = new JsArray<>(); | ||
| 87 | + LegendData ld = new LegendData(); | ||
| 88 | + ld.name = legend; | ||
| 89 | + array.push(ld); | ||
| 90 | + if (moreLegends != null) { | ||
| 91 | + for (String l : moreLegends) { | ||
| 92 | + ld = new LegendData(); | ||
| 93 | + ld.name = l; | ||
| 94 | + array.push(ld); | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | + element().legendData = array; | ||
| 98 | + return that(); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public B legend(LegendData legend, LegendData... moreLegends) { | ||
| 102 | + JsArray<LegendData> array = new JsArray<>(); | ||
| 103 | + array.push(legend); | ||
| 104 | + array.push(moreLegends); | ||
| 105 | + element().legendData = array; | ||
| 106 | + return that(); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + public B legendOrientation(LegendOrientation orientation) { | ||
| 110 | + element().legendOrientation = orientation.name().toLowerCase(); | ||
| 111 | + return that(); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + public B legendPosition(LegendPosition position) { | ||
| 115 | + element().legendPosition = position.name().toLowerCase(); | ||
| 116 | + return that(); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + public B padding(Padding padding) { | ||
| 120 | + element().padding = padding; | ||
| 121 | + return that(); | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + public B subTitle(String subTitle) { | ||
| 125 | + element().subtitle = subTitle; | ||
| 126 | + return that(); | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + public B subTitlePosition(SubTitlePosition position) { | ||
| 130 | + element().subTitlePosition = position.name().toLowerCase(); | ||
| 131 | + return that(); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + public B themeColor(ChartThemeColor themeColor) { | ||
| 135 | + element().themeColor = themeColor.color; | ||
| 136 | + return that(); | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + public B title(String title) { | ||
| 140 | + element().title = title; | ||
| 141 | + return that(); | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + public B width(int width) { | ||
| 145 | + element().width = width; | ||
| 146 | + return that(); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + // ------------------------------------------------------ aria | ||
| 150 | + | ||
| 151 | + public B ariaTitle(String ariaTitle) { | ||
| 152 | + element().setAttribute("aria-title", ariaTitle); | ||
| 153 | + return that(); | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + public B ariaDesc(String ariaDesc) { | ||
| 157 | + element().setAttribute("aria-desc", ariaDesc); | ||
| 158 | + return that(); | ||
| 159 | + } | ||
| 67 | 160 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,24 @@ | |||
| 1 | + package org.patternfly.chart; | ||
| 2 | + | ||
| 3 | + import elemental2.core.JsArray; | ||
| 4 | + import elemental2.dom.HTMLElement; | ||
| 5 | + import jsinterop.annotations.JsPackage; | ||
| 6 | + import jsinterop.annotations.JsType; | ||
| 7 | + | ||
| 8 | + @JsType(isNative = true, namespace = JsPackage.GLOBAL) | ||
| 9 | + public class ChartElement extends HTMLElement { | ||
| 10 | + | ||
| 11 | + public JsArray<String> categories; | ||
| 12 | + public double height; | ||
| 13 | + public LabelsFn labels; | ||
| 14 | + public boolean legendAllowWrap; | ||
| 15 | + public JsArray<LegendData> legendData; | ||
| 16 | + public String legendOrientation; | ||
| 17 | + public String legendPosition; | ||
| 18 | + public Padding padding; | ||
| 19 | + public String subtitle; | ||
| 20 | + public String subTitlePosition; | ||
| 21 | + public String themeColor; | ||
| 22 | + public String title; | ||
| 23 | + public double width; | ||
| 24 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,10 @@ | |||
| 18 | 18 | public enum ChartType { | |
| 19 | 19 | ||
| 20 | 20 | Donut("dnt", "PF6/Donut"), | |
| 21 | + | ||
| 22 | + DonutUtilization("dntu", "PF6/DonutUtilization"), | ||
| 23 | + | ||
| 24 | + DonutThreshold("dntt", "PF6/DonutThreshold"), | ||
| 21 | 25 | ; | |
| 22 | 26 | ||
| 23 | 27 | public final String id; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + package org.patternfly.chart; | ||
| 2 | + | ||
| 3 | + public enum LegendPosition { | ||
| 4 | + | ||
| 5 | + bottom, right | ||
| 6 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,16 @@ | |||
| 7 | 7 | @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") | |
| 8 | 8 | public class Padding { | |
| 9 | 9 | ||
| 10 | + @JsOverlay | ||
| 11 | + public static Padding padding(double top, double right, double bottom, double left) { | ||
| 12 | + Padding padding = new Padding(); | ||
| 13 | + padding.top = top; | ||
| 14 | + padding.right = right; | ||
| 15 | + padding.bottom = bottom; | ||
| 16 | + padding.left = left; | ||
| 17 | + return padding; | ||
| 18 | + } | ||
| 19 | + | ||
| 10 | 20 | public double top; | |
| 11 | 21 | public double right; | |
| 12 | 22 | public double bottom; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,27 @@ | |||
| 1 | + package org.patternfly.chart; | ||
| 2 | + | ||
| 3 | + import jsinterop.annotations.JsOverlay; | ||
| 4 | + import jsinterop.annotations.JsPackage; | ||
| 5 | + import jsinterop.annotations.JsType; | ||
| 6 | + | ||
| 7 | + @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") | ||
| 8 | + public class Threshold { | ||
| 9 | + | ||
| 10 | + @JsOverlay | ||
| 11 | + public static Threshold threshold(double value) { | ||
| 12 | + Threshold threshold = new Threshold(); | ||
| 13 | + threshold.value = value; | ||
| 14 | + return threshold; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + @JsOverlay | ||
| 18 | + public static Threshold threshold(double value, String color) { | ||
| 19 | + Threshold threshold = new Threshold(); | ||
| 20 | + threshold.value = value; | ||
| 21 | + threshold.color = color; | ||
| 22 | + return threshold; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public double value; | ||
| 26 | + public String color; | ||
| 27 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,16 +15,9 @@ | |||
| 15 | 15 | */ | |
| 16 | 16 | package org.patternfly.chart.donut; | |
| 17 | 17 | ||
| 18 | - import java.util.function.Function; | ||
| 19 | - | ||
| 20 | 18 | import org.patternfly.chart.BaseChart; | |
| 21 | - import org.patternfly.chart.ChartThemeColor; | ||
| 22 | 19 | import org.patternfly.chart.ChartType; | |
| 23 | 20 | import org.patternfly.chart.Data; | |
| 24 | - import org.patternfly.chart.LegendData; | ||
| 25 | - import org.patternfly.chart.LegendOrientation; | ||
| 26 | - import org.patternfly.chart.Padding; | ||
| 27 | - import org.patternfly.chart.SubTitlePosition; | ||
| 28 | 21 | import elemental2.core.JsArray; | |
| 29 | 22 | import jsinterop.base.Js; | |
| 30 | 23 | ||
@@ -41,7 +34,7 @@ public static Donut donut() { | |||
| 41 | 34 | // ------------------------------------------------------ instance | |
| 42 | 35 | ||
| 43 | 36 | Donut() { | |
| 44 | - super(ChartType.Donut, createHtmlElement("pfj-chart-donut", DonutElement.class)); | ||
| 37 | + super(ChartType.Donut, Js.uncheckedCast(createHtmlElement("pfj-chart-donut", DonutElement.class))); | ||
| 45 | 38 | } | |
| 46 | 39 | ||
| 47 | 40 | // ------------------------------------------------------ builder | |
@@ -54,92 +47,8 @@ public Donut data(Data data, Data... moreData) { | |||
| 54 | 47 | return this; | |
| 55 | 48 | } | |
| 56 | 49 | ||
| 57 | - public Donut height(int height) { | ||
| 58 | - element().setAttribute("height", height); | ||
| 59 | - return this; | ||
| 60 | - } | ||
| 61 | - | ||
| 62 | - public Donut labels(Function<Data, String> labels) { | ||
| 63 | - // There's a lot more in 'data', but we just want the 'datum' property | ||
| 64 | - element().labels = (data -> labels.apply(Js.cast(data.asPropertyMap().get("datum")))); | ||
| 65 | - return this; | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - public Donut legend(String legend, String... moreLegends) { | ||
| 69 | - JsArray<LegendData> array = new JsArray<>(); | ||
| 70 | - LegendData ld = new LegendData(); | ||
| 71 | - ld.name = legend; | ||
| 72 | - array.push(ld); | ||
| 73 | - if (moreLegends != null) { | ||
| 74 | - for (String more : moreLegends) { | ||
| 75 | - ld = new LegendData(); | ||
| 76 | - ld.name = more; | ||
| 77 | - array.push(ld); | ||
| 78 | - } | ||
| 79 | - } | ||
| 80 | - element().legendData = array; | ||
| 81 | - return this; | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - public Donut legendOrientation(LegendOrientation orientation) { | ||
| 85 | - element().setAttribute("legend-orientation", orientation.name().toLowerCase()); | ||
| 86 | - return this; | ||
| 87 | - } | ||
| 88 | - | ||
| 89 | - public Donut legendPosition(SubTitlePosition position) { | ||
| 90 | - element().setAttribute("legend-position", position.name().toLowerCase()); | ||
| 91 | - return this; | ||
| 92 | - } | ||
| 93 | - | ||
| 94 | - public Donut padding(int top, int right, int bottom, int left) { | ||
| 95 | - Padding padding = new Padding(); | ||
| 96 | - padding.top = top; | ||
| 97 | - padding.right = right; | ||
| 98 | - padding.bottom = bottom; | ||
| 99 | - padding.left = left; | ||
| 100 | - element().padding = padding; | ||
| 101 | - return this; | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | - public Donut subTitle(String subTitle) { | ||
| 105 | - element().setAttribute("sub-title", subTitle); | ||
| 106 | - return this; | ||
| 107 | - } | ||
| 108 | - | ||
| 109 | - public Donut subTitlePosition(SubTitlePosition position) { | ||
| 110 | - element().setAttribute("sub-title-position", position.name().toLowerCase()); | ||
| 111 | - return this; | ||
| 112 | - } | ||
| 113 | - | ||
| 114 | - public Donut themeColor(ChartThemeColor themeColor) { | ||
| 115 | - element().setAttribute("theme-color", themeColor.color); | ||
| 116 | - return this; | ||
| 117 | - } | ||
| 118 | - | ||
| 119 | - public Donut title(String title) { | ||
| 120 | - element().setAttribute("title", title); | ||
| 121 | - return this; | ||
| 122 | - } | ||
| 123 | - | ||
| 124 | - public Donut width(int width) { | ||
| 125 | - element().setAttribute("width", width); | ||
| 126 | - return this; | ||
| 127 | - } | ||
| 128 | - | ||
| 129 | 50 | @Override | |
| 130 | 51 | public Donut that() { | |
| 131 | 52 | return this; | |
| 132 | 53 | } | |
| 133 | - | ||
| 134 | - // ------------------------------------------------------ aria | ||
| 135 | - | ||
| 136 | - public Donut ariaTitle(String ariaTitle) { | ||
| 137 | - element().setAttribute("aria-title", ariaTitle); | ||
| 138 | - return this; | ||
| 139 | - } | ||
| 140 | - | ||
| 141 | - public Donut ariaDesc(String ariaDesc) { | ||
| 142 | - element().setAttribute("aria-desc", ariaDesc); | ||
| 143 | - return this; | ||
| 144 | - } | ||
| 145 | 54 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,19 +1,13 @@ | |||
| 1 | 1 | package org.patternfly.chart.donut; | |
| 2 | 2 | ||
| 3 | + import org.patternfly.chart.ChartElement; | ||
| 3 | 4 | import org.patternfly.chart.Data; | |
| 4 | - import org.patternfly.chart.LabelsFn; | ||
| 5 | - import org.patternfly.chart.LegendData; | ||
| 6 | - import org.patternfly.chart.Padding; | ||
| 7 | 5 | import elemental2.core.JsArray; | |
| 8 | - import elemental2.dom.HTMLElement; | ||
| 9 | 6 | import jsinterop.annotations.JsPackage; | |
| 10 | 7 | import jsinterop.annotations.JsType; | |
| 11 | 8 | ||
| 12 | 9 | @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "HTMLElement") | |
| 13 | - public class DonutElement extends HTMLElement { | ||
| 10 | + public class DonutElement extends ChartElement { | ||
| 14 | 11 | ||
| 15 | 12 | public JsArray<Data> data; | |
| 16 | - public LabelsFn labels; | ||
| 17 | - public JsArray<LegendData> legendData; | ||
| 18 | - public Padding padding; | ||
| 19 | 13 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments