ui/uichart
라인 차트.
Line chart.
UILineChartextends Component
라인 차트.
- 값 배열을 노드 영역에 폴리라인으로 그린다. pushValue 로 매 프레임 / 매 초 새 값을 밀어 넣으면 오래된 값이 밀려나는 실시간 그래프가 된다.
- 사용:
const lineChart = chartNode.addComponent(UILineChart);
lineChart.setMaxSampleCount(60);
매 초: lineChart.pushValue(newValue);Line chart.
- Draws a value array as a polyline in the node area. Pushing new values with pushValue every frame / every second makes it a real-time graph where old values are pushed out.
- Usage:
const lineChart = chartNode.addComponent(UILineChart);
lineChart.setMaxSampleCount(60);
every second: lineChart.pushValue(newValue);import { Engine, EngineConfiguration, UIScene, UILineChart, WorldNode, Color, Pivot, Vector2 } from "./build/vanilla.js";
class LineChartScene extends UIScene {
create() {
super.create();
const chartNode = new WorldNode();
chartNode.setPivot(Pivot.topLeft.clone());
chartNode.setAnchor(Pivot.topLeft.clone());
chartNode.setContentSize(Vector2.create(480, 160));
chartNode.setLocalPosition(Vector2.create(80, 100));
const lineChart = chartNode.addComponent(UILineChart);
lineChart.setMaxSampleCount(60);
lineChart.setValueRange(0, 100);
lineChart.setLineColor(new Color(0.3, 0.8, 1, 1));
lineChart.setLineWidth(2);
for (let sampleIndex = 0; sampleIndex < 80; ++sampleIndex) {
lineChart.pushValue(50 + Math.sin(sampleIndex * 0.3) * 30);
}
const valueList = lineChart.getValueList();
console.log(valueList.length);
const root = this.getRoot();
root.addChild(chartNode);
}
}
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new LineChartScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);값 하나 추가. (표본 수를 넘기면 앞에서 밀려난다)
Adds one value. (when the sample count is exceeded, values are pushed out from the front)
- valuenumber
- 새 표본 값. (맨 뒤에 붙는다)New sample value. (appended at the end)
짝Counterpart: vanilla-engine UILineChart.push_value
출력.
Draw.
- graphicGraphic
- 그릴 그래픽. (노드 로컬 좌표, 내용 영역 왼쪽 위가 원점)Graphic to draw with. (node local coordinates, origin at the top-left of the content area)
그리는 사각형을 rect 에 적기. (오버라이드: 격자는 내용 영역 안, 선은 값이 정한 범위 밖으로 나간 만큼 위아래로 넘친다)
- 가로는 표본이 내용 폭 안에 퍼지므로 내용 폭. 세로는 내용 높이와 가장 큰 값, 가장 작은 값이 놓이는 높이를 합친다.
- 선 두께만큼(이음새를 메우는 반두께 연장까지) 사방으로 넓혀 본다.
Writes the drawn rectangle to rect. (Override: the grid stays inside the content area, the line spills up or down as far as values leave the set range)
- Horizontally the content width, since samples spread within it. Vertically the union of the content height and the heights of the largest and smallest values.
- Grown on all sides by the line width (including the half-width extension that fills joints).
- rectRect
- 그리는 사각형을 적을 곳. (노드 내용 영역의 왼쪽 위가 원점)Where to write the drawn rectangle. (origin at the top-left of the node's content area)
반환Returnsboolean 노드에 붙어 있으면 참.True if attached to a node.
import { WorldNode, UILineChart, Rect, Vector2 } from "./build/vanilla.js";
const node = new WorldNode();
node.setContentSize(Vector2.create(160, 60));
const chart = node.addComponent(UILineChart);
chart.setValueRange(0, 1);
chart.setValueList([0.5, 2, 0.2]);
const drawnRect = Rect.zero();
chart.calculateDrawnRect(drawnRect);
console.log(drawnRect.position.y < 0);폴리라인 점 계산. (그리기와 같은 자리, 표본이 둘보다 적으면 빈 목록)
Computes the polyline points. (same positions as drawing, an empty list if fewer than two samples)
- widthnumber
- 그래프 너비. (픽셀, 표본 수 상한을 채웠을 때 마지막 점이 이 자리)Graph width. (pixels, where the last point lands when the sample count limit is reached)
- heightnumber
- 그래프 높이. (픽셀, 위아래 2 픽셀은 비운다)Graph height. (pixels, 2 pixels are left empty at the top and bottom)
반환ReturnsVector2[] 표본마다 점 하나. (왼쪽 위가 원점, 값이 클수록 위)One point per sample. (origin at the top left, larger values are higher)
짝Counterpart: vanilla-engine UILineChart.calculate_points
표본 수 상한 설정. (2 보다 작으면 2, 이미 든 표본이 새 상한보다 많으면 오래된 것부터 버린다)
Sets the maximum sample count. (Below 2 becomes 2, if more samples are held than the new limit the oldest are dropped)
- maxSampleCountnumber
- 표본 수 상한.Sample count limit.
짝Counterpart: vanilla-engine UILineChart.set_max_sample_count
import { UILineChart } from "./build/vanilla.js";
const lineChart = new UILineChart();
lineChart.setValueList([1, 2, 3, 4, 5]);
lineChart.setMaxSampleCount(3);
const valueList = lineChart.getValueList();
console.log(valueList.join(", "));표본 수 상한 반환.
Returns the sample count limit.
반환Returnsnumber 표본 수 상한. (2 이상)Sample count limit. (2 or more)
짝Counterpart: vanilla-engine UILineChart.get_max_sample_count
세로 값 범위 설정. (null 인 끝은 표본의 최소, 최대로 자동으로 맞춘다)
Sets the vertical value range. (an end that is null automatically fits the samples' minimum or maximum)
- minValuenumber | null
- 아래 끝 값. (null 이면 자동)Bottom end value. (automatic if null)
- maxValuenumber | null
- 위 끝 값. (null 이면 자동)Top end value. (automatic if null)
짝Counterpart: vanilla-engine UILineChart.set_value_range
import { UILineChart } from "./build/vanilla.js";
const lineChart = new UILineChart();
lineChart.setMaxSampleCount(3);
lineChart.setValueList([20, 40, 60]);
lineChart.setValueRange(0, 100);
const fixedPoints = lineChart.calculatePoints(200, 104);
console.log(fixedPoints[2].y);
lineChart.setValueRange(null, null);
const autoPoints = lineChart.calculatePoints(200, 104);
console.log(autoPoints[2].y);표본 목록 설정. (표본 수 상한보다 길면 뒤쪽만 남긴다)
Sets the sample list. (keeps only the tail if longer than the sample count limit)
- valueListnumber[]
- 표본 값 목록. (복사해 쥔다)Sample value list. (copied and kept)
짝Counterpart: vanilla-engine UILineChart.set_value_list
표본 목록 반환.
Returns the sample list.
반환Returnsnumber[] 표본 값 목록의 복사본. (오래된 것부터)Copy of the sample value list. (oldest first)
짝Counterpart: vanilla-engine UILineChart.get_value_list
선 색 설정.
Sets the line color.
- lineColorColor | string
- 선 색. (복제해 쥔다)Line color. (cloned and kept)
짝Counterpart: vanilla-engine UILineChart.set_line_color
격자 색 설정. (가로 격자선 3 개)
Sets the grid color. (3 horizontal grid lines)
- gridColorColor | string
- 격자 색. (복제해 쥔다)Grid color. (cloned and kept)
짝Counterpart: vanilla-engine UILineChart.set_grid_color
선 굵기 설정.
Sets the line thickness.
- lineWidthnumber
- 선 굵기. (픽셀)Line width. (pixels)
짝Counterpart: vanilla-engine UILineChart.set_line_width
UIBarChartextends Component
바 차트.
- 값 배열을 세로 막대로 그린다. 값이 바뀌면 다음 프레임에 그대로 반영된다.
Bar chart.
- Draws a value array as vertical bars. Value changes are reflected as is on the next frame.
import { Engine, EngineConfiguration, UIScene, UIBarChart, WorldNode, Color, Pivot, Vector2 } from "./build/vanilla.js";
class BarChartScene extends UIScene {
create() {
super.create();
const chartNode = new WorldNode();
chartNode.setPivot(Pivot.topLeft.clone());
chartNode.setAnchor(Pivot.topLeft.clone());
chartNode.setContentSize(Vector2.create(420, 160));
chartNode.setLocalPosition(Vector2.create(110, 100));
const barChart = chartNode.addComponent(UIBarChart);
barChart.setValueList([12, 30, 22, 48, 36, 54, 41]);
barChart.setMaxValue(60);
barChart.setBarGap(8);
barChart.setBarColor(new Color(0.42, 0.48, 1, 0.6));
barChart.setHighlightColor(new Color(0.22, 0.84, 1, 1));
barChart.setHighlightIndex(5);
const root = this.getRoot();
root.addChild(chartNode);
}
}
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new BarChartScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);출력.
Draw.
- graphicGraphic
- 그릴 그래픽. (노드 로컬 좌표, 내용 영역 왼쪽 위가 원점)Graphic to draw with. (node local coordinates, origin at the top-left of the content area)
그리는 사각형을 rect 에 적기. (오버라이드: 막대는 내용 영역 안, 막대 사이가 너무 넓어 막대 폭이 음수가 되면 그만큼 옆으로 넘친다)
- 세로는 막대가 가장 낮아도 한 단위 높이로 그리므로 내용 높이가 한 단위보다 작으면 위로 넘친다. 한 단위씩 넓혀 본다.
Writes the drawn rectangle to rect. (Override: bars stay inside the content area; if the gaps are so wide that the bar width turns negative, it spills sideways by that much)
- Vertically, the lowest bar is still drawn one unit tall, so it spills upward when the content height is under one unit. Grown by one unit.
- rectRect
- 그리는 사각형을 적을 곳. (노드 내용 영역의 왼쪽 위가 원점)Where to write the drawn rectangle. (origin at the top-left of the node's content area)
반환Returnsboolean 노드에 붙어 있으면 참.True if attached to a node.
import { WorldNode, UIBarChart, Rect, Vector2 } from "./build/vanilla.js";
const node = new WorldNode();
node.setContentSize(Vector2.create(120, 40));
const chart = node.addComponent(UIBarChart);
chart.setValueList([3, 5, 2]);
const drawnRect = Rect.zero();
chart.calculateDrawnRect(drawnRect);
console.log(drawnRect.size.x, drawnRect.size.y);막대 사각형 목록 계산. (그리기와 같은 자리)
Computes the bar rectangle list. (same positions as drawing)
- widthnumber
- 그래프 너비. (픽셀, 막대 사이 간격을 뺀 나머지를 막대 수로 나눈다)Graph width. (pixels, the remainder after the gaps between bars is divided by the bar count)
- heightnumber
- 그래프 높이. (픽셀, 최대 값이 이 높이)Graph height. (pixels, the maximum value reaches this height)
반환ReturnsRect[] 막대마다 사각형 하나. (바닥에 붙고, 값이 0 이하여도 높이 1 픽셀)One rectangle per bar. (sits on the bottom, 1 pixel tall even if the value is 0 or less)
짝Counterpart: vanilla-engine UIBarChart.calculate_bar_rects
막대 값 목록 설정.
Sets the bar value list.
- valueListnumber[]
- 막대 값 목록. (복사해 쥔다)Bar value list. (copied and kept)
짝Counterpart: vanilla-engine UIBarChart.set_value_list
막대 값 목록 반환.
Returns the bar value list.
반환Returnsnumber[] 막대 값 목록의 복사본.Copy of the bar value list.
짝Counterpart: vanilla-engine UIBarChart.get_value_list
최대 값 설정. (막대가 높이를 다 채우는 값, 넘는 값은 잘린다)
Sets the maximum value. (the value at which a bar fills the full height, larger values are clipped)
- maxValuenumber | null
- 최대 값. (null 이면 값 목록의 최대)Maximum value. (the largest value in the list if null)
짝Counterpart: vanilla-engine UIBarChart.set_max_value
막대 색 설정.
Sets the bar color.
- barColorColor | string
- 막대 색. (복제해 쥔다)Bar color. (cloned and kept)
짝Counterpart: vanilla-engine UIBarChart.set_bar_color
강조 막대 색 설정.
Sets the highlighted bar color.
- highlightColorColor | string
- 강조 막대 색. (복제해 쥔다)Highlighted bar color. (cloned and kept)
짝Counterpart: vanilla-engine UIBarChart.set_highlight_color
강조할 막대 순서 설정.
Sets the index of the bar to highlight.
- highlightIndexnumber
- -1 이면 강조 없음.-1 means no highlight.
짝Counterpart: vanilla-engine UIBarChart.set_highlight_index
막대 사이 간격 설정.
Sets the gap between bars.
- barGapnumber
- 막대 사이 간격. (픽셀)Gap between bars. (pixels)
짝Counterpart: vanilla-engine UIBarChart.set_bar_gap